@tsed/platform-test-sdk 7.73.1 → 7.73.3

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 (121) hide show
  1. package/package.json +14 -14
  2. package/lib/cjs/components/PlatformTestSdk.js.map +0 -1
  3. package/lib/cjs/errors/CustomBadRequest.js.map +0 -1
  4. package/lib/cjs/errors/CustomInternalError.js.map +0 -1
  5. package/lib/cjs/index.js.map +0 -1
  6. package/lib/cjs/interfaces/PlatformTestingSdkOpts.js.map +0 -1
  7. package/lib/cjs/interfaces/index.js.map +0 -1
  8. package/lib/cjs/modules/feature/FeatureModule.js.map +0 -1
  9. package/lib/cjs/modules/feature/controllers/FeatureController.js.map +0 -1
  10. package/lib/cjs/tests/exports.js.map +0 -1
  11. package/lib/cjs/tests/testAcceptMime.js.map +0 -1
  12. package/lib/cjs/tests/testAuth.js.map +0 -1
  13. package/lib/cjs/tests/testBodyParams.js.map +0 -1
  14. package/lib/cjs/tests/testCache.js.map +0 -1
  15. package/lib/cjs/tests/testChildrenControllers.js.map +0 -1
  16. package/lib/cjs/tests/testCookies.js.map +0 -1
  17. package/lib/cjs/tests/testCustom404.js.map +0 -1
  18. package/lib/cjs/tests/testDeepQueryParams.js.map +0 -1
  19. package/lib/cjs/tests/testErrors.js.map +0 -1
  20. package/lib/cjs/tests/testHandlers.js.map +0 -1
  21. package/lib/cjs/tests/testHeaderParams.js.map +0 -1
  22. package/lib/cjs/tests/testHeaders.js.map +0 -1
  23. package/lib/cjs/tests/testInheritanceController.js.map +0 -1
  24. package/lib/cjs/tests/testLocals.js.map +0 -1
  25. package/lib/cjs/tests/testLocation.js.map +0 -1
  26. package/lib/cjs/tests/testMiddlewares.js.map +0 -1
  27. package/lib/cjs/tests/testModule.js.map +0 -1
  28. package/lib/cjs/tests/testMulter.js.map +0 -1
  29. package/lib/cjs/tests/testPathParams.js.map +0 -1
  30. package/lib/cjs/tests/testQueryParams.js.map +0 -1
  31. package/lib/cjs/tests/testRedirect.js.map +0 -1
  32. package/lib/cjs/tests/testResponse.js.map +0 -1
  33. package/lib/cjs/tests/testResponseFilter.js.map +0 -1
  34. package/lib/cjs/tests/testRouting.js.map +0 -1
  35. package/lib/cjs/tests/testScopeRequest.js.map +0 -1
  36. package/lib/cjs/tests/testSession.js.map +0 -1
  37. package/lib/cjs/tests/testStatics.js.map +0 -1
  38. package/lib/cjs/tests/testStream.js.map +0 -1
  39. package/lib/cjs/tests/testView.js.map +0 -1
  40. package/lib/esm/components/PlatformTestSdk.js.map +0 -1
  41. package/lib/esm/errors/CustomBadRequest.js.map +0 -1
  42. package/lib/esm/errors/CustomInternalError.js.map +0 -1
  43. package/lib/esm/index.js.map +0 -1
  44. package/lib/esm/interfaces/PlatformTestingSdkOpts.js.map +0 -1
  45. package/lib/esm/interfaces/index.js.map +0 -1
  46. package/lib/esm/modules/feature/FeatureModule.js.map +0 -1
  47. package/lib/esm/modules/feature/controllers/FeatureController.js.map +0 -1
  48. package/lib/esm/tests/exports.js.map +0 -1
  49. package/lib/esm/tests/testAcceptMime.js.map +0 -1
  50. package/lib/esm/tests/testAuth.js.map +0 -1
  51. package/lib/esm/tests/testBodyParams.js.map +0 -1
  52. package/lib/esm/tests/testCache.js.map +0 -1
  53. package/lib/esm/tests/testChildrenControllers.js.map +0 -1
  54. package/lib/esm/tests/testCookies.js.map +0 -1
  55. package/lib/esm/tests/testCustom404.js.map +0 -1
  56. package/lib/esm/tests/testDeepQueryParams.js.map +0 -1
  57. package/lib/esm/tests/testErrors.js.map +0 -1
  58. package/lib/esm/tests/testHandlers.js.map +0 -1
  59. package/lib/esm/tests/testHeaderParams.js.map +0 -1
  60. package/lib/esm/tests/testHeaders.js.map +0 -1
  61. package/lib/esm/tests/testInheritanceController.js.map +0 -1
  62. package/lib/esm/tests/testLocals.js.map +0 -1
  63. package/lib/esm/tests/testLocation.js.map +0 -1
  64. package/lib/esm/tests/testMiddlewares.js.map +0 -1
  65. package/lib/esm/tests/testModule.js.map +0 -1
  66. package/lib/esm/tests/testMulter.js.map +0 -1
  67. package/lib/esm/tests/testPathParams.js.map +0 -1
  68. package/lib/esm/tests/testQueryParams.js.map +0 -1
  69. package/lib/esm/tests/testRedirect.js.map +0 -1
  70. package/lib/esm/tests/testResponse.js.map +0 -1
  71. package/lib/esm/tests/testResponseFilter.js.map +0 -1
  72. package/lib/esm/tests/testRouting.js.map +0 -1
  73. package/lib/esm/tests/testScopeRequest.js.map +0 -1
  74. package/lib/esm/tests/testSession.js.map +0 -1
  75. package/lib/esm/tests/testStatics.js.map +0 -1
  76. package/lib/esm/tests/testStream.js.map +0 -1
  77. package/lib/esm/tests/testView.js.map +0 -1
  78. package/lib/tsconfig.esm.tsbuildinfo +0 -1
  79. package/lib/tsconfig.tsbuildinfo +0 -1
  80. package/src/components/PlatformTestSdk.ts +0 -29
  81. package/src/data/file.txt +0 -1
  82. package/src/data/response.data.json +0 -3
  83. package/src/data/swagger.json +0 -32
  84. package/src/errors/CustomBadRequest.ts +0 -16
  85. package/src/errors/CustomInternalError.ts +0 -16
  86. package/src/index.ts +0 -40
  87. package/src/interfaces/PlatformTestingSdkOpts.ts +0 -10
  88. package/src/interfaces/index.ts +0 -4
  89. package/src/modules/feature/FeatureModule.ts +0 -9
  90. package/src/modules/feature/controllers/FeatureController.ts +0 -11
  91. package/src/tests/exports.ts +0 -71
  92. package/src/tests/testAcceptMime.ts +0 -95
  93. package/src/tests/testAuth.ts +0 -339
  94. package/src/tests/testBodyParams.ts +0 -483
  95. package/src/tests/testCache.ts +0 -279
  96. package/src/tests/testChildrenControllers.ts +0 -55
  97. package/src/tests/testCookies.ts +0 -36
  98. package/src/tests/testCustom404.ts +0 -33
  99. package/src/tests/testDeepQueryParams.ts +0 -120
  100. package/src/tests/testErrors.ts +0 -226
  101. package/src/tests/testHandlers.ts +0 -90
  102. package/src/tests/testHeaderParams.ts +0 -152
  103. package/src/tests/testHeaders.ts +0 -91
  104. package/src/tests/testInheritanceController.ts +0 -200
  105. package/src/tests/testLocals.ts +0 -46
  106. package/src/tests/testLocation.ts +0 -37
  107. package/src/tests/testMiddlewares.ts +0 -159
  108. package/src/tests/testModule.ts +0 -46
  109. package/src/tests/testMulter.ts +0 -151
  110. package/src/tests/testPathParams.ts +0 -123
  111. package/src/tests/testQueryParams.ts +0 -233
  112. package/src/tests/testRedirect.ts +0 -124
  113. package/src/tests/testResponse.ts +0 -528
  114. package/src/tests/testResponseFilter.ts +0 -101
  115. package/src/tests/testRouting.ts +0 -65
  116. package/src/tests/testScopeRequest.ts +0 -111
  117. package/src/tests/testSession.ts +0 -103
  118. package/src/tests/testStatics.ts +0 -61
  119. package/src/tests/testStream.ts +0 -59
  120. package/src/tests/testView.ts +0 -68
  121. package/tsconfig.json +0 -63
@@ -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
- }