updated openapi
This commit is contained in:
41
tests/routes.test.ts
Normal file
41
tests/routes.test.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { openApiDocument } from "../src/openapi";
|
||||
import { matchRoute, routes } from "../src/routes";
|
||||
|
||||
describe("route registry", () => {
|
||||
it("matches concrete paths and extracts route params", () => {
|
||||
const matched = matchRoute("GET", "/orgs/org_acme/tasks");
|
||||
|
||||
expect(matched).not.toBeNull();
|
||||
expect(matched?.route.operationId).toBe("listOrganizationTasks");
|
||||
expect(matched?.params).toEqual({ orgId: "org_acme" });
|
||||
});
|
||||
|
||||
it("returns null for unsupported methods and unknown paths", () => {
|
||||
expect(matchRoute("DELETE", "/tasks/task_1001")).toBeNull();
|
||||
expect(matchRoute("GET", "/does-not-exist")).toBeNull();
|
||||
});
|
||||
|
||||
it("builds an openapi path entry for every registered route", () => {
|
||||
const registeredOperations = routes.map(
|
||||
(route) => `${route.method} ${route.path}:${route.operationId}`,
|
||||
);
|
||||
const documentedOperations = Object.entries(openApiDocument.paths).flatMap(
|
||||
([path, pathItem]) =>
|
||||
Object.entries(pathItem).map(
|
||||
([method, operation]) =>
|
||||
`${method.toUpperCase()} ${path}:${(operation as { operationId?: string }).operationId ?? ""}`,
|
||||
),
|
||||
);
|
||||
|
||||
expect(documentedOperations).toEqual(registeredOperations);
|
||||
});
|
||||
|
||||
it("keeps spec-serving routes explicit in the registry", () => {
|
||||
const openApiAliases = routes
|
||||
.filter((route) => route.servesOpenApiDocument)
|
||||
.map((route) => route.path);
|
||||
|
||||
expect(openApiAliases).toEqual(["/openapi.json", "/swagger.json", "/api-docs"]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user