Skip to content

Commit 2495851

Browse files
Jeniterclaude
andauthored
test: add unit tests for getOperationId (#6825)
Adds coverage for the previously untested getOperationId helper in app/utils.ts (explicit operationId, method+path derivation, slash replacement, and the allowed id pattern). Purely additive — no existing files are changed. Co-authored-by: ytj-zuel <15623621570> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 9214000 commit 2495851

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

test/get-operation-id.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { getOperationId } from "../app/utils";
2+
3+
describe("getOperationId", () => {
4+
test("prefers an explicit operationId when provided", () => {
5+
expect(
6+
getOperationId({
7+
operationId: "listPets",
8+
method: "get",
9+
path: "/pets",
10+
}),
11+
).toBe("listPets");
12+
});
13+
14+
test("derives an id from method and path when operationId is missing", () => {
15+
expect(
16+
getOperationId({
17+
method: "get",
18+
path: "/pets/list",
19+
}),
20+
).toBe("GET_pets_list");
21+
});
22+
23+
test("uppercases the method and replaces every slash in the path", () => {
24+
expect(
25+
getOperationId({
26+
method: "post",
27+
path: "/v1/users/create",
28+
}),
29+
).toBe("POST_v1_users_create");
30+
});
31+
32+
test("produces an id matching the allowed pattern ^[a-zA-Z0-9_-]+$", () => {
33+
const id = getOperationId({ method: "delete", path: "/a/b/c" });
34+
expect(id).toMatch(/^[a-zA-Z0-9_-]+$/);
35+
});
36+
});

0 commit comments

Comments
 (0)