import { describe, expect, it } from "@suaveplan/testing/runner"; import { SsePluginOptionsSchema } from "./options.js"; describe("SsePluginOptionsSchema", () => { it("applies defaults when nothing is supplied", { timeout: 5000 }, () => { const parsed = SsePluginOptionsSchema.parse({}); expect(parsed.heartbeatIntervalMs).toBe(30_000); expect(parsed.routePrefix).toBe("/sse"); expect(parsed.attachDefaultRoute).toBe(true); expect(parsed.retentionPerChannel).toBe(100); expect(parsed.maxConnectionsPerPrincipal).toBe(16); expect(parsed.maxTotalConnections).toBe(10_000); expect(parsed.queueHighWaterMark).toBe(256); expect(parsed.overflowPolicy).toBe("drop-oldest"); }); it("rejects non-positive heartbeat", { timeout: 5000 }, () => { const r = SsePluginOptionsSchema.safeParse({ heartbeatIntervalMs: 0 }); expect(r.success).toBe(false); }); it("rejects non-integer retention", { timeout: 5000 }, () => { const r = SsePluginOptionsSchema.safeParse({ retentionPerChannel: 1.5, }); expect(r.success).toBe(false); }); it("rejects invalid overflowPolicy", { timeout: 5000 }, () => { const r = SsePluginOptionsSchema.safeParse({ overflowPolicy: "explode", }); expect(r.success).toBe(false); }); it("rejects routePrefix without leading slash", { timeout: 5000 }, () => { const r = SsePluginOptionsSchema.safeParse({ routePrefix: "sse" }); expect(r.success).toBe(false); }); it("accepts a custom idGenerator function", { timeout: 5000 }, () => { const r = SsePluginOptionsSchema.safeParse({ idGenerator: () => "x" }); expect(r.success).toBe(true); }); it("rejects a non-function idGenerator", { timeout: 5000 }, () => { const r = SsePluginOptionsSchema.safeParse({ idGenerator: 42 }); expect(r.success).toBe(false); }); it("accepts a LoggerLike object", { timeout: 5000 }, () => { const logger = { debug: () => undefined, info: () => undefined, warn: () => undefined, error: () => undefined, }; const r = SsePluginOptionsSchema.safeParse({ logger }); expect(r.success).toBe(true); }); it("rejects a non-LoggerLike value", { timeout: 5000 }, () => { const r = SsePluginOptionsSchema.safeParse({ logger: {} }); expect(r.success).toBe(false); }); it("accepts a Clock object", { timeout: 5000 }, () => { const r = SsePluginOptionsSchema.safeParse({ clock: { now: () => 0 } }); expect(r.success).toBe(true); }); it("rejects a non-Clock value", { timeout: 5000 }, () => { const r = SsePluginOptionsSchema.safeParse({ clock: {} }); expect(r.success).toBe(false); }); });