mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-16 12:33:48 +00:00
Updated tests from modified code
This commit is contained in:
@@ -51,7 +51,7 @@ export default class ShlinkApiClient {
|
|||||||
|
|
||||||
updateShortUrlMeta = (shortCode, meta) =>
|
updateShortUrlMeta = (shortCode, meta) =>
|
||||||
this._performRequest(`/short-urls/${shortCode}`, 'PATCH', {}, meta)
|
this._performRequest(`/short-urls/${shortCode}`, 'PATCH', {}, meta)
|
||||||
.then(() => ({ meta }));
|
.then(() => meta);
|
||||||
|
|
||||||
listTags = () =>
|
listTags = () =>
|
||||||
this._performRequest('/tags', 'GET')
|
this._performRequest('/tags', 'GET')
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import reducer, {
|
|||||||
} from '../../../src/short-urls/reducers/shortUrlsList';
|
} from '../../../src/short-urls/reducers/shortUrlsList';
|
||||||
import { SHORT_URL_TAGS_EDITED } from '../../../src/short-urls/reducers/shortUrlTags';
|
import { SHORT_URL_TAGS_EDITED } from '../../../src/short-urls/reducers/shortUrlTags';
|
||||||
import { SHORT_URL_DELETED } from '../../../src/short-urls/reducers/shortUrlDeletion';
|
import { SHORT_URL_DELETED } from '../../../src/short-urls/reducers/shortUrlDeletion';
|
||||||
|
import { SHORT_URL_META_EDITED } from '../../../src/short-urls/reducers/shortUrlMeta';
|
||||||
|
|
||||||
describe('shortUrlsListReducer', () => {
|
describe('shortUrlsListReducer', () => {
|
||||||
describe('reducer', () => {
|
describe('reducer', () => {
|
||||||
@@ -52,6 +53,31 @@ describe('shortUrlsListReducer', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Updates meta on matching URL on SHORT_URL_META_EDITED', () => {
|
||||||
|
const shortCode = 'abc123';
|
||||||
|
const meta = {
|
||||||
|
maxVisits: 5,
|
||||||
|
validSince: '2020-05-05',
|
||||||
|
};
|
||||||
|
const state = {
|
||||||
|
shortUrls: {
|
||||||
|
data: [
|
||||||
|
{ shortCode, meta: { maxVisits: 10 } },
|
||||||
|
{ shortCode: 'foo', meta: null },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(reducer(state, { type: SHORT_URL_META_EDITED, shortCode, meta })).toEqual({
|
||||||
|
shortUrls: {
|
||||||
|
data: [
|
||||||
|
{ shortCode, meta },
|
||||||
|
{ shortCode: 'foo', meta: null },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Removes matching URL on SHORT_URL_DELETED', () => {
|
it('Removes matching URL on SHORT_URL_DELETED', () => {
|
||||||
const shortCode = 'abc123';
|
const shortCode = 'abc123';
|
||||||
const state = {
|
const state = {
|
||||||
|
|||||||
@@ -102,6 +102,25 @@ describe('ShlinkApiClient', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('updateShortUrlMeta', () => {
|
||||||
|
it('properly updates short URL meta', async () => {
|
||||||
|
const expectedMeta = {
|
||||||
|
maxVisits: 50,
|
||||||
|
validSince: '2025-01-01T10:00:00+01:00',
|
||||||
|
};
|
||||||
|
const axiosSpy = jest.fn(createAxiosMock());
|
||||||
|
const { updateShortUrlMeta } = new ShlinkApiClient(axiosSpy);
|
||||||
|
|
||||||
|
const result = await updateShortUrlMeta('abc123', expectedMeta);
|
||||||
|
|
||||||
|
expect(expectedMeta).toEqual(result);
|
||||||
|
expect(axiosSpy).toHaveBeenCalledWith(expect.objectContaining({
|
||||||
|
url: '/short-urls/abc123',
|
||||||
|
method: 'PATCH',
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('listTags', () => {
|
describe('listTags', () => {
|
||||||
it('properly returns list of tags', async () => {
|
it('properly returns list of tags', async () => {
|
||||||
const expectedTags = [ 'foo', 'bar' ];
|
const expectedTags = [ 'foo', 'bar' ];
|
||||||
|
|||||||
Reference in New Issue
Block a user