- Add a new fusion-plugin-even-cards package with typed card formatting utilities and board/task card generation - Implement authenticated plugin routes for board card endpoints and plugin registration wiring - Add unit tests for auth handling, board routes, and card formatting behavior - Document plugin in PLUGIN_AUTHORING guide and register it in pnpm workspace Fusion-Task-Id: FN-3739
27 lines
1.2 KiB
TypeScript
27 lines
1.2 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { requireApiKey } from "../routes/auth.js";
|
|
|
|
const logger = { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() };
|
|
|
|
describe("requireApiKey", () => {
|
|
it("returns 503 when api key setting is missing", () => {
|
|
const result = requireApiKey({ settings: {}, logger } as any, { headers: {} });
|
|
expect(result).toEqual({ ok: false, response: { status: 503, body: { error: "plugin not configured" } } });
|
|
});
|
|
|
|
it("returns 401 when header missing", () => {
|
|
const result = requireApiKey({ settings: { apiKey: "secret" }, logger } as any, { headers: {} });
|
|
expect(result).toEqual({ ok: false, response: { status: 401, body: { error: "unauthorized" } } });
|
|
});
|
|
|
|
it("returns 401 when key does not match", () => {
|
|
const result = requireApiKey({ settings: { apiKey: "secret" }, logger } as any, { headers: { authorization: "Bearer nope" } });
|
|
expect(result).toEqual({ ok: false, response: { status: 401, body: { error: "unauthorized" } } });
|
|
});
|
|
|
|
it("returns ok on matching key", () => {
|
|
const result = requireApiKey({ settings: { apiKey: "secret" }, logger } as any, { headers: { authorization: "Bearer secret" } });
|
|
expect(result).toEqual({ ok: true });
|
|
});
|
|
});
|