Added more tests covering new use cases

This commit is contained in:
Alejandro Celaya
2020-04-18 12:09:51 +02:00
parent 91488ae294
commit ed40b79c8d
4 changed files with 128 additions and 4 deletions

View File

@@ -52,7 +52,7 @@ describe('shortUrlCreationReducer', () => {
const dispatch = jest.fn();
const getState = () => ({});
afterEach(() => dispatch.mockReset());
afterEach(jest.resetAllMocks);
it('calls API on success', async () => {
const result = 'foo';

View File

@@ -7,6 +7,7 @@ import reducer, {
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';
import { CREATE_SHORT_URL_VISIT } from '../../../src/visits/reducers/shortUrlVisits';
describe('shortUrlsListReducer', () => {
describe('reducer', () => {
@@ -31,7 +32,7 @@ describe('shortUrlsListReducer', () => {
error: true,
}));
it('Updates tags on matching URL on SHORT_URL_TAGS_EDITED', () => {
it('updates tags on matching URL on SHORT_URL_TAGS_EDITED', () => {
const shortCode = 'abc123';
const tags = [ 'foo', 'bar', 'baz' ];
const state = {
@@ -55,7 +56,7 @@ describe('shortUrlsListReducer', () => {
});
});
it('Updates meta on matching URL on SHORT_URL_META_EDITED', () => {
it('updates meta on matching URL on SHORT_URL_META_EDITED', () => {
const shortCode = 'abc123';
const domain = 'example.com';
const meta = {
@@ -83,7 +84,7 @@ describe('shortUrlsListReducer', () => {
});
});
it('Removes matching URL on SHORT_URL_DELETED', () => {
it('removes matching URL on SHORT_URL_DELETED', () => {
const shortCode = 'abc123';
const state = {
shortUrls: {
@@ -101,6 +102,33 @@ describe('shortUrlsListReducer', () => {
},
});
});
it('updates visits count on CREATE_SHORT_URL_VISIT', () => {
const shortCode = 'abc123';
const shortUrl = {
shortCode,
visitsCount: 11,
};
const state = {
shortUrls: {
data: [
{ shortCode, domain: 'example.com', visitsCount: 5 },
{ shortCode, visitsCount: 10 },
{ shortCode: 'foo', visitsCount: 8 },
],
},
};
expect(reducer(state, { type: CREATE_SHORT_URL_VISIT, shortUrl })).toEqual({
shortUrls: {
data: [
{ shortCode, domain: 'example.com', visitsCount: 5 },
{ shortCode, visitsCount: 11 },
{ shortCode: 'foo', visitsCount: 8 },
],
},
});
});
});
describe('listShortUrls', () => {