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

@@ -1,11 +1,13 @@
import reducer, {
getShortUrlVisits,
cancelGetShortUrlVisits,
createNewVisit,
GET_SHORT_URL_VISITS_START,
GET_SHORT_URL_VISITS_ERROR,
GET_SHORT_URL_VISITS,
GET_SHORT_URL_VISITS_LARGE,
GET_SHORT_URL_VISITS_CANCEL,
CREATE_SHORT_URL_VISIT,
} from '../../../src/visits/reducers/shortUrlVisits';
describe('shortUrlVisitsReducer', () => {
@@ -48,6 +50,23 @@ describe('shortUrlVisitsReducer', () => {
expect(error).toEqual(false);
expect(visits).toEqual(actionVisits);
});
it.each([
[{ shortCode: 'abc123' }, [{}, {}, {}]],
[{ shortCode: 'def456' }, [{}, {}]],
])('appends a new visit on CREATE_SHORT_URL_VISIT', (state, expectedVisits) => {
const shortUrl = {
shortCode: 'abc123',
};
const prevState = {
...state,
visits: [{}, {}],
};
const { visits } = reducer(prevState, { type: CREATE_SHORT_URL_VISIT, shortUrl, visit: {} });
expect(visits).toEqual(expectedVisits);
});
});
describe('getShortUrlVisits', () => {
@@ -119,4 +138,11 @@ describe('shortUrlVisitsReducer', () => {
it('just returns the action with proper type', () =>
expect(cancelGetShortUrlVisits()).toEqual({ type: GET_SHORT_URL_VISITS_CANCEL }));
});
describe('createNewVisit', () => {
it('just returns the action with proper type', () =>
expect(createNewVisit({ shortUrl: {}, visit: {} })).toEqual(
{ type: CREATE_SHORT_URL_VISIT, shortUrl: {}, visit: {} }
));
});
});