From 207a8cef206f7cb1752e4afc1d41f49756b698ac Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 19 Jan 2020 13:20:46 +0100 Subject: [PATCH] Updated tests from modified code --- src/utils/services/ShlinkApiClient.js | 2 +- .../short-urls/reducers/shortUrlsList.test.js | 26 +++++++++++++++++++ test/utils/services/ShlinkApiClient.test.js | 19 ++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/utils/services/ShlinkApiClient.js b/src/utils/services/ShlinkApiClient.js index 1d9190f7..fe9ce69a 100644 --- a/src/utils/services/ShlinkApiClient.js +++ b/src/utils/services/ShlinkApiClient.js @@ -51,7 +51,7 @@ export default class ShlinkApiClient { updateShortUrlMeta = (shortCode, meta) => this._performRequest(`/short-urls/${shortCode}`, 'PATCH', {}, meta) - .then(() => ({ meta })); + .then(() => meta); listTags = () => this._performRequest('/tags', 'GET') diff --git a/test/short-urls/reducers/shortUrlsList.test.js b/test/short-urls/reducers/shortUrlsList.test.js index 5af7b9cd..a34786f3 100644 --- a/test/short-urls/reducers/shortUrlsList.test.js +++ b/test/short-urls/reducers/shortUrlsList.test.js @@ -6,6 +6,7 @@ import reducer, { } from '../../../src/short-urls/reducers/shortUrlsList'; import { SHORT_URL_TAGS_EDITED } from '../../../src/short-urls/reducers/shortUrlTags'; import { SHORT_URL_DELETED } from '../../../src/short-urls/reducers/shortUrlDeletion'; +import { SHORT_URL_META_EDITED } from '../../../src/short-urls/reducers/shortUrlMeta'; describe('shortUrlsListReducer', () => { 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', () => { const shortCode = 'abc123'; const state = { diff --git a/test/utils/services/ShlinkApiClient.test.js b/test/utils/services/ShlinkApiClient.test.js index c2ef2f2a..09697bd6 100644 --- a/test/utils/services/ShlinkApiClient.test.js +++ b/test/utils/services/ShlinkApiClient.test.js @@ -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', () => { it('properly returns list of tags', async () => { const expectedTags = [ 'foo', 'bar' ];