mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 17:40:23 +03:00
Added toApiParams test
This commit is contained in:
parent
56a3dbd07f
commit
8df1ba4671
1 changed files with 51 additions and 2 deletions
|
@ -1,6 +1,8 @@
|
||||||
import { Mock } from 'ts-mockery';
|
import { Mock } from 'ts-mockery';
|
||||||
import { GroupedNewVisits, groupNewVisitsByType } from '../../../src/visits/types/helpers';
|
import { GroupedNewVisits, groupNewVisitsByType, toApiParams } from '../../../src/visits/types/helpers';
|
||||||
import { CreateVisit, OrphanVisit, Visit } from '../../../src/visits/types';
|
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('visitsTypeHelpers', () => {
|
||||||
describe('groupNewVisitsByType', () => {
|
describe('groupNewVisitsByType', () => {
|
||||||
|
@ -56,4 +58,51 @@ describe('visitsTypeHelpers', () => {
|
||||||
expect(groupNewVisitsByType(createdVisits)).toEqual(expectedResult);
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue