feat(api): 搭建 API 与 Worker 骨架及契约基线
NestJS 11 + Fastify 统一错误体与 trace_id,/health 真实探活 DB/Redis,OpenAPI 3.1 契约含 20 个错误码;shared 包提供错误码、权限点、ULID、分页与通用 schema;worker 完成队列进程骨架。
This commit is contained in:
1 parent
09dbb27b66
commit
23067edb8f
70 files changed
+2445
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { addSeconds, isIsoDateString, nowIso, toIsoString } from './time.js';
|
||||
|
||||
describe('time utils', () => {
|
||||
it('nowIso 返回 UTC ISO 字符串', () => {
|
||||
expect(isIsoDateString(nowIso())).toBe(true);
|
||||
});
|
||||
|
||||
it('toIsoString 支持 Date / 时间戳 / 字符串', () => {
|
||||
const date = new Date('2026-11-02T08:00:00.000Z');
|
||||
expect(toIsoString(date)).toBe('2026-11-02T08:00:00.000Z');
|
||||
expect(toIsoString(date.getTime())).toBe('2026-11-02T08:00:00.000Z');
|
||||
expect(toIsoString('2026-11-02T08:00:00.000Z')).toBe('2026-11-02T08:00:00.000Z');
|
||||
});
|
||||
|
||||
it('非法时间抛错', () => {
|
||||
expect(() => toIsoString('not-a-date')).toThrow(TypeError);
|
||||
});
|
||||
|
||||
it('addSeconds 不修改原对象', () => {
|
||||
const date = new Date('2026-11-02T08:00:00.000Z');
|
||||
expect(addSeconds(date, 90).toISOString()).toBe('2026-11-02T08:01:30.000Z');
|
||||
expect(date.toISOString()).toBe('2026-11-02T08:00:00.000Z');
|
||||
});
|
||||
|
||||
it('isIsoDateString 拒绝非 UTC 格式', () => {
|
||||
expect(isIsoDateString('2026-11-02T08:00:00+08:00')).toBe(false);
|
||||
expect(isIsoDateString('2026-13-02T08:00:00.000Z')).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user