40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import {
|
|
analyticsWindowSchema,
|
|
analyticsVariantsSchema,
|
|
} from '../src/analytics/analytics.schemas';
|
|
|
|
it('normalizes offsets, bounds windows and validates paginated currency filters', () => {
|
|
const input = {
|
|
from: '2026-01-01T05:30:00+05:30',
|
|
to: '2027-01-01T00:00:00Z',
|
|
};
|
|
expect(analyticsWindowSchema.parse(input).from.toISOString()).toBe(
|
|
'2026-01-01T00:00:00.000Z',
|
|
);
|
|
expect(
|
|
analyticsWindowSchema.safeParse({
|
|
from: '2024-01-01T00:00:00Z',
|
|
to: '2025-01-01T00:00:00Z',
|
|
}).success,
|
|
).toBe(true);
|
|
for (const values of [
|
|
{ to: input.from },
|
|
{ to: '2027-01-03T00:00:00Z' },
|
|
{ from: '2026-01-01' },
|
|
{ from: '2026-01-01T00:00:00.0001Z' },
|
|
{ from: '0000-01-01T00:00:00Z', to: '0000-01-02T00:00:00Z' },
|
|
{ currency: 'inr' },
|
|
{ organizationId: 'foreign' },
|
|
])
|
|
expect(
|
|
analyticsWindowSchema.safeParse({ ...input, ...values }).success,
|
|
).toBe(false);
|
|
expect(analyticsVariantsSchema.parse(input)).toMatchObject({
|
|
limit: 25,
|
|
offset: 0,
|
|
});
|
|
expect(
|
|
analyticsVariantsSchema.safeParse({ ...input, limit: 101 }).success,
|
|
).toBe(false);
|
|
});
|