@tsed/platform-test-sdk 8.11.1 → 8.11.2-rc.1

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.
Files changed (119) hide show
  1. package/lib/esm/components/PlatformTestSdk.js +0 -1
  2. package/lib/esm/errors/CustomBadRequest.js +0 -1
  3. package/lib/esm/errors/CustomInternalError.js +0 -1
  4. package/lib/esm/index.js +0 -1
  5. package/lib/esm/interfaces/PlatformTestingSdkOpts.js +0 -1
  6. package/lib/esm/interfaces/index.js +0 -1
  7. package/lib/esm/modules/feature/FeatureModule.js +0 -1
  8. package/lib/esm/modules/feature/controllers/FeatureController.js +0 -1
  9. package/lib/esm/tests/exports.js +0 -1
  10. package/lib/esm/tests/testAcceptMime.js +0 -1
  11. package/lib/esm/tests/testAuth.js +0 -1
  12. package/lib/esm/tests/testBodyParams.js +0 -1
  13. package/lib/esm/tests/testCache.js +0 -1
  14. package/lib/esm/tests/testChildrenControllers.js +0 -1
  15. package/lib/esm/tests/testCookies.js +0 -1
  16. package/lib/esm/tests/testCustom404.js +0 -1
  17. package/lib/esm/tests/testDeepQueryParams.js +0 -1
  18. package/lib/esm/tests/testErrors.js +0 -1
  19. package/lib/esm/tests/testHandlers.js +0 -1
  20. package/lib/esm/tests/testHeaderParams.js +0 -1
  21. package/lib/esm/tests/testHeaders.js +0 -1
  22. package/lib/esm/tests/testInheritanceController.js +0 -1
  23. package/lib/esm/tests/testLocals.js +0 -1
  24. package/lib/esm/tests/testLocation.js +0 -1
  25. package/lib/esm/tests/testMiddlewares.js +0 -1
  26. package/lib/esm/tests/testModule.js +0 -1
  27. package/lib/esm/tests/testMulter.js +0 -1
  28. package/lib/esm/tests/testPathParams.js +0 -1
  29. package/lib/esm/tests/testQueryParams.js +0 -1
  30. package/lib/esm/tests/testRedirect.js +0 -1
  31. package/lib/esm/tests/testResponse.js +0 -1
  32. package/lib/esm/tests/testResponseFilter.js +0 -1
  33. package/lib/esm/tests/testRouting.js +0 -1
  34. package/lib/esm/tests/testScopeRequest.js +0 -1
  35. package/lib/esm/tests/testSession.js +0 -1
  36. package/lib/esm/tests/testStatics.js +0 -1
  37. package/lib/esm/tests/testStream.js +0 -1
  38. package/lib/esm/tests/testView.js +0 -1
  39. package/package.json +18 -15
  40. package/.barrelsby.json +0 -5
  41. package/lib/esm/components/PlatformTestSdk.js.map +0 -1
  42. package/lib/esm/errors/CustomBadRequest.js.map +0 -1
  43. package/lib/esm/errors/CustomInternalError.js.map +0 -1
  44. package/lib/esm/index.js.map +0 -1
  45. package/lib/esm/interfaces/PlatformTestingSdkOpts.js.map +0 -1
  46. package/lib/esm/interfaces/index.js.map +0 -1
  47. package/lib/esm/modules/feature/FeatureModule.js.map +0 -1
  48. package/lib/esm/modules/feature/controllers/FeatureController.js.map +0 -1
  49. package/lib/esm/tests/exports.js.map +0 -1
  50. package/lib/esm/tests/testAcceptMime.js.map +0 -1
  51. package/lib/esm/tests/testAuth.js.map +0 -1
  52. package/lib/esm/tests/testBodyParams.js.map +0 -1
  53. package/lib/esm/tests/testCache.js.map +0 -1
  54. package/lib/esm/tests/testChildrenControllers.js.map +0 -1
  55. package/lib/esm/tests/testCookies.js.map +0 -1
  56. package/lib/esm/tests/testCustom404.js.map +0 -1
  57. package/lib/esm/tests/testDeepQueryParams.js.map +0 -1
  58. package/lib/esm/tests/testErrors.js.map +0 -1
  59. package/lib/esm/tests/testHandlers.js.map +0 -1
  60. package/lib/esm/tests/testHeaderParams.js.map +0 -1
  61. package/lib/esm/tests/testHeaders.js.map +0 -1
  62. package/lib/esm/tests/testInheritanceController.js.map +0 -1
  63. package/lib/esm/tests/testLocals.js.map +0 -1
  64. package/lib/esm/tests/testLocation.js.map +0 -1
  65. package/lib/esm/tests/testMiddlewares.js.map +0 -1
  66. package/lib/esm/tests/testModule.js.map +0 -1
  67. package/lib/esm/tests/testMulter.js.map +0 -1
  68. package/lib/esm/tests/testPathParams.js.map +0 -1
  69. package/lib/esm/tests/testQueryParams.js.map +0 -1
  70. package/lib/esm/tests/testRedirect.js.map +0 -1
  71. package/lib/esm/tests/testResponse.js.map +0 -1
  72. package/lib/esm/tests/testResponseFilter.js.map +0 -1
  73. package/lib/esm/tests/testRouting.js.map +0 -1
  74. package/lib/esm/tests/testScopeRequest.js.map +0 -1
  75. package/lib/esm/tests/testSession.js.map +0 -1
  76. package/lib/esm/tests/testStatics.js.map +0 -1
  77. package/lib/esm/tests/testStream.js.map +0 -1
  78. package/lib/esm/tests/testView.js.map +0 -1
  79. package/src/components/PlatformTestSdk.ts +0 -30
  80. package/src/data/file.txt +0 -1
  81. package/src/data/response.data.json +0 -3
  82. package/src/data/swagger.json +0 -32
  83. package/src/errors/CustomBadRequest.ts +0 -16
  84. package/src/errors/CustomInternalError.ts +0 -16
  85. package/src/index.ts +0 -40
  86. package/src/interfaces/PlatformTestingSdkOpts.ts +0 -10
  87. package/src/interfaces/index.ts +0 -4
  88. package/src/modules/feature/FeatureModule.ts +0 -10
  89. package/src/modules/feature/controllers/FeatureController.ts +0 -11
  90. package/src/tests/exports.ts +0 -71
  91. package/src/tests/testAcceptMime.ts +0 -99
  92. package/src/tests/testAuth.ts +0 -345
  93. package/src/tests/testBodyParams.ts +0 -525
  94. package/src/tests/testCache.ts +0 -283
  95. package/src/tests/testChildrenControllers.ts +0 -59
  96. package/src/tests/testCookies.ts +0 -41
  97. package/src/tests/testCustom404.ts +0 -35
  98. package/src/tests/testDeepQueryParams.ts +0 -125
  99. package/src/tests/testErrors.ts +0 -233
  100. package/src/tests/testHandlers.ts +0 -94
  101. package/src/tests/testHeaderParams.ts +0 -158
  102. package/src/tests/testHeaders.ts +0 -78
  103. package/src/tests/testInheritanceController.ts +0 -206
  104. package/src/tests/testLocals.ts +0 -53
  105. package/src/tests/testLocation.ts +0 -40
  106. package/src/tests/testMiddlewares.ts +0 -155
  107. package/src/tests/testModule.ts +0 -50
  108. package/src/tests/testMulter.ts +0 -186
  109. package/src/tests/testPathParams.ts +0 -127
  110. package/src/tests/testQueryParams.ts +0 -238
  111. package/src/tests/testRedirect.ts +0 -129
  112. package/src/tests/testResponse.ts +0 -573
  113. package/src/tests/testResponseFilter.ts +0 -106
  114. package/src/tests/testRouting.ts +0 -71
  115. package/src/tests/testScopeRequest.ts +0 -116
  116. package/src/tests/testSession.ts +0 -109
  117. package/src/tests/testStatics.ts +0 -64
  118. package/src/tests/testStream.ts +0 -63
  119. package/src/tests/testView.ts +0 -75
@@ -1,525 +0,0 @@
1
- import "@tsed/ajv";
2
-
3
- import {Controller} from "@tsed/di";
4
- import {PlatformTest} from "@tsed/platform-http/testing";
5
- import {BodyParams, Context, HeaderParams, RawBodyParams} from "@tsed/platform-params";
6
- import {
7
- Consumes,
8
- Default,
9
- Description,
10
- GenericOf,
11
- Generics,
12
- Maximum,
13
- Minimum,
14
- Nullable,
15
- Post,
16
- Property,
17
- Required,
18
- Status
19
- } from "@tsed/schema";
20
- import SuperTest from "supertest";
21
- import {afterAll, beforeAll, describe, expect, it} from "vitest";
22
-
23
- import {PlatformTestingSdkOpts} from "../interfaces/index.js";
24
-
25
- enum MyEnum {
26
- TITLE,
27
- AGE
28
- }
29
-
30
- class NestedModel {
31
- @Property()
32
- id: string;
33
- }
34
-
35
- class NullModel {
36
- @Property()
37
- prop1: string;
38
-
39
- @Property()
40
- prop2: number;
41
-
42
- @Property()
43
- prop3: Date;
44
-
45
- @Nullable(NestedModel)
46
- prop4: NestedModel;
47
- }
48
-
49
- class FindQuery {
50
- @Property()
51
- a?: string;
52
-
53
- @Property()
54
- b?: string;
55
- }
56
-
57
- @Generics("T")
58
- class PaginationQuery<T> {
59
- // things about pagination
60
- @Minimum(0)
61
- @Default(0)
62
- offset?: number;
63
-
64
- @Minimum(1)
65
- @Maximum(1000)
66
- @Default(50)
67
- limit?: number;
68
-
69
- @Property("T")
70
- where?: T;
71
- }
72
-
73
- class Param1Type {
74
- @Required()
75
- value1!: string;
76
- }
77
-
78
- class Param2Type {
79
- @Required()
80
- value2!: string;
81
- }
82
-
83
- export class TestModel {
84
- @Required()
85
- name: string;
86
- }
87
-
88
- @Controller("/body-params")
89
- class TestBodyParamsCtrl {
90
- @Post("/scenario-1")
91
- @Status(201)
92
- @Description("retrieve body and header content-type")
93
- testScenario1(@HeaderParams("Content-type") contentType: string, @BodyParams() payload: any) {
94
- return {payload, contentType};
95
- }
96
-
97
- @Post("/scenario-2")
98
- @Description("Extract field from body payload as string[]")
99
- testScenario2(@BodyParams("test") value: string[]): any {
100
- return {value};
101
- }
102
-
103
- @Post("/scenario-3")
104
- @Description("Extract body payload as string[]")
105
- testScenario3(@BodyParams() value: string[]): any {
106
- return {value};
107
- }
108
-
109
- @Post("/scenario-4")
110
- @Description("Extract field from body payload as string[] with required annotation")
111
- testScenario4(@Required() @BodyParams("test") value: string[]): any {
112
- return {value};
113
- }
114
-
115
- @Post("/scenario-4b")
116
- @Description("Extract field from body payload as string")
117
- testScenario4b(@Required() @BodyParams("test") value: string): any {
118
- return {value};
119
- }
120
-
121
- @Post("/scenario-4c")
122
- @Description("Extract field from body payload as number with required annotation")
123
- testScenario4c(@Required() @BodyParams("test") value: number): any {
124
- return {value};
125
- }
126
-
127
- @Post("/scenario-5")
128
- @Description("Extract raw body payload as Buffer")
129
- testScenario5(@RawBodyParams() raw: Buffer, @BodyParams() payload: any, @Context() context: Context): any {
130
- return {value: raw.toString("utf8")};
131
- }
132
-
133
- @Post("/scenario-6")
134
- testScenario6(@BodyParams("type", String) type: keyof typeof MyEnum): any {
135
- return {type};
136
- }
137
-
138
- @Post("/scenario-7")
139
- testScenario7(@BodyParams("test") value: string): any {
140
- return {value};
141
- }
142
-
143
- @Post("/scenario-8")
144
- testScenario8(@BodyParams() model: NullModel) {
145
- return {model};
146
- }
147
-
148
- @Post("/scenario-9")
149
- testScenario9(@BodyParams() @GenericOf(FindQuery) q: PaginationQuery<FindQuery>) {
150
- return {q};
151
- }
152
-
153
- @Post("/scenario-10")
154
- testScenario10(
155
- @Required() @BodyParams("param1", Param1Type) param1: Param1Type,
156
- @Required() @BodyParams("param2", Param2Type) param2: Param2Type
157
- ) {
158
- return {param1, param2};
159
- }
160
-
161
- @Post("/scenario-11")
162
- @Consumes("application/x-www-form-urlencoded")
163
- testScenario11(@Required() @BodyParams("client_id") client_id: string) {
164
- return {client_id};
165
- }
166
-
167
- @Post("/scenario-12")
168
- @Description("Test payload given to BodyParams with any type to emulate metadata less behavior")
169
- testScenario12(@BodyParams(TestModel) payload: any) {
170
- return {payload};
171
- }
172
- }
173
-
174
- export function testBodyParams(options: PlatformTestingSdkOpts) {
175
- let request: SuperTest.Agent;
176
-
177
- beforeAll(
178
- PlatformTest.bootstrap(options.server, {
179
- ...options,
180
- mount: {
181
- "/rest": [TestBodyParamsCtrl]
182
- }
183
- })
184
- );
185
- beforeAll(() => {
186
- request = SuperTest(PlatformTest.callback());
187
- });
188
- afterAll(PlatformTest.reset);
189
-
190
- describe("Scenario 1: POST /rest/body-params/scenario-1", () => {
191
- it("should return a 201 response", async () => {
192
- const response = await request
193
- .post("/rest/body-params/scenario-1")
194
- .set({
195
- "Content-Type": "application/json"
196
- })
197
- .send({
198
- id: "id"
199
- })
200
- .expect(201);
201
-
202
- expect(response.body).toEqual({
203
- contentType: "application/json",
204
- payload: {
205
- id: "id"
206
- }
207
- });
208
- });
209
- });
210
- describe("Scenario2: with expression Array<string>", () => {
211
- it("should return value", async () => {
212
- const response = await request
213
- .post("/rest/body-params/scenario-2")
214
- .send({
215
- test: ["value"]
216
- })
217
- .expect(200);
218
-
219
- expect(response.body).toEqual({value: ["value"]});
220
- });
221
- it("should return an empty array (1)", async () => {
222
- const response = await request.post("/rest/body-params/scenario-2").send().expect(200);
223
-
224
- expect(response.body).toEqual({});
225
- });
226
- it("should return an empty value (2)", async () => {
227
- const response = await request.post("/rest/body-params/scenario-2").send({}).expect(200);
228
-
229
- expect(response.body).toEqual({});
230
- });
231
- });
232
- describe("Scenario3: without expression Array<string>", () => {
233
- it("should return value", async () => {
234
- const response = await request.post("/rest/body-params/scenario-3").send(["value"]).expect(200);
235
-
236
- expect(response.body).toEqual({value: ["value"]});
237
- });
238
- it("should return an empty array (1)", async () => {
239
- const response = await request.post("/rest/body-params/scenario-3").send({}).expect(200);
240
-
241
- expect(response.body).toEqual({value: [{}]});
242
- });
243
- });
244
- describe("Scenario4: with expression required Array<string>", () => {
245
- it("should return value", async () => {
246
- const response = await request
247
- .post("/rest/body-params/scenario-4")
248
- .send({test: ["value"]})
249
- .expect(200);
250
-
251
- expect(response.body).toEqual({value: ["value"]});
252
- });
253
- it("should throw an exception", async () => {
254
- const response = await request.post("/rest/body-params/scenario-4").send().expect(400);
255
-
256
- expect(response.body).toEqual({
257
- name: "REQUIRED_VALIDATION_ERROR",
258
- message: "Bad request on parameter \"request.body.test\".\nIt should have required parameter 'test'",
259
- status: 400,
260
- errors: [
261
- {
262
- requestPath: "body",
263
- dataPath: ".test",
264
- keyword: "required",
265
- message: "It should have required parameter 'test'",
266
- modelName: "body",
267
- params: {missingProperty: "test"},
268
- schemaPath: "#/required"
269
- }
270
- ]
271
- });
272
- });
273
- });
274
- describe("Scenario4b: with expression required String", () => {
275
- it("should return value", async () => {
276
- const response = await request.post("/rest/body-params/scenario-4b").send({test: "value"}).expect(200);
277
-
278
- expect(response.body).toEqual({value: "value"});
279
- });
280
- it("should throw an exception when nothing is sent", async () => {
281
- const response = await request.post("/rest/body-params/scenario-4b").send().expect(400);
282
-
283
- expect(response.body).toEqual({
284
- name: "REQUIRED_VALIDATION_ERROR",
285
- message: "Bad request on parameter \"request.body.test\".\nIt should have required parameter 'test'",
286
- status: 400,
287
- errors: [
288
- {
289
- requestPath: "body",
290
- dataPath: ".test",
291
- keyword: "required",
292
- message: "It should have required parameter 'test'",
293
- modelName: "body",
294
- params: {missingProperty: "test"},
295
- schemaPath: "#/required"
296
- }
297
- ]
298
- });
299
- });
300
- it("should throw an exception when nothing is an empty string is sent", async () => {
301
- const response = await request.post("/rest/body-params/scenario-4b").send({test: ""}).expect(400);
302
-
303
- expect(response.body).toEqual({
304
- name: "REQUIRED_VALIDATION_ERROR",
305
- message: "Bad request on parameter \"request.body.test\".\nIt should have required parameter 'test'",
306
- status: 400,
307
- errors: [
308
- {
309
- dataPath: ".test",
310
- requestPath: "body",
311
- keyword: "required",
312
- message: "It should have required parameter 'test'",
313
- modelName: "body",
314
- params: {missingProperty: "test"},
315
- schemaPath: "#/required"
316
- }
317
- ]
318
- });
319
- });
320
- });
321
- describe("Scenario4c: with expression required Number", () => {
322
- it("should return value (with 1)", async () => {
323
- const response = await request.post("/rest/body-params/scenario-4c").send({test: 1}).expect(200);
324
-
325
- expect(response.body).toEqual({value: 1});
326
- });
327
- it("should return value (with 0)", async () => {
328
- const response = await request.post("/rest/body-params/scenario-4c").send({test: 0}).expect(200);
329
-
330
- expect(response.body).toEqual({value: 0});
331
- });
332
- it("should throw an exception when nothing is sent", async () => {
333
- const response = await request.post("/rest/body-params/scenario-4b").send().expect(400);
334
-
335
- expect(response.body).toEqual({
336
- name: "REQUIRED_VALIDATION_ERROR",
337
- message: "Bad request on parameter \"request.body.test\".\nIt should have required parameter 'test'",
338
- status: 400,
339
- errors: [
340
- {
341
- dataPath: ".test",
342
- requestPath: "body",
343
- keyword: "required",
344
- message: "It should have required parameter 'test'",
345
- modelName: "body",
346
- params: {missingProperty: "test"},
347
- schemaPath: "#/required"
348
- }
349
- ]
350
- });
351
- });
352
- });
353
- describe("Scenario5: with raw payload", () => {
354
- it("should return value", async () => {
355
- const response = await request.post("/rest/body-params/scenario-5").send('{"test": ["value"]}').expect(200);
356
-
357
- expect(response.body).toEqual({
358
- value: '{"test": ["value"]}'
359
- });
360
- });
361
- });
362
- describe("Scenario6: Enum", () => {
363
- it("should return value", async () => {
364
- const response = await request.post("/rest/body-params/scenario-6").send({
365
- type: "TITLE"
366
- });
367
-
368
- expect(response.body).toEqual({
369
- type: "TITLE"
370
- });
371
- });
372
- });
373
- describe("Scenario7: payload with Null", () => {
374
- it("should return value", async () => {
375
- const response = await request.post("/rest/body-params/scenario-7").send({
376
- test: null
377
- });
378
-
379
- expect(response.body).toEqual({
380
- value: null
381
- });
382
- });
383
- });
384
- describe("Scenario8: payload with props to null", () => {
385
- it("should return value with null value", async () => {
386
- const response = await request.post("/rest/body-params/scenario-8").send({
387
- prop1: null,
388
- prop2: null,
389
- prop3: null,
390
- prop4: null
391
- });
392
-
393
- expect(response.body).toEqual({
394
- model: {
395
- prop1: null,
396
- prop2: null,
397
- prop3: null,
398
- prop4: null
399
- }
400
- });
401
- });
402
- });
403
- describe("Scenario9: payload with Generics", () => {
404
- it("should return value", async () => {
405
- const response = await request
406
- .post("/rest/body-params/scenario-9")
407
- .send({
408
- offset: 0,
409
- limit: 10,
410
- where: {
411
- a: "ca",
412
- b: "cb"
413
- }
414
- })
415
- .expect(200);
416
-
417
- expect(response.body).toEqual({
418
- q: {
419
- limit: 10,
420
- offset: 0,
421
- where: {
422
- a: "ca",
423
- b: "cb"
424
- }
425
- }
426
- });
427
- });
428
- it("should throw a bad request", async () => {
429
- const response = await request
430
- .post("/rest/body-params/scenario-9")
431
- .send({
432
- offset: 0,
433
- limit: 0,
434
- where: {
435
- a: "ca",
436
- b: "cb"
437
- }
438
- })
439
- .expect(400);
440
-
441
- expect(response.body).toEqual({
442
- errors: [
443
- {
444
- data: 0,
445
- requestPath: "body",
446
- dataPath: ".limit",
447
- instancePath: "/limit",
448
- keyword: "minimum",
449
- message: "must be >= 1",
450
- modelName: "PaginationQuery",
451
- params: {
452
- comparison: ">=",
453
- limit: 1
454
- },
455
- schemaPath: "#/properties/limit/minimum"
456
- }
457
- ],
458
- message: 'Bad request on parameter "request.body".\nPaginationQuery.limit must be >= 1. Given value: 0',
459
- name: "AJV_VALIDATION_ERROR",
460
- status: 400
461
- });
462
- });
463
- });
464
- describe("Scenario10: validate two payload", () => {
465
- it("should throw a Bad request if body params is missing (1)", async () => {
466
- await request
467
- .post("/rest/body-params/scenario-10")
468
- .send({param1: {}, param2: {value2: "value"}})
469
- .expect(400);
470
- });
471
- it("should throw a Bad request if body params is missing (2)", async () => {
472
- await request.post("/rest/body-params/scenario-10").send({param1: {}, param2: {}}).expect(400);
473
- });
474
- it("should throw a Bad request if body params is missing (3)", async () => {
475
- await request
476
- .post("/rest/body-params/scenario-10")
477
- .send({param1: {value: "value"}, param2: {}})
478
- .expect(400);
479
- });
480
- it("should throw a Bad request if body params is missing (4)", async () => {
481
- await request.post("/rest/body-params/scenario-10").send({}).expect(400);
482
- });
483
- it("should validate the body params", async () => {
484
- await request
485
- .post("/rest/body-params/scenario-10")
486
- .send({param1: {value1: "value"}, param2: {value2: "value"}})
487
- .expect(200);
488
- });
489
- });
490
- describe("Scenario11: validate application/x-www-form-urlencoded body", () => {
491
- it("should validate the body params", async () => {
492
- await request
493
- .post("/rest/body-params/scenario-11")
494
- .set("Content-Type", "application/x-www-form-urlencoded")
495
- .send("client_id=id&grant_type=grant")
496
- .expect(200);
497
- });
498
- });
499
-
500
- describe("Scenario12: validate payload with any type", () => {
501
- it("should throw a Bad Request if the payload is invalid", async () => {
502
- const response = await request.post("/rest/body-params/scenario-12").send({}).expect(400);
503
-
504
- expect(response.body).toEqual({
505
- errors: [
506
- {
507
- dataPath: ".name",
508
- instancePath: "",
509
- keyword: "required",
510
- message: "must have required property 'name'",
511
- modelName: "TestModel",
512
- params: {
513
- missingProperty: "name"
514
- },
515
- requestPath: "body",
516
- schemaPath: "#/required"
517
- }
518
- ],
519
- message: 'Bad request on parameter "request.body".\nTestModel must have required property \'name\'. Given value: "undefined"',
520
- name: "AJV_VALIDATION_ERROR",
521
- status: 400
522
- });
523
- });
524
- });
525
- }