Replace local ShlinkApiClient with the one from shlink-js-sdk

This commit is contained in:
Alejandro Celaya
2023-08-29 23:12:25 +02:00
parent ccfedc20e9
commit 9f7ac09fb0
14 changed files with 62 additions and 745 deletions

View File

@@ -1,12 +1,12 @@
import type { HttpClient } from '@shlinkio/shlink-js-sdk';
import { fromPartial } from '@total-typescript/shoehorn';
import type { HttpClient } from '../../../src/common/services/HttpClient';
import { fetchServers } from '../../../src/servers/reducers/remoteServers';
describe('remoteServersReducer', () => {
describe('fetchServers', () => {
const dispatch = vi.fn();
const fetchJson = vi.fn();
const httpClient = fromPartial<HttpClient>({ fetchJson });
const jsonRequest = vi.fn();
const httpClient = fromPartial<HttpClient>({ jsonRequest });
it.each([
[
@@ -76,7 +76,7 @@ describe('remoteServersReducer', () => {
['<html></html>', {}],
[{}, {}],
])('tries to fetch servers from remote', async (mockedValue, expectedNewServers) => {
fetchJson.mockResolvedValue(mockedValue);
jsonRequest.mockResolvedValue(mockedValue);
const doFetchServers = fetchServers(httpClient);
await doFetchServers()(dispatch, vi.fn(), {});
@@ -84,7 +84,7 @@ describe('remoteServersReducer', () => {
expect(dispatch).toHaveBeenCalledTimes(3);
expect(dispatch).toHaveBeenNthCalledWith(2, expect.objectContaining({ payload: expectedNewServers }));
expect(dispatch).toHaveBeenNthCalledWith(3, expect.objectContaining({ payload: undefined }));
expect(fetchJson).toHaveBeenCalledTimes(1);
expect(jsonRequest).toHaveBeenCalledTimes(1);
});
});
});

View File

@@ -1,6 +1,6 @@
import type { ShlinkApiClient } from '@shlinkio/shlink-js-sdk';
import { fromPartial } from '@total-typescript/shoehorn';
import { v4 as uuid } from 'uuid';
import type { ShlinkApiClient } from '../../../src/api/services/ShlinkApiClient';
import type { ShlinkState } from '../../../src/container/types';
import type { NonReachableServer, NotFoundServer, RegularServer } from '../../../src/servers/data';
import {