Ensured domain is passed when editing meta for a short URL on a specific domain

This commit is contained in:
Alejandro Celaya
2020-02-08 09:52:30 +01:00
parent 3b95e8ebc0
commit 861a3c068f
3 changed files with 8 additions and 7 deletions

View File

@@ -36,7 +36,7 @@ const EditMetaModal = (
const [ maxVisits, setMaxVisits ] = useState(shortUrl && shortUrl.meta && shortUrl.meta.maxVisits); const [ maxVisits, setMaxVisits ] = useState(shortUrl && shortUrl.meta && shortUrl.meta.maxVisits);
const close = pipe(resetShortUrlMeta, toggle); const close = pipe(resetShortUrlMeta, toggle);
const doEdit = () => editShortUrlMeta(shortUrl.shortCode, { const doEdit = () => editShortUrlMeta(shortUrl.shortCode, shortUrl.domain, {
maxVisits: maxVisits && !isEmpty(maxVisits) ? parseInt(maxVisits) : null, maxVisits: maxVisits && !isEmpty(maxVisits) ? parseInt(maxVisits) : null,
validSince: validSince && formatIsoDate(validSince), validSince: validSince && formatIsoDate(validSince),
validUntil: validUntil && formatIsoDate(validUntil), validUntil: validUntil && formatIsoDate(validUntil),

View File

@@ -35,12 +35,12 @@ export default handleActions({
[RESET_EDIT_SHORT_URL_META]: () => initialState, [RESET_EDIT_SHORT_URL_META]: () => initialState,
}, initialState); }, initialState);
export const editShortUrlMeta = (buildShlinkApiClient) => (shortCode, meta) => async (dispatch, getState) => { export const editShortUrlMeta = (buildShlinkApiClient) => (shortCode, domain, meta) => async (dispatch, getState) => {
dispatch({ type: EDIT_SHORT_URL_META_START }); dispatch({ type: EDIT_SHORT_URL_META_START });
const { updateShortUrlMeta } = await buildShlinkApiClient(getState); const { updateShortUrlMeta } = await buildShlinkApiClient(getState);
try { try {
await updateShortUrlMeta(shortCode, undefined, meta); await updateShortUrlMeta(shortCode, domain, meta);
dispatch({ shortCode, meta, type: SHORT_URL_META_EDITED }); dispatch({ shortCode, meta, type: SHORT_URL_META_EDITED });
} catch (e) { } catch (e) {
dispatch({ type: EDIT_SHORT_URL_META_ERROR }); dispatch({ type: EDIT_SHORT_URL_META_ERROR });

View File

@@ -1,4 +1,5 @@
import moment from 'moment'; import moment from 'moment';
import each from 'jest-each';
import reducer, { import reducer, {
EDIT_SHORT_URL_META_START, EDIT_SHORT_URL_META_START,
EDIT_SHORT_URL_META_ERROR, EDIT_SHORT_URL_META_ERROR,
@@ -56,12 +57,12 @@ describe('shortUrlMetaReducer', () => {
afterEach(jest.clearAllMocks); afterEach(jest.clearAllMocks);
it('dispatches metadata on success', async () => { each([[ undefined ], [ null ], [ 'example.com' ]]).it('dispatches metadata on success', async (domain) => {
await editShortUrlMeta(buildShlinkApiClient)(shortCode, meta)(dispatch); await editShortUrlMeta(buildShlinkApiClient)(shortCode, domain, meta)(dispatch);
expect(buildShlinkApiClient).toHaveBeenCalledTimes(1); expect(buildShlinkApiClient).toHaveBeenCalledTimes(1);
expect(updateShortUrlMeta).toHaveBeenCalledTimes(1); expect(updateShortUrlMeta).toHaveBeenCalledTimes(1);
expect(updateShortUrlMeta).toHaveBeenCalledWith(shortCode, undefined, meta); expect(updateShortUrlMeta).toHaveBeenCalledWith(shortCode, domain, meta);
expect(dispatch).toHaveBeenCalledTimes(2); expect(dispatch).toHaveBeenCalledTimes(2);
expect(dispatch).toHaveBeenNthCalledWith(1, { type: EDIT_SHORT_URL_META_START }); expect(dispatch).toHaveBeenNthCalledWith(1, { type: EDIT_SHORT_URL_META_START });
expect(dispatch).toHaveBeenNthCalledWith(2, { type: SHORT_URL_META_EDITED, meta, shortCode }); expect(dispatch).toHaveBeenNthCalledWith(2, { type: SHORT_URL_META_EDITED, meta, shortCode });
@@ -73,7 +74,7 @@ describe('shortUrlMetaReducer', () => {
updateShortUrlMeta.mockRejectedValue(error); updateShortUrlMeta.mockRejectedValue(error);
try { try {
await editShortUrlMeta(buildShlinkApiClient)(shortCode, meta)(dispatch); await editShortUrlMeta(buildShlinkApiClient)(shortCode, undefined, meta)(dispatch);
} catch (e) { } catch (e) {
expect(e).toBe(error); expect(e).toBe(error);
} }