Added toApiParams test

This commit is contained in:
Alejandro Celaya 2021-09-20 20:48:52 +02:00
parent 56a3dbd07f
commit 8df1ba4671

View file

@ -1,6 +1,8 @@
import { Mock } from 'ts-mockery';
import { GroupedNewVisits, groupNewVisitsByType } from '../../../src/visits/types/helpers';
import { CreateVisit, OrphanVisit, Visit } from '../../../src/visits/types';
import { GroupedNewVisits, groupNewVisitsByType, toApiParams } from '../../../src/visits/types/helpers';
import { CreateVisit, OrphanVisit, Visit, VisitsParams } from '../../../src/visits/types';
import { ShlinkVisitsParams } from '../../../src/api/types';
import { formatIsoDate, parseDate } from '../../../src/utils/helpers/date';
describe('visitsTypeHelpers', () => {
describe('groupNewVisitsByType', () => {
@ -56,4 +58,51 @@ describe('visitsTypeHelpers', () => {
expect(groupNewVisitsByType(createdVisits)).toEqual(expectedResult);
});
});
describe('toApiParams', () => {
test.each([
[ { page: 5, itemsPerPage: 100 } as VisitsParams, { page: 5, itemsPerPage: 100 } as ShlinkVisitsParams ],
[
{
page: 1,
itemsPerPage: 30,
filter: { excludeBots: true },
} as VisitsParams,
{ page: 1, itemsPerPage: 30, excludeBots: true } as ShlinkVisitsParams,
],
(() => {
const endDate = parseDate('2020-05-05', 'yyyy-MM-dd');
return [
{
page: 20,
itemsPerPage: 1,
dateRange: { endDate },
} as VisitsParams,
{ page: 20, itemsPerPage: 1, endDate: formatIsoDate(endDate) } as ShlinkVisitsParams,
];
})(),
(() => {
const startDate = parseDate('2020-05-05', 'yyyy-MM-dd');
const endDate = parseDate('2021-10-30', 'yyyy-MM-dd');
return [
{
page: 20,
itemsPerPage: 1,
dateRange: { startDate, endDate },
filter: { excludeBots: false },
} as VisitsParams,
{
page: 20,
itemsPerPage: 1,
startDate: formatIsoDate(startDate),
endDate: formatIsoDate(endDate),
} as ShlinkVisitsParams,
];
})(),
])('converts param as expected', (visitsParams, expectedResult) => {
expect(toApiParams(visitsParams)).toEqual(expectedResult);
});
});
});