@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,97 @@
1
+ import { __decorate, __metadata, __param } from "tslib";
2
+ import { BodyParams, Controller, Get, PlatformResponse, PlatformTest, Res } from "@tsed/common";
3
+ import { Returns } from "@tsed/schema";
4
+ import SuperTest from "supertest";
5
+ let HeadersCtrl = class HeadersCtrl {
6
+ testScenario1(value) {
7
+ return "hello";
8
+ }
9
+ testScenario2() {
10
+ return "<xml></xml>";
11
+ }
12
+ testScenario3(response) {
13
+ response.setHeader("Location", `/v1/location`);
14
+ return "Hello";
15
+ }
16
+ };
17
+ __decorate([
18
+ Get("/scenario-1"),
19
+ Returns(200, String).Header("test", "x-token"),
20
+ __param(0, BodyParams("test")),
21
+ __metadata("design:type", Function),
22
+ __metadata("design:paramtypes", [Array]),
23
+ __metadata("design:returntype", Object)
24
+ ], HeadersCtrl.prototype, "testScenario1", null);
25
+ __decorate([
26
+ Get("/scenario-2"),
27
+ Returns(200, String).Header("x-token-test", "test").Header("x-token-test-2", "test2").ContentType("application/xml"),
28
+ __metadata("design:type", Function),
29
+ __metadata("design:paramtypes", []),
30
+ __metadata("design:returntype", void 0)
31
+ ], HeadersCtrl.prototype, "testScenario2", null);
32
+ __decorate([
33
+ Get("/scenario-3"),
34
+ Returns(200, String).Headers({
35
+ Location: {
36
+ description: "URL to the new xxx",
37
+ type: "string",
38
+ value: "/v1/location/header"
39
+ }
40
+ }),
41
+ __param(0, Res()),
42
+ __metadata("design:type", Function),
43
+ __metadata("design:paramtypes", [PlatformResponse]),
44
+ __metadata("design:returntype", void 0)
45
+ ], HeadersCtrl.prototype, "testScenario3", null);
46
+ HeadersCtrl = __decorate([
47
+ Controller("/headers")
48
+ ], HeadersCtrl);
49
+ export { HeadersCtrl };
50
+ export function testHeaders(options) {
51
+ let request;
52
+ beforeAll(PlatformTest.bootstrap(options.server, {
53
+ ...options,
54
+ logger: {
55
+ level: "off"
56
+ },
57
+ mount: {
58
+ "/rest": [HeadersCtrl]
59
+ }
60
+ }));
61
+ beforeAll(() => {
62
+ request = SuperTest(PlatformTest.callback());
63
+ });
64
+ afterAll(PlatformTest.reset);
65
+ it("Scenario1: GET /rest/headers/scenario-1", async () => {
66
+ const response = await request.get("/rest/headers/scenario-1").expect(200);
67
+ expect(response.text).toEqual("hello");
68
+ expect(response.header["test"]).toEqual("x-token");
69
+ });
70
+ it("Scenario2: GET /rest/headers/scenario-2", (done) => {
71
+ request
72
+ .get("/rest/headers/scenario-2")
73
+ .expect(200)
74
+ .end((err, response) => {
75
+ if (err) {
76
+ throw err;
77
+ }
78
+ expect(response.headers["x-token-test"]).toEqual("test");
79
+ expect(response.headers["x-token-test-2"]).toEqual("test2");
80
+ expect(response.headers["content-type"]).toContain("application/xml");
81
+ done();
82
+ });
83
+ });
84
+ it("Scenario3: GET /rest/headers/scenario-3", (done) => {
85
+ request
86
+ .get("/rest/headers/scenario-3")
87
+ .expect(200)
88
+ .end((err, response) => {
89
+ if (err) {
90
+ throw err;
91
+ }
92
+ expect(response.headers["location"]).toEqual("/v1/location");
93
+ done();
94
+ });
95
+ });
96
+ }
97
+ //# sourceMappingURL=testHeaders.js.map
@@ -0,0 +1 @@
1
+ {"version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,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC5D,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC;YAEtE,IAAI,EAAE,CAAC;QACT,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yCAAyC,EAAE,CAAC,IAAc,EAAE,EAAE;QAC/D,OAAO;aACJ,GAAG,CAAC,0BAA0B,CAAC;aAC/B,MAAM,CAAC,GAAG,CAAC;aACX,GAAG,CAAC,CAAC,GAAQ,EAAE,QAAa,EAAE,EAAE;YAC/B,IAAI,GAAG,EAAE;gBACP,MAAM,GAAG,CAAC;aACX;YAED,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;YAE7D,IAAI,EAAE,CAAC;QACT,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {BodyParams, Controller, Get, PlatformResponse, PlatformTest, Res} from \"@tsed/common\";\nimport {Returns} from \"@tsed/schema\";\nimport SuperTest from \"supertest\";\nimport {PlatformTestingSdkOpts} from \"../interfaces\";\n\n@Controller(\"/headers\")\nexport class HeadersCtrl {\n @Get(\"/scenario-1\")\n @Returns(200, String).Header(\"test\", \"x-token\")\n testScenario1(@BodyParams(\"test\") value: string[]): any {\n return \"hello\";\n }\n\n @Get(\"/scenario-2\")\n @Returns(200, String).Header(\"x-token-test\", \"test\").Header(\"x-token-test-2\", \"test2\").ContentType(\"application/xml\")\n testScenario2() {\n return \"<xml></xml>\";\n }\n\n @Get(\"/scenario-3\")\n @Returns(200, String).Headers({\n Location: {\n description: \"URL to the new xxx\",\n type: \"string\",\n value: \"/v1/location/header\"\n }\n })\n testScenario3(@Res() response: PlatformResponse) {\n response.setHeader(\"Location\", `/v1/location`);\n return \"Hello\";\n }\n}\n\nexport function testHeaders(options: PlatformTestingSdkOpts) {\n let request: SuperTest.SuperTest<SuperTest.Test>;\n\n beforeAll(\n PlatformTest.bootstrap(options.server, {\n ...options,\n logger: {\n level: \"off\"\n },\n mount: {\n \"/rest\": [HeadersCtrl]\n }\n })\n );\n beforeAll(() => {\n request = SuperTest(PlatformTest.callback());\n });\n afterAll(PlatformTest.reset);\n\n it(\"Scenario1: GET /rest/headers/scenario-1\", async () => {\n const response = await request.get(\"/rest/headers/scenario-1\").expect(200);\n\n expect(response.text).toEqual(\"hello\");\n expect(response.header[\"test\"]).toEqual(\"x-token\");\n });\n\n it(\"Scenario2: GET /rest/headers/scenario-2\", (done: Function) => {\n request\n .get(\"/rest/headers/scenario-2\")\n .expect(200)\n .end((err: any, response: any) => {\n if (err) {\n throw err;\n }\n\n expect(response.headers[\"x-token-test\"]).toEqual(\"test\");\n expect(response.headers[\"x-token-test-2\"]).toEqual(\"test2\");\n expect(response.headers[\"content-type\"]).toContain(\"application/xml\");\n\n done();\n });\n });\n\n it(\"Scenario3: GET /rest/headers/scenario-3\", (done: Function) => {\n request\n .get(\"/rest/headers/scenario-3\")\n .expect(200)\n .end((err: any, response: any) => {\n if (err) {\n throw err;\n }\n\n expect(response.headers[\"location\"]).toEqual(\"/v1/location\");\n\n done();\n });\n });\n}\n"]}
@@ -0,0 +1,167 @@
1
+ import { __decorate, __metadata, __param } from "tslib";
2
+ import { BodyParams, Controller, Get, Middleware, PathParams, PlatformTest, Post, UseAuth } from "@tsed/common";
3
+ import { NotFound } from "@tsed/exceptions";
4
+ import { Description, MaxLength, MinLength, Property, Returns, Summary } from "@tsed/schema";
5
+ import SuperTest from "supertest";
6
+ export class Resource {
7
+ id;
8
+ name;
9
+ }
10
+ __decorate([
11
+ Property(),
12
+ __metadata("design:type", String)
13
+ ], Resource.prototype, "id", void 0);
14
+ __decorate([
15
+ Property(),
16
+ MinLength(3),
17
+ MaxLength(100),
18
+ __metadata("design:type", String)
19
+ ], Resource.prototype, "name", void 0);
20
+ export class BaseController {
21
+ resources;
22
+ async get(id) {
23
+ const resource = this.resources.find((resource) => resource.id === id);
24
+ if (!resource) {
25
+ throw new NotFound("Not found");
26
+ }
27
+ return resource;
28
+ }
29
+ async list() {
30
+ return this.resources;
31
+ }
32
+ }
33
+ __decorate([
34
+ Get("/:id"),
35
+ Summary("Return an element by his resource"),
36
+ __param(0, Description("Id of the resource")),
37
+ __param(0, PathParams("id")),
38
+ __metadata("design:type", Function),
39
+ __metadata("design:paramtypes", [String]),
40
+ __metadata("design:returntype", Promise)
41
+ ], BaseController.prototype, "get", null);
42
+ __decorate([
43
+ Get("/"),
44
+ Summary("Return all elements from a service"),
45
+ __metadata("design:type", Function),
46
+ __metadata("design:paramtypes", []),
47
+ __metadata("design:returntype", Promise)
48
+ ], BaseController.prototype, "list", null);
49
+ let ResourcesCtrl = class ResourcesCtrl extends BaseController {
50
+ resources = [{ id: "1", name: "John" }];
51
+ async get(id) {
52
+ const resource = await super.get(id);
53
+ resource.name = resource.name + " hello You!";
54
+ return resource;
55
+ }
56
+ async post(resource) {
57
+ resource.id = require("uuid").v4();
58
+ this.resources.push(resource);
59
+ return resource;
60
+ }
61
+ };
62
+ __decorate([
63
+ Get("/:id"),
64
+ Summary("Return an element by his resource"),
65
+ __param(0, Description("Id of the resource")),
66
+ __param(0, PathParams("id")),
67
+ __metadata("design:type", Function),
68
+ __metadata("design:paramtypes", [String]),
69
+ __metadata("design:returntype", Promise)
70
+ ], ResourcesCtrl.prototype, "get", null);
71
+ __decorate([
72
+ Post("/"),
73
+ Returns(201).Type(Resource),
74
+ __param(0, BodyParams()),
75
+ __metadata("design:type", Function),
76
+ __metadata("design:paramtypes", [Resource]),
77
+ __metadata("design:returntype", Promise)
78
+ ], ResourcesCtrl.prototype, "post", null);
79
+ ResourcesCtrl = __decorate([
80
+ Controller("/resources")
81
+ ], ResourcesCtrl);
82
+ export { ResourcesCtrl };
83
+ let AuthMiddleware = class AuthMiddleware {
84
+ use() {
85
+ return true;
86
+ }
87
+ };
88
+ AuthMiddleware = __decorate([
89
+ Middleware()
90
+ ], AuthMiddleware);
91
+ class AttachmentController {
92
+ getAll(parentID) {
93
+ return `All attachments of ${parentID}`;
94
+ }
95
+ }
96
+ __decorate([
97
+ Get("/:parentID/attachments"),
98
+ __param(0, PathParams("parentID")),
99
+ __metadata("design:type", Function),
100
+ __metadata("design:paramtypes", [String]),
101
+ __metadata("design:returntype", void 0)
102
+ ], AttachmentController.prototype, "getAll", null);
103
+ let FindingsController = class FindingsController extends AttachmentController {
104
+ get() {
105
+ return "hello Finding";
106
+ }
107
+ };
108
+ __decorate([
109
+ Get("/"),
110
+ __metadata("design:type", Function),
111
+ __metadata("design:paramtypes", []),
112
+ __metadata("design:returntype", void 0)
113
+ ], FindingsController.prototype, "get", null);
114
+ FindingsController = __decorate([
115
+ Controller("/findings"),
116
+ UseAuth(AuthMiddleware)
117
+ ], FindingsController);
118
+ export { FindingsController };
119
+ export function testInheritanceController(options) {
120
+ let request;
121
+ beforeAll(PlatformTest.bootstrap(options.server, {
122
+ ...options,
123
+ mount: {
124
+ "/rest": [ResourcesCtrl, FindingsController]
125
+ }
126
+ }));
127
+ beforeAll(() => {
128
+ request = SuperTest(PlatformTest.callback());
129
+ });
130
+ afterAll(PlatformTest.reset);
131
+ describe("Scenario 1:", () => {
132
+ it("should return list", async () => {
133
+ const { body } = await request.get("/rest/resources").expect(200);
134
+ expect(body).toEqual([{ id: "1", name: "John" }]);
135
+ });
136
+ it("should return a resource", async () => {
137
+ const { body } = await request.get("/rest/resources/1").expect(200);
138
+ expect(body).toEqual({
139
+ id: "1",
140
+ name: "John hello You!"
141
+ });
142
+ });
143
+ it("should add a resource", async () => {
144
+ const { body } = await request
145
+ .post("/rest/resources")
146
+ .send({
147
+ name: "july"
148
+ })
149
+ .expect(201);
150
+ expect(body.name).toEqual("july");
151
+ expect(typeof body.id).toBe("string");
152
+ const { body: resource } = await request.get(`/rest/resources/${body.id}`).expect(200);
153
+ expect(resource.id).toEqual(body.id);
154
+ });
155
+ });
156
+ describe("scenario2: FindingsController", () => {
157
+ it("should call /rest/findings/:parentID/attachments", async () => {
158
+ const { text } = await request.get("/rest/findings/1/attachments").expect(200);
159
+ expect(text).toEqual("All attachments of 1");
160
+ });
161
+ it("should call /rest/findings/", async () => {
162
+ const { text } = await request.get("/rest/findings").expect(200);
163
+ expect(text).toEqual("hello Finding");
164
+ });
165
+ });
166
+ }
167
+ //# sourceMappingURL=testInheritanceController.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testInheritanceController.js","sourceRoot":"","sources":["../../../src/tests/testInheritanceController.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,EAAC,MAAM,cAAc,CAAC;AAC9G,OAAO,EAAC,QAAQ,EAAC,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAC,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAC,MAAM,cAAc,CAAC;AAC3F,OAAO,SAAS,MAAM,WAAW,CAAC;AAGlC,MAAM,OAAO,QAAQ;IAEnB,EAAE,CAAS;IAKX,IAAI,CAAS;CACd;AANC;IADC,QAAQ,EAAE;;oCACA;AAKX;IAHC,QAAQ,EAAE;IACV,SAAS,CAAC,CAAC,CAAC;IACZ,SAAS,CAAC,GAAG,CAAC;;sCACF;AAGf,MAAM,OAAO,cAAc;IACzB,SAAS,CAAM;IAIf,KAAK,CAAC,GAAG,CAGP,EAAU;QAEV,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAEvE,IAAI,CAAC,QAAQ,EAAE;YACb,MAAM,IAAI,QAAQ,CAAC,WAAW,CAAC,CAAC;SACjC;QAED,OAAO,QAA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AAC;IAEH,QAAQ,CAAC,+BAA+B,EAAE,GAAG,EAAE;QAC7C,EAAE,CAAC,kDAAkD,EAAE,KAAK,IAAI,EAAE;YAChE,MAAM,EAAC,IAAI,EAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAE7E,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,6BAA6B,EAAE,KAAK,IAAI,EAAE;YAC3C,MAAM,EAAC,IAAI,EAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAE/D,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {BodyParams, Controller, Get, Middleware, PathParams, PlatformTest, Post, UseAuth} from \"@tsed/common\";\nimport {NotFound} from \"@tsed/exceptions\";\nimport {Description, MaxLength, MinLength, Property, Returns, Summary} from \"@tsed/schema\";\nimport SuperTest from \"supertest\";\nimport {PlatformTestingSdkOpts} from \"../interfaces\";\n\nexport class Resource {\n @Property()\n id: string;\n\n @Property()\n @MinLength(3)\n @MaxLength(100)\n name: string;\n}\n\nexport class BaseController<T extends {id: string}> {\n resources: T[];\n\n @Get(\"/:id\")\n @Summary(\"Return an element by his resource\")\n async get(\n @Description(\"Id of the resource\")\n @PathParams(\"id\")\n id: string\n ): Promise<any> {\n const resource = this.resources.find((resource) => resource.id === id);\n\n if (!resource) {\n throw new NotFound(\"Not found\");\n }\n\n return resource;\n }\n\n @Get(\"/\")\n @Summary(\"Return all elements from a service\")\n async list(): Promise<any[]> {\n return this.resources;\n }\n}\n\n@Controller(\"/resources\")\nexport class ResourcesCtrl extends BaseController<Resource> {\n resources = [{id: \"1\", name: \"John\"}];\n\n @Get(\"/:id\")\n @Summary(\"Return an element by his resource\")\n async get(\n @Description(\"Id of the resource\")\n @PathParams(\"id\")\n id: string\n ): Promise<any> {\n const resource = await super.get(id);\n\n resource.name = resource.name + \" hello You!\";\n\n return resource;\n }\n\n @Post(\"/\")\n @Returns(201).Type(Resource)\n async post(@BodyParams() resource: Resource) {\n resource.id = require(\"uuid\").v4();\n this.resources.push(resource);\n\n return resource;\n }\n}\n\n@Middleware()\nclass AuthMiddleware {\n use() {\n return true;\n }\n}\n\nabstract class AttachmentController {\n @Get(\"/:parentID/attachments\")\n getAll(@PathParams(\"parentID\") parentID: string) {\n return `All attachments of ${parentID}`;\n }\n}\n\n@Controller(\"/findings\")\n@UseAuth(AuthMiddleware)\nexport class FindingsController extends AttachmentController {\n @Get(\"/\")\n get() {\n return \"hello Finding\";\n }\n}\n\nexport function testInheritanceController(options: PlatformTestingSdkOpts) {\n let request: SuperTest.SuperTest<SuperTest.Test>;\n\n beforeAll(\n PlatformTest.bootstrap(options.server, {\n ...options,\n mount: {\n \"/rest\": [ResourcesCtrl, FindingsController]\n }\n })\n );\n beforeAll(() => {\n request = SuperTest(PlatformTest.callback());\n });\n afterAll(PlatformTest.reset);\n\n describe(\"Scenario 1:\", () => {\n it(\"should return list\", async () => {\n const {body} = await request.get(\"/rest/resources\").expect(200);\n\n expect(body).toEqual([{id: \"1\", name: \"John\"}]);\n });\n\n it(\"should return a resource\", async () => {\n const {body} = await request.get(\"/rest/resources/1\").expect(200);\n\n expect(body).toEqual({\n id: \"1\",\n name: \"John hello You!\"\n });\n });\n\n it(\"should add a resource\", async () => {\n const {body} = await request\n .post(\"/rest/resources\")\n .send({\n name: \"july\"\n })\n .expect(201);\n\n expect(body.name).toEqual(\"july\");\n expect(typeof body.id).toBe(\"string\");\n\n const {body: resource} = await request.get(`/rest/resources/${body.id}`).expect(200);\n\n expect(resource.id).toEqual(body.id);\n });\n });\n\n describe(\"scenario2: FindingsController\", () => {\n it(\"should call /rest/findings/:parentID/attachments\", async () => {\n const {text} = await request.get(\"/rest/findings/1/attachments\").expect(200);\n\n expect(text).toEqual(\"All attachments of 1\");\n });\n\n it(\"should call /rest/findings/\", async () => {\n const {text} = await request.get(\"/rest/findings\").expect(200);\n\n expect(text).toEqual(\"hello Finding\");\n });\n });\n}\n"]}
@@ -0,0 +1,59 @@
1
+ import { __decorate, __metadata, __param } from "tslib";
2
+ import { Context, Controller, Get, Locals, Middleware, PlatformContext, PlatformTest, Req, Use } from "@tsed/common";
3
+ import SuperTest from "supertest";
4
+ let LocalsMiddleware = class LocalsMiddleware {
5
+ use(request, locals, ctx) {
6
+ locals.id = "local-10909";
7
+ ctx.set("uid", "ctx-10909");
8
+ }
9
+ };
10
+ __decorate([
11
+ __param(0, Req()),
12
+ __param(1, Locals()),
13
+ __param(2, Context()),
14
+ __metadata("design:type", Function),
15
+ __metadata("design:paramtypes", [Object, Object, PlatformContext]),
16
+ __metadata("design:returntype", void 0)
17
+ ], LocalsMiddleware.prototype, "use", null);
18
+ LocalsMiddleware = __decorate([
19
+ Middleware()
20
+ ], LocalsMiddleware);
21
+ let LocalsCtrl = class LocalsCtrl {
22
+ testStackMiddlewares(id, uid) {
23
+ return {
24
+ id: `${id}-${uid}`
25
+ };
26
+ }
27
+ };
28
+ __decorate([
29
+ Get("/scenario-1"),
30
+ Use(LocalsMiddleware),
31
+ __param(0, Locals("id")),
32
+ __param(1, Context("uid")),
33
+ __metadata("design:type", Function),
34
+ __metadata("design:paramtypes", [Object, String]),
35
+ __metadata("design:returntype", Object)
36
+ ], LocalsCtrl.prototype, "testStackMiddlewares", null);
37
+ LocalsCtrl = __decorate([
38
+ Controller("/locals")
39
+ ], LocalsCtrl);
40
+ export function testLocals(options) {
41
+ let request;
42
+ beforeAll(PlatformTest.bootstrap(options.server, {
43
+ ...options,
44
+ mount: {
45
+ "/rest": [LocalsCtrl]
46
+ }
47
+ }));
48
+ beforeAll(() => {
49
+ request = SuperTest(PlatformTest.callback());
50
+ });
51
+ afterAll(PlatformTest.reset);
52
+ describe("Scenario 1: GET /rest/locals/scenario-1", () => {
53
+ it("should call middleware and set a id in locals", async () => {
54
+ const { body } = await request.get("/rest/locals/scenario-1").expect(200);
55
+ expect(body.id).toEqual("local-10909-ctx-10909");
56
+ });
57
+ });
58
+ }
59
+ //# sourceMappingURL=testLocals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testLocals.js","sourceRoot":"","sources":["../../../src/tests/testLocals.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAQ,eAAe,EAAE,YAAY,EAAE,GAAG,EAAgB,GAAG,EAAC,MAAM,cAAc,CAAC;AACvI,OAAO,SAAS,MAAM,WAAW,CAAC;AAIlC,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IACpB,GAAG,CAAQ,OAAY,EAAY,MAAW,EAAa,GAAoB;QAC7E,MAAM,CAAC,EAAE,GAAG,aAAa,CAAC;QAC1B,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAC9B,CAAC;CACF,CAAA;AAJC;IAAK,WAAA,GAAG,EAAE,CAAA;IAAgB,WAAA,MAAM,EAAE,CAAA;IAAe,WAAA,OAAO,EAAE,CAAA;;qDAAM,eAAe;;2CAG9E;AAJG,gBAAgB;IADrB,UAAU,EAAE;GACP,gBAAgB,CAKrB;AAGD,IAAM,UAAU,GAAhB,MAAM,UAAU;IAGP,oBAAoB,CAAe,EAAO,EAAkB,GAAW;QAC5E,OAAO;YACL,EAAE,EAAE,GAAG,EAAE,IAAI,GAAG,EAAE;SACnB,CAAC;IACJ,CAAC;CACF,CAAA;AALC;IAFC,GAAG,CAAC,aAAa,CAAC;IAClB,GAAG,CAAC,gBAAgB,CAAC;IACO,WAAA,MAAM,CAAC,IAAI,CAAC,CAAA;IAAW,WAAA,OAAO,CAAC,KAAK,CAAC,CAAA;;;;sDAIjE;AAPG,UAAU;IADf,UAAU,CAAC,SAAS,CAAC;GAChB,UAAU,CAQf;AAED,MAAM,UAAU,UAAU,CAAC,OAA+B;IACxD,IAAI,OAA4C,CAAC;IACjD,SAAS,CACP,YAAY,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE;QACrC,GAAG,OAAO;QACV,KAAK,EAAE;YACL,OAAO,EAAE,CAAC,UAAU,CAAC;SACtB;KACF,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,yCAAyC,EAAE,GAAG,EAAE;QACvD,EAAE,CAAC,+CAA+C,EAAE,KAAK,IAAI,EAAE;YAC7D,MAAM,EAAC,IAAI,EAAC,GAAQ,MAAM,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAE7E,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {Context, Controller, Get, Locals, Middleware, Next, PlatformContext, PlatformTest, Req, Request, Res, Use} from \"@tsed/common\";\nimport SuperTest from \"supertest\";\nimport {PlatformTestingSdkOpts} from \"../interfaces\";\n\n@Middleware()\nclass LocalsMiddleware {\n use(@Req() request: any, @Locals() locals: any, @Context() ctx: PlatformContext) {\n locals.id = \"local-10909\";\n ctx.set(\"uid\", \"ctx-10909\");\n }\n}\n\n@Controller(\"/locals\")\nclass LocalsCtrl {\n @Get(\"/scenario-1\")\n @Use(LocalsMiddleware)\n public testStackMiddlewares(@Locals(\"id\") id: any, @Context(\"uid\") uid: string): any {\n return {\n id: `${id}-${uid}`\n };\n }\n}\n\nexport function testLocals(options: PlatformTestingSdkOpts) {\n let request: SuperTest.SuperTest<SuperTest.Test>;\n beforeAll(\n PlatformTest.bootstrap(options.server, {\n ...options,\n mount: {\n \"/rest\": [LocalsCtrl]\n }\n })\n );\n beforeAll(() => {\n request = SuperTest(PlatformTest.callback());\n });\n afterAll(PlatformTest.reset);\n\n describe(\"Scenario 1: GET /rest/locals/scenario-1\", () => {\n it(\"should call middleware and set a id in locals\", async () => {\n const {body}: any = await request.get(\"/rest/locals/scenario-1\").expect(200);\n\n expect(body.id).toEqual(\"local-10909-ctx-10909\");\n });\n });\n}\n"]}
@@ -0,0 +1,38 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { Controller, Get, PlatformTest } from "@tsed/common";
3
+ import SuperTest from "supertest";
4
+ import { Location } from "@tsed/schema";
5
+ let LocationCtrl = class LocationCtrl {
6
+ testScenario1() {
7
+ return "Hello";
8
+ }
9
+ };
10
+ __decorate([
11
+ Get("/scenario-1"),
12
+ Location("/test"),
13
+ __metadata("design:type", Function),
14
+ __metadata("design:paramtypes", []),
15
+ __metadata("design:returntype", void 0)
16
+ ], LocationCtrl.prototype, "testScenario1", null);
17
+ LocationCtrl = __decorate([
18
+ Controller("/location")
19
+ ], LocationCtrl);
20
+ export function testLocation(options) {
21
+ let request;
22
+ beforeAll(PlatformTest.bootstrap(options.server, {
23
+ ...options,
24
+ mount: {
25
+ "/rest": [LocationCtrl]
26
+ }
27
+ }));
28
+ beforeAll(() => {
29
+ request = SuperTest(PlatformTest.callback());
30
+ });
31
+ afterAll(PlatformTest.reset);
32
+ it("Scenario1: GET /rest/location/scenario-1", async () => {
33
+ const response = await request.get("/rest/location/scenario-1").expect(200);
34
+ expect(response.text).toEqual("Hello");
35
+ expect(response.header.location).toEqual("/test");
36
+ });
37
+ }
38
+ //# sourceMappingURL=testLocation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testLocation.js","sourceRoot":"","sources":["../../../src/tests/testLocation.ts"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\nimport {Location} from \"@tsed/schema\";\nimport {PlatformTestingSdkOpts} from \"../interfaces\";\n\n@Controller(\"/location\")\nclass LocationCtrl {\n @Get(\"/scenario-1\")\n @Location(\"/test\")\n testScenario1() {\n return \"Hello\";\n }\n}\n\nexport function testLocation(options: PlatformTestingSdkOpts) {\n let request: SuperTest.SuperTest<SuperTest.Test>;\n\n beforeAll(\n PlatformTest.bootstrap(options.server, {\n ...options,\n mount: {\n \"/rest\": [LocationCtrl]\n }\n })\n );\n beforeAll(() => {\n request = SuperTest(PlatformTest.callback());\n });\n afterAll(PlatformTest.reset);\n\n it(\"Scenario1: GET /rest/location/scenario-1\", async () => {\n const response = await request.get(\"/rest/location/scenario-1\").expect(200);\n\n expect(response.text).toEqual(\"Hello\");\n expect(response.header.location).toEqual(\"/test\");\n });\n}\n"]}
@@ -0,0 +1,206 @@
1
+ import { __decorate, __metadata, __param } from "tslib";
2
+ import "@tsed/ajv";
3
+ import { Context, Controller, Err, Get, Middleware, PlatformTest, QueryParams, Use, UseAfter, UseBefore } from "@tsed/common";
4
+ import { BadRequest, Exception, Unauthorized } from "@tsed/exceptions";
5
+ import SuperTest from "supertest";
6
+ let BeforeCustomMiddleware = class BeforeCustomMiddleware {
7
+ use(ctx) {
8
+ ctx.set("stacks", ["UseBefore - Ctrl"]);
9
+ }
10
+ };
11
+ __decorate([
12
+ __param(0, Context()),
13
+ __metadata("design:type", Function),
14
+ __metadata("design:paramtypes", [Object]),
15
+ __metadata("design:returntype", void 0)
16
+ ], BeforeCustomMiddleware.prototype, "use", null);
17
+ BeforeCustomMiddleware = __decorate([
18
+ Middleware()
19
+ ], BeforeCustomMiddleware);
20
+ let BeforeEndpointCustomMiddleware = class BeforeEndpointCustomMiddleware {
21
+ use(ctx) {
22
+ ctx.get("stacks").push("UseBefore - endpoint");
23
+ }
24
+ };
25
+ __decorate([
26
+ __param(0, Context()),
27
+ __metadata("design:type", Function),
28
+ __metadata("design:paramtypes", [Object]),
29
+ __metadata("design:returntype", void 0)
30
+ ], BeforeEndpointCustomMiddleware.prototype, "use", null);
31
+ BeforeEndpointCustomMiddleware = __decorate([
32
+ Middleware()
33
+ ], BeforeEndpointCustomMiddleware);
34
+ let AfterCustomMiddleware = class AfterCustomMiddleware {
35
+ use(ctx) {
36
+ ctx.get("stacks").push("UseAfter - Ctrl");
37
+ }
38
+ };
39
+ __decorate([
40
+ __param(0, Context()),
41
+ __metadata("design:type", Function),
42
+ __metadata("design:paramtypes", [Object]),
43
+ __metadata("design:returntype", void 0)
44
+ ], AfterCustomMiddleware.prototype, "use", null);
45
+ AfterCustomMiddleware = __decorate([
46
+ Middleware()
47
+ ], AfterCustomMiddleware);
48
+ let UseCustomMiddleware = class UseCustomMiddleware {
49
+ use(ctx) {
50
+ ctx.get("stacks").push("Use - Ctrl");
51
+ }
52
+ };
53
+ __decorate([
54
+ __param(0, Context()),
55
+ __metadata("design:type", Function),
56
+ __metadata("design:paramtypes", [Object]),
57
+ __metadata("design:returntype", void 0)
58
+ ], UseCustomMiddleware.prototype, "use", null);
59
+ UseCustomMiddleware = __decorate([
60
+ Middleware()
61
+ ], UseCustomMiddleware);
62
+ let AfterEndpointCustomMiddleware = class AfterEndpointCustomMiddleware {
63
+ use(ctx) {
64
+ ctx.get("stacks").push("UseAfter - endpoint");
65
+ }
66
+ };
67
+ __decorate([
68
+ __param(0, Context()),
69
+ __metadata("design:type", Function),
70
+ __metadata("design:paramtypes", [Object]),
71
+ __metadata("design:returntype", void 0)
72
+ ], AfterEndpointCustomMiddleware.prototype, "use", null);
73
+ AfterEndpointCustomMiddleware = __decorate([
74
+ Middleware()
75
+ ], AfterEndpointCustomMiddleware);
76
+ let UseMiddleware = class UseMiddleware {
77
+ use(ctx) {
78
+ ctx.get("stacks").push("Use - Ctrl");
79
+ }
80
+ };
81
+ __decorate([
82
+ __param(0, Context()),
83
+ __metadata("design:type", Function),
84
+ __metadata("design:paramtypes", [Object]),
85
+ __metadata("design:returntype", void 0)
86
+ ], UseMiddleware.prototype, "use", null);
87
+ UseMiddleware = __decorate([
88
+ Middleware()
89
+ ], UseMiddleware);
90
+ let UseEndpointMiddleware = class UseEndpointMiddleware {
91
+ use(ctx) {
92
+ ctx.get("stacks").push("Use - endpoint");
93
+ }
94
+ };
95
+ __decorate([
96
+ __param(0, Context()),
97
+ __metadata("design:type", Function),
98
+ __metadata("design:paramtypes", [Object]),
99
+ __metadata("design:returntype", void 0)
100
+ ], UseEndpointMiddleware.prototype, "use", null);
101
+ UseEndpointMiddleware = __decorate([
102
+ Middleware()
103
+ ], UseEndpointMiddleware);
104
+ let CatchErrorMiddleware = class CatchErrorMiddleware {
105
+ use(err) {
106
+ if ([401].includes(err.status)) {
107
+ throw new BadRequest("Bad format");
108
+ }
109
+ throw err;
110
+ }
111
+ };
112
+ __decorate([
113
+ __param(0, Err()),
114
+ __metadata("design:type", Function),
115
+ __metadata("design:paramtypes", [Exception]),
116
+ __metadata("design:returntype", void 0)
117
+ ], CatchErrorMiddleware.prototype, "use", null);
118
+ CatchErrorMiddleware = __decorate([
119
+ Middleware()
120
+ ], CatchErrorMiddleware);
121
+ export { CatchErrorMiddleware };
122
+ let TestMiddlewaresCtrl = class TestMiddlewaresCtrl {
123
+ scenario1(context) {
124
+ context.get("stacks").push("endpoint");
125
+ return { stacks: context.get("stacks") };
126
+ }
127
+ scenario2(test) {
128
+ if (test === "error") {
129
+ throw new Unauthorized("Unauthorized");
130
+ }
131
+ return {
132
+ hello: "world"
133
+ };
134
+ }
135
+ };
136
+ __decorate([
137
+ Get("/scenario-1"),
138
+ UseBefore(BeforeEndpointCustomMiddleware),
139
+ UseAfter(AfterEndpointCustomMiddleware),
140
+ Use(UseEndpointMiddleware),
141
+ __param(0, Context()),
142
+ __metadata("design:type", Function),
143
+ __metadata("design:paramtypes", [Object]),
144
+ __metadata("design:returntype", void 0)
145
+ ], TestMiddlewaresCtrl.prototype, "scenario1", null);
146
+ __decorate([
147
+ Get("/scenario-2"),
148
+ __param(0, QueryParams("test")),
149
+ __metadata("design:type", Function),
150
+ __metadata("design:paramtypes", [String]),
151
+ __metadata("design:returntype", void 0)
152
+ ], TestMiddlewaresCtrl.prototype, "scenario2", null);
153
+ TestMiddlewaresCtrl = __decorate([
154
+ Controller("/middlewares"),
155
+ UseBefore(BeforeCustomMiddleware),
156
+ UseAfter(AfterCustomMiddleware),
157
+ UseAfter(CatchErrorMiddleware),
158
+ Use(UseCustomMiddleware)
159
+ ], TestMiddlewaresCtrl);
160
+ export function testMiddlewares(options) {
161
+ let request;
162
+ beforeAll(PlatformTest.bootstrap(options.server, {
163
+ ...options,
164
+ mount: {
165
+ "/rest": [TestMiddlewaresCtrl]
166
+ }
167
+ }));
168
+ beforeAll(() => {
169
+ request = SuperTest(PlatformTest.callback());
170
+ });
171
+ afterAll(PlatformTest.reset);
172
+ describe("Scenario 1: GET /rest/middlewares/scenario-1", () => {
173
+ it("should call all middlewares", async () => {
174
+ const response = await request.get("/rest/middlewares/scenario-1").expect(200);
175
+ expect(response.body).toEqual({
176
+ stacks: [
177
+ "UseBefore - Ctrl",
178
+ "UseBefore - endpoint",
179
+ "Use - Ctrl",
180
+ "Use - endpoint",
181
+ "endpoint",
182
+ "UseAfter - endpoint",
183
+ "UseAfter - Ctrl"
184
+ ]
185
+ });
186
+ });
187
+ });
188
+ describe("Scenario 2: GET /rest/middlewares/scenario-2", () => {
189
+ it("should call the endpoint without triggering middleware", async () => {
190
+ const response = await request.get("/rest/middlewares/scenario-2").expect(200);
191
+ expect(response.body).toEqual({
192
+ hello: "world"
193
+ });
194
+ });
195
+ it("should call the endpoint, throw an error and transform the error by calling the error middleware", async () => {
196
+ const response = await request.get("/rest/middlewares/scenario-2?test=error").expect(400);
197
+ expect(response.body).toEqual({
198
+ errors: [],
199
+ message: "Bad format",
200
+ name: "BAD_REQUEST",
201
+ status: 400
202
+ });
203
+ });
204
+ });
205
+ }
206
+ //# sourceMappingURL=testMiddlewares.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testMiddlewares.js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AO,EAAE,YAAY;gBACrB,IAAI,EAAE,aAAa;gBACnB,MAAM,EAAE,GAAG;aACZ,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import \"@tsed/ajv\";\nimport {\n Context,\n Controller,\n Err,\n Get,\n Middleware,\n MiddlewareMethods,\n PlatformTest,\n QueryParams,\n Use,\n UseAfter,\n UseBefore\n} from \"@tsed/common\";\nimport {BadRequest, Exception, Unauthorized} from \"@tsed/exceptions\";\nimport SuperTest from \"supertest\";\nimport {PlatformTestingSdkOpts} from \"../interfaces\";\n\n@Middleware()\nclass BeforeCustomMiddleware {\n use(@Context() ctx: Context) {\n ctx.set(\"stacks\", [\"UseBefore - Ctrl\"]);\n }\n}\n\n@Middleware()\nclass BeforeEndpointCustomMiddleware {\n use(@Context() ctx: Context) {\n ctx.get(\"stacks\").push(\"UseBefore - endpoint\");\n }\n}\n\n@Middleware()\nclass AfterCustomMiddleware {\n use(@Context() ctx: Context) {\n ctx.get(\"stacks\").push(\"UseAfter - Ctrl\");\n }\n}\n\n@Middleware()\nclass UseCustomMiddleware {\n use(@Context() ctx: Context) {\n ctx.get(\"stacks\").push(\"Use - Ctrl\");\n }\n}\n\n@Middleware()\nclass AfterEndpointCustomMiddleware {\n use(@Context() ctx: Context) {\n ctx.get(\"stacks\").push(\"UseAfter - endpoint\");\n }\n}\n\n@Middleware()\nclass UseMiddleware {\n use(@Context() ctx: Context) {\n ctx.get(\"stacks\").push(\"Use - Ctrl\");\n }\n}\n\n@Middleware()\nclass UseEndpointMiddleware {\n use(@Context() ctx: Context) {\n ctx.get(\"stacks\").push(\"Use - endpoint\");\n }\n}\n\n@Middleware()\nexport class CatchErrorMiddleware implements MiddlewareMethods {\n use(@Err() err: Exception) {\n if ([401].includes(err.status)) {\n throw new BadRequest(\"Bad format\");\n }\n\n throw err;\n }\n}\n\n@Controller(\"/middlewares\")\n@UseBefore(BeforeCustomMiddleware)\n@UseAfter(AfterCustomMiddleware)\n@UseAfter(CatchErrorMiddleware)\n@Use(UseCustomMiddleware)\nclass TestMiddlewaresCtrl {\n @Get(\"/scenario-1\")\n @UseBefore(BeforeEndpointCustomMiddleware)\n @UseAfter(AfterEndpointCustomMiddleware)\n @Use(UseEndpointMiddleware)\n scenario1(@Context() context: Context) {\n context.get(\"stacks\").push(\"endpoint\");\n\n return {stacks: context.get(\"stacks\")};\n }\n\n @Get(\"/scenario-2\")\n scenario2(@QueryParams(\"test\") test: string) {\n if (test === \"error\") {\n throw new Unauthorized(\"Unauthorized\");\n }\n\n return {\n hello: \"world\"\n };\n }\n}\n\nexport function testMiddlewares(options: PlatformTestingSdkOpts) {\n let request: SuperTest.SuperTest<SuperTest.Test>;\n\n beforeAll(\n PlatformTest.bootstrap(options.server, {\n ...options,\n mount: {\n \"/rest\": [TestMiddlewaresCtrl]\n }\n })\n );\n beforeAll(() => {\n request = SuperTest(PlatformTest.callback());\n });\n afterAll(PlatformTest.reset);\n\n describe(\"Scenario 1: GET /rest/middlewares/scenario-1\", () => {\n it(\"should call all middlewares\", async () => {\n const response = await request.get(\"/rest/middlewares/scenario-1\").expect(200);\n\n expect(response.body).toEqual({\n stacks: [\n \"UseBefore - Ctrl\",\n \"UseBefore - endpoint\",\n \"Use - Ctrl\",\n \"Use - endpoint\",\n \"endpoint\",\n \"UseAfter - endpoint\",\n \"UseAfter - Ctrl\"\n ]\n });\n });\n });\n describe(\"Scenario 2: GET /rest/middlewares/scenario-2\", () => {\n it(\"should call the endpoint without triggering middleware\", async () => {\n const response = await request.get(\"/rest/middlewares/scenario-2\").expect(200);\n\n expect(response.body).toEqual({\n hello: \"world\"\n });\n });\n it(\"should call the endpoint, throw an error and transform the error by calling the error middleware\", async () => {\n const response = await request.get(\"/rest/middlewares/scenario-2?test=error\").expect(400);\n\n expect(response.body).toEqual({\n errors: [],\n message: \"Bad format\",\n name: \"BAD_REQUEST\",\n status: 400\n });\n });\n });\n}\n"]}