From 098c94bccf33398023ac0dae77cb6b7df8575ad3 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 8 Feb 2020 09:57:18 +0100 Subject: [PATCH] Ensured domain is passed when deleting a short URL on a specific domain --- src/short-urls/helpers/DeleteShortUrlModal.js | 4 ++-- src/short-urls/reducers/shortUrlDeletion.js | 4 ++-- test/short-urls/reducers/shortUrlDeletion.test.js | 11 +++++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/short-urls/helpers/DeleteShortUrlModal.js b/src/short-urls/helpers/DeleteShortUrlModal.js index a7a0affb..6121b9a2 100644 --- a/src/short-urls/helpers/DeleteShortUrlModal.js +++ b/src/short-urls/helpers/DeleteShortUrlModal.js @@ -22,9 +22,9 @@ export default class DeleteShortUrlModal extends React.Component { e.preventDefault(); const { deleteShortUrl, shortUrl, toggle } = this.props; - const { shortCode } = shortUrl; + const { shortCode, domain } = shortUrl; - deleteShortUrl(shortCode) + deleteShortUrl(shortCode, domain) .then(toggle) .catch(identity); }; diff --git a/src/short-urls/reducers/shortUrlDeletion.js b/src/short-urls/reducers/shortUrlDeletion.js index 9d86ccf1..6754527a 100644 --- a/src/short-urls/reducers/shortUrlDeletion.js +++ b/src/short-urls/reducers/shortUrlDeletion.js @@ -30,13 +30,13 @@ export default handleActions({ [RESET_DELETE_SHORT_URL]: () => initialState, }, initialState); -export const deleteShortUrl = (buildShlinkApiClient) => (shortCode) => async (dispatch, getState) => { +export const deleteShortUrl = (buildShlinkApiClient) => (shortCode, domain) => async (dispatch, getState) => { dispatch({ type: DELETE_SHORT_URL_START }); const { deleteShortUrl } = await buildShlinkApiClient(getState); try { - await deleteShortUrl(shortCode); + await deleteShortUrl(shortCode, domain); dispatch({ type: SHORT_URL_DELETED, shortCode }); } catch (e) { dispatch({ type: DELETE_SHORT_URL_ERROR, errorData: e.response.data }); diff --git a/test/short-urls/reducers/shortUrlDeletion.test.js b/test/short-urls/reducers/shortUrlDeletion.test.js index 4c62133b..be7f3adf 100644 --- a/test/short-urls/reducers/shortUrlDeletion.test.js +++ b/test/short-urls/reducers/shortUrlDeletion.test.js @@ -1,3 +1,4 @@ +import each from 'jest-each'; import reducer, { DELETE_SHORT_URL_ERROR, DELETE_SHORT_URL_START, @@ -59,20 +60,22 @@ describe('shortUrlDeletionReducer', () => { getState.mockClear(); }); - it('dispatches proper actions if API client request succeeds', async () => { + each( + [[ undefined ], [ null ], [ 'example.com' ]] + ).it('dispatches proper actions if API client request succeeds', async (domain) => { const apiClientMock = { deleteShortUrl: jest.fn(() => ''), }; const shortCode = 'abc123'; - await deleteShortUrl(() => apiClientMock)(shortCode)(dispatch, getState); + await deleteShortUrl(() => apiClientMock)(shortCode, domain)(dispatch, getState); expect(dispatch).toHaveBeenCalledTimes(2); expect(dispatch).toHaveBeenNthCalledWith(1, { type: DELETE_SHORT_URL_START }); expect(dispatch).toHaveBeenNthCalledWith(2, { type: SHORT_URL_DELETED, shortCode }); expect(apiClientMock.deleteShortUrl).toHaveBeenCalledTimes(1); - expect(apiClientMock.deleteShortUrl).toHaveBeenCalledWith(shortCode); + expect(apiClientMock.deleteShortUrl).toHaveBeenCalledWith(shortCode, domain); }); it('dispatches proper actions if API client request fails', async () => { @@ -94,7 +97,7 @@ describe('shortUrlDeletionReducer', () => { expect(dispatch).toHaveBeenNthCalledWith(2, { type: DELETE_SHORT_URL_ERROR, errorData: data }); expect(apiClientMock.deleteShortUrl).toHaveBeenCalledTimes(1); - expect(apiClientMock.deleteShortUrl).toHaveBeenCalledWith(shortCode); + expect(apiClientMock.deleteShortUrl).toHaveBeenCalledWith(shortCode, undefined); }); }); });