/** * TASK-0130 — unit: the webhook event catalog (the single source of truth). * * - the exact 13-event set from docs/api/webhooks.md §3, * - every example validates against its own payloadSchema, * - subscription validation (unknown event → listed; `*` allowed), * - the build gate: a NEW catalog entry must be backed by an emitter * (documented per entry in `firedBy`; the integration completeness test * proves it at runtime — here we at least require the field). */ import { describe, expect, it } from "vitest"; import { WEBHOOK_EVENT_CATALOG, WEBHOOK_EVENT_NAMES, catalogSelfTestFailures, isWebhookEvent, validateWebhookEvents, webhookEventCatalogEntry } from "./catalog.js"; describe("webhook event catalog", () => { it("has exactly the 13 events from docs §3 (in order)", () => { expect(WEBHOOK_EVENT_NAMES).toEqual([ "page.created", "page.updated", "page.deleted", "page.shared", "database.created", "database.updated", "record.created", "record.updated", "comment.created", "form.submitted", "automation.executed", "file.uploaded", "api_key.created" ]); }); it("every entry has a non-empty description + firedBy (build-gate documentation)", () => { for (const e of WEBHOOK_EVENT_CATALOG) { expect(e.description.length, e.name).toBeGreaterThan(0); expect(e.firedBy.length, e.name).toBeGreaterThan(0); } }); it("every example validates against its own payloadSchema", () => { expect(catalogSelfTestFailures()).toEqual([]); }); it("lookup + membership", () => { expect(webhookEventCatalogEntry("page.created")?.name).toBe("page.created"); expect(webhookEventCatalogEntry("not.an.event")).toBeNull(); expect(isWebhookEvent("record.updated")).toBe(true); expect(isWebhookEvent("*")).toBe(true); expect(isWebhookEvent("user.login")).toBe(false); }); it("validateWebhookEvents flags unknowns and allows the wildcard", () => { expect(validateWebhookEvents(["page.created", "record.updated"])).toEqual({ valid: true, unknown: [] }); expect(validateWebhookEvents(["*", "page.created"])).toEqual({ valid: true, unknown: [] }); expect(validateWebhookEvents(["page.created", "bogus.event"])).toEqual({ valid: false, unknown: ["bogus.event"] }); expect(validateWebhookEvents([])).toEqual({ valid: true, unknown: [] }); }); });