|
| 1 | +import { expect, it } from "@effect/vitest"; |
| 2 | +import * as Schema from "effect/Schema"; |
| 3 | +import { CreateScheduledPromptInput } from "./scheduling.ts"; |
| 4 | + |
| 5 | +const decode = Schema.decodeSync(CreateScheduledPromptInput); |
| 6 | + |
| 7 | +it("rejects impossible calendar dates for both exact starts and interval starts", () => { |
| 8 | + for (const at of [ |
| 9 | + "2026-02-30T09:00:00Z", |
| 10 | + "2025-02-29T09:00:00Z", |
| 11 | + "2100-02-29T09:00:00Z", |
| 12 | + "2026-04-31T09:00:00+02:00", |
| 13 | + "2026-00-01T09:00:00Z", |
| 14 | + "2026-01-00T09:00:00Z", |
| 15 | + ]) { |
| 16 | + expect(() => decode({ prompt: "Check", schedule: { kind: "once", at } })).toThrow(); |
| 17 | + expect(() => |
| 18 | + decode({ prompt: "Check", schedule: { kind: "interval", seconds: 60, startAt: at } }), |
| 19 | + ).toThrow(); |
| 20 | + } |
| 21 | +}); |
| 22 | + |
| 23 | +it("rejects invalid clocks, offsets, and timestamps without an offset", () => { |
| 24 | + for (const at of [ |
| 25 | + "2026-10-01T24:00:00Z", |
| 26 | + "2026-10-01T09:60:00Z", |
| 27 | + "2026-10-01T09:00:60Z", |
| 28 | + "2026-10-01T09:00:00+24:00", |
| 29 | + "2026-10-01T09:00:00+02:60", |
| 30 | + "2026-10-01T09:00:00", |
| 31 | + "garbageTZ", |
| 32 | + ]) { |
| 33 | + expect(() => decode({ prompt: "Check", schedule: { kind: "once", at } })).toThrow(); |
| 34 | + } |
| 35 | +}); |
| 36 | + |
| 37 | +it("accepts leap days and explicit offsets without changing the input", () => { |
| 38 | + for (const at of [ |
| 39 | + "2024-02-29T09:00:00Z", |
| 40 | + "2000-02-29T09:00:00Z", |
| 41 | + "2026-10-01T09:00:00.123+02:00", |
| 42 | + "2026-10-01T09:00:00-07:00", |
| 43 | + ]) { |
| 44 | + expect(decode({ prompt: "Check", schedule: { kind: "once", at } }).schedule).toEqual({ |
| 45 | + kind: "once", |
| 46 | + at, |
| 47 | + }); |
| 48 | + } |
| 49 | +}); |
0 commit comments