@hyper-fetch/elysia 0.0.0-stage → 9.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,345 @@
1
+ import { createClient, createSdk } from "@hyper-fetch/core";
2
+ import type {
3
+ ExtractEndpointType,
4
+ ExtractLocalErrorType,
5
+ ExtractPayloadType,
6
+ ExtractQueryParamsType,
7
+ ExtractResponseType,
8
+ } from "@hyper-fetch/core";
9
+ import { Elysia } from "elysia";
10
+ import { expectTypeOf } from "vitest";
11
+
12
+ import type { ElysiaAppToHyperFetch } from "../../../src";
13
+ import type { edgeApp, rootParamApp } from "../../utils/edge-app";
14
+
15
+ type Schema = ElysiaAppToHyperFetch<typeof edgeApp>;
16
+
17
+ type ValidationError = { type: "validation" };
18
+
19
+ describe("ElysiaAppToHyperFetch [ Paths ]", () => {
20
+ it("should keep every HTTP route and leave out the mounted handler", () => {
21
+ expectTypeOf<keyof Schema>().toEqualTypeOf<
22
+ | "$get"
23
+ | "level"
24
+ | "search"
25
+ | "number"
26
+ | "true"
27
+ | "null"
28
+ | "void"
29
+ | "date"
30
+ | "generator"
31
+ | "asyncGenerator"
32
+ | "sse"
33
+ | "stream"
34
+ | "response"
35
+ | "redirect"
36
+ | "form"
37
+ | "teapot"
38
+ | "multipleChoices"
39
+ | "schemaStatuses"
40
+ | "secret"
41
+ | "head"
42
+ | "options"
43
+ | "deep"
44
+ | "string"
45
+ | "array"
46
+ | "optionalBody"
47
+ | "unionBody"
48
+ | "dateBody"
49
+ | "upload"
50
+ | "uploads"
51
+ | "noSchema"
52
+ | "empty"
53
+ | "queryTypes"
54
+ | "queryLiteral"
55
+ | "queryArray"
56
+ | "queryPartial"
57
+ | "queryOptional"
58
+ | "queryUnknown"
59
+ | "queryEmpty"
60
+ | "guarded"
61
+ | "nested"
62
+ | "params"
63
+ | "headers"
64
+ | "throws"
65
+ | "a"
66
+ | "jsonSerializationDeserialization"
67
+ | "any"
68
+ | "optionalFile"
69
+ | "anySchema"
70
+ >();
71
+ expect(true).toBe(true);
72
+ });
73
+
74
+ it("should put a route registered on an empty path at the top level", () => {
75
+ expectTypeOf<ExtractEndpointType<Schema["$get"]>>().toEqualTypeOf<"/">();
76
+ expectTypeOf<ExtractResponseType<Schema["$get"]>>().toEqualTypeOf<"root">();
77
+ expect(true).toBe(true);
78
+ });
79
+
80
+ it("should put the / route of a prefixed plugin on the prefix", () => {
81
+ expectTypeOf<keyof Schema["level"]>().toEqualTypeOf<"$get" | "level" | "$id">();
82
+ expectTypeOf<ExtractEndpointType<Schema["level"]["$get"]>>().toEqualTypeOf<"/level">();
83
+ expectTypeOf<ExtractResponseType<Schema["level"]["$get"]>>().toEqualTypeOf<"level-index">();
84
+ expectTypeOf<ExtractEndpointType<Schema["level"]["level"]["$get"]>>().toEqualTypeOf<"/level/level">();
85
+ expectTypeOf<ExtractEndpointType<Schema["level"]["$id"]["ok"]["$get"]>>().toEqualTypeOf<"/level/:id/ok">();
86
+ expect(true).toBe(true);
87
+ });
88
+
89
+ it("should treat a segment named index as a regular segment", () => {
90
+ expectTypeOf<
91
+ ExtractEndpointType<Schema["search"]["index"]["$indexId"]["stocks"]["$get"]>
92
+ >().toEqualTypeOf<"/search/index/:indexId/stocks">();
93
+ expect(true).toBe(true);
94
+ });
95
+
96
+ it("should camelCase a segment with several hyphens", () => {
97
+ expectTypeOf<
98
+ ExtractEndpointType<Schema["jsonSerializationDeserialization"]["$get"]>
99
+ >().toEqualTypeOf<"/json-serialization-deserialization">();
100
+ expect(true).toBe(true);
101
+ });
102
+
103
+ it("should keep segments named like keywords and literals", () => {
104
+ expectTypeOf<ExtractEndpointType<Schema["number"]["$get"]>>().toEqualTypeOf<"/number">();
105
+ expectTypeOf<ExtractEndpointType<Schema["true"]["$get"]>>().toEqualTypeOf<"/true">();
106
+ expectTypeOf<ExtractEndpointType<Schema["null"]["$get"]>>().toEqualTypeOf<"/null">();
107
+ expectTypeOf<ExtractEndpointType<Schema["void"]["$get"]>>().toEqualTypeOf<"/void">();
108
+ expect(true).toBe(true);
109
+ });
110
+
111
+ it("should nest deep paths", () => {
112
+ expectTypeOf<
113
+ ExtractEndpointType<Schema["deep"]["nested"]["mirror"]["$post"]>
114
+ >().toEqualTypeOf<"/deep/nested/mirror">();
115
+ expect(true).toBe(true);
116
+ });
117
+
118
+ it("should nest a group with an empty guard", () => {
119
+ expectTypeOf<ExtractEndpointType<Schema["nested"]["data"]["$get"]>>().toEqualTypeOf<"/nested/data">();
120
+ expectTypeOf<ExtractResponseType<Schema["nested"]["data"]["$get"]>>().toEqualTypeOf<{ nested: true }>();
121
+ expect(true).toBe(true);
122
+ });
123
+
124
+ it("should put a root param at the top level", () => {
125
+ type RootSchema = ElysiaAppToHyperFetch<typeof rootParamApp>;
126
+
127
+ expectTypeOf<keyof RootSchema>().toEqualTypeOf<"$id">();
128
+ expectTypeOf<ExtractEndpointType<RootSchema["$id"]["$get"]>>().toEqualTypeOf<"/:id">();
129
+ expect(true).toBe(true);
130
+ });
131
+
132
+ it("should type a param from the path even when a params schema transforms it", () => {
133
+ expectTypeOf<ExtractEndpointType<Schema["params"]["$count"]["$get"]>>().toEqualTypeOf<"/params/:count">();
134
+ expectTypeOf<ExtractResponseType<Schema["params"]["$count"]["$get"]>>().toEqualTypeOf<{ count: number }>();
135
+ expect(true).toBe(true);
136
+ });
137
+
138
+ it("should resolve paths up to the depth createSdk injects its client into", () => {
139
+ const sdk = createSdk<ReturnType<typeof createClient>, Schema>(createClient({ url: "http://localhost" }));
140
+
141
+ expectTypeOf<
142
+ ExtractEndpointType<Schema["a"]["b"]["c"]["d"]["e"]["f"]["g"]["h"]["$get"]>
143
+ >().toEqualTypeOf<"/a/b/c/d/e/f/g/h">();
144
+ expectTypeOf<ExtractResponseType<typeof sdk.a.b.c.d.e.f.g.h.$get>>().toEqualTypeOf<{ depth: 8 }>();
145
+ expect(true).toBe(true);
146
+ });
147
+
148
+ it("should leave out paths with ten or more segments", () => {
149
+ const deep = new Elysia()
150
+ .get("/1/2/3/4/5/6/7/8/9", () => 9 as const)
151
+ .get("/a/2/3/4/5/6/7/8/9/10", () => 10 as const);
152
+ type DeepSchema = ElysiaAppToHyperFetch<typeof deep>;
153
+
154
+ expectTypeOf<ExtractResponseType<DeepSchema[1][2][3][4][5][6][7][8][9]["$get"]>>().toEqualTypeOf<9>();
155
+ expectTypeOf<keyof DeepSchema>().toEqualTypeOf<"1">();
156
+ expect(true).toBe(true);
157
+ });
158
+
159
+ it("should map the HEAD and OPTIONS methods", () => {
160
+ expectTypeOf<keyof Schema["head"]>().toEqualTypeOf<"$head">();
161
+ expectTypeOf<keyof Schema["options"]>().toEqualTypeOf<"$options">();
162
+ expect(true).toBe(true);
163
+ });
164
+ });
165
+
166
+ describe("ElysiaAppToHyperFetch [ Responses ]", () => {
167
+ it("should keep literal and primitive responses", () => {
168
+ expectTypeOf<ExtractResponseType<Schema["number"]["$get"]>>().toEqualTypeOf<1>();
169
+ expectTypeOf<ExtractResponseType<Schema["true"]["$get"]>>().toEqualTypeOf<boolean>();
170
+ expect(true).toBe(true);
171
+ });
172
+
173
+ it("should type null as the empty body Elysia sends", () => {
174
+ expectTypeOf<ExtractResponseType<Schema["null"]["$get"]>>().toEqualTypeOf<"">();
175
+ expect(true).toBe(true);
176
+ });
177
+
178
+ it("should type a handler without a return value or returning any as unknown", () => {
179
+ expectTypeOf<ExtractResponseType<Schema["void"]["$get"]>>().toBeUnknown();
180
+ expectTypeOf<ExtractResponseType<Schema["any"]["$get"]>>().toBeUnknown();
181
+ expectTypeOf<ExtractLocalErrorType<Schema["void"]["$get"]>>().toEqualTypeOf<undefined>();
182
+ expect(true).toBe(true);
183
+ });
184
+
185
+ it("should keep a response schema of any as any", () => {
186
+ expectTypeOf<ExtractResponseType<Schema["anySchema"]["$get"]>>().toBeAny();
187
+ expect(true).toBe(true);
188
+ });
189
+
190
+ it("should type dates as the ISO strings JSON carries", () => {
191
+ expectTypeOf<ExtractResponseType<Schema["date"]["$get"]>>().toEqualTypeOf<{ date: string; history: string[] }>();
192
+ expect(true).toBe(true);
193
+ });
194
+
195
+ it("should type bodies that are not JSON as unknown", () => {
196
+ expectTypeOf<ExtractResponseType<Schema["generator"]["$get"]>>().toBeUnknown();
197
+ expectTypeOf<ExtractResponseType<Schema["asyncGenerator"]["$get"]>>().toBeUnknown();
198
+ expectTypeOf<ExtractResponseType<Schema["sse"]["$get"]>>().toBeUnknown();
199
+ expectTypeOf<ExtractResponseType<Schema["stream"]["$get"]>>().toBeUnknown();
200
+ expectTypeOf<ExtractResponseType<Schema["response"]["$get"]>>().toBeUnknown();
201
+ expectTypeOf<ExtractResponseType<Schema["redirect"]["$get"]>>().toBeUnknown();
202
+ expectTypeOf<ExtractResponseType<Schema["form"]["$get"]>>().toBeUnknown();
203
+ expect(true).toBe(true);
204
+ });
205
+
206
+ it("should type a status passed by name", () => {
207
+ expectTypeOf<ExtractResponseType<Schema["teapot"]["$get"]>>().toEqualTypeOf<undefined>();
208
+ expectTypeOf<ExtractLocalErrorType<Schema["teapot"]["$get"]>>().toEqualTypeOf<{ readonly brewing: false }>();
209
+ expect(true).toBe(true);
210
+ });
211
+
212
+ it("should type a 3xx status as an error", () => {
213
+ expectTypeOf<ExtractResponseType<Schema["multipleChoices"]["$get"]>>().toEqualTypeOf<undefined>();
214
+ expectTypeOf<ExtractLocalErrorType<Schema["multipleChoices"]["$get"]>>().toEqualTypeOf<{
215
+ readonly choices: readonly ["a", "b"];
216
+ }>();
217
+ expect(true).toBe(true);
218
+ });
219
+
220
+ it("should split a response schema into the response and the local error", () => {
221
+ type SchemaError = ExtractLocalErrorType<Schema["schemaStatuses"]["$get"]>;
222
+
223
+ expectTypeOf<ExtractResponseType<Schema["schemaStatuses"]["$get"]>>().toEqualTypeOf<"">();
224
+ expectTypeOf<Exclude<SchemaError, ValidationError>>().toEqualTypeOf<"teapot" | "calm">();
225
+ expectTypeOf<Extract<SchemaError, ValidationError>>().not.toBeNever();
226
+ expect(true).toBe(true);
227
+ });
228
+
229
+ it("should not type headers, which requests set with setHeaders", () => {
230
+ expectTypeOf<ExtractPayloadType<Schema["headers"]["$get"]>>().toEqualTypeOf<undefined>();
231
+ expectTypeOf<ExtractQueryParamsType<Schema["headers"]["$get"]>>().toEqualTypeOf<undefined>();
232
+ expect(true).toBe(true);
233
+ });
234
+
235
+ it("should leave errors a handler throws to the global error of the client", () => {
236
+ expectTypeOf<ExtractLocalErrorType<Schema["throws"]["$get"]>>().toEqualTypeOf<undefined>();
237
+ expect(true).toBe(true);
238
+ });
239
+
240
+ it("should add the status a macro resolves with to the local error", () => {
241
+ expectTypeOf<ExtractResponseType<Schema["secret"]["$get"]>>().toEqualTypeOf<{ userId: string }>();
242
+ expectTypeOf<ExtractLocalErrorType<Schema["secret"]["$get"]>>().toEqualTypeOf<{ readonly reason: "forbidden" }>();
243
+ expect(true).toBe(true);
244
+ });
245
+ });
246
+
247
+ describe("ElysiaAppToHyperFetch [ Payloads ]", () => {
248
+ it("should resolve a body schema referenced by its model name", () => {
249
+ expectTypeOf<ExtractPayloadType<Schema["deep"]["nested"]["mirror"]["$post"]>>().toEqualTypeOf<{
250
+ username: string;
251
+ password: string;
252
+ }>();
253
+ expect(true).toBe(true);
254
+ });
255
+
256
+ it("should type primitive, array, optional and union bodies", () => {
257
+ expectTypeOf<ExtractPayloadType<Schema["string"]["$post"]>>().toEqualTypeOf<string>();
258
+ expectTypeOf<ExtractPayloadType<Schema["array"]["$post"]>>().toEqualTypeOf<string[]>();
259
+ expectTypeOf<ExtractPayloadType<Schema["optionalBody"]["$post"]>>().toEqualTypeOf<{ note?: string } | null>();
260
+ expectTypeOf<ExtractPayloadType<Schema["unionBody"]["$post"]>>().toEqualTypeOf<{ a: string } | { b: number }>();
261
+ expect(true).toBe(true);
262
+ });
263
+
264
+ it("should accept a Date where the body schema reads one", () => {
265
+ expectTypeOf<ExtractPayloadType<Schema["dateBody"]["$post"]>>().toEqualTypeOf<{ date: Date }>();
266
+ expect(true).toBe(true);
267
+ });
268
+
269
+ it("should type a body with file fields as FormData", () => {
270
+ expectTypeOf<ExtractPayloadType<Schema["upload"]["$post"]>>().toEqualTypeOf<FormData>();
271
+ expectTypeOf<ExtractPayloadType<Schema["uploads"]["$post"]>>().toEqualTypeOf<FormData>();
272
+ expectTypeOf<ExtractPayloadType<Schema["optionalFile"]["$post"]>>().toEqualTypeOf<FormData>();
273
+ expect(true).toBe(true);
274
+ });
275
+
276
+ it("should leave the payload undefined without a body schema", () => {
277
+ expectTypeOf<ExtractPayloadType<Schema["noSchema"]["$post"]>>().toEqualTypeOf<undefined>();
278
+ expectTypeOf<ExtractPayloadType<Schema["empty"]["$delete"]>>().toEqualTypeOf<undefined>();
279
+ expect(true).toBe(true);
280
+ });
281
+
282
+ it("should leave the payload undefined on routes that use status() or a macro", () => {
283
+ expectTypeOf<ExtractPayloadType<Schema["teapot"]["$get"]>>().toEqualTypeOf<undefined>();
284
+ expectTypeOf<ExtractPayloadType<Schema["secret"]["$get"]>>().toEqualTypeOf<undefined>();
285
+ expectTypeOf<ExtractPayloadType<Schema["head"]["$head"]>>().toEqualTypeOf<undefined>();
286
+ expect(true).toBe(true);
287
+ });
288
+ });
289
+
290
+ describe("ElysiaAppToHyperFetch [ Query params ]", () => {
291
+ it("should type transformed, literal and array query fields", () => {
292
+ expectTypeOf<ExtractQueryParamsType<Schema["queryTypes"]["$get"]>>().toEqualTypeOf<{
293
+ day: Date;
294
+ count: number;
295
+ note?: string;
296
+ }>();
297
+ expectTypeOf<ExtractQueryParamsType<Schema["queryLiteral"]["$get"]>>().toEqualTypeOf<{ alias: "Kristen" }>();
298
+ expectTypeOf<ExtractQueryParamsType<Schema["queryArray"]["$get"]>>().toEqualTypeOf<{ tags: string[] }>();
299
+ expect(true).toBe(true);
300
+ });
301
+
302
+ it("should type partial and optional query schemas with optional fields", () => {
303
+ expectTypeOf<ExtractQueryParamsType<Schema["queryPartial"]["$get"]>>().toEqualTypeOf<{ page?: string }>();
304
+ expectTypeOf<ExtractQueryParamsType<Schema["queryOptional"]["$get"]>>().toEqualTypeOf<{ page?: string }>();
305
+ expect(true).toBe(true);
306
+ });
307
+
308
+ it("should leave the query params undefined for unknown and empty query schemas", () => {
309
+ expectTypeOf<ExtractQueryParamsType<Schema["queryUnknown"]["$get"]>>().toEqualTypeOf<undefined>();
310
+ expectTypeOf<ExtractQueryParamsType<Schema["queryEmpty"]["$get"]>>().toEqualTypeOf<undefined>();
311
+ expect(true).toBe(true);
312
+ });
313
+
314
+ it("should type the query a guard adds to its routes", () => {
315
+ expectTypeOf<ExtractQueryParamsType<Schema["guarded"]["$get"]>>().toEqualTypeOf<{ token: string }>();
316
+ expect(true).toBe(true);
317
+ });
318
+ });
319
+
320
+ describe("ElysiaAppToHyperFetch [ createSdk inputs ]", () => {
321
+ const client = createClient({ url: "http://localhost" });
322
+ const sdk = createSdk<typeof client, Schema>(client);
323
+
324
+ it("should accept string and number params", () => {
325
+ sdk.params.$count.$get.setParams({ count: 1 });
326
+ sdk.params.$count.$get.setParams({ count: "1" });
327
+ // @ts-expect-error - the path names the param count
328
+ sdk.params.$count.$get.setParams({ amount: 1 });
329
+ expect(true).toBe(true);
330
+ });
331
+
332
+ it("should take FormData for a body with files", () => {
333
+ sdk.upload.$post.setPayload(new FormData());
334
+ // @ts-expect-error - a file can not be sent as JSON
335
+ sdk.upload.$post.setPayload({ title: "a", file: new Blob() });
336
+ expect(true).toBe(true);
337
+ });
338
+
339
+ it("should reject query values the schema does not accept", () => {
340
+ sdk.queryLiteral.$get.setQueryParams({ alias: "Kristen" });
341
+ // @ts-expect-error - the schema only accepts the literal
342
+ sdk.queryLiteral.$get.setQueryParams({ alias: "Other" });
343
+ expect(true).toBe(true);
344
+ });
345
+ });
@@ -0,0 +1,148 @@
1
+ import { serve } from "@hono/node-server";
2
+ import type { ServerType } from "@hono/node-server";
3
+ import { createClient, createSdk } from "@hyper-fetch/core";
4
+ import type { AddressInfo } from "node:net";
5
+
6
+ import type { ElysiaAppToHyperFetch } from "../../../src";
7
+ import { app } from "../../utils/app";
8
+
9
+ type Schema = ElysiaAppToHyperFetch<typeof app>;
10
+
11
+ // `app.fetch` is the web standard handler Elysia runs on every runtime, served here on a free port
12
+ const startServer = () =>
13
+ new Promise<ServerType>((resolve) => {
14
+ const server = serve({ fetch: app.fetch, port: 0 }, () => resolve(server));
15
+ });
16
+
17
+ const stopServer = (server: ServerType) =>
18
+ new Promise<void>((resolve, reject) => {
19
+ server.close((error) => (error ? reject(error) : resolve()));
20
+ });
21
+
22
+ describe("ElysiaAppToHyperFetch [ Requests against an Elysia server ]", () => {
23
+ let server: ServerType;
24
+ let url: string;
25
+
26
+ const createAppSdk = () => {
27
+ const client = createClient({ url });
28
+ return createSdk<typeof client, Schema>(client);
29
+ };
30
+
31
+ beforeAll(async () => {
32
+ server = await startServer();
33
+ url = `http://localhost:${(server.address() as AddressInfo).port}`;
34
+ });
35
+
36
+ afterAll(async () => {
37
+ await stopServer(server);
38
+ });
39
+
40
+ it("should send a GET to a plugin route", async () => {
41
+ const sdk = createAppSdk();
42
+
43
+ const { data, error, status } = await sdk.users.$get.send();
44
+
45
+ expect(status).toBe(200);
46
+ expect(error).toBeNull();
47
+ expect(data).toStrictEqual([{ id: "1", name: "Ann" }]);
48
+ });
49
+
50
+ it("should send to the root route", async () => {
51
+ const sdk = createAppSdk();
52
+
53
+ const { data } = await sdk.$get.send();
54
+
55
+ expect(data).toStrictEqual({ ok: true });
56
+ });
57
+
58
+ it("should fill :param segments from setParams", async () => {
59
+ const sdk = createAppSdk();
60
+
61
+ const { data } = await sdk.users.$userId.$get.setParams({ userId: "42" }).send();
62
+
63
+ expect(data).toStrictEqual({ id: "42", name: "Ann" });
64
+ });
65
+
66
+ it("should call a route with an optional param both without and with the param", async () => {
67
+ const sdk = createAppSdk();
68
+
69
+ const withoutParam = await sdk.files.$get.send();
70
+ const withParam = await sdk.files.$fileId.$get.setParams({ fileId: "report" }).send();
71
+
72
+ expect(withoutParam.data).toStrictEqual({ fileId: null });
73
+ expect(withParam.data).toStrictEqual({ fileId: "report" });
74
+ });
75
+
76
+ it("should send the payload as the JSON body the schema reads", async () => {
77
+ const sdk = createAppSdk();
78
+
79
+ const { data, status } = await sdk.users.$post.setPayload({ name: "Bob" }).send();
80
+
81
+ expect(status).toBe(201);
82
+ expect(data).toStrictEqual({ id: "2", name: "Bob" });
83
+ });
84
+
85
+ it("should send query params the schema reads", async () => {
86
+ const sdk = createAppSdk();
87
+
88
+ const { data } = await sdk.users.$userId.posts.$get.setParams({ userId: "7" }).setQueryParams({ page: "3" }).send();
89
+
90
+ expect(data).toStrictEqual({ userId: "7", page: "3" });
91
+ });
92
+
93
+ it("should resolve camelCase accessors to the kebab-case Elysia path", async () => {
94
+ const sdk = createAppSdk();
95
+ const request = sdk.auth.googleLogin.$get;
96
+
97
+ const { data } = await request.send();
98
+
99
+ expect(request.endpoint).toBe("/auth/google-login");
100
+ expect(data).toStrictEqual({ authUrl: "https://accounts.example.com" });
101
+ });
102
+
103
+ it("should send the HTTP method named by the key", async () => {
104
+ const sdk = createAppSdk();
105
+ const deleteRequest = sdk.auth.session.$delete;
106
+ const customRequest = sdk.dav.$propfind;
107
+
108
+ const deleted = await deleteRequest.send();
109
+ const custom = await customRequest.send();
110
+
111
+ expect(deleteRequest.method).toBe("DELETE");
112
+ expect(deleted.data).toStrictEqual({ loggedOut: true });
113
+ expect(customRequest.method).toBe("PROPFIND");
114
+ expect(custom.data).toStrictEqual({ dav: true });
115
+ });
116
+
117
+ it("should resolve an error status through the response", async () => {
118
+ const sdk = createAppSdk();
119
+
120
+ const { data, error, status, success } = await sdk.users.$userId.$get.setParams({ userId: "missing" }).send();
121
+
122
+ expect(success).toBe(false);
123
+ expect(status).toBe(404);
124
+ expect(data).toBeNull();
125
+ expect(error).toStrictEqual({ message: "User not found" });
126
+ });
127
+
128
+ it("should resolve a route without a 2xx status with its error", async () => {
129
+ const sdk = createAppSdk();
130
+
131
+ const { data, error, status } = await sdk.maintenance.$get.send();
132
+
133
+ expect(status).toBe(503);
134
+ expect(data).toBeNull();
135
+ expect(error).toStrictEqual({ retryAfter: 60 });
136
+ });
137
+
138
+ it("should resolve the validation error of a rejected body", async () => {
139
+ const client = createClient({ url });
140
+ const request = client.createRequest<{ payload: { name: number } }>()({ endpoint: "/users", method: "POST" });
141
+
142
+ const { error, status, success } = await request.setPayload({ name: 1 }).send();
143
+
144
+ expect(success).toBe(false);
145
+ expect(status).toBe(422);
146
+ expect(error).toMatchObject({ type: "validation", on: "body" });
147
+ });
148
+ });