Fixed ShlinkApiClient test

This commit is contained in:
Alejandro Celaya 2022-11-15 12:19:21 +01:00
parent f7ba974d97
commit 790c69ba80

View file

@ -4,6 +4,7 @@ import { OptionalString } from '../../../src/utils/utils';
import { ShlinkDomain, ShlinkVisits, ShlinkVisitsOverview } from '../../../src/api/types'; import { ShlinkDomain, ShlinkVisits, ShlinkVisitsOverview } from '../../../src/api/types';
import { ShortUrl, ShortUrlsOrder } from '../../../src/short-urls/data'; import { ShortUrl, ShortUrlsOrder } from '../../../src/short-urls/data';
import { JsonFetch } from '../../../src/utils/types'; import { JsonFetch } from '../../../src/utils/types';
import { ErrorTypeV2, ErrorTypeV3 } from '../../../src/api/types/errors';
describe('ShlinkApiClient', () => { describe('ShlinkApiClient', () => {
const buildFetch = (data: any) => jest.fn().mockResolvedValue(data); const buildFetch = (data: any) => jest.fn().mockResolvedValue(data);
@ -318,8 +319,14 @@ describe('ShlinkApiClient', () => {
expect(result).toEqual(resp); expect(result).toEqual(resp);
}); });
it('retries request if API version is not supported', async () => { it.each([
const fetch = buildRejectedFetch({ type: 'NOT_FOUND', status: 404 }).mockImplementation(buildFetch({})); ['NOT_FOUND'],
[ErrorTypeV2.NOT_FOUND],
[ErrorTypeV3.NOT_FOUND],
])('retries request if API version is not supported', async (type) => {
const fetch = buildRejectedFetch({ type, detail: 'detail', title: 'title', status: 404 }).mockImplementation(
buildFetch({}),
);
const { editDomainRedirects } = buildApiClient(fetch); const { editDomainRedirects } = buildApiClient(fetch);
await editDomainRedirects({ domain: 'foo' }); await editDomainRedirects({ domain: 'foo' });