@tsed/platform-test-sdk 7.12.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 (231) hide show
  1. package/lib/cjs/components/PlatformTestSdk.js +31 -0
  2. package/lib/cjs/components/PlatformTestSdk.js.map +1 -0
  3. package/lib/cjs/data/swagger.json +32 -0
  4. package/lib/cjs/errors/CustomBadRequest.js +18 -0
  5. package/lib/cjs/errors/CustomBadRequest.js.map +1 -0
  6. package/lib/cjs/errors/CustomInternalError.js +18 -0
  7. package/lib/cjs/errors/CustomInternalError.js.map +1 -0
  8. package/lib/cjs/index.js +42 -0
  9. package/lib/cjs/index.js.map +1 -0
  10. package/lib/cjs/interfaces/PlatformTestingSdkOpts.js +3 -0
  11. package/lib/cjs/interfaces/PlatformTestingSdkOpts.js.map +1 -0
  12. package/lib/cjs/interfaces/index.js +8 -0
  13. package/lib/cjs/interfaces/index.js.map +1 -0
  14. package/lib/cjs/modules/feature/FeatureModule.js +17 -0
  15. package/lib/cjs/modules/feature/FeatureModule.js.map +1 -0
  16. package/lib/cjs/modules/feature/controllers/FeatureController.js +23 -0
  17. package/lib/cjs/modules/feature/controllers/FeatureController.js.map +1 -0
  18. package/lib/cjs/package.json +3 -0
  19. package/lib/cjs/tests/exports.js +66 -0
  20. package/lib/cjs/tests/exports.js.map +1 -0
  21. package/lib/cjs/tests/testAcceptMime.js +103 -0
  22. package/lib/cjs/tests/testAcceptMime.js.map +1 -0
  23. package/lib/cjs/tests/testAuth.js +343 -0
  24. package/lib/cjs/tests/testAuth.js.map +1 -0
  25. package/lib/cjs/tests/testBodyParams.js +526 -0
  26. package/lib/cjs/tests/testBodyParams.js.map +1 -0
  27. package/lib/cjs/tests/testCache.js +292 -0
  28. package/lib/cjs/tests/testCache.js.map +1 -0
  29. package/lib/cjs/tests/testChildrenControllers.js +64 -0
  30. package/lib/cjs/tests/testChildrenControllers.js.map +1 -0
  31. package/lib/cjs/tests/testCookies.js +45 -0
  32. package/lib/cjs/tests/testCookies.js.map +1 -0
  33. package/lib/cjs/tests/testCtrlInheritance.js +161 -0
  34. package/lib/cjs/tests/testCtrlInheritance.js.map +1 -0
  35. package/lib/cjs/tests/testCustom404.js +32 -0
  36. package/lib/cjs/tests/testCustom404.js.map +1 -0
  37. package/lib/cjs/tests/testErrors.js +252 -0
  38. package/lib/cjs/tests/testErrors.js.map +1 -0
  39. package/lib/cjs/tests/testHandlers.js +110 -0
  40. package/lib/cjs/tests/testHandlers.js.map +1 -0
  41. package/lib/cjs/tests/testHeaderParams.js +166 -0
  42. package/lib/cjs/tests/testHeaderParams.js.map +1 -0
  43. package/lib/cjs/tests/testHeaders.js +101 -0
  44. package/lib/cjs/tests/testHeaders.js.map +1 -0
  45. package/lib/cjs/tests/testInheritanceController.js +173 -0
  46. package/lib/cjs/tests/testInheritanceController.js.map +1 -0
  47. package/lib/cjs/tests/testLocals.js +63 -0
  48. package/lib/cjs/tests/testLocals.js.map +1 -0
  49. package/lib/cjs/tests/testLocation.js +42 -0
  50. package/lib/cjs/tests/testLocation.js.map +1 -0
  51. package/lib/cjs/tests/testMiddlewares.js +210 -0
  52. package/lib/cjs/tests/testMiddlewares.js.map +1 -0
  53. package/lib/cjs/tests/testModule.js +49 -0
  54. package/lib/cjs/tests/testModule.js.map +1 -0
  55. package/lib/cjs/tests/testMulter.js +162 -0
  56. package/lib/cjs/tests/testMulter.js.map +1 -0
  57. package/lib/cjs/tests/testPathParams.js +142 -0
  58. package/lib/cjs/tests/testPathParams.js.map +1 -0
  59. package/lib/cjs/tests/testQueryParams.js +354 -0
  60. package/lib/cjs/tests/testQueryParams.js.map +1 -0
  61. package/lib/cjs/tests/testRedirect.js +143 -0
  62. package/lib/cjs/tests/testRedirect.js.map +1 -0
  63. package/lib/cjs/tests/testResponse.js +622 -0
  64. package/lib/cjs/tests/testResponse.js.map +1 -0
  65. package/lib/cjs/tests/testResponseFilter.js +107 -0
  66. package/lib/cjs/tests/testResponseFilter.js.map +1 -0
  67. package/lib/cjs/tests/testRouting.js +75 -0
  68. package/lib/cjs/tests/testRouting.js.map +1 -0
  69. package/lib/cjs/tests/testScopeRequest.js +116 -0
  70. package/lib/cjs/tests/testScopeRequest.js.map +1 -0
  71. package/lib/cjs/tests/testSession.js +128 -0
  72. package/lib/cjs/tests/testSession.js.map +1 -0
  73. package/lib/cjs/tests/testStatics.js +58 -0
  74. package/lib/cjs/tests/testStatics.js.map +1 -0
  75. package/lib/cjs/tests/testView.js +83 -0
  76. package/lib/cjs/tests/testView.js.map +1 -0
  77. package/lib/esm/components/PlatformTestSdk.js +27 -0
  78. package/lib/esm/components/PlatformTestSdk.js.map +1 -0
  79. package/lib/esm/data/swagger.json +32 -0
  80. package/lib/esm/errors/CustomBadRequest.js +14 -0
  81. package/lib/esm/errors/CustomBadRequest.js.map +1 -0
  82. package/lib/esm/errors/CustomInternalError.js +14 -0
  83. package/lib/esm/errors/CustomInternalError.js.map +1 -0
  84. package/lib/esm/index.js +39 -0
  85. package/lib/esm/index.js.map +1 -0
  86. package/lib/esm/interfaces/PlatformTestingSdkOpts.js +2 -0
  87. package/lib/esm/interfaces/PlatformTestingSdkOpts.js.map +1 -0
  88. package/lib/esm/interfaces/index.js +5 -0
  89. package/lib/esm/interfaces/index.js.map +1 -0
  90. package/lib/esm/modules/feature/FeatureModule.js +14 -0
  91. package/lib/esm/modules/feature/FeatureModule.js.map +1 -0
  92. package/lib/esm/modules/feature/controllers/FeatureController.js +20 -0
  93. package/lib/esm/modules/feature/controllers/FeatureController.js.map +1 -0
  94. package/lib/esm/package.json +3 -0
  95. package/lib/esm/tests/exports.js +63 -0
  96. package/lib/esm/tests/exports.js.map +1 -0
  97. package/lib/esm/tests/testAcceptMime.js +99 -0
  98. package/lib/esm/tests/testAcceptMime.js.map +1 -0
  99. package/lib/esm/tests/testAuth.js +338 -0
  100. package/lib/esm/tests/testAuth.js.map +1 -0
  101. package/lib/esm/tests/testBodyParams.js +522 -0
  102. package/lib/esm/tests/testBodyParams.js.map +1 -0
  103. package/lib/esm/tests/testCache.js +288 -0
  104. package/lib/esm/tests/testCache.js.map +1 -0
  105. package/lib/esm/tests/testChildrenControllers.js +60 -0
  106. package/lib/esm/tests/testChildrenControllers.js.map +1 -0
  107. package/lib/esm/tests/testCookies.js +41 -0
  108. package/lib/esm/tests/testCookies.js.map +1 -0
  109. package/lib/esm/tests/testCtrlInheritance.js +156 -0
  110. package/lib/esm/tests/testCtrlInheritance.js.map +1 -0
  111. package/lib/esm/tests/testCustom404.js +27 -0
  112. package/lib/esm/tests/testCustom404.js.map +1 -0
  113. package/lib/esm/tests/testErrors.js +248 -0
  114. package/lib/esm/tests/testErrors.js.map +1 -0
  115. package/lib/esm/tests/testHandlers.js +105 -0
  116. package/lib/esm/tests/testHandlers.js.map +1 -0
  117. package/lib/esm/tests/testHeaderParams.js +162 -0
  118. package/lib/esm/tests/testHeaderParams.js.map +1 -0
  119. package/lib/esm/tests/testHeaders.js +97 -0
  120. package/lib/esm/tests/testHeaders.js.map +1 -0
  121. package/lib/esm/tests/testInheritanceController.js +167 -0
  122. package/lib/esm/tests/testInheritanceController.js.map +1 -0
  123. package/lib/esm/tests/testLocals.js +59 -0
  124. package/lib/esm/tests/testLocals.js.map +1 -0
  125. package/lib/esm/tests/testLocation.js +38 -0
  126. package/lib/esm/tests/testLocation.js.map +1 -0
  127. package/lib/esm/tests/testMiddlewares.js +206 -0
  128. package/lib/esm/tests/testMiddlewares.js.map +1 -0
  129. package/lib/esm/tests/testModule.js +45 -0
  130. package/lib/esm/tests/testModule.js.map +1 -0
  131. package/lib/esm/tests/testMulter.js +156 -0
  132. package/lib/esm/tests/testMulter.js.map +1 -0
  133. package/lib/esm/tests/testPathParams.js +138 -0
  134. package/lib/esm/tests/testPathParams.js.map +1 -0
  135. package/lib/esm/tests/testQueryParams.js +349 -0
  136. package/lib/esm/tests/testQueryParams.js.map +1 -0
  137. package/lib/esm/tests/testRedirect.js +139 -0
  138. package/lib/esm/tests/testRedirect.js.map +1 -0
  139. package/lib/esm/tests/testResponse.js +615 -0
  140. package/lib/esm/tests/testResponse.js.map +1 -0
  141. package/lib/esm/tests/testResponseFilter.js +103 -0
  142. package/lib/esm/tests/testResponseFilter.js.map +1 -0
  143. package/lib/esm/tests/testRouting.js +71 -0
  144. package/lib/esm/tests/testRouting.js.map +1 -0
  145. package/lib/esm/tests/testScopeRequest.js +112 -0
  146. package/lib/esm/tests/testScopeRequest.js.map +1 -0
  147. package/lib/esm/tests/testSession.js +122 -0
  148. package/lib/esm/tests/testSession.js.map +1 -0
  149. package/lib/esm/tests/testStatics.js +54 -0
  150. package/lib/esm/tests/testStatics.js.map +1 -0
  151. package/lib/esm/tests/testView.js +79 -0
  152. package/lib/esm/tests/testView.js.map +1 -0
  153. package/lib/types/components/PlatformTestSdk.d.ts +9 -0
  154. package/lib/types/errors/CustomBadRequest.d.ts +8 -0
  155. package/lib/types/errors/CustomInternalError.d.ts +8 -0
  156. package/lib/types/index.d.ts +38 -0
  157. package/lib/types/interfaces/PlatformTestingSdkOpts.d.ts +8 -0
  158. package/lib/types/interfaces/index.d.ts +4 -0
  159. package/lib/types/modules/feature/FeatureModule.d.ts +2 -0
  160. package/lib/types/modules/feature/controllers/FeatureController.d.ts +3 -0
  161. package/lib/types/tests/exports.d.ts +2 -0
  162. package/lib/types/tests/testAcceptMime.d.ts +2 -0
  163. package/lib/types/tests/testAuth.d.ts +8 -0
  164. package/lib/types/tests/testBodyParams.d.ts +3 -0
  165. package/lib/types/tests/testCache.d.ts +2 -0
  166. package/lib/types/tests/testChildrenControllers.d.ts +2 -0
  167. package/lib/types/tests/testCookies.d.ts +11 -0
  168. package/lib/types/tests/testCtrlInheritance.d.ts +18 -0
  169. package/lib/types/tests/testCustom404.d.ts +2 -0
  170. package/lib/types/tests/testErrors.d.ts +19 -0
  171. package/lib/types/tests/testHandlers.d.ts +12 -0
  172. package/lib/types/tests/testHeaderParams.d.ts +16 -0
  173. package/lib/types/tests/testHeaders.d.ts +8 -0
  174. package/lib/types/tests/testInheritanceController.d.ts +28 -0
  175. package/lib/types/tests/testLocals.d.ts +2 -0
  176. package/lib/types/tests/testLocation.d.ts +2 -0
  177. package/lib/types/tests/testMiddlewares.d.ts +8 -0
  178. package/lib/types/tests/testModule.d.ts +2 -0
  179. package/lib/types/tests/testMulter.d.ts +21 -0
  180. package/lib/types/tests/testPathParams.d.ts +2 -0
  181. package/lib/types/tests/testQueryParams.d.ts +6 -0
  182. package/lib/types/tests/testRedirect.d.ts +2 -0
  183. package/lib/types/tests/testResponse.d.ts +16 -0
  184. package/lib/types/tests/testResponseFilter.d.ts +2 -0
  185. package/lib/types/tests/testRouting.d.ts +7 -0
  186. package/lib/types/tests/testScopeRequest.d.ts +12 -0
  187. package/lib/types/tests/testSession.d.ts +16 -0
  188. package/lib/types/tests/testStatics.d.ts +2 -0
  189. package/lib/types/tests/testView.d.ts +2 -0
  190. package/package.json +44 -0
  191. package/src/components/PlatformTestSdk.ts +29 -0
  192. package/src/data/file.txt +1 -0
  193. package/src/data/response.data.json +3 -0
  194. package/src/data/swagger.json +32 -0
  195. package/src/errors/CustomBadRequest.ts +16 -0
  196. package/src/errors/CustomInternalError.ts +16 -0
  197. package/src/index.ts +39 -0
  198. package/src/interfaces/PlatformTestingSdkOpts.ts +10 -0
  199. package/src/interfaces/index.ts +5 -0
  200. package/src/modules/feature/FeatureModule.ts +9 -0
  201. package/src/modules/feature/controllers/FeatureController.ts +11 -0
  202. package/src/tests/exports.ts +69 -0
  203. package/src/tests/testAcceptMime.ts +95 -0
  204. package/src/tests/testAuth.ts +339 -0
  205. package/src/tests/testBodyParams.ts +455 -0
  206. package/src/tests/testCache.ts +270 -0
  207. package/src/tests/testChildrenControllers.ts +55 -0
  208. package/src/tests/testCookies.ts +36 -0
  209. package/src/tests/testCtrlInheritance.ts +140 -0
  210. package/src/tests/testCustom404.ts +33 -0
  211. package/src/tests/testErrors.ts +223 -0
  212. package/src/tests/testHandlers.ts +92 -0
  213. package/src/tests/testHeaderParams.ts +149 -0
  214. package/src/tests/testHeaders.ts +91 -0
  215. package/src/tests/testInheritanceController.ts +156 -0
  216. package/src/tests/testLocals.ts +46 -0
  217. package/src/tests/testLocation.ts +37 -0
  218. package/src/tests/testMiddlewares.ts +159 -0
  219. package/src/tests/testModule.ts +46 -0
  220. package/src/tests/testMulter.ts +140 -0
  221. package/src/tests/testPathParams.ts +122 -0
  222. package/src/tests/testQueryParams.ts +323 -0
  223. package/src/tests/testRedirect.ts +124 -0
  224. package/src/tests/testResponse.ts +558 -0
  225. package/src/tests/testResponseFilter.ts +101 -0
  226. package/src/tests/testRouting.ts +65 -0
  227. package/src/tests/testScopeRequest.ts +111 -0
  228. package/src/tests/testSession.ts +104 -0
  229. package/src/tests/testStatics.ts +61 -0
  230. package/src/tests/testView.ts +68 -0
  231. package/tsconfig.compile.esm.json +12 -0
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.testModule = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@tsed/common");
6
+ const supertest_1 = tslib_1.__importDefault(require("supertest"));
7
+ const FeatureModule_1 = require("../modules/feature/FeatureModule");
8
+ let TestRootCtrl = class TestRootCtrl {
9
+ testScenario1() {
10
+ return "From root";
11
+ }
12
+ };
13
+ tslib_1.__decorate([
14
+ (0, common_1.Get)("/"),
15
+ tslib_1.__metadata("design:type", Function),
16
+ tslib_1.__metadata("design:paramtypes", []),
17
+ tslib_1.__metadata("design:returntype", void 0)
18
+ ], TestRootCtrl.prototype, "testScenario1", null);
19
+ TestRootCtrl = tslib_1.__decorate([
20
+ (0, common_1.Controller)("/root")
21
+ ], TestRootCtrl);
22
+ function testModule(options) {
23
+ let request;
24
+ beforeAll(common_1.PlatformTest.bootstrap(options.server, {
25
+ ...options,
26
+ mount: {
27
+ "/rest": [TestRootCtrl]
28
+ },
29
+ imports: [FeatureModule_1.FeatureModule]
30
+ }));
31
+ beforeAll(() => {
32
+ request = (0, supertest_1.default)(common_1.PlatformTest.callback());
33
+ });
34
+ afterAll(common_1.PlatformTest.reset);
35
+ describe("Scenario1: GET /rest/root", () => {
36
+ it("should get content from root controller", async () => {
37
+ const response = await request.get("/rest/root").expect(200);
38
+ expect(response.text).toEqual("From root");
39
+ });
40
+ });
41
+ describe("Scenario2: GET /rest/features", () => {
42
+ it("should get content from a module with his controller", async () => {
43
+ const response = await request.get("/rest/features").expect(200);
44
+ expect(response.text).toEqual("From feature");
45
+ });
46
+ });
47
+ }
48
+ exports.testModule = testModule;
49
+ //# sourceMappingURL=testModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testModule.js","sourceRoot":"","sources":["../../../src/tests/testModule.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAC3D,kEAAkC;AAElC,oEAA+D;AAG/D,IAAM,YAAY,GAAlB,MAAM,YAAY;IAEhB,aAAa;QACX,OAAO,WAAW,CAAC;IACrB,CAAC;CACF,CAAA;AAHC;IADC,IAAA,YAAG,EAAC,GAAG,CAAC;;;;iDAGR;AAJG,YAAY;IADjB,IAAA,mBAAU,EAAC,OAAO,CAAC;GACd,YAAY,CAKjB;AAED,SAAgB,UAAU,CAAC,OAA+B;IACxD,IAAI,OAA4C,CAAC;IAEjD,SAAS,CACP,qBAAY,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE;QACrC,GAAG,OAAO;QACV,KAAK,EAAE;YACL,OAAO,EAAE,CAAC,YAAY,CAAC;SACxB;QACD,OAAO,EAAE,CAAC,6BAAa,CAAC;KACzB,CAAC,CACH,CAAC;IACF,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,GAAG,IAAA,mBAAS,EAAC,qBAAY,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IACH,QAAQ,CAAC,qBAAY,CAAC,KAAK,CAAC,CAAC;IAE7B,QAAQ,CAAC,2BAA2B,EAAE,GAAG,EAAE;QACzC,EAAE,CAAC,yCAAyC,EAAE,KAAK,IAAI,EAAE;YACvD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAE7D,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,+BAA+B,EAAE,GAAG,EAAE;QAC7C,EAAE,CAAC,sDAAsD,EAAE,KAAK,IAAI,EAAE;YACpE,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAEjE,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAhCD,gCAgCC","sourcesContent":["import {Controller, Get, PlatformTest} from \"@tsed/common\";\nimport SuperTest from \"supertest\";\nimport {PlatformTestingSdkOpts} from \"../interfaces\";\nimport {FeatureModule} from \"../modules/feature/FeatureModule\";\n\n@Controller(\"/root\")\nclass TestRootCtrl {\n @Get(\"/\")\n testScenario1() {\n return \"From root\";\n }\n}\n\nexport function testModule(options: PlatformTestingSdkOpts) {\n let request: SuperTest.SuperTest<SuperTest.Test>;\n\n beforeAll(\n PlatformTest.bootstrap(options.server, {\n ...options,\n mount: {\n \"/rest\": [TestRootCtrl]\n },\n imports: [FeatureModule]\n })\n );\n beforeAll(() => {\n request = SuperTest(PlatformTest.callback());\n });\n afterAll(PlatformTest.reset);\n\n describe(\"Scenario1: GET /rest/root\", () => {\n it(\"should get content from root controller\", async () => {\n const response = await request.get(\"/rest/root\").expect(200);\n\n expect(response.text).toEqual(\"From root\");\n });\n });\n\n describe(\"Scenario2: GET /rest/features\", () => {\n it(\"should get content from a module with his controller\", async () => {\n const response = await request.get(\"/rest/features\").expect(200);\n\n expect(response.text).toEqual(\"From feature\");\n });\n });\n}\n"]}
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.testMulter = exports.TestMulterController = exports.Event = exports.Task = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@tsed/common");
6
+ const schema_1 = require("@tsed/schema");
7
+ const multer_1 = tslib_1.__importDefault(require("multer"));
8
+ const supertest_1 = tslib_1.__importDefault(require("supertest"));
9
+ class Task {
10
+ id;
11
+ title;
12
+ }
13
+ tslib_1.__decorate([
14
+ (0, schema_1.Property)(),
15
+ tslib_1.__metadata("design:type", String)
16
+ ], Task.prototype, "id", void 0);
17
+ tslib_1.__decorate([
18
+ (0, schema_1.Property)(),
19
+ tslib_1.__metadata("design:type", String)
20
+ ], Task.prototype, "title", void 0);
21
+ exports.Task = Task;
22
+ class Event {
23
+ id;
24
+ tasks;
25
+ }
26
+ tslib_1.__decorate([
27
+ (0, schema_1.Property)(),
28
+ (0, schema_1.Required)(),
29
+ tslib_1.__metadata("design:type", String)
30
+ ], Event.prototype, "id", void 0);
31
+ tslib_1.__decorate([
32
+ (0, schema_1.CollectionOf)(Task),
33
+ tslib_1.__metadata("design:type", Array)
34
+ ], Event.prototype, "tasks", void 0);
35
+ exports.Event = Event;
36
+ const fileFilterStub = jest.fn();
37
+ const fileFilter = (req, file, callback) => {
38
+ fileFilterStub();
39
+ callback(null, true);
40
+ };
41
+ function getFileConfig() {
42
+ return {
43
+ storage: multer_1.default.diskStorage({
44
+ destination: (req, _fileItem, cb) => {
45
+ const path = `${__dirname}/../.tmp`;
46
+ cb(null, path);
47
+ }
48
+ }),
49
+ fileFilter
50
+ };
51
+ }
52
+ let TestMulterController = class TestMulterController {
53
+ uploadWithName(media) {
54
+ return media.originalname;
55
+ }
56
+ uploadWithPayload(media, formId) {
57
+ return {
58
+ file: media.originalname,
59
+ formId
60
+ };
61
+ }
62
+ uploadWithOptions(media) {
63
+ return {
64
+ file: media.originalname
65
+ };
66
+ }
67
+ };
68
+ tslib_1.__decorate([
69
+ (0, common_1.Post)("/scenario-1"),
70
+ (0, schema_1.Status)(201),
71
+ (0, common_1.MulterOptions)({ dest: `${__dirname}/../.tmp` }),
72
+ tslib_1.__param(0, (0, schema_1.Required)()),
73
+ tslib_1.__param(0, (0, common_1.MultipartFile)("media")),
74
+ tslib_1.__metadata("design:type", Function),
75
+ tslib_1.__metadata("design:paramtypes", [Object]),
76
+ tslib_1.__metadata("design:returntype", void 0)
77
+ ], TestMulterController.prototype, "uploadWithName", null);
78
+ tslib_1.__decorate([
79
+ (0, common_1.Post)("/scenario-2"),
80
+ (0, schema_1.Status)(201),
81
+ (0, common_1.MulterOptions)({ dest: `${__dirname}/../.tmp` }),
82
+ tslib_1.__param(0, (0, common_1.MultipartFile)("media")),
83
+ tslib_1.__param(1, (0, common_1.BodyParams)("form_id")),
84
+ tslib_1.__metadata("design:type", Function),
85
+ tslib_1.__metadata("design:paramtypes", [Object, String]),
86
+ tslib_1.__metadata("design:returntype", void 0)
87
+ ], TestMulterController.prototype, "uploadWithPayload", null);
88
+ tslib_1.__decorate([
89
+ (0, common_1.Post)("/scenario-3"),
90
+ (0, schema_1.Status)(201),
91
+ (0, common_1.MulterOptions)(getFileConfig()),
92
+ tslib_1.__param(0, (0, common_1.MultipartFile)("media")),
93
+ tslib_1.__metadata("design:type", Function),
94
+ tslib_1.__metadata("design:paramtypes", [Object]),
95
+ tslib_1.__metadata("design:returntype", void 0)
96
+ ], TestMulterController.prototype, "uploadWithOptions", null);
97
+ TestMulterController = tslib_1.__decorate([
98
+ (0, common_1.Controller)("/multer")
99
+ ], TestMulterController);
100
+ exports.TestMulterController = TestMulterController;
101
+ function testMulter(options) {
102
+ let request;
103
+ beforeAll(common_1.PlatformTest.bootstrap(options.server, {
104
+ ...options,
105
+ mount: {
106
+ "/rest": [TestMulterController]
107
+ }
108
+ }));
109
+ beforeAll(() => {
110
+ request = (0, supertest_1.default)(common_1.PlatformTest.callback());
111
+ });
112
+ afterAll(common_1.PlatformTest.reset);
113
+ beforeAll(() => jest.resetAllMocks());
114
+ describe("Scenario 1: POST /rest/multer/scenario-1", () => {
115
+ it("should upload file with multer", async () => {
116
+ const result = await request.post("/rest/multer/scenario-1").attach("media", `${__dirname}/../data/file.txt`).expect(201);
117
+ expect(result.text).toEqual("file.txt");
118
+ });
119
+ it("should throw an exception when there is no file", async () => {
120
+ const result = await request.post("/rest/multer/scenario-1").expect(400);
121
+ expect(result.body).toEqual({
122
+ name: "REQUIRED_VALIDATION_ERROR",
123
+ message: "Bad request on parameter \"request.files.media.0\".\nIt should have required parameter 'media.0'",
124
+ status: 400,
125
+ errors: [
126
+ {
127
+ dataPath: "",
128
+ keyword: "required",
129
+ message: "It should have required parameter 'media.0'",
130
+ modelName: "files",
131
+ params: { missingProperty: "media.0" },
132
+ schemaPath: "#/required"
133
+ }
134
+ ]
135
+ });
136
+ });
137
+ });
138
+ describe("Scenario 2: POST /rest/multer/scenario-2", () => {
139
+ it("should upload file with multer", async () => {
140
+ const result = await request
141
+ .post("/rest/multer/scenario-2")
142
+ .attach("media", `${__dirname}/../data/file.txt`)
143
+ .field({
144
+ form_id: "form_id"
145
+ })
146
+ .expect(201);
147
+ expect(result.body).toEqual({ file: "file.txt", formId: "form_id" });
148
+ });
149
+ });
150
+ describe("Scenario 3: POST /rest/multer/scenario-3", () => {
151
+ it("should upload file with multer", async () => {
152
+ const result = await request.post("/rest/multer/scenario-3").attach("media", `${__dirname}/../data/file.txt`).field({}).expect(201);
153
+ expect(result.body).toEqual({
154
+ file: "file.txt"
155
+ });
156
+ // filterFilter is called
157
+ expect(fileFilterStub).toBeCalled();
158
+ });
159
+ });
160
+ }
161
+ exports.testMulter = testMulter;
162
+ //# sourceMappingURL=testMulter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testMulter.js","sourceRoot":"","sources":["../../../src/tests/testMulter.ts"],"names":[],"mappings":";;;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BAAmB,CAAC;iBAChD,KAAK,CAAC;gBACL,OAAO,EAAE,SAAS;aACnB,CAAC;iBACD,MAAM,CAAC,GAAG,CAAC,CAAC;YAEf,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,EAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAC,CAAC,CAAC;QACrE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,QAAQ,CAAC,0CAA0C,EAAE,GAAG,EAAE;QACxD,EAAE,CAAC,gCAAgC,EAAE,KAAK,IAAI,EAAE;YAC9C,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,SAAS,mBAAmB,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAEpI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC;gBAC1B,IAAI,EAAE,UAAU;aACjB,CAAC,CAAC;YAEH,yBAAyB;YACzB,MAAM,CAAC,cAAc,CAAC,CAAC,UAAU,EAAE,CAAC;QACtC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AApED,gCAoEC","sourcesContent":["import {BodyParams, Controller, MulterOptions, MultipartFile, PlatformMulterFile, PlatformTest, Post} from \"@tsed/common\";\nimport {CollectionOf, Property, Required, Status} from \"@tsed/schema\";\nimport {Request} from \"express\";\nimport multer, {FileFilterCallback} from \"multer\";\nimport SuperTest from \"supertest\";\nimport {PlatformTestingSdkOpts} from \"../interfaces\";\n\nexport class Task {\n @Property()\n id: string;\n\n @Property()\n title: string;\n}\n\nexport class Event {\n @Property()\n @Required()\n id: string;\n\n @CollectionOf(Task)\n tasks: Task[];\n}\n\nconst fileFilterStub = jest.fn();\nconst fileFilter = (req: Request, file: PlatformMulterFile, callback: FileFilterCallback) => {\n fileFilterStub();\n callback(null, true);\n};\n\nfunction getFileConfig(): any {\n return {\n storage: multer.diskStorage({\n destination: (req: Express.Request, _fileItem, cb) => {\n const path = `${__dirname}/../.tmp`;\n cb(null, path);\n }\n }),\n fileFilter\n };\n}\n\n@Controller(\"/multer\")\nexport class TestMulterController {\n @Post(\"/scenario-1\")\n @Status(201)\n @MulterOptions({dest: `${__dirname}/../.tmp`})\n uploadWithName(@Required() @MultipartFile(\"media\") media: PlatformMulterFile) {\n return media.originalname;\n }\n\n @Post(\"/scenario-2\")\n @Status(201)\n @MulterOptions({dest: `${__dirname}/../.tmp`})\n uploadWithPayload(@MultipartFile(\"media\") media: PlatformMulterFile, @BodyParams(\"form_id\") formId: string) {\n return {\n file: media.originalname,\n formId\n };\n }\n\n @Post(\"/scenario-3\")\n @Status(201)\n @MulterOptions(getFileConfig())\n uploadWithOptions(@MultipartFile(\"media\") media: PlatformMulterFile) {\n return {\n file: media.originalname\n };\n }\n}\n\nexport function testMulter(options: PlatformTestingSdkOpts) {\n let request: SuperTest.SuperTest<SuperTest.Test>;\n\n beforeAll(\n PlatformTest.bootstrap(options.server, {\n ...options,\n mount: {\n \"/rest\": [TestMulterController]\n }\n })\n );\n beforeAll(() => {\n request = SuperTest(PlatformTest.callback());\n });\n afterAll(PlatformTest.reset);\n beforeAll(() => jest.resetAllMocks());\n describe(\"Scenario 1: POST /rest/multer/scenario-1\", () => {\n it(\"should upload file with multer\", async () => {\n const result = await request.post(\"/rest/multer/scenario-1\").attach(\"media\", `${__dirname}/../data/file.txt`).expect(201);\n\n expect(result.text).toEqual(\"file.txt\");\n });\n\n it(\"should throw an exception when there is no file\", async () => {\n const result = await request.post(\"/rest/multer/scenario-1\").expect(400);\n\n expect(result.body).toEqual({\n name: \"REQUIRED_VALIDATION_ERROR\",\n message: \"Bad request on parameter \\\"request.files.media.0\\\".\\nIt should have required parameter 'media.0'\",\n status: 400,\n errors: [\n {\n dataPath: \"\",\n keyword: \"required\",\n message: \"It should have required parameter 'media.0'\",\n modelName: \"files\",\n params: {missingProperty: \"media.0\"},\n schemaPath: \"#/required\"\n }\n ]\n });\n });\n });\n describe(\"Scenario 2: POST /rest/multer/scenario-2\", () => {\n it(\"should upload file with multer\", async () => {\n const result = await request\n .post(\"/rest/multer/scenario-2\")\n .attach(\"media\", `${__dirname}/../data/file.txt`)\n .field({\n form_id: \"form_id\"\n })\n .expect(201);\n\n expect(result.body).toEqual({file: \"file.txt\", formId: \"form_id\"});\n });\n });\n describe(\"Scenario 3: POST /rest/multer/scenario-3\", () => {\n it(\"should upload file with multer\", async () => {\n const result = await request.post(\"/rest/multer/scenario-3\").attach(\"media\", `${__dirname}/../data/file.txt`).field({}).expect(201);\n\n expect(result.body).toEqual({\n file: \"file.txt\"\n });\n\n // filterFilter is called\n expect(fileFilterStub).toBeCalled();\n });\n });\n}\n"]}
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.testPathParams = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@tsed/common");
6
+ const schema_1 = require("@tsed/schema");
7
+ const supertest_1 = tslib_1.__importDefault(require("supertest"));
8
+ let TestPathParamsCtrl = class TestPathParamsCtrl {
9
+ async testScenario1(scope) {
10
+ // Here scope will be {0: 'a', 1: 'b', 2: 'c'} instead of 'abc' in version 5.47.0
11
+ expect(scope).toEqual("abc");
12
+ return scope;
13
+ }
14
+ async testScenario2(scope) {
15
+ // This way it works in version 5.47.0
16
+ expect(scope).toEqual("abc");
17
+ return scope;
18
+ }
19
+ async testScenario3(scope) {
20
+ expect(scope).toEqual("abc");
21
+ // Here the function will return {0: 'a', 1: 'b', 2: 'c'} instead of ['a','b','c'] in version 5.44.13
22
+ return ["a", "b", "c"];
23
+ }
24
+ async testScenario4(scope, ctx) {
25
+ expect(scope).toEqual("abc");
26
+ // This way it works in version 5.44.13
27
+ ctx.response.body(["a", "b", "c"]);
28
+ }
29
+ async testScenario5(scopeId, ctx) {
30
+ return "test";
31
+ }
32
+ async testScenario6(id) {
33
+ return { id };
34
+ }
35
+ };
36
+ tslib_1.__decorate([
37
+ (0, common_1.Get)("/scenario-1/:scope/:scopeId"),
38
+ tslib_1.__param(0, (0, common_1.PathParams)("scope")),
39
+ tslib_1.__metadata("design:type", Function),
40
+ tslib_1.__metadata("design:paramtypes", [String]),
41
+ tslib_1.__metadata("design:returntype", Promise)
42
+ ], TestPathParamsCtrl.prototype, "testScenario1", null);
43
+ tslib_1.__decorate([
44
+ (0, common_1.Get)("/scenario-2/:scope/:scopeId"),
45
+ tslib_1.__param(0, (0, common_1.PathParams)("scope")),
46
+ tslib_1.__metadata("design:type", Function),
47
+ tslib_1.__metadata("design:paramtypes", [Object]),
48
+ tslib_1.__metadata("design:returntype", Promise)
49
+ ], TestPathParamsCtrl.prototype, "testScenario2", null);
50
+ tslib_1.__decorate([
51
+ (0, common_1.Post)("/scenario-3/:scope/:scopeId"),
52
+ tslib_1.__param(0, (0, common_1.PathParams)("scope")),
53
+ tslib_1.__metadata("design:type", Function),
54
+ tslib_1.__metadata("design:paramtypes", [String]),
55
+ tslib_1.__metadata("design:returntype", Promise)
56
+ ], TestPathParamsCtrl.prototype, "testScenario3", null);
57
+ tslib_1.__decorate([
58
+ (0, common_1.Post)("/scenario-4/:scope/:scopeId"),
59
+ tslib_1.__param(0, (0, common_1.PathParams)("scope")),
60
+ tslib_1.__param(1, (0, common_1.Context)()),
61
+ tslib_1.__metadata("design:type", Function),
62
+ tslib_1.__metadata("design:paramtypes", [String, Object]),
63
+ tslib_1.__metadata("design:returntype", Promise)
64
+ ], TestPathParamsCtrl.prototype, "testScenario4", null);
65
+ tslib_1.__decorate([
66
+ (0, common_1.Get)("/scenario-5/:scopeId"),
67
+ tslib_1.__param(0, (0, common_1.PathParams)("scopeId")),
68
+ tslib_1.__param(0, (0, schema_1.Pattern)(/^[0-9a-fA-F]{24}$/)),
69
+ tslib_1.__param(1, (0, common_1.Context)()),
70
+ tslib_1.__metadata("design:type", Function),
71
+ tslib_1.__metadata("design:paramtypes", [String, Object]),
72
+ tslib_1.__metadata("design:returntype", Promise)
73
+ ], TestPathParamsCtrl.prototype, "testScenario5", null);
74
+ tslib_1.__decorate([
75
+ (0, common_1.Get)("/scenario-6/:id"),
76
+ tslib_1.__param(0, (0, common_1.PathParams)("id")),
77
+ tslib_1.__metadata("design:type", Function),
78
+ tslib_1.__metadata("design:paramtypes", [Number]),
79
+ tslib_1.__metadata("design:returntype", Promise)
80
+ ], TestPathParamsCtrl.prototype, "testScenario6", null);
81
+ TestPathParamsCtrl = tslib_1.__decorate([
82
+ (0, common_1.Controller)("/path-params")
83
+ ], TestPathParamsCtrl);
84
+ function testPathParams(options) {
85
+ let request;
86
+ beforeAll(common_1.PlatformTest.bootstrap(options.server, {
87
+ ...options,
88
+ mount: {
89
+ "/rest": [TestPathParamsCtrl]
90
+ }
91
+ }));
92
+ beforeAll(() => {
93
+ request = (0, supertest_1.default)(common_1.PlatformTest.callback());
94
+ });
95
+ afterAll(common_1.PlatformTest.reset);
96
+ it("Scenario 1: GET /rest/path-params/scenario-1/scope/scopeId", async () => {
97
+ const response = await request.get("/rest/path-params/scenario-1/abc/1").expect(200);
98
+ expect(response.text).toEqual("abc");
99
+ });
100
+ it("Scenario 2: GET /rest/path-params/scenario-2/scopeId", async () => {
101
+ const response = await request.get("/rest/path-params/scenario-2/abc/1").expect(200);
102
+ expect(response.text).toEqual("abc");
103
+ });
104
+ it("Scenario 3: POST /rest/path-params/scenario-3/scope/scopeId", async () => {
105
+ const response = await request.post("/rest/path-params/scenario-3/abc/1").expect(200);
106
+ expect(response.body).toEqual(["a", "b", "c"]);
107
+ });
108
+ it("Scenario 4: POST /rest/path-params/scenario-4/scope/scopeId", async () => {
109
+ const response = await request.post("/rest/path-params/scenario-4/abc/1").expect(200);
110
+ expect(response.body).toEqual(["a", "b", "c"]);
111
+ });
112
+ it("Scenario 5 a: GET /rest/path-params/scenario-5/scopeId", async () => {
113
+ const response = await request.get("/rest/path-params/scenario-5/1").expect(400);
114
+ expect(response.body).toEqual({
115
+ errors: [
116
+ {
117
+ data: "1",
118
+ dataPath: "",
119
+ instancePath: "",
120
+ keyword: "pattern",
121
+ message: 'must match pattern "^[0-9a-fA-F]{24}$"',
122
+ params: {
123
+ pattern: "^[0-9a-fA-F]{24}$"
124
+ },
125
+ schemaPath: "#/pattern"
126
+ }
127
+ ],
128
+ message: 'Bad request on parameter "request.path.scopeId".\nValue must match pattern "^[0-9a-fA-F]{24}$". Given value: "1"',
129
+ name: "AJV_VALIDATION_ERROR",
130
+ status: 400
131
+ });
132
+ });
133
+ it("Scenario 5b: GET /rest/path-params/scenario-5/scopeId", async () => {
134
+ await request.get("/rest/path-params/scenario-5/5ce4ee471495836c5e2e4cb0").expect(200);
135
+ });
136
+ it("Scenario 6: GET /rest/path-params/scenario-6/id", async () => {
137
+ const response = await request.get("/rest/path-params/scenario-6/1").expect(200);
138
+ expect(response.body).toEqual({ id: 1 });
139
+ });
140
+ }
141
+ exports.testPathParams = testPathParams;
142
+ //# sourceMappingURL=testPathParams.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testPathParams.js","sourceRoot":"","sources":["../../../src/tests/testPathParams.ts"],"names":[],"mappings":";;;;AAAA,yCAAsF;AACtF,yCAAqC;AACrC,kEAAkC;AAIlC,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAEtB,KAAK,CAAC,aAAa,CAAsB,KAAa;QACpD,iFAAiF;QACjF,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAE7B,OAAO,KAAK,CAAC;IACf,CAAC;IAGD,KAAK,CAAC,aAAa,CAAsB,KAAU;QACjD,sCAAsC;QACtC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAE7B,OAAO,KAAK,CAAC;IACf,CAAC;IAGD,KAAK,CAAC,aAAa,CAAsB,KAAa;QACpD,MAAM,CAAC,KAAK,CAAC,CAAC,OA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/D,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAEjF,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,EAAC,EAAE,EAAE,CAAC,EAAC,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC;AAvED,wCAuEC","sourcesContent":["import {Context, Controller, Get, PathParams, PlatformTest, Post} from \"@tsed/common\";\nimport {Pattern} from \"@tsed/schema\";\nimport SuperTest from \"supertest\";\nimport {PlatformTestingSdkOpts} from \"../interfaces\";\n\n@Controller(\"/path-params\")\nclass TestPathParamsCtrl {\n @Get(\"/scenario-1/:scope/:scopeId\")\n async testScenario1(@PathParams(\"scope\") scope: string) {\n // Here scope will be {0: 'a', 1: 'b', 2: 'c'} instead of 'abc' in version 5.47.0\n expect(scope).toEqual(\"abc\");\n\n return scope;\n }\n\n @Get(\"/scenario-2/:scope/:scopeId\")\n async testScenario2(@PathParams(\"scope\") scope: any) {\n // This way it works in version 5.47.0\n expect(scope).toEqual(\"abc\");\n\n return scope;\n }\n\n @Post(\"/scenario-3/:scope/:scopeId\")\n async testScenario3(@PathParams(\"scope\") scope: string): Promise<any[]> {\n expect(scope).toEqual(\"abc\");\n\n // Here the function will return {0: 'a', 1: 'b', 2: 'c'} instead of ['a','b','c'] in version 5.44.13\n return [\"a\", \"b\", \"c\"];\n }\n\n @Post(\"/scenario-4/:scope/:scopeId\")\n async testScenario4(@PathParams(\"scope\") scope: string, @Context() ctx: Context) {\n expect(scope).toEqual(\"abc\");\n\n // This way it works in version 5.44.13\n ctx.response.body([\"a\", \"b\", \"c\"]);\n }\n\n @Get(\"/scenario-5/:scopeId\")\n async testScenario5(@PathParams(\"scopeId\") @Pattern(/^[0-9a-fA-F]{24}$/) scopeId: string, @Context() ctx: Context) {\n return \"test\";\n }\n\n @Get(\"/scenario-6/:id\")\n async testScenario6(@PathParams(\"id\") id: number) {\n return {id};\n }\n}\n\nexport function testPathParams(options: PlatformTestingSdkOpts) {\n let request: SuperTest.SuperTest<SuperTest.Test>;\n\n beforeAll(\n PlatformTest.bootstrap(options.server, {\n ...options,\n mount: {\n \"/rest\": [TestPathParamsCtrl]\n }\n })\n );\n beforeAll(() => {\n request = SuperTest(PlatformTest.callback());\n });\n afterAll(PlatformTest.reset);\n\n it(\"Scenario 1: GET /rest/path-params/scenario-1/scope/scopeId\", async () => {\n const response = await request.get(\"/rest/path-params/scenario-1/abc/1\").expect(200);\n\n expect(response.text).toEqual(\"abc\");\n });\n\n it(\"Scenario 2: GET /rest/path-params/scenario-2/scopeId\", async () => {\n const response = await request.get(\"/rest/path-params/scenario-2/abc/1\").expect(200);\n\n expect(response.text).toEqual(\"abc\");\n });\n\n it(\"Scenario 3: POST /rest/path-params/scenario-3/scope/scopeId\", async () => {\n const response = await request.post(\"/rest/path-params/scenario-3/abc/1\").expect(200);\n\n expect(response.body).toEqual([\"a\", \"b\", \"c\"]);\n });\n\n it(\"Scenario 4: POST /rest/path-params/scenario-4/scope/scopeId\", async () => {\n const response = await request.post(\"/rest/path-params/scenario-4/abc/1\").expect(200);\n\n expect(response.body).toEqual([\"a\", \"b\", \"c\"]);\n });\n\n it(\"Scenario 5 a: GET /rest/path-params/scenario-5/scopeId\", async () => {\n const response = await request.get(\"/rest/path-params/scenario-5/1\").expect(400);\n\n expect(response.body).toEqual({\n errors: [\n {\n data: \"1\",\n dataPath: \"\",\n instancePath: \"\",\n keyword: \"pattern\",\n message: 'must match pattern \"^[0-9a-fA-F]{24}$\"',\n params: {\n pattern: \"^[0-9a-fA-F]{24}$\"\n },\n schemaPath: \"#/pattern\"\n }\n ],\n message: 'Bad request on parameter \"request.path.scopeId\".\\nValue must match pattern \"^[0-9a-fA-F]{24}$\". Given value: \"1\"',\n name: \"AJV_VALIDATION_ERROR\",\n status: 400\n });\n });\n it(\"Scenario 5b: GET /rest/path-params/scenario-5/scopeId\", async () => {\n await request.get(\"/rest/path-params/scenario-5/5ce4ee471495836c5e2e4cb0\").expect(200);\n });\n\n it(\"Scenario 6: GET /rest/path-params/scenario-6/id\", async () => {\n const response = await request.get(\"/rest/path-params/scenario-6/1\").expect(200);\n\n expect(response.body).toEqual({id: 1});\n });\n}\n"]}