Files
Ydisks-Xianyu-Helper/frontend/dateRange.test.ts
Christ 2f20a54f30 修复前后端逻辑并完善多数据库测试
统一仪表盘、AI 回复、卡密、扫码和通知等前后端行为,补齐并发与失败恢复测试。新增 MySQL 8.4、PostgreSQL 17 持久化 Docker 功能测试和 SQLite 脱敏播种工具。
2026-07-10 14:39:13 +08:00

31 lines
1.1 KiB
TypeScript

import { describe, expect, test } from 'vitest';
import { getDateRange, getPreviousDateRange } from './dateRange';
describe('date ranges', () => {
const now = new Date('2026-07-10T12:00:00');
test.each([
['3days', '2026-07-08'],
['7days', '2026-07-04'],
['30days', '2026-06-11'],
] as const)('%s includes exactly the requested number of days', (range, startDate) => {
expect(getDateRange(range, now)).toEqual({ startDate, endDate: '2026-07-10' });
});
test('previous range has the same length without overlap', () => {
const current = getDateRange('7days', now);
expect(getPreviousDateRange(current)).toEqual({ startDate: '2026-06-27', endDate: '2026-07-03' });
});
test('works across year boundaries', () => {
expect(getDateRange('3days', new Date('2026-01-01T12:00:00'))).toEqual({
startDate: '2025-12-30',
endDate: '2026-01-01',
});
});
test('rejects reversed custom dates', () => {
expect(() => getDateRange('custom', now, '2026-07-11', '2026-07-10')).toThrow('开始日期不能晚于结束日期');
});
});