tests/tasks.test.ts
此代码来自构建时的仓库快照。修改源码后重新构建即可更新。
import { describe, expect, it } from 'vitest';
import { csvCell, csvLine } from '@/server/jobs/csv';
import { defaultDueAt } from '@/server/jobs/outbox';
describe('后台任务基础规则', () => {
it('CSV 转义分隔符、引号和换行', () => {
expect(csvLine(['甲,乙', '"内容"', '多\n行'])).toBe(
'"甲,乙","""内容""","多\n行"\r\n',
);
});
it('CSV 防止表格公式注入,包含前置空格和制表符', () => {
for (const value of ['=1+1', ' +cmd', '-1', '@SUM(A1)', '\t=1'])
expect(csvCell(value)).toBe(`"'${value}"`);
});
it('新工单按优先级设置 1/4/24/48 小时提醒', () => {
const now = new Date('2026-01-01T00:00:00Z');
for (const [priority, hours] of [
['URGENT', 1],
['HIGH', 4],
['NORMAL', 24],
['LOW', 48],
] as const)
expect(defaultDueAt(priority, now).getTime() - now.getTime()).toBe(
hours * 3600000,
);
});
});