Skip to content

Commit 1e7069d

Browse files
committed
Add default test case
1 parent 12f9c29 commit 1e7069d

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { fileURLToPath } from "node:url";
2+
import { astToString } from "../../src/lib/ts.js";
3+
import transformPathsObject from "../../src/transform/paths-object.js";
4+
import type { GlobalContext } from "../../src/types.js";
5+
import { DEFAULT_CTX, type TestCase } from "../test-helpers.js";
6+
7+
const DEFAULT_OPTIONS = DEFAULT_CTX;
8+
9+
describe("parametersWithDefaults", () => {
10+
const tests: TestCase<any, GlobalContext>[] = [
11+
[
12+
"options > default",
13+
{
14+
given: {
15+
"/api/{version}/user/{user_id}": {
16+
parameters: [
17+
{ in: "query", name: "no_default", required: false, schema: { type: "number" } },
18+
{ in: "query", name: "with_default", required: false, schema: { type: "number", default: 1337 } },
19+
],
20+
},
21+
},
22+
want: `{
23+
"/api/{version}/user/{user_id}": {
24+
parameters: {
25+
query?: {
26+
no_default?: number;
27+
with_default?: number;
28+
};
29+
header?: never;
30+
path?: never;
31+
cookie?: never;
32+
};
33+
get?: never;
34+
put?: never;
35+
post?: never;
36+
delete?: never;
37+
options?: never;
38+
head?: never;
39+
patch?: never;
40+
trace?: never;
41+
};
42+
}`,
43+
options: {
44+
...DEFAULT_OPTIONS,
45+
},
46+
},
47+
],
48+
];
49+
50+
for (const [testName, { given, want, options = DEFAULT_OPTIONS, ci }] of tests) {
51+
test.skipIf(ci?.skipIf)(
52+
testName,
53+
async () => {
54+
const result = astToString(transformPathsObject(given, options));
55+
if (want instanceof URL) {
56+
await expect(result).toMatchFileSnapshot(fileURLToPath(want));
57+
} else {
58+
expect(result).toBe(`${want}\n`);
59+
}
60+
},
61+
ci?.timeout,
62+
);
63+
}
64+
});

0 commit comments

Comments
 (0)