mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-04-19 21:16:18 +00:00
Updates ShlinkApiClint to use different methods to fetch, and fixed tests
This commit is contained in:
@@ -8,7 +8,8 @@ import { HttpClient } from '../../../src/common/services/HttpClient';
|
||||
|
||||
describe('ShlinkApiClient', () => {
|
||||
const fetchJson = jest.fn().mockResolvedValue({});
|
||||
const httpClient = Mock.of<HttpClient>({ fetchJson });
|
||||
const fetchEmpty = jest.fn().mockResolvedValue(undefined);
|
||||
const httpClient = Mock.of<HttpClient>({ fetchJson, fetchEmpty });
|
||||
const buildApiClient = () => new ShlinkApiClient(httpClient, '', '');
|
||||
const shortCodesWithDomainCombinations: [string, OptionalString][] = [
|
||||
['abc123', null],
|
||||
@@ -196,7 +197,7 @@ describe('ShlinkApiClient', () => {
|
||||
|
||||
await deleteTags(tags);
|
||||
|
||||
expect(fetchJson).toHaveBeenCalledWith(
|
||||
expect(fetchEmpty).toHaveBeenCalledWith(
|
||||
expect.stringContaining(`/tags?${tags.map((tag) => `tags%5B%5D=${tag}`).join('&')}`),
|
||||
expect.objectContaining({ method: 'DELETE' }),
|
||||
);
|
||||
@@ -211,7 +212,7 @@ describe('ShlinkApiClient', () => {
|
||||
|
||||
await editTag(oldName, newName);
|
||||
|
||||
expect(fetchJson).toHaveBeenCalledWith(expect.stringContaining('/tags'), expect.objectContaining({
|
||||
expect(fetchEmpty).toHaveBeenCalledWith(expect.stringContaining('/tags'), expect.objectContaining({
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({ oldName, newName }),
|
||||
}));
|
||||
@@ -225,7 +226,7 @@ describe('ShlinkApiClient', () => {
|
||||
|
||||
await deleteShortUrl(shortCode, domain);
|
||||
|
||||
expect(fetchJson).toHaveBeenCalledWith(
|
||||
expect(fetchEmpty).toHaveBeenCalledWith(
|
||||
expect.stringContaining(`/short-urls/${shortCode}${expectedQuery}`),
|
||||
expect.objectContaining({ method: 'DELETE' }),
|
||||
);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Mock } from 'ts-mockery';
|
||||
import { tagEdited, EditTagAction, tagEditReducerCreator } from '../../../src/tags/reducers/tagEdit';
|
||||
import { tagEdited, editTag as editTagCreator, EditTagAction, tagEditReducerCreator } from '../../../src/tags/reducers/tagEdit';
|
||||
import { ShlinkApiClient } from '../../../src/api/services/ShlinkApiClient';
|
||||
import { ColorGenerator } from '../../../src/utils/services/ColorGenerator';
|
||||
import { ShlinkState } from '../../../src/container/types';
|
||||
@@ -11,7 +11,8 @@ describe('tagEditReducer', () => {
|
||||
const editTagCall = jest.fn();
|
||||
const buildShlinkApiClient = () => Mock.of<ShlinkApiClient>({ editTag: editTagCall });
|
||||
const colorGenerator = Mock.of<ColorGenerator>({ setColorForKey: jest.fn() });
|
||||
const { reducer, editTag } = tagEditReducerCreator(buildShlinkApiClient, colorGenerator);
|
||||
const editTag = editTagCreator(buildShlinkApiClient, colorGenerator);
|
||||
const { reducer } = tagEditReducerCreator(editTag);
|
||||
|
||||
describe('reducer', () => {
|
||||
it('returns loading on EDIT_TAG_START', () => {
|
||||
|
||||
@@ -70,14 +70,30 @@ describe('tagsListReducer', () => {
|
||||
const expectedTags = ['foo', 'renamed', 'baz'].sort();
|
||||
|
||||
expect(reducer(
|
||||
state({ tags, filteredTags: tags }),
|
||||
{
|
||||
type: tagEdited.toString(),
|
||||
payload: { oldName, newName },
|
||||
},
|
||||
state({
|
||||
tags,
|
||||
filteredTags: tags,
|
||||
stats: {
|
||||
[oldName]: {
|
||||
shortUrlsCount: 35,
|
||||
visitsCount: 35,
|
||||
},
|
||||
},
|
||||
}),
|
||||
{ type: tagEdited.toString(), payload: { oldName, newName } },
|
||||
)).toEqual({
|
||||
tags: expectedTags,
|
||||
filteredTags: expectedTags,
|
||||
stats: {
|
||||
[oldName]: {
|
||||
shortUrlsCount: 35,
|
||||
visitsCount: 35,
|
||||
},
|
||||
[newName]: {
|
||||
shortUrlsCount: 35,
|
||||
visitsCount: 35,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user