Skip to content

Commit 58c57bf

Browse files
committed
Tests for it.
1 parent d42c08b commit 58c57bf

4 files changed

Lines changed: 175 additions & 34 deletions

File tree

express-zod-api/tests/__snapshots__/documentation.spec.ts.snap

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -789,40 +789,6 @@ paths:
789789
status: error
790790
error:
791791
message: Sample error message
792-
head:
793-
operationId: HeadV1GetSomething
794-
parameters:
795-
- name: array
796-
in: query
797-
required: true
798-
description: HEAD /v1/getSomething Parameter
799-
schema:
800-
minItems: 1
801-
maxItems: 3
802-
type: array
803-
items:
804-
type: integer
805-
exclusiveMinimum: 0
806-
maximum: 9007199254740991
807-
- name: unlimited
808-
in: query
809-
required: true
810-
description: HEAD /v1/getSomething Parameter
811-
schema:
812-
type: array
813-
items:
814-
type: boolean
815-
- name: transformer
816-
in: query
817-
required: true
818-
description: HEAD /v1/getSomething Parameter
819-
schema:
820-
type: string
821-
responses:
822-
"200":
823-
description: HEAD /v1/getSomething Positive response
824-
"400":
825-
description: HEAD /v1/getSomething Negative response
826792
components:
827793
schemas: {}
828794
responses: {}

express-zod-api/tests/__snapshots__/integration.spec.ts.snap

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,161 @@ export type Request = keyof Input;
6666
"
6767
`;
6868
69+
exports[`Integration > Should support HEAD method by default 0 1`] = `
70+
"type SomeOf<T> = T[keyof T];
71+
72+
/** get /v1/path */
73+
type GetV1PathInput = {
74+
some: string;
75+
};
76+
77+
/** get /v1/path */
78+
type GetV1PathPositiveVariant1 = {
79+
status: "success";
80+
data: {};
81+
};
82+
83+
/** get /v1/path */
84+
interface GetV1PathPositiveResponseVariants {
85+
200: GetV1PathPositiveVariant1;
86+
}
87+
88+
/** get /v1/path */
89+
type GetV1PathNegativeVariant1 = {
90+
status: "error";
91+
error: {
92+
message: string;
93+
};
94+
};
95+
96+
/** get /v1/path */
97+
interface GetV1PathNegativeResponseVariants {
98+
400: GetV1PathNegativeVariant1;
99+
}
100+
101+
/** head /v1/path */
102+
type HeadV1PathInput = {
103+
some: string;
104+
};
105+
106+
/** head /v1/path */
107+
type HeadV1PathPositiveVariant1 = undefined;
108+
109+
/** head /v1/path */
110+
interface HeadV1PathPositiveResponseVariants {
111+
200: HeadV1PathPositiveVariant1;
112+
}
113+
114+
/** head /v1/path */
115+
type HeadV1PathNegativeVariant1 = undefined;
116+
117+
/** head /v1/path */
118+
interface HeadV1PathNegativeResponseVariants {
119+
400: HeadV1PathNegativeVariant1;
120+
}
121+
122+
export type Path = "/v1/path";
123+
124+
export type Method = "get" | "post" | "put" | "delete" | "patch" | "head";
125+
126+
export interface Input {
127+
"get /v1/path": GetV1PathInput;
128+
"head /v1/path": HeadV1PathInput;
129+
}
130+
131+
export interface PositiveResponse {
132+
"get /v1/path": SomeOf<GetV1PathPositiveResponseVariants>;
133+
"head /v1/path": SomeOf<HeadV1PathPositiveResponseVariants>;
134+
}
135+
136+
export interface NegativeResponse {
137+
"get /v1/path": SomeOf<GetV1PathNegativeResponseVariants>;
138+
"head /v1/path": SomeOf<HeadV1PathNegativeResponseVariants>;
139+
}
140+
141+
export interface EncodedResponse {
142+
"get /v1/path": GetV1PathPositiveResponseVariants &
143+
GetV1PathNegativeResponseVariants;
144+
"head /v1/path": HeadV1PathPositiveResponseVariants &
145+
HeadV1PathNegativeResponseVariants;
146+
}
147+
148+
export interface Response {
149+
"get /v1/path":
150+
| PositiveResponse["get /v1/path"]
151+
| NegativeResponse["get /v1/path"];
152+
"head /v1/path":
153+
| PositiveResponse["head /v1/path"]
154+
| NegativeResponse["head /v1/path"];
155+
}
156+
157+
export type Request = keyof Input;
158+
"
159+
`;
160+
161+
exports[`Integration > Should support HEAD method by default 1 1`] = `
162+
"type SomeOf<T> = T[keyof T];
163+
164+
/** get /v1/path */
165+
type GetV1PathInput = {
166+
some: string;
167+
};
168+
169+
/** get /v1/path */
170+
type GetV1PathPositiveVariant1 = {
171+
status: "success";
172+
data: {};
173+
};
174+
175+
/** get /v1/path */
176+
interface GetV1PathPositiveResponseVariants {
177+
200: GetV1PathPositiveVariant1;
178+
}
179+
180+
/** get /v1/path */
181+
type GetV1PathNegativeVariant1 = {
182+
status: "error";
183+
error: {
184+
message: string;
185+
};
186+
};
187+
188+
/** get /v1/path */
189+
interface GetV1PathNegativeResponseVariants {
190+
400: GetV1PathNegativeVariant1;
191+
}
192+
193+
export type Path = "/v1/path";
194+
195+
export type Method = "get" | "post" | "put" | "delete" | "patch" | "head";
196+
197+
export interface Input {
198+
"get /v1/path": GetV1PathInput;
199+
}
200+
201+
export interface PositiveResponse {
202+
"get /v1/path": SomeOf<GetV1PathPositiveResponseVariants>;
203+
}
204+
205+
export interface NegativeResponse {
206+
"get /v1/path": SomeOf<GetV1PathNegativeResponseVariants>;
207+
}
208+
209+
export interface EncodedResponse {
210+
"get /v1/path": GetV1PathPositiveResponseVariants &
211+
GetV1PathNegativeResponseVariants;
212+
}
213+
214+
export interface Response {
215+
"get /v1/path":
216+
| PositiveResponse["get /v1/path"]
217+
| NegativeResponse["get /v1/path"];
218+
}
219+
220+
export type Request = keyof Input;
221+
"
222+
`;
223+
69224
exports[`Integration > Should support multiple response schemas depending on status code 1`] = `
70225
"type SomeOf<T> = T[keyof T];
71226

express-zod-api/tests/documentation.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ describe("Documentation", () => {
5252
const literalValue = "something" as const;
5353
const spec = new Documentation({
5454
config: sampleConfig,
55+
hasHeadMethod: false,
5556
routing: {
5657
v1: {
5758
getSomething: defaultEndpointsFactory.build({

express-zod-api/tests/integration.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,25 @@ describe("Integration", () => {
6666
expect(await client.printFormatted()).toMatchSnapshot();
6767
});
6868

69+
test.each([undefined, false])(
70+
"Should support HEAD method by default %#",
71+
async (hasHeadMethod) => {
72+
const client = new Integration({
73+
hasHeadMethod,
74+
variant: "types",
75+
routing: {
76+
v1: {
77+
"get path": defaultEndpointsFactory.buildVoid({
78+
input: z.object({ some: z.string() }),
79+
handler: vi.fn(),
80+
}),
81+
},
82+
},
83+
});
84+
expect(await client.printFormatted()).toMatchSnapshot();
85+
},
86+
);
87+
6988
test("Should support multiple response schemas depending on status code", async () => {
7089
const factory = new EndpointsFactory(
7190
new ResultHandler({

0 commit comments

Comments
 (0)