mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-02-27 12:16:36 +00:00
Ensured domain is passed when loading visits for a short URL on a specific domain
This commit is contained in:
@@ -7,8 +7,8 @@ import ShortUrlVisitsCount from '../../../src/short-urls/helpers/ShortUrlVisitsC
|
||||
describe('<ShortUrlVisitsCount />', () => {
|
||||
let wrapper;
|
||||
|
||||
const createWrapper = (visitsCount, meta) => {
|
||||
wrapper = shallow(<ShortUrlVisitsCount visitsCount={visitsCount} meta={meta} />);
|
||||
const createWrapper = (visitsCount, shortUrl) => {
|
||||
wrapper = shallow(<ShortUrlVisitsCount visitsCount={visitsCount} shortUrl={shortUrl} />);
|
||||
|
||||
return wrapper;
|
||||
};
|
||||
@@ -17,11 +17,11 @@ describe('<ShortUrlVisitsCount />', () => {
|
||||
|
||||
each([ undefined, {}]).it('just returns visits when no maxVisits is provided', (meta) => {
|
||||
const visitsCount = 45;
|
||||
const wrapper = createWrapper(visitsCount, meta);
|
||||
const wrapper = createWrapper(visitsCount, { meta });
|
||||
const maxVisitsHelper = wrapper.find('.short-urls-visits-count__max-visits-control');
|
||||
const maxVisitsTooltip = wrapper.find(UncontrolledTooltip);
|
||||
|
||||
expect(wrapper.html()).toEqual(`<span>${visitsCount}</span>`);
|
||||
expect(wrapper.html()).toEqual(`<span><strong>${visitsCount}</strong></span>`);
|
||||
expect(maxVisitsHelper).toHaveLength(0);
|
||||
expect(maxVisitsTooltip).toHaveLength(0);
|
||||
});
|
||||
@@ -30,7 +30,7 @@ describe('<ShortUrlVisitsCount />', () => {
|
||||
const visitsCount = 45;
|
||||
const maxVisits = 500;
|
||||
const meta = { maxVisits };
|
||||
const wrapper = createWrapper(visitsCount, meta);
|
||||
const wrapper = createWrapper(visitsCount, { meta });
|
||||
const maxVisitsHelper = wrapper.find('.short-urls-visits-count__max-visits-control');
|
||||
const maxVisitsTooltip = wrapper.find(UncontrolledTooltip);
|
||||
|
||||
|
||||
@@ -83,4 +83,6 @@ describe('<ShortUrlsRowMenu />', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('generates expected visits page link', () => {})
|
||||
});
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
import each from 'jest-each';
|
||||
import ShlinkApiClient from '../../../src/utils/services/ShlinkApiClient';
|
||||
|
||||
describe('ShlinkApiClient', () => {
|
||||
const createAxiosMock = (data) => () => Promise.resolve(data);
|
||||
const createApiClient = (data) => new ShlinkApiClient(createAxiosMock(data));
|
||||
const shortCodesWithDomainCombinations = [
|
||||
[ 'abc123', null ],
|
||||
[ 'abc123', undefined ],
|
||||
[ 'abc123', 'example.com' ],
|
||||
];
|
||||
|
||||
describe('listShortUrls', () => {
|
||||
it('properly returns short URLs list', async () => {
|
||||
@@ -67,43 +73,45 @@ describe('ShlinkApiClient', () => {
|
||||
});
|
||||
|
||||
describe('getShortUrl', () => {
|
||||
it('properly returns short URL', async () => {
|
||||
each(shortCodesWithDomainCombinations).it('properly returns short URL', async (shortCode, domain) => {
|
||||
const expectedShortUrl = { foo: 'bar' };
|
||||
const axiosSpy = jest.fn(createAxiosMock({
|
||||
data: expectedShortUrl,
|
||||
}));
|
||||
const { getShortUrl } = new ShlinkApiClient(axiosSpy);
|
||||
|
||||
const result = await getShortUrl('abc123');
|
||||
const result = await getShortUrl(shortCode, domain);
|
||||
|
||||
expect(expectedShortUrl).toEqual(result);
|
||||
expect(axiosSpy).toHaveBeenCalledWith(expect.objectContaining({
|
||||
url: '/short-urls/abc123',
|
||||
url: `/short-urls/${shortCode}`,
|
||||
method: 'GET',
|
||||
params: domain ? { domain } : {},
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('updateShortUrlTags', () => {
|
||||
it('properly updates short URL tags', async () => {
|
||||
each(shortCodesWithDomainCombinations).it('properly updates short URL tags', async (shortCode, domain) => {
|
||||
const expectedTags = [ 'foo', 'bar' ];
|
||||
const axiosSpy = jest.fn(createAxiosMock({
|
||||
data: { tags: expectedTags },
|
||||
}));
|
||||
const { updateShortUrlTags } = new ShlinkApiClient(axiosSpy);
|
||||
|
||||
const result = await updateShortUrlTags('abc123', expectedTags);
|
||||
const result = await updateShortUrlTags(shortCode, domain, expectedTags);
|
||||
|
||||
expect(expectedTags).toEqual(result);
|
||||
expect(axiosSpy).toHaveBeenCalledWith(expect.objectContaining({
|
||||
url: '/short-urls/abc123/tags',
|
||||
url: `/short-urls/${shortCode}/tags`,
|
||||
method: 'PUT',
|
||||
params: domain ? { domain } : {},
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('updateShortUrlMeta', () => {
|
||||
it('properly updates short URL meta', async () => {
|
||||
each(shortCodesWithDomainCombinations).it('properly updates short URL meta', async (shortCode, domain) => {
|
||||
const expectedMeta = {
|
||||
maxVisits: 50,
|
||||
validSince: '2025-01-01T10:00:00+01:00',
|
||||
@@ -111,12 +119,13 @@ describe('ShlinkApiClient', () => {
|
||||
const axiosSpy = jest.fn(createAxiosMock());
|
||||
const { updateShortUrlMeta } = new ShlinkApiClient(axiosSpy);
|
||||
|
||||
const result = await updateShortUrlMeta('abc123', expectedMeta);
|
||||
const result = await updateShortUrlMeta(shortCode, domain, expectedMeta);
|
||||
|
||||
expect(expectedMeta).toEqual(result);
|
||||
expect(axiosSpy).toHaveBeenCalledWith(expect.objectContaining({
|
||||
url: '/short-urls/abc123',
|
||||
url: `/short-urls/${shortCode}`,
|
||||
method: 'PATCH',
|
||||
params: domain ? { domain } : {},
|
||||
}));
|
||||
});
|
||||
});
|
||||
@@ -172,15 +181,16 @@ describe('ShlinkApiClient', () => {
|
||||
});
|
||||
|
||||
describe('deleteShortUrl', () => {
|
||||
it('properly deletes provided short URL', async () => {
|
||||
each(shortCodesWithDomainCombinations).it('properly deletes provided short URL', async (shortCode, domain) => {
|
||||
const axiosSpy = jest.fn(createAxiosMock({}));
|
||||
const { deleteShortUrl } = new ShlinkApiClient(axiosSpy);
|
||||
|
||||
await deleteShortUrl('abc123');
|
||||
await deleteShortUrl(shortCode, domain);
|
||||
|
||||
expect(axiosSpy).toHaveBeenCalledWith(expect.objectContaining({
|
||||
url: '/short-urls/abc123',
|
||||
url: `/short-urls/${shortCode}`,
|
||||
method: 'DELETE',
|
||||
params: domain ? { domain } : {},
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,15 +17,17 @@ describe('<ShortUrlVisits />', () => {
|
||||
const match = {
|
||||
params: { shortCode: 'abc123' },
|
||||
};
|
||||
const location = { search: '' };
|
||||
|
||||
const createComponent = (shortUrlVisits) => {
|
||||
const ShortUrlVisits = createShortUrlVisits({ processStatsFromVisits });
|
||||
const ShortUrlVisits = createShortUrlVisits({ processStatsFromVisits }, () => '');
|
||||
|
||||
wrapper = shallow(
|
||||
<ShortUrlVisits
|
||||
getShortUrlDetail={identity}
|
||||
getShortUrlVisits={getShortUrlVisitsMock}
|
||||
match={match}
|
||||
location={location}
|
||||
shortUrlVisits={shortUrlVisits}
|
||||
shortUrlDetail={{}}
|
||||
cancelGetShortUrlVisits={identity}
|
||||
|
||||
@@ -26,7 +26,7 @@ describe('<VisitsHeader />', () => {
|
||||
it('shows the amount of visits', () => {
|
||||
const visitsBadge = wrapper.find('.badge');
|
||||
|
||||
expect(visitsBadge.html()).toContain(`Visits: <span>${shortUrlVisits.visits.length}</span>`);
|
||||
expect(visitsBadge.html()).toContain(`Visits: <span><strong>${shortUrlVisits.visits.length}</strong></span>`);
|
||||
});
|
||||
|
||||
it('shows when the URL was created', () => {
|
||||
|
||||
Reference in New Issue
Block a user