import { describe, expect, it } from "@suaveplan/testing/runner"; import { createPerPluginScalarUiHandler } from "./per-plugin.js"; describe("createPerPluginScalarUiHandler", () => { it("per-plugin handler embeds filtered URL", { timeout: 5000 }, () => { const bundle = createPerPluginScalarUiHandler({ plugin: "billing", openapiUrlForPlugin: "/openapi.json?plugin=billing", }); const response = bundle.handler({ method: "GET", path: "/docs/ui/scalar/billing", }); expect(response.status).toBe(200); const occurrences = response.body.split("/openapi.json?plugin=billing").length - 1; expect(occurrences).toBe(1); expect(bundle.plugin).toBe("billing"); expect(bundle.options.uiEndpoint).toBe("/docs/ui/scalar/billing"); }); it("honours caller-supplied uiEndpoint override", { timeout: 5000 }, () => { const bundle = createPerPluginScalarUiHandler({ plugin: "billing", openapiUrlForPlugin: "/openapi.json?plugin=billing", uiEndpoint: "/docs/billing", }); expect(bundle.options.uiEndpoint).toBe("/docs/billing"); }); it("supports nonce passthrough", { timeout: 5000 }, () => { const { handler } = createPerPluginScalarUiHandler({ plugin: "billing", openapiUrlForPlugin: "/openapi.json?plugin=billing", }); const response = handler({ method: "GET", path: "/docs/ui/scalar/billing", nonce: "n-9b2f7c2a", }); expect(response.body).toContain('nonce="n-9b2f7c2a"'); }); it("exposes the underlying assetHandler", { timeout: 5000 }, () => { const bundle = createPerPluginScalarUiHandler({ plugin: "billing", openapiUrlForPlugin: "/openapi.json?plugin=billing", assetMode: "bundled", }); const response = bundle.assetHandler({ method: "GET", path: `${bundle.options.uiEndpoint}/assets/scalar.js`, }); expect(response.status).toBe(200); }); });