@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,45 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { Controller, Get, PlatformTest } from "@tsed/common";
3
+ import SuperTest from "supertest";
4
+ import { FeatureModule } from "../modules/feature/FeatureModule.js";
5
+ let TestRootCtrl = class TestRootCtrl {
6
+ testScenario1() {
7
+ return "From root";
8
+ }
9
+ };
10
+ __decorate([
11
+ Get("/"),
12
+ __metadata("design:type", Function),
13
+ __metadata("design:paramtypes", []),
14
+ __metadata("design:returntype", void 0)
15
+ ], TestRootCtrl.prototype, "testScenario1", null);
16
+ TestRootCtrl = __decorate([
17
+ Controller("/root")
18
+ ], TestRootCtrl);
19
+ export function testModule(options) {
20
+ let request;
21
+ beforeAll(PlatformTest.bootstrap(options.server, {
22
+ ...options,
23
+ mount: {
24
+ "/rest": [TestRootCtrl]
25
+ },
26
+ imports: [FeatureModule]
27
+ }));
28
+ beforeAll(() => {
29
+ request = SuperTest(PlatformTest.callback());
30
+ });
31
+ afterAll(PlatformTest.reset);
32
+ describe("Scenario1: GET /rest/root", () => {
33
+ it("should get content from root controller", async () => {
34
+ const response = await request.get("/rest/root").expect(200);
35
+ expect(response.text).toEqual("From root");
36
+ });
37
+ });
38
+ describe("Scenario2: GET /rest/features", () => {
39
+ it("should get content from a module with his controller", async () => {
40
+ const response = await request.get("/rest/features").expect(200);
41
+ expect(response.text).toEqual("From feature");
42
+ });
43
+ });
44
+ }
45
+ //# sourceMappingURL=testModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testModule.js","sourceRoot":"","sources":["../../../src/tests/testModule.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAE,GAAG,EAAE,YAAY,EAAC,MAAM,cAAc,CAAC;AAC3D,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,OAAO,EAAC,aAAa,EAAC,MAAM,kCAAkC,CAAC;AAG/D,IAAM,YAAY,GAAlB,MAAM,YAAY;IAEhB,aAAa;QACX,OAAO,WAAW,CAAC;IACrB,CAAC;CACF,CAAA;AAHC;IADC,GAAG,CAAC,GAAG,CAAC;;;;iDAGR;AAJG,YAAY;IADjB,UAAU,CAAC,OAAO,CAAC;GACd,YAAY,CAKjB;AAED,MAAM,UAAU,UAAU,CAAC,OAA+B;IACxD,IAAI,OAA4C,CAAC;IAEjD,SAAS,CACP,YAAY,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE;QACrC,GAAG,OAAO;QACV,KAAK,EAAE;YACL,OAAO,EAAE,CAAC,YAAY,CAAC;SACxB;QACD,OAAO,EAAE,CAAC,aAAa,CAAC;KACzB,CAAC,CACH,CAAC;IACF,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,GAAG,SAAS,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IACH,QAAQ,CAAC,YAAY,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","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,156 @@
1
+ import { __decorate, __metadata, __param } from "tslib";
2
+ import { BodyParams, Controller, MulterOptions, MultipartFile, PlatformTest, Post } from "@tsed/common";
3
+ import { CollectionOf, Property, Required, Status } from "@tsed/schema";
4
+ import multer from "multer";
5
+ import SuperTest from "supertest";
6
+ export class Task {
7
+ id;
8
+ title;
9
+ }
10
+ __decorate([
11
+ Property(),
12
+ __metadata("design:type", String)
13
+ ], Task.prototype, "id", void 0);
14
+ __decorate([
15
+ Property(),
16
+ __metadata("design:type", String)
17
+ ], Task.prototype, "title", void 0);
18
+ export class Event {
19
+ id;
20
+ tasks;
21
+ }
22
+ __decorate([
23
+ Property(),
24
+ Required(),
25
+ __metadata("design:type", String)
26
+ ], Event.prototype, "id", void 0);
27
+ __decorate([
28
+ CollectionOf(Task),
29
+ __metadata("design:type", Array)
30
+ ], Event.prototype, "tasks", void 0);
31
+ const fileFilterStub = jest.fn();
32
+ const fileFilter = (req, file, callback) => {
33
+ fileFilterStub();
34
+ callback(null, true);
35
+ };
36
+ function getFileConfig() {
37
+ return {
38
+ storage: multer.diskStorage({
39
+ destination: (req, _fileItem, cb) => {
40
+ const path = `${__dirname}/../.tmp`;
41
+ cb(null, path);
42
+ }
43
+ }),
44
+ fileFilter
45
+ };
46
+ }
47
+ let TestMulterController = class TestMulterController {
48
+ uploadWithName(media) {
49
+ return media.originalname;
50
+ }
51
+ uploadWithPayload(media, formId) {
52
+ return {
53
+ file: media.originalname,
54
+ formId
55
+ };
56
+ }
57
+ uploadWithOptions(media) {
58
+ return {
59
+ file: media.originalname
60
+ };
61
+ }
62
+ };
63
+ __decorate([
64
+ Post("/scenario-1"),
65
+ Status(201),
66
+ MulterOptions({ dest: `${__dirname}/../.tmp` }),
67
+ __param(0, Required()),
68
+ __param(0, MultipartFile("media")),
69
+ __metadata("design:type", Function),
70
+ __metadata("design:paramtypes", [Object]),
71
+ __metadata("design:returntype", void 0)
72
+ ], TestMulterController.prototype, "uploadWithName", null);
73
+ __decorate([
74
+ Post("/scenario-2"),
75
+ Status(201),
76
+ MulterOptions({ dest: `${__dirname}/../.tmp` }),
77
+ __param(0, MultipartFile("media")),
78
+ __param(1, BodyParams("form_id")),
79
+ __metadata("design:type", Function),
80
+ __metadata("design:paramtypes", [Object, String]),
81
+ __metadata("design:returntype", void 0)
82
+ ], TestMulterController.prototype, "uploadWithPayload", null);
83
+ __decorate([
84
+ Post("/scenario-3"),
85
+ Status(201),
86
+ MulterOptions(getFileConfig()),
87
+ __param(0, MultipartFile("media")),
88
+ __metadata("design:type", Function),
89
+ __metadata("design:paramtypes", [Object]),
90
+ __metadata("design:returntype", void 0)
91
+ ], TestMulterController.prototype, "uploadWithOptions", null);
92
+ TestMulterController = __decorate([
93
+ Controller("/multer")
94
+ ], TestMulterController);
95
+ export { TestMulterController };
96
+ export function testMulter(options) {
97
+ let request;
98
+ beforeAll(PlatformTest.bootstrap(options.server, {
99
+ ...options,
100
+ mount: {
101
+ "/rest": [TestMulterController]
102
+ }
103
+ }));
104
+ beforeAll(() => {
105
+ request = SuperTest(PlatformTest.callback());
106
+ });
107
+ afterAll(PlatformTest.reset);
108
+ beforeAll(() => jest.resetAllMocks());
109
+ describe("Scenario 1: POST /rest/multer/scenario-1", () => {
110
+ it("should upload file with multer", async () => {
111
+ const result = await request.post("/rest/multer/scenario-1").attach("media", `${__dirname}/../data/file.txt`).expect(201);
112
+ expect(result.text).toEqual("file.txt");
113
+ });
114
+ it("should throw an exception when there is no file", async () => {
115
+ const result = await request.post("/rest/multer/scenario-1").expect(400);
116
+ expect(result.body).toEqual({
117
+ name: "REQUIRED_VALIDATION_ERROR",
118
+ message: "Bad request on parameter \"request.files.media.0\".\nIt should have required parameter 'media.0'",
119
+ status: 400,
120
+ errors: [
121
+ {
122
+ dataPath: "",
123
+ keyword: "required",
124
+ message: "It should have required parameter 'media.0'",
125
+ modelName: "files",
126
+ params: { missingProperty: "media.0" },
127
+ schemaPath: "#/required"
128
+ }
129
+ ]
130
+ });
131
+ });
132
+ });
133
+ describe("Scenario 2: POST /rest/multer/scenario-2", () => {
134
+ it("should upload file with multer", async () => {
135
+ const result = await request
136
+ .post("/rest/multer/scenario-2")
137
+ .attach("media", `${__dirname}/../data/file.txt`)
138
+ .field({
139
+ form_id: "form_id"
140
+ })
141
+ .expect(201);
142
+ expect(result.body).toEqual({ file: "file.txt", formId: "form_id" });
143
+ });
144
+ });
145
+ describe("Scenario 3: POST /rest/multer/scenario-3", () => {
146
+ it("should upload file with multer", async () => {
147
+ const result = await request.post("/rest/multer/scenario-3").attach("media", `${__dirname}/../data/file.txt`).field({}).expect(201);
148
+ expect(result.body).toEqual({
149
+ file: "file.txt"
150
+ });
151
+ // filterFilter is called
152
+ expect(fileFilterStub).toBeCalled();
153
+ });
154
+ });
155
+ }
156
+ //# sourceMappingURL=testMulter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testMulter.js","sourceRoot":"","sources":["../../../src/tests/testMulter.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAsB,YAAY,EAAE,IAAI,EAAC,MAAM,cAAc,CAAC;AAC1H,OAAO,EAAC,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAC,MAAM,cAAc,CAAC;AAEtE,OAAO,MAA4B,MAAM,QAAQ,CAAC;AAClD,OAAO,SAAS,MAAM,WAAW,CAAC;AAGlC,MAAM,OAAO,IAAI;IAEf,EAAE,CAAS;IAGX,KAAK,CAAS;CACf;AAJC;IADC,QAAQ,EAAE;;gCACA;AAGX;IADC,QAAQ,EAAE;;mCACG;AAGhB,MAAM,OAAO,KAAK;IAGhB,EAAE,CAAS;IAGX,KAAK,CAAS;CACf;AAJC;IAFC,QAAQ,EAAE;IACV,QAAQ,EAAE;;iCACA;AAGX;IADC,YAAY,CAAC,IAAI,CAAC;;oCACL;AAGhB,MAAM,cAAc,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AACjC,MAAM,UAAU,GAAG,CAAC,GAA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AI,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","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,138 @@
1
+ import { __decorate, __metadata, __param } from "tslib";
2
+ import { Context, Controller, Get, PathParams, PlatformTest, Post } from "@tsed/common";
3
+ import { Pattern } from "@tsed/schema";
4
+ import SuperTest from "supertest";
5
+ let TestPathParamsCtrl = class TestPathParamsCtrl {
6
+ async testScenario1(scope) {
7
+ // Here scope will be {0: 'a', 1: 'b', 2: 'c'} instead of 'abc' in version 5.47.0
8
+ expect(scope).toEqual("abc");
9
+ return scope;
10
+ }
11
+ async testScenario2(scope) {
12
+ // This way it works in version 5.47.0
13
+ expect(scope).toEqual("abc");
14
+ return scope;
15
+ }
16
+ async testScenario3(scope) {
17
+ expect(scope).toEqual("abc");
18
+ // Here the function will return {0: 'a', 1: 'b', 2: 'c'} instead of ['a','b','c'] in version 5.44.13
19
+ return ["a", "b", "c"];
20
+ }
21
+ async testScenario4(scope, ctx) {
22
+ expect(scope).toEqual("abc");
23
+ // This way it works in version 5.44.13
24
+ ctx.response.body(["a", "b", "c"]);
25
+ }
26
+ async testScenario5(scopeId, ctx) {
27
+ return "test";
28
+ }
29
+ async testScenario6(id) {
30
+ return { id };
31
+ }
32
+ };
33
+ __decorate([
34
+ Get("/scenario-1/:scope/:scopeId"),
35
+ __param(0, PathParams("scope")),
36
+ __metadata("design:type", Function),
37
+ __metadata("design:paramtypes", [String]),
38
+ __metadata("design:returntype", Promise)
39
+ ], TestPathParamsCtrl.prototype, "testScenario1", null);
40
+ __decorate([
41
+ Get("/scenario-2/:scope/:scopeId"),
42
+ __param(0, PathParams("scope")),
43
+ __metadata("design:type", Function),
44
+ __metadata("design:paramtypes", [Object]),
45
+ __metadata("design:returntype", Promise)
46
+ ], TestPathParamsCtrl.prototype, "testScenario2", null);
47
+ __decorate([
48
+ Post("/scenario-3/:scope/:scopeId"),
49
+ __param(0, PathParams("scope")),
50
+ __metadata("design:type", Function),
51
+ __metadata("design:paramtypes", [String]),
52
+ __metadata("design:returntype", Promise)
53
+ ], TestPathParamsCtrl.prototype, "testScenario3", null);
54
+ __decorate([
55
+ Post("/scenario-4/:scope/:scopeId"),
56
+ __param(0, PathParams("scope")),
57
+ __param(1, Context()),
58
+ __metadata("design:type", Function),
59
+ __metadata("design:paramtypes", [String, Object]),
60
+ __metadata("design:returntype", Promise)
61
+ ], TestPathParamsCtrl.prototype, "testScenario4", null);
62
+ __decorate([
63
+ Get("/scenario-5/:scopeId"),
64
+ __param(0, PathParams("scopeId")),
65
+ __param(0, Pattern(/^[0-9a-fA-F]{24}$/)),
66
+ __param(1, Context()),
67
+ __metadata("design:type", Function),
68
+ __metadata("design:paramtypes", [String, Object]),
69
+ __metadata("design:returntype", Promise)
70
+ ], TestPathParamsCtrl.prototype, "testScenario5", null);
71
+ __decorate([
72
+ Get("/scenario-6/:id"),
73
+ __param(0, PathParams("id")),
74
+ __metadata("design:type", Function),
75
+ __metadata("design:paramtypes", [Number]),
76
+ __metadata("design:returntype", Promise)
77
+ ], TestPathParamsCtrl.prototype, "testScenario6", null);
78
+ TestPathParamsCtrl = __decorate([
79
+ Controller("/path-params")
80
+ ], TestPathParamsCtrl);
81
+ export function testPathParams(options) {
82
+ let request;
83
+ beforeAll(PlatformTest.bootstrap(options.server, {
84
+ ...options,
85
+ mount: {
86
+ "/rest": [TestPathParamsCtrl]
87
+ }
88
+ }));
89
+ beforeAll(() => {
90
+ request = SuperTest(PlatformTest.callback());
91
+ });
92
+ afterAll(PlatformTest.reset);
93
+ it("Scenario 1: GET /rest/path-params/scenario-1/scope/scopeId", async () => {
94
+ const response = await request.get("/rest/path-params/scenario-1/abc/1").expect(200);
95
+ expect(response.text).toEqual("abc");
96
+ });
97
+ it("Scenario 2: GET /rest/path-params/scenario-2/scopeId", async () => {
98
+ const response = await request.get("/rest/path-params/scenario-2/abc/1").expect(200);
99
+ expect(response.text).toEqual("abc");
100
+ });
101
+ it("Scenario 3: POST /rest/path-params/scenario-3/scope/scopeId", async () => {
102
+ const response = await request.post("/rest/path-params/scenario-3/abc/1").expect(200);
103
+ expect(response.body).toEqual(["a", "b", "c"]);
104
+ });
105
+ it("Scenario 4: POST /rest/path-params/scenario-4/scope/scopeId", async () => {
106
+ const response = await request.post("/rest/path-params/scenario-4/abc/1").expect(200);
107
+ expect(response.body).toEqual(["a", "b", "c"]);
108
+ });
109
+ it("Scenario 5 a: GET /rest/path-params/scenario-5/scopeId", async () => {
110
+ const response = await request.get("/rest/path-params/scenario-5/1").expect(400);
111
+ expect(response.body).toEqual({
112
+ errors: [
113
+ {
114
+ data: "1",
115
+ dataPath: "",
116
+ instancePath: "",
117
+ keyword: "pattern",
118
+ message: 'must match pattern "^[0-9a-fA-F]{24}$"',
119
+ params: {
120
+ pattern: "^[0-9a-fA-F]{24}$"
121
+ },
122
+ schemaPath: "#/pattern"
123
+ }
124
+ ],
125
+ message: 'Bad request on parameter "request.path.scopeId".\nValue must match pattern "^[0-9a-fA-F]{24}$". Given value: "1"',
126
+ name: "AJV_VALIDATION_ERROR",
127
+ status: 400
128
+ });
129
+ });
130
+ it("Scenario 5b: GET /rest/path-params/scenario-5/scopeId", async () => {
131
+ await request.get("/rest/path-params/scenario-5/5ce4ee471495836c5e2e4cb0").expect(200);
132
+ });
133
+ it("Scenario 6: GET /rest/path-params/scenario-6/id", async () => {
134
+ const response = await request.get("/rest/path-params/scenario-6/1").expect(200);
135
+ expect(response.body).toEqual({ id: 1 });
136
+ });
137
+ }
138
+ //# sourceMappingURL=testPathParams.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testPathParams.js","sourceRoot":"","sources":["../../../src/tests/testPathParams.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,EAAE,YAAY,EAAE,IAAI,EAAC,MAAM,cAAc,CAAC;AACtF,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AACrC,OAAO,SAAS,MAAM,WAAW,CAAC;AAIlC,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAEtB,KAAK,CAAC,aAAa,CAAsB,KAAa;QACpD,iFAAiF;QACjF,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAA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C,GAAG,CAAC,uDAAuD,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACzF,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iDAAiD,EAAE,KAAK,IAAI,EAAE;QAC/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","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"]}