Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions test/get-operation-id.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { getOperationId } from "../app/utils";

describe("getOperationId", () => {
test("prefers an explicit operationId when provided", () => {
expect(
getOperationId({
operationId: "listPets",
method: "get",
path: "/pets",
}),
).toBe("listPets");
});

test("derives an id from method and path when operationId is missing", () => {
expect(
getOperationId({
method: "get",
path: "/pets/list",
}),
).toBe("GET_pets_list");
});

test("uppercases the method and replaces every slash in the path", () => {
expect(
getOperationId({
method: "post",
path: "/v1/users/create",
}),
).toBe("POST_v1_users_create");
});

test("produces an id matching the allowed pattern ^[a-zA-Z0-9_-]+$", () => {
const id = getOperationId({ method: "delete", path: "/a/b/c" });
expect(id).toMatch(/^[a-zA-Z0-9_-]+$/);
});
});
Loading