import { describe, expect, it } from "vitest"; import { APPS_WORKSPACE_RESOURCE_ID, type InfraAsCodeIntent } from "../notion-as-code/intents.js"; import { validateCustomBlockReferences } from "./validate-custom-block-references.js"; function page(content: string): InfraAsCodeIntent { return { type: "page", resourceId: "home", parent: { type: "resourceId", resourceId: APPS_WORKSPACE_RESOURCE_ID }, content, }; } describe("App page custom block references", () => { it("accepts declared keys and workspace definition IDs", () => { expect(() => validateCustomBlockReferences( [ page( '\n', ), ], new Set(["board"]), ), ).not.toThrow(); }); it("reports the page and undeclared key, including nested placements", () => { expect(() => validateCustomBlockReferences( [page('- ')], new Set(), ), ).toThrow('Page "home" references undeclared custom block key "missing"'); }); it("ignores fenced and inline code examples", () => { expect(() => validateCustomBlockReferences( [ page( '```xml\n\n```\n``\n~~~xml\n\n~~~', ), ], new Set(), ), ).not.toThrow(); }); });