import { describe, it, expect, vi, beforeEach } from "vitest"; // Mock sendFile to track calls const sendFileMock = vi.fn(); const setHeaderMock = vi.fn().mockReturnThis(); vi.mock("express", async () => { const actual = await vi.importActual("express"); return actual; }); describe("pages router", () => { it("exports a pagesRouter express Router", async () => { const { pagesRouter } = await import("../routes/pages.js"); expect(pagesRouter).toBeDefined(); expect(typeof pagesRouter).toBe("function"); // Express routers are functions }); it("defines GET routes for all static pages", async () => { const { pagesRouter } = await import("../routes/pages.js"); // Express Router stores routes in router.stack const routes = (pagesRouter as any).stack .filter((layer: any) => layer.route) .map((layer: any) => ({ path: layer.route.path, method: Object.keys(layer.route.methods)[0], })); const expectedPages = [ { path: "/", method: "get" }, { path: "/docs", method: "get" }, { path: "/impressum", method: "get" }, { path: "/privacy", method: "get" }, { path: "/terms", method: "get" }, { path: "/examples", method: "get" }, { path: "/status", method: "get" }, { path: "/favicon.ico", method: "get" }, ]; for (const expected of expectedPages) { const found = routes.find( (r: any) => r.path === expected.path && r.method === expected.method ); expect(found, `Missing route: GET ${expected.path}`).toBeDefined(); } }); it("defines GET /openapi.json route", async () => { const { pagesRouter } = await import("../routes/pages.js"); const routes = (pagesRouter as any).stack .filter((layer: any) => layer.route) .map((layer: any) => ({ path: layer.route.path, method: Object.keys(layer.route.methods)[0], })); const found = routes.find( (r: any) => r.path === "/openapi.json" && r.method === "get" ); expect(found, "Missing route: GET /openapi.json").toBeDefined(); }); it("defines GET /api route", async () => { const { pagesRouter } = await import("../routes/pages.js"); const routes = (pagesRouter as any).stack .filter((layer: any) => layer.route) .map((layer: any) => ({ path: layer.route.path, method: Object.keys(layer.route.methods)[0], })); const found = routes.find( (r: any) => r.path === "/api" && r.method === "get" ); expect(found, "Missing route: GET /api").toBeDefined(); }); });