mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-10 18:27:25 +03:00
Created visits type helpers test
This commit is contained in:
parent
5479210366
commit
115038f80f
2 changed files with 60 additions and 1 deletions
|
@ -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[];
|
||||
}
|
||||
|
|
59
test/visits/types/helpers.test.ts
Normal file
59
test/visits/types/helpers.test.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue