Files
dashboard/tests/dateFilter.test.ts
T
Alberto-Audrix 32a36cceff
CI / lint-and-test (push) Canceled after 0s
first commit
2026-07-28 08:55:05 +07:00

36 lines
1.1 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import {
formatDateForDb,
getAdjustedDateRange,
getEffectiveCycleDay,
getEffectiveDate,
} from '../utils/dateFilter.ts';
describe('dateFilter', () => {
it('uses the previous day before 17:00 WIB', () => {
const referenceDate = new Date('2026-06-09T08:30:00.000Z'); // 15:30 WIB
const effectiveDate = getEffectiveDate(referenceDate);
expect(formatDateForDb(effectiveDate)).toBe('2026-06-08');
expect(getEffectiveCycleDay('2026-06-01', referenceDate)).toBe(7);
expect(getAdjustedDateRange('2026-06-09', '2026-06-09', referenceDate)).toEqual({
start: '2026-06-08',
end: '2026-06-08',
});
});
it('uses the current day at or after 17:00 WIB', () => {
const referenceDate = new Date('2026-06-09T10:30:00.000Z'); // 17:30 WIB
const effectiveDate = getEffectiveDate(referenceDate);
expect(formatDateForDb(effectiveDate)).toBe('2026-06-09');
expect(getEffectiveCycleDay('2026-06-01', referenceDate)).toBe(8);
expect(getAdjustedDateRange('2026-06-09', '2026-06-09', referenceDate)).toEqual({
start: '2026-06-09',
end: '2026-06-09',
});
});
});