Ensured domain is passed when deleting a short URL on a specific domain

This commit is contained in:
Alejandro Celaya 2020-02-08 09:57:18 +01:00
parent 861a3c068f
commit 098c94bccf
3 changed files with 11 additions and 8 deletions

View file

@ -22,9 +22,9 @@ export default class DeleteShortUrlModal extends React.Component {
e.preventDefault(); e.preventDefault();
const { deleteShortUrl, shortUrl, toggle } = this.props; const { deleteShortUrl, shortUrl, toggle } = this.props;
const { shortCode } = shortUrl; const { shortCode, domain } = shortUrl;
deleteShortUrl(shortCode) deleteShortUrl(shortCode, domain)
.then(toggle) .then(toggle)
.catch(identity); .catch(identity);
}; };

View file

@ -30,13 +30,13 @@ export default handleActions({
[RESET_DELETE_SHORT_URL]: () => initialState, [RESET_DELETE_SHORT_URL]: () => initialState,
}, 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 }); dispatch({ type: DELETE_SHORT_URL_START });
const { deleteShortUrl } = await buildShlinkApiClient(getState); const { deleteShortUrl } = await buildShlinkApiClient(getState);
try { try {
await deleteShortUrl(shortCode); await deleteShortUrl(shortCode, domain);
dispatch({ type: SHORT_URL_DELETED, shortCode }); dispatch({ type: SHORT_URL_DELETED, shortCode });
} catch (e) { } catch (e) {
dispatch({ type: DELETE_SHORT_URL_ERROR, errorData: e.response.data }); dispatch({ type: DELETE_SHORT_URL_ERROR, errorData: e.response.data });

View file

@ -1,3 +1,4 @@
import each from 'jest-each';
import reducer, { import reducer, {
DELETE_SHORT_URL_ERROR, DELETE_SHORT_URL_ERROR,
DELETE_SHORT_URL_START, DELETE_SHORT_URL_START,
@ -59,20 +60,22 @@ describe('shortUrlDeletionReducer', () => {
getState.mockClear(); 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 = { const apiClientMock = {
deleteShortUrl: jest.fn(() => ''), deleteShortUrl: jest.fn(() => ''),
}; };
const shortCode = 'abc123'; const shortCode = 'abc123';
await deleteShortUrl(() => apiClientMock)(shortCode)(dispatch, getState); await deleteShortUrl(() => apiClientMock)(shortCode, domain)(dispatch, getState);
expect(dispatch).toHaveBeenCalledTimes(2); expect(dispatch).toHaveBeenCalledTimes(2);
expect(dispatch).toHaveBeenNthCalledWith(1, { type: DELETE_SHORT_URL_START }); expect(dispatch).toHaveBeenNthCalledWith(1, { type: DELETE_SHORT_URL_START });
expect(dispatch).toHaveBeenNthCalledWith(2, { type: SHORT_URL_DELETED, shortCode }); expect(dispatch).toHaveBeenNthCalledWith(2, { type: SHORT_URL_DELETED, shortCode });
expect(apiClientMock.deleteShortUrl).toHaveBeenCalledTimes(1); 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 () => { 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(dispatch).toHaveBeenNthCalledWith(2, { type: DELETE_SHORT_URL_ERROR, errorData: data });
expect(apiClientMock.deleteShortUrl).toHaveBeenCalledTimes(1); expect(apiClientMock.deleteShortUrl).toHaveBeenCalledTimes(1);
expect(apiClientMock.deleteShortUrl).toHaveBeenCalledWith(shortCode); expect(apiClientMock.deleteShortUrl).toHaveBeenCalledWith(shortCode, undefined);
}); });
}); });
}); });