import { describe, it, expect } from "vitest"; import { z } from "zod"; import { DateTime } from "luxon"; /** * Regression test for the "Invalid datetime" error. * * Earlier the action used `z.string().datetime()` (strict — UTC `Z` only). * Luxon's `dt.toISO()` produces an offset-suffixed form like * `2026-05-10T09:00:00.000+08:00`, which the strict validator rejects. * The fix uses `.datetime({ offset: true })`. * * If this test ever fails again it means the schema regressed and any * Asia/Kuala_Lumpur reminder will be rejected at submit. */ describe("createReminderAction Zod schema (datetime validator)", () => { const offsetIso = DateTime.fromISO("2026-05-10T09:00:00", { zone: "Asia/Kuala_Lumpur" }).toISO()!; const utcIso = DateTime.fromISO("2026-05-10T09:00:00", { zone: "UTC" }).toISO()!; it("strict .datetime() (no options) rejects offset-suffixed ISO — that was the bug", () => { const strict = z.string().datetime(); expect(strict.safeParse(offsetIso).success).toBe(false); }); it(".datetime({ offset: true }) accepts both offset and UTC ISO — that's the fix", () => { const lenient = z.string().datetime({ offset: true }); expect(lenient.safeParse(offsetIso).success).toBe(true); expect(lenient.safeParse(utcIso).success).toBe(true); }); });