import { describe, expect, it } from "vitest"; import { Timestamp } from "firebase-admin/firestore"; import { toIso, toIsoOrUndefined } from "../../src/types/dto/iso"; const UTC_ISO = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/; describe("toIso", () => { it("Timestamp 를 UTC ISO 문자열로 바꾼다", () => { const ts = Timestamp.fromDate(new Date("2026-07-20T05:30:00.000Z")); expect(toIso(ts)).toBe("2026-07-20T05:30:00.000Z"); }); it("항상 Z 로 끝나는 UTC 형식을 낸다 (KST 오프셋 없음)", () => { const ts = Timestamp.fromDate(new Date("2026-07-20T14:30:00+09:00")); const iso = toIso(ts); expect(iso).toMatch(UTC_ISO); expect(iso).not.toContain("+09:00"); expect(iso).toBe("2026-07-20T05:30:00.000Z"); }); }); describe("toIsoOrUndefined", () => { it("값이 있으면 toIso 와 같은 결과를 낸다", () => { const ts = Timestamp.fromDate(new Date("2026-01-02T03:04:05.678Z")); expect(toIsoOrUndefined(ts)).toBe("2026-01-02T03:04:05.678Z"); }); it("undefined / null 이면 undefined 를 낸다", () => { expect(toIsoOrUndefined(undefined)).toBeUndefined(); expect(toIsoOrUndefined(null)).toBeUndefined(); }); it("undefined 필드는 JSON 직렬화에서 키가 사라진다", () => { const dto = { at: toIsoOrUndefined(undefined) }; expect(JSON.parse(JSON.stringify(dto))).toEqual({}); }); });