mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-10 02:07:26 +03:00
Created shortUrlMetaReducer test
This commit is contained in:
parent
207a8cef20
commit
caa6f7bcd8
2 changed files with 80 additions and 1 deletions
78
test/short-urls/reducers/shortUrlMeta.test.js
Normal file
78
test/short-urls/reducers/shortUrlMeta.test.js
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
import moment from 'moment';
|
||||||
|
import reducer, {
|
||||||
|
EDIT_SHORT_URL_META_START,
|
||||||
|
EDIT_SHORT_URL_META_ERROR,
|
||||||
|
SHORT_URL_META_EDITED,
|
||||||
|
editShortUrlMeta,
|
||||||
|
} from '../../../src/short-urls/reducers/shortUrlMeta';
|
||||||
|
|
||||||
|
describe('shortUrlMetaReducer', () => {
|
||||||
|
const meta = {
|
||||||
|
maxVisits: 50,
|
||||||
|
startDate: moment('2020-01-01').format(),
|
||||||
|
};
|
||||||
|
const shortCode = 'abc123';
|
||||||
|
|
||||||
|
describe('reducer', () => {
|
||||||
|
it('returns loading on EDIT_SHORT_URL_META_START', () => {
|
||||||
|
expect(reducer({}, { type: EDIT_SHORT_URL_META_START })).toEqual({
|
||||||
|
saving: true,
|
||||||
|
error: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns error on EDIT_SHORT_URL_META_ERROR', () => {
|
||||||
|
expect(reducer({}, { type: EDIT_SHORT_URL_META_ERROR })).toEqual({
|
||||||
|
saving: false,
|
||||||
|
error: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns provided tags and shortCode on SHORT_URL_META_EDITED', () => {
|
||||||
|
expect(reducer({}, { type: SHORT_URL_META_EDITED, meta, shortCode })).toEqual({
|
||||||
|
meta,
|
||||||
|
shortCode,
|
||||||
|
saving: false,
|
||||||
|
error: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('editShortUrlMeta', () => {
|
||||||
|
const updateShortUrlMeta = jest.fn().mockResolvedValue({});
|
||||||
|
const buildShlinkApiClient = jest.fn().mockResolvedValue({ updateShortUrlMeta });
|
||||||
|
const dispatch = jest.fn();
|
||||||
|
|
||||||
|
afterEach(jest.clearAllMocks);
|
||||||
|
|
||||||
|
it('dispatches metadata on success', async () => {
|
||||||
|
await editShortUrlMeta(buildShlinkApiClient)(shortCode, meta)(dispatch);
|
||||||
|
|
||||||
|
expect(buildShlinkApiClient).toHaveBeenCalledTimes(1);
|
||||||
|
expect(updateShortUrlMeta).toHaveBeenCalledTimes(1);
|
||||||
|
expect(updateShortUrlMeta).toHaveBeenCalledWith(shortCode, meta);
|
||||||
|
expect(dispatch).toHaveBeenCalledTimes(2);
|
||||||
|
expect(dispatch).toHaveBeenNthCalledWith(1, { type: EDIT_SHORT_URL_META_START });
|
||||||
|
expect(dispatch).toHaveBeenNthCalledWith(2, { type: SHORT_URL_META_EDITED, meta, shortCode });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('dispatches error on failure', async () => {
|
||||||
|
const error = new Error();
|
||||||
|
|
||||||
|
updateShortUrlMeta.mockRejectedValue(error);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await editShortUrlMeta(buildShlinkApiClient)(shortCode, meta)(dispatch);
|
||||||
|
} catch (e) {
|
||||||
|
expect(e).toBe(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(buildShlinkApiClient).toHaveBeenCalledTimes(1);
|
||||||
|
expect(updateShortUrlMeta).toHaveBeenCalledTimes(1);
|
||||||
|
expect(updateShortUrlMeta).toHaveBeenCalledWith(shortCode, meta);
|
||||||
|
expect(dispatch).toHaveBeenCalledTimes(2);
|
||||||
|
expect(dispatch).toHaveBeenNthCalledWith(1, { type: EDIT_SHORT_URL_META_START });
|
||||||
|
expect(dispatch).toHaveBeenNthCalledWith(2, { type: EDIT_SHORT_URL_META_ERROR });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,10 +1,11 @@
|
||||||
import reducer, {
|
import reducer, {
|
||||||
EDIT_SHORT_URL_TAGS,
|
EDIT_SHORT_URL_TAGS,
|
||||||
EDIT_SHORT_URL_TAGS_ERROR,
|
EDIT_SHORT_URL_TAGS_ERROR,
|
||||||
EDIT_SHORT_URL_TAGS_START, editShortUrlTags,
|
EDIT_SHORT_URL_TAGS_START,
|
||||||
RESET_EDIT_SHORT_URL_TAGS,
|
RESET_EDIT_SHORT_URL_TAGS,
|
||||||
resetShortUrlsTags,
|
resetShortUrlsTags,
|
||||||
SHORT_URL_TAGS_EDITED,
|
SHORT_URL_TAGS_EDITED,
|
||||||
|
editShortUrlTags,
|
||||||
shortUrlTagsEdited,
|
shortUrlTagsEdited,
|
||||||
} from '../../../src/short-urls/reducers/shortUrlTags';
|
} from '../../../src/short-urls/reducers/shortUrlTags';
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue