From bbaa4d0f05a3fe43cbf6ac1e40153a9a64be3142 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 30 Apr 2022 09:18:53 +0200 Subject: [PATCH] Improved domainVisits reducer covering new visits for different domains and default domain --- test/visits/reducers/domainVisits.test.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/test/visits/reducers/domainVisits.test.ts b/test/visits/reducers/domainVisits.test.ts index 9470777e..d223a013 100644 --- a/test/visits/reducers/domainVisits.test.ts +++ b/test/visits/reducers/domainVisits.test.ts @@ -10,7 +10,7 @@ import reducer, { GET_DOMAIN_VISITS_CANCEL, GET_DOMAIN_VISITS_PROGRESS_CHANGED, GET_DOMAIN_VISITS_FALLBACK_TO_INTERVAL, - DomainVisits, + DomainVisits, DEFAULT_DOMAIN } from '../../../src/visits/reducers/domainVisits'; import { CREATE_VISITS } from '../../../src/visits/reducers/visitCreation'; import { rangeOf } from '../../../src/utils/utils'; @@ -20,6 +20,7 @@ import ShlinkApiClient from '../../../src/api/services/ShlinkApiClient'; import { ShlinkState } from '../../../src/container/types'; import { formatIsoDate } from '../../../src/utils/helpers/date'; import { DateInterval } from '../../../src/utils/dates/types'; +import { ShortUrl } from '../../../src/short-urls/data'; describe('domainVisitsReducer', () => { const now = new Date(); @@ -71,13 +72,16 @@ describe('domainVisitsReducer', () => { }); it.each([ - [{ domain: 'foo.com' }, visitsMocks.length + 1], - [{ domain: 'bar.com' }, visitsMocks.length], + [{ domain: 'foo.com' }, 'foo.com', visitsMocks.length + 1], + [{ domain: 'bar.com' }, 'foo.com', visitsMocks.length], + [Mock.of({ domain: 'foo.com' }), 'foo.com', visitsMocks.length + 1], + [Mock.of({ domain: DEFAULT_DOMAIN }), null, visitsMocks.length + 1], [ Mock.of({ domain: 'foo.com', query: { endDate: formatIsoDate(subDays(now, 1)) ?? undefined }, }), + 'foo.com', visitsMocks.length, ], [ @@ -85,6 +89,7 @@ describe('domainVisitsReducer', () => { domain: 'foo.com', query: { startDate: formatIsoDate(addDays(now, 1)) ?? undefined }, }), + 'foo.com', visitsMocks.length, ], [ @@ -95,6 +100,7 @@ describe('domainVisitsReducer', () => { endDate: formatIsoDate(subDays(now, 2)) ?? undefined, }, }), + 'foo.com', visitsMocks.length, ], [ @@ -105,6 +111,7 @@ describe('domainVisitsReducer', () => { endDate: formatIsoDate(addDays(now, 3)) ?? undefined, }, }), + 'foo.com', visitsMocks.length + 1, ], [ @@ -115,12 +122,11 @@ describe('domainVisitsReducer', () => { endDate: formatIsoDate(addDays(now, 3)) ?? undefined, }, }), + 'foo.com', visitsMocks.length, ], - ])('prepends new visits on CREATE_VISIT', (state, expectedVisits) => { - const shortUrl = { - domain: 'foo.com', - }; + ])('prepends new visits on CREATE_VISIT', (state, shortUrlDomain, expectedVisits) => { + const shortUrl = Mock.of({ domain: shortUrlDomain }); const prevState = buildState({ ...state, visits: visitsMocks,