37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import {
|
|
projectedCaptures,
|
|
utcDayStart,
|
|
} from '../src/analytics/forecast-policy';
|
|
import { captureForecastSchema } from '../src/analytics/forecast.schemas';
|
|
|
|
it('projects exact integer quantities over all history days with ceiling rounding', () => {
|
|
expect(projectedCaptures('13', 14, 30)).toBe('28');
|
|
expect(projectedCaptures('14', 14, 30)).toBe('30');
|
|
expect(projectedCaptures('0', 14, 30)).toBe('0');
|
|
expect(projectedCaptures('9007199254740993', 7, 7)).toBe('9007199254740993');
|
|
expect(utcDayStart(new Date('2026-10-08T12:34:00Z')).toISOString()).toBe(
|
|
'2026-10-08T00:00:00.000Z',
|
|
);
|
|
});
|
|
it('requires complete historical days, preserves analytics bounds and limits horizons', () => {
|
|
const input = { from: '2026-01-01T00:00:00Z', to: '2026-01-15T00:00:00Z' };
|
|
expect(captureForecastSchema.parse(input)).toMatchObject({
|
|
horizonDays: 30,
|
|
limit: 25,
|
|
offset: 0,
|
|
});
|
|
for (const change of [
|
|
{ from: '2026-01-01T01:00:00Z' },
|
|
{ to: '2026-01-02T00:00:00Z' },
|
|
{ to: '2027-01-03T00:00:00Z' },
|
|
{ from: '2024-01-01T00:00:00Z' },
|
|
{ horizonDays: 91 },
|
|
{ horizonDays: 0 },
|
|
{ limit: 101 },
|
|
{ currency: 'inr' },
|
|
])
|
|
expect(
|
|
captureForecastSchema.safeParse({ ...input, ...change }).success,
|
|
).toBe(false);
|
|
});
|