mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-14 11:33:51 +00:00
Fixed tests
This commit is contained in:
@@ -64,7 +64,7 @@ describe('ShlinkApiClient', () => {
|
|||||||
const lastAxiosCall = last(axiosSpy.getCalls());
|
const lastAxiosCall = last(axiosSpy.getCalls());
|
||||||
const axiosArgs = head(lastAxiosCall.args);
|
const axiosArgs = head(lastAxiosCall.args);
|
||||||
|
|
||||||
expect(expectedVisits).toEqual(actualVisits);
|
expect({ data: expectedVisits }).toEqual(actualVisits);
|
||||||
expect(axiosArgs.url).toContain('/short-urls/abc123/visits');
|
expect(axiosArgs.url).toContain('/short-urls/abc123/visits');
|
||||||
expect(axiosArgs.method).toEqual('GET');
|
expect(axiosArgs.method).toEqual('GET');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ describe('shortUrlVisitsReducer', () => {
|
|||||||
|
|
||||||
describe('getShortUrlVisits', () => {
|
describe('getShortUrlVisits', () => {
|
||||||
const buildApiClientMock = (returned) => ({
|
const buildApiClientMock = (returned) => ({
|
||||||
getShortUrlVisits: sinon.fake.returns(returned),
|
getShortUrlVisits: typeof returned === 'function' ? sinon.fake(returned) : sinon.fake.returns(returned),
|
||||||
});
|
});
|
||||||
const dispatchMock = sinon.spy();
|
const dispatchMock = sinon.spy();
|
||||||
const getState = () => ({});
|
const getState = () => ({});
|
||||||
@@ -74,7 +74,13 @@ describe('shortUrlVisitsReducer', () => {
|
|||||||
|
|
||||||
it('dispatches start and success when promise is resolved', async () => {
|
it('dispatches start and success when promise is resolved', async () => {
|
||||||
const resolvedVisits = [{}, {}];
|
const resolvedVisits = [{}, {}];
|
||||||
const ShlinkApiClient = buildApiClientMock(Promise.resolve(resolvedVisits));
|
const ShlinkApiClient = buildApiClientMock(Promise.resolve({
|
||||||
|
data: resolvedVisits,
|
||||||
|
pagination: {
|
||||||
|
currentPage: 1,
|
||||||
|
pagesCount: 1,
|
||||||
|
},
|
||||||
|
}));
|
||||||
const expectedDispatchCalls = 2;
|
const expectedDispatchCalls = 2;
|
||||||
|
|
||||||
await getShortUrlVisits(() => ShlinkApiClient)('abc123')(dispatchMock, getState);
|
await getShortUrlVisits(() => ShlinkApiClient)('abc123')(dispatchMock, getState);
|
||||||
@@ -91,5 +97,25 @@ describe('shortUrlVisitsReducer', () => {
|
|||||||
expect(secondCallType).toEqual(GET_SHORT_URL_VISITS);
|
expect(secondCallType).toEqual(GET_SHORT_URL_VISITS);
|
||||||
expect(visits).toEqual(resolvedVisits);
|
expect(visits).toEqual(resolvedVisits);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('performs two API requests when response contains more pages', async () => {
|
||||||
|
const expectedRequests = 3;
|
||||||
|
const ShlinkApiClient = buildApiClientMock((shortCode, { page }) =>
|
||||||
|
Promise.resolve({
|
||||||
|
data: [{}, {}],
|
||||||
|
pagination: {
|
||||||
|
currentPage: page,
|
||||||
|
pagesCount: expectedRequests,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
await getShortUrlVisits(() => ShlinkApiClient)('abc123')(dispatchMock, getState);
|
||||||
|
|
||||||
|
const [ secondCallArg ] = dispatchMock.getCall(1).args;
|
||||||
|
const { visits } = secondCallArg;
|
||||||
|
|
||||||
|
expect(ShlinkApiClient.getShortUrlVisits.callCount).toEqual(expectedRequests);
|
||||||
|
expect(visits).toEqual([{}, {}, {}, {}, {}, {}]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user