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