From 115038f80ff971e930fe9825662d7a4de387f7c1 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 27 Feb 2021 20:13:18 +0100 Subject: [PATCH] Created visits type helpers test --- src/visits/types/helpers.ts | 2 +- test/visits/types/helpers.test.ts | 59 +++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 test/visits/types/helpers.test.ts diff --git a/src/visits/types/helpers.ts b/src/visits/types/helpers.ts index c87d95f9..51a896f2 100644 --- a/src/visits/types/helpers.ts +++ b/src/visits/types/helpers.ts @@ -3,7 +3,7 @@ import { Visit, OrphanVisit, CreateVisit } from './index'; export const isOrphanVisit = (visit: Visit): visit is OrphanVisit => visit.hasOwnProperty('visitedUrl'); -interface GroupedNewVisits { +export interface GroupedNewVisits { orphanVisits: CreateVisit[]; regularVisits: CreateVisit[]; } diff --git a/test/visits/types/helpers.test.ts b/test/visits/types/helpers.test.ts new file mode 100644 index 00000000..d87c7bd1 --- /dev/null +++ b/test/visits/types/helpers.test.ts @@ -0,0 +1,59 @@ +import { GroupedNewVisits, groupNewVisitsByType } from '../../../src/visits/types/helpers'; +import { CreateVisit, OrphanVisit, Visit } from '../../../src/visits/types'; +import { Mock } from 'ts-mockery'; + +describe('visitsTypeHelpers', () => { + describe('groupNewVisitsByType', () => { + it.each([ + [[], { orphanVisits: [], regularVisits: [] }], + ((): [CreateVisit[], GroupedNewVisits] => { + const orphanVisits: CreateVisit[] = [ + Mock.of({ + visit: Mock.of({ visitedUrl: '' }), + }), + Mock.of({ + visit: Mock.of({ visitedUrl: '' }), + }), + ]; + const regularVisits: CreateVisit[] = [ + Mock.of({ visit: Mock.all() }), + Mock.of({ visit: Mock.all() }), + Mock.of({ visit: Mock.all() }), + Mock.of({ visit: Mock.all() }), + Mock.of({ visit: Mock.all() }), + ]; + + return [ + [ ...orphanVisits, ...regularVisits ], + { orphanVisits, regularVisits }, + ]; + })(), + ((): [CreateVisit[], GroupedNewVisits] => { + const orphanVisits: CreateVisit[] = [ + Mock.of({ + visit: Mock.of({ visitedUrl: '' }), + }), + Mock.of({ + visit: Mock.of({ visitedUrl: '' }), + }), + Mock.of({ + visit: Mock.of({ visitedUrl: '' }), + }), + ]; + + return [ orphanVisits, { orphanVisits, regularVisits: [] }]; + })(), + ((): [CreateVisit[], GroupedNewVisits] => { + const regularVisits: CreateVisit[] = [ + Mock.of({ visit: Mock.all() }), + Mock.of({ visit: Mock.all() }), + Mock.of({ visit: Mock.all() }), + ]; + + return [ regularVisits, { orphanVisits: [], regularVisits }]; + })(), + ])('groups new visits as expected', (createdVisits, expectedResult) => { + expect(groupNewVisitsByType(createdVisits)).toEqual(expectedResult); + }); + }); +});