mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-04-19 04:56:17 +00:00
Migrated ImageDownloader from axios to fetch
This commit is contained in:
@@ -3,12 +3,12 @@ import { ShlinkApiClient } from '../../../src/api/services/ShlinkApiClient';
|
||||
import { OptionalString } from '../../../src/utils/utils';
|
||||
import { ShlinkDomain, ShlinkVisits, ShlinkVisitsOverview } from '../../../src/api/types';
|
||||
import { ShortUrl, ShortUrlsOrder } from '../../../src/short-urls/data';
|
||||
import { Fetch } from '../../../src/utils/types';
|
||||
import { JsonFetch } from '../../../src/utils/types';
|
||||
|
||||
describe('ShlinkApiClient', () => {
|
||||
const buildFetch = (data: any) => jest.fn().mockResolvedValue(data);
|
||||
const buildRejectedFetch = (error: any) => jest.fn().mockRejectedValueOnce(error);
|
||||
const buildApiClient = (fetch: Fetch) => new ShlinkApiClient(fetch, '', '');
|
||||
const buildApiClient = (fetch: JsonFetch) => new ShlinkApiClient(fetch, '', '');
|
||||
const shortCodesWithDomainCombinations: [string, OptionalString][] = [
|
||||
['abc123', null],
|
||||
['abc123', undefined],
|
||||
|
||||
@@ -1,25 +1,22 @@
|
||||
import { Mock } from 'ts-mockery';
|
||||
import { AxiosInstance } from 'axios';
|
||||
import { ImageDownloader } from '../../../src/common/services/ImageDownloader';
|
||||
import { windowMock } from '../../__mocks__/Window.mock';
|
||||
|
||||
describe('ImageDownloader', () => {
|
||||
const get = jest.fn();
|
||||
const axios = Mock.of<AxiosInstance>({ get });
|
||||
const fetch = jest.fn();
|
||||
let imageDownloader: ImageDownloader;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
(global as any).URL = { createObjectURL: () => '' };
|
||||
|
||||
imageDownloader = new ImageDownloader(axios, windowMock);
|
||||
imageDownloader = new ImageDownloader(fetch, windowMock);
|
||||
});
|
||||
|
||||
it('calls URL with response type blob', async () => {
|
||||
get.mockResolvedValue({ data: {} });
|
||||
fetch.mockResolvedValue({ blob: () => new Blob() });
|
||||
|
||||
await imageDownloader.saveImage('/foo/bar.png', 'my-image.png');
|
||||
|
||||
expect(get).toHaveBeenCalledWith('/foo/bar.png', { responseType: 'blob' });
|
||||
expect(fetch).toHaveBeenCalledWith('/foo/bar.png');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user