mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-09 01:37:24 +03:00
Fixed tests
This commit is contained in:
parent
0c1f533747
commit
dee5994b1e
2 changed files with 29 additions and 3 deletions
|
@ -64,7 +64,7 @@ describe('ShlinkApiClient', () => {
|
|||
const lastAxiosCall = last(axiosSpy.getCalls());
|
||||
const axiosArgs = head(lastAxiosCall.args);
|
||||
|
||||
expect(expectedVisits).toEqual(actualVisits);
|
||||
expect({ data: expectedVisits }).toEqual(actualVisits);
|
||||
expect(axiosArgs.url).toContain('/short-urls/abc123/visits');
|
||||
expect(axiosArgs.method).toEqual('GET');
|
||||
});
|
||||
|
|
|
@ -47,7 +47,7 @@ describe('shortUrlVisitsReducer', () => {
|
|||
|
||||
describe('getShortUrlVisits', () => {
|
||||
const buildApiClientMock = (returned) => ({
|
||||
getShortUrlVisits: sinon.fake.returns(returned),
|
||||
getShortUrlVisits: typeof returned === 'function' ? sinon.fake(returned) : sinon.fake.returns(returned),
|
||||
});
|
||||
const dispatchMock = sinon.spy();
|
||||
const getState = () => ({});
|
||||
|
@ -74,7 +74,13 @@ describe('shortUrlVisitsReducer', () => {
|
|||
|
||||
it('dispatches start and success when promise is resolved', async () => {
|
||||
const resolvedVisits = [{}, {}];
|
||||
const ShlinkApiClient = buildApiClientMock(Promise.resolve(resolvedVisits));
|
||||
const ShlinkApiClient = buildApiClientMock(Promise.resolve({
|
||||
data: resolvedVisits,
|
||||
pagination: {
|
||||
currentPage: 1,
|
||||
pagesCount: 1,
|
||||
},
|
||||
}));
|
||||
const expectedDispatchCalls = 2;
|
||||
|
||||
await getShortUrlVisits(() => ShlinkApiClient)('abc123')(dispatchMock, getState);
|
||||
|
@ -91,5 +97,25 @@ describe('shortUrlVisitsReducer', () => {
|
|||
expect(secondCallType).toEqual(GET_SHORT_URL_VISITS);
|
||||
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([{}, {}, {}, {}, {}, {}]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue