Created visits type helpers test

This commit is contained in:
Alejandro Celaya 2021-02-27 20:13:18 +01:00
parent 5479210366
commit 115038f80f
2 changed files with 60 additions and 1 deletions

View file

@ -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[];
}

View file

@ -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<CreateVisit>({
visit: Mock.of<OrphanVisit>({ visitedUrl: '' }),
}),
Mock.of<CreateVisit>({
visit: Mock.of<OrphanVisit>({ visitedUrl: '' }),
}),
];
const regularVisits: CreateVisit[] = [
Mock.of<CreateVisit>({ visit: Mock.all<Visit>() }),
Mock.of<CreateVisit>({ visit: Mock.all<Visit>() }),
Mock.of<CreateVisit>({ visit: Mock.all<Visit>() }),
Mock.of<CreateVisit>({ visit: Mock.all<Visit>() }),
Mock.of<CreateVisit>({ visit: Mock.all<Visit>() }),
];
return [
[ ...orphanVisits, ...regularVisits ],
{ orphanVisits, regularVisits },
];
})(),
((): [CreateVisit[], GroupedNewVisits] => {
const orphanVisits: CreateVisit[] = [
Mock.of<CreateVisit>({
visit: Mock.of<OrphanVisit>({ visitedUrl: '' }),
}),
Mock.of<CreateVisit>({
visit: Mock.of<OrphanVisit>({ visitedUrl: '' }),
}),
Mock.of<CreateVisit>({
visit: Mock.of<OrphanVisit>({ visitedUrl: '' }),
}),
];
return [ orphanVisits, { orphanVisits, regularVisits: [] }];
})(),
((): [CreateVisit[], GroupedNewVisits] => {
const regularVisits: CreateVisit[] = [
Mock.of<CreateVisit>({ visit: Mock.all<Visit>() }),
Mock.of<CreateVisit>({ visit: Mock.all<Visit>() }),
Mock.of<CreateVisit>({ visit: Mock.all<Visit>() }),
];
return [ regularVisits, { orphanVisits: [], regularVisits }];
})(),
])('groups new visits as expected', (createdVisits, expectedResult) => {
expect(groupNewVisitsByType(createdVisits)).toEqual(expectedResult);
});
});
});