import { describe, expect, it } from "vitest"; import { notion } from "./index.js"; import { createProvisioningArtifact } from "./provisioning.js"; import { finishMetadataRecording, startMetadataRecording } from "./recorder.js"; import type { CustomViewSchema } from "./views.js"; const customView: CustomViewSchema = { resourceId: "tasks-board-view", dataSourceResourceId: "tasks-source", type: "custom", customBlockKey: "board", }; const databaseArgs = { name: "Tasks", dataSourceResourceId: "tasks-source", schema: { Name: { resourceId: "task-name", type: "title" } }, } as const; describe.each([ { name: "standalone views", declare: (view: CustomViewSchema) => notion.view({ ...view, databaseResourceId: "tasks-db" }), }, { name: "database views", declare: (view: CustomViewSchema) => notion.database("tasks-db", { ...databaseArgs, views: [view] }), }, { name: "addView", declare: (view: CustomViewSchema) => notion.database("tasks-db", databaseArgs).addView(view), }, ])("provisioning $name", ({ declare }) => { it.each([ ["sorts", []], ["filters", []], ["properties", []], ["showPageIcon", true], ["defaultTemplate", "template"], ] as const)("rejects %s on custom views when creating the artifact", (field, value) => { const recorder = startMetadataRecording(); // Extra fields can arrive from JavaScript callers despite the TypeScript contract. declare({ ...customView, [field]: value }); const { intents } = finishMetadataRecording(recorder); expect(() => createProvisioningArtifact(intents)).toThrow( `Custom views do not support ${field}`, ); }); it("rejects a blank custom block key when creating the artifact", () => { const recorder = startMetadataRecording(); declare({ ...customView, customBlockKey: " " }); const { intents } = finishMetadataRecording(recorder); expect(() => createProvisioningArtifact(intents)).toThrow("non-empty customBlockKey"); }); it("preserves the custom block key for server-side capability resolution", () => { const recorder = startMetadataRecording(); declare(customView); const { intents } = finishMetadataRecording(recorder); expect(createProvisioningArtifact(intents).intents).toEqual(intents); }); });