@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,101 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.testHeaders = exports.HeadersCtrl = 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 HeadersCtrl = class HeadersCtrl {
9
+ testScenario1(value) {
10
+ return "hello";
11
+ }
12
+ testScenario2() {
13
+ return "<xml></xml>";
14
+ }
15
+ testScenario3(response) {
16
+ response.setHeader("Location", `/v1/location`);
17
+ return "Hello";
18
+ }
19
+ };
20
+ tslib_1.__decorate([
21
+ (0, common_1.Get)("/scenario-1"),
22
+ (0, schema_1.Returns)(200, String).Header("test", "x-token"),
23
+ tslib_1.__param(0, (0, common_1.BodyParams)("test")),
24
+ tslib_1.__metadata("design:type", Function),
25
+ tslib_1.__metadata("design:paramtypes", [Array]),
26
+ tslib_1.__metadata("design:returntype", Object)
27
+ ], HeadersCtrl.prototype, "testScenario1", null);
28
+ tslib_1.__decorate([
29
+ (0, common_1.Get)("/scenario-2"),
30
+ (0, schema_1.Returns)(200, String).Header("x-token-test", "test").Header("x-token-test-2", "test2").ContentType("application/xml"),
31
+ tslib_1.__metadata("design:type", Function),
32
+ tslib_1.__metadata("design:paramtypes", []),
33
+ tslib_1.__metadata("design:returntype", void 0)
34
+ ], HeadersCtrl.prototype, "testScenario2", null);
35
+ tslib_1.__decorate([
36
+ (0, common_1.Get)("/scenario-3"),
37
+ (0, schema_1.Returns)(200, String).Headers({
38
+ Location: {
39
+ description: "URL to the new xxx",
40
+ type: "string",
41
+ value: "/v1/location/header"
42
+ }
43
+ }),
44
+ tslib_1.__param(0, (0, common_1.Res)()),
45
+ tslib_1.__metadata("design:type", Function),
46
+ tslib_1.__metadata("design:paramtypes", [common_1.PlatformResponse]),
47
+ tslib_1.__metadata("design:returntype", void 0)
48
+ ], HeadersCtrl.prototype, "testScenario3", null);
49
+ HeadersCtrl = tslib_1.__decorate([
50
+ (0, common_1.Controller)("/headers")
51
+ ], HeadersCtrl);
52
+ exports.HeadersCtrl = HeadersCtrl;
53
+ function testHeaders(options) {
54
+ let request;
55
+ beforeAll(common_1.PlatformTest.bootstrap(options.server, {
56
+ ...options,
57
+ logger: {
58
+ level: "off"
59
+ },
60
+ mount: {
61
+ "/rest": [HeadersCtrl]
62
+ }
63
+ }));
64
+ beforeAll(() => {
65
+ request = (0, supertest_1.default)(common_1.PlatformTest.callback());
66
+ });
67
+ afterAll(common_1.PlatformTest.reset);
68
+ it("Scenario1: GET /rest/headers/scenario-1", async () => {
69
+ const response = await request.get("/rest/headers/scenario-1").expect(200);
70
+ expect(response.text).toEqual("hello");
71
+ expect(response.header["test"]).toEqual("x-token");
72
+ });
73
+ it("Scenario2: GET /rest/headers/scenario-2", (done) => {
74
+ request
75
+ .get("/rest/headers/scenario-2")
76
+ .expect(200)
77
+ .end((err, response) => {
78
+ if (err) {
79
+ throw err;
80
+ }
81
+ expect(response.headers["x-token-test"]).toEqual("test");
82
+ expect(response.headers["x-token-test-2"]).toEqual("test2");
83
+ expect(response.headers["content-type"]).toContain("application/xml");
84
+ done();
85
+ });
86
+ });
87
+ it("Scenario3: GET /rest/headers/scenario-3", (done) => {
88
+ request
89
+ .get("/rest/headers/scenario-3")
90
+ .expect(200)
91
+ .end((err, response) => {
92
+ if (err) {
93
+ throw err;
94
+ }
95
+ expect(response.headers["location"]).toEqual("/v1/location");
96
+ done();
97
+ });
98
+ });
99
+ }
100
+ exports.testHeaders = testHeaders;
101
+ //# sourceMappingURL=testHeaders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testHeaders.js","sourceRoot":"","sources":["../../../src/tests/testHeaders.ts"],"names":[],"mappings":";;;;AAAA,yCAA8F;AAC9F,yCAAqC;AACrC,kEAAkC;AAIlC,IAAa,WAAW,GAAxB,MAAa,WAAW;IAGtB,aAAa,CAAqB,KAAe;QAC/C,OAAO,OAAO,CAAC;IACjB,CAAC;IAID,aAAa;QACX,OAAO,aAAa,CAAC;IACvB,CAAC;IAUD,aAAa,CAAQ,QAA0B;QAC7C,QAAQ,CAAC,SAAS,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;QAC/C,OAAO,OAAO,CAAC;IACjB,CAAC;CACF,CAAA;AAtBC;IAFC,IAAA,YAAG,EAAC,aAAa,CAAC;IAClB,IAAA,gBAAO,EAAC,GAAG,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;IAChC,mBAAA,IAAA,mBAAU,EAAC,MAAM,CAAC,CAAA;;;;gDAEhC;AAID;IAFC,IAAA,YAAG,EAAC,aAAa,CAAC;IAClB,IAAA,gBAAO,EAAC,GAAG,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC,WAAW,CAAC,iBAAiB,CAAC;;;;gDAGpH;AAUD;IARC,IAAA,YAAG,EAAC,aAAa,CAAC;IAClB,IAAA,gBAAO,EAAC,GAAG,EAAE,MAAM,CAAC,C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AC,CAAC,GAAQ,EAAE,QAAa,EAAE,EAAE;YAC/B,IAAI,GAAG,EAAE;gBACP,MAAM,GAAG,CAAC;aACX;YAED,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACzD,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,gBAAgB,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;AAzDD,kCAyDC","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,173 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.testInheritanceController = exports.FindingsController = exports.ResourcesCtrl = exports.BaseController = exports.Resource = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@tsed/common");
6
+ const exceptions_1 = require("@tsed/exceptions");
7
+ const schema_1 = require("@tsed/schema");
8
+ const supertest_1 = tslib_1.__importDefault(require("supertest"));
9
+ class Resource {
10
+ id;
11
+ name;
12
+ }
13
+ tslib_1.__decorate([
14
+ (0, schema_1.Property)(),
15
+ tslib_1.__metadata("design:type", String)
16
+ ], Resource.prototype, "id", void 0);
17
+ tslib_1.__decorate([
18
+ (0, schema_1.Property)(),
19
+ (0, schema_1.MinLength)(3),
20
+ (0, schema_1.MaxLength)(100),
21
+ tslib_1.__metadata("design:type", String)
22
+ ], Resource.prototype, "name", void 0);
23
+ exports.Resource = Resource;
24
+ class BaseController {
25
+ resources;
26
+ async get(id) {
27
+ const resource = this.resources.find((resource) => resource.id === id);
28
+ if (!resource) {
29
+ throw new exceptions_1.NotFound("Not found");
30
+ }
31
+ return resource;
32
+ }
33
+ async list() {
34
+ return this.resources;
35
+ }
36
+ }
37
+ tslib_1.__decorate([
38
+ (0, common_1.Get)("/:id"),
39
+ (0, schema_1.Summary)("Return an element by his resource"),
40
+ tslib_1.__param(0, (0, schema_1.Description)("Id of the resource")),
41
+ tslib_1.__param(0, (0, common_1.PathParams)("id")),
42
+ tslib_1.__metadata("design:type", Function),
43
+ tslib_1.__metadata("design:paramtypes", [String]),
44
+ tslib_1.__metadata("design:returntype", Promise)
45
+ ], BaseController.prototype, "get", null);
46
+ tslib_1.__decorate([
47
+ (0, common_1.Get)("/"),
48
+ (0, schema_1.Summary)("Return all elements from a service"),
49
+ tslib_1.__metadata("design:type", Function),
50
+ tslib_1.__metadata("design:paramtypes", []),
51
+ tslib_1.__metadata("design:returntype", Promise)
52
+ ], BaseController.prototype, "list", null);
53
+ exports.BaseController = BaseController;
54
+ let ResourcesCtrl = class ResourcesCtrl extends BaseController {
55
+ resources = [{ id: "1", name: "John" }];
56
+ async get(id) {
57
+ const resource = await super.get(id);
58
+ resource.name = resource.name + " hello You!";
59
+ return resource;
60
+ }
61
+ async post(resource) {
62
+ resource.id = require("uuid").v4();
63
+ this.resources.push(resource);
64
+ return resource;
65
+ }
66
+ };
67
+ tslib_1.__decorate([
68
+ (0, common_1.Get)("/:id"),
69
+ (0, schema_1.Summary)("Return an element by his resource"),
70
+ tslib_1.__param(0, (0, schema_1.Description)("Id of the resource")),
71
+ tslib_1.__param(0, (0, common_1.PathParams)("id")),
72
+ tslib_1.__metadata("design:type", Function),
73
+ tslib_1.__metadata("design:paramtypes", [String]),
74
+ tslib_1.__metadata("design:returntype", Promise)
75
+ ], ResourcesCtrl.prototype, "get", null);
76
+ tslib_1.__decorate([
77
+ (0, common_1.Post)("/"),
78
+ (0, schema_1.Returns)(201).Type(Resource),
79
+ tslib_1.__param(0, (0, common_1.BodyParams)()),
80
+ tslib_1.__metadata("design:type", Function),
81
+ tslib_1.__metadata("design:paramtypes", [Resource]),
82
+ tslib_1.__metadata("design:returntype", Promise)
83
+ ], ResourcesCtrl.prototype, "post", null);
84
+ ResourcesCtrl = tslib_1.__decorate([
85
+ (0, common_1.Controller)("/resources")
86
+ ], ResourcesCtrl);
87
+ exports.ResourcesCtrl = ResourcesCtrl;
88
+ let AuthMiddleware = class AuthMiddleware {
89
+ use() {
90
+ return true;
91
+ }
92
+ };
93
+ AuthMiddleware = tslib_1.__decorate([
94
+ (0, common_1.Middleware)()
95
+ ], AuthMiddleware);
96
+ class AttachmentController {
97
+ getAll(parentID) {
98
+ return `All attachments of ${parentID}`;
99
+ }
100
+ }
101
+ tslib_1.__decorate([
102
+ (0, common_1.Get)("/:parentID/attachments"),
103
+ tslib_1.__param(0, (0, common_1.PathParams)("parentID")),
104
+ tslib_1.__metadata("design:type", Function),
105
+ tslib_1.__metadata("design:paramtypes", [String]),
106
+ tslib_1.__metadata("design:returntype", void 0)
107
+ ], AttachmentController.prototype, "getAll", null);
108
+ let FindingsController = class FindingsController extends AttachmentController {
109
+ get() {
110
+ return "hello Finding";
111
+ }
112
+ };
113
+ tslib_1.__decorate([
114
+ (0, common_1.Get)("/"),
115
+ tslib_1.__metadata("design:type", Function),
116
+ tslib_1.__metadata("design:paramtypes", []),
117
+ tslib_1.__metadata("design:returntype", void 0)
118
+ ], FindingsController.prototype, "get", null);
119
+ FindingsController = tslib_1.__decorate([
120
+ (0, common_1.Controller)("/findings"),
121
+ (0, common_1.UseAuth)(AuthMiddleware)
122
+ ], FindingsController);
123
+ exports.FindingsController = FindingsController;
124
+ function testInheritanceController(options) {
125
+ let request;
126
+ beforeAll(common_1.PlatformTest.bootstrap(options.server, {
127
+ ...options,
128
+ mount: {
129
+ "/rest": [ResourcesCtrl, FindingsController]
130
+ }
131
+ }));
132
+ beforeAll(() => {
133
+ request = (0, supertest_1.default)(common_1.PlatformTest.callback());
134
+ });
135
+ afterAll(common_1.PlatformTest.reset);
136
+ describe("Scenario 1:", () => {
137
+ it("should return list", async () => {
138
+ const { body } = await request.get("/rest/resources").expect(200);
139
+ expect(body).toEqual([{ id: "1", name: "John" }]);
140
+ });
141
+ it("should return a resource", async () => {
142
+ const { body } = await request.get("/rest/resources/1").expect(200);
143
+ expect(body).toEqual({
144
+ id: "1",
145
+ name: "John hello You!"
146
+ });
147
+ });
148
+ it("should add a resource", async () => {
149
+ const { body } = await request
150
+ .post("/rest/resources")
151
+ .send({
152
+ name: "july"
153
+ })
154
+ .expect(201);
155
+ expect(body.name).toEqual("july");
156
+ expect(typeof body.id).toBe("string");
157
+ const { body: resource } = await request.get(`/rest/resources/${body.id}`).expect(200);
158
+ expect(resource.id).toEqual(body.id);
159
+ });
160
+ });
161
+ describe("scenario2: FindingsController", () => {
162
+ it("should call /rest/findings/:parentID/attachments", async () => {
163
+ const { text } = await request.get("/rest/findings/1/attachments").expect(200);
164
+ expect(text).toEqual("All attachments of 1");
165
+ });
166
+ it("should call /rest/findings/", async () => {
167
+ const { text } = await request.get("/rest/findings").expect(200);
168
+ expect(text).toEqual("hello Finding");
169
+ });
170
+ });
171
+ }
172
+ exports.testInheritanceController = testInheritanceController;
173
+ //# sourceMappingURL=testInheritanceController.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testInheritanceController.js","sourceRoot":"","sources":["../../../src/tests/testInheritanceController.ts"],"names":[],"mappings":";;;;AAAA,yCAA8G;AAC9G,iDAA0C;AAC1C,yCAA2F;AAC3F,kEAAkC;AAGlC,MAAa,QAAQ;IAEnB,EAAE,CAAS;IAKX,IAAI,CAAS;CACd;AANC;IADC,IAAA,iBAAQ,GAAE;;oCACA;AAKX;IAHC,IAAA,iBAAQ,GAAE;IACV,IAAA,kBAAS,EAAC,CAAC,CAAC;IACZ,IAAA,kBAAS,EAAC,GAAG,CAAC;;sCACF;AAPf,4BAQC;AAED,MAAa,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,qBAAQ,CAAC,WAAW,CAAC,CAAC;SACjC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAID,KAAK,CAAC,IAAI;QACR,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;CACF;AAnBC;IAFC,IAAA,YAAG,EAAC,MAAM,CAAC;IACX,IAAA,gBAAO,EAAC,mCAAmC,CAAC;IAE1C,mBAAA,IAAA,oBAAW,EAAC,oBAAoB,CAAC,CAAA;IACjC,mBAAA,IAAA,mBAAU,EAAC,IAAI,CAAC,CAAA;;;;yCAUlB;AAID;IAFC,IAAA,YAAG,EAAC,GAAG,CAAC;IACR,IAAA,gBAAO,EAAC,oCAAoC,CAAC;;;;0CAG7C;AAvBH,wCAwBC;AAGD,IAAa,aAAa,GAA1B,MAAa,aAAc,SAAQ,cAAwB;IACzD,SAAS,GAAG,CAAC,EAAC,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM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,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;AA9DD,8DA8DC","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,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.testLocals = 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
+ let LocalsMiddleware = class LocalsMiddleware {
8
+ use(request, locals, ctx) {
9
+ locals.id = "local-10909";
10
+ ctx.set("uid", "ctx-10909");
11
+ }
12
+ };
13
+ tslib_1.__decorate([
14
+ tslib_1.__param(0, (0, common_1.Req)()),
15
+ tslib_1.__param(1, (0, common_1.Locals)()),
16
+ tslib_1.__param(2, (0, common_1.Context)()),
17
+ tslib_1.__metadata("design:type", Function),
18
+ tslib_1.__metadata("design:paramtypes", [Object, Object, common_1.PlatformContext]),
19
+ tslib_1.__metadata("design:returntype", void 0)
20
+ ], LocalsMiddleware.prototype, "use", null);
21
+ LocalsMiddleware = tslib_1.__decorate([
22
+ (0, common_1.Middleware)()
23
+ ], LocalsMiddleware);
24
+ let LocalsCtrl = class LocalsCtrl {
25
+ testStackMiddlewares(id, uid) {
26
+ return {
27
+ id: `${id}-${uid}`
28
+ };
29
+ }
30
+ };
31
+ tslib_1.__decorate([
32
+ (0, common_1.Get)("/scenario-1"),
33
+ (0, common_1.Use)(LocalsMiddleware),
34
+ tslib_1.__param(0, (0, common_1.Locals)("id")),
35
+ tslib_1.__param(1, (0, common_1.Context)("uid")),
36
+ tslib_1.__metadata("design:type", Function),
37
+ tslib_1.__metadata("design:paramtypes", [Object, String]),
38
+ tslib_1.__metadata("design:returntype", Object)
39
+ ], LocalsCtrl.prototype, "testStackMiddlewares", null);
40
+ LocalsCtrl = tslib_1.__decorate([
41
+ (0, common_1.Controller)("/locals")
42
+ ], LocalsCtrl);
43
+ function testLocals(options) {
44
+ let request;
45
+ beforeAll(common_1.PlatformTest.bootstrap(options.server, {
46
+ ...options,
47
+ mount: {
48
+ "/rest": [LocalsCtrl]
49
+ }
50
+ }));
51
+ beforeAll(() => {
52
+ request = (0, supertest_1.default)(common_1.PlatformTest.callback());
53
+ });
54
+ afterAll(common_1.PlatformTest.reset);
55
+ describe("Scenario 1: GET /rest/locals/scenario-1", () => {
56
+ it("should call middleware and set a id in locals", async () => {
57
+ const { body } = await request.get("/rest/locals/scenario-1").expect(200);
58
+ expect(body.id).toEqual("local-10909-ctx-10909");
59
+ });
60
+ });
61
+ }
62
+ exports.testLocals = testLocals;
63
+ //# sourceMappingURL=testLocals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testLocals.js","sourceRoot":"","sources":["../../../src/tests/testLocals.ts"],"names":[],"mappings":";;;;AAAA,yCAAuI;AACvI,kEAAkC;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,mBAAA,IAAA,YAAG,GAAE,CAAA;IAAgB,mBAAA,IAAA,eAAM,GAAE,CAAA;IAAe,mBAAA,IAAA,gBAAO,GAAE,CAAA;;6DAAM,wBAAe;;2CAG9E;AAJG,gBAAgB;IADrB,IAAA,mBAAU,GAAE;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,IAAA,YAAG,EAAC,aAAa,CAAC;IAClB,IAAA,YAAG,EAAC,gBAAgB,CAAC;IACO,mBAAA,IAAA,eAAM,EAAC,IAAI,CAAC,CAAA;IAAW,mBAAA,IAAA,gBAAO,EAAC,KAAK,CAAC,CAAA;;;;sDAIjE;AAPG,UAAU;IADf,IAAA,mBAAU,EAAC,SAAS,CAAC;GAChB,UAAU,CAQf;AAED,SAAgB,UAAU,CAAC,OAA+B;IACxD,IAAI,OAA4C,CAAC;IACjD,SAAS,CACP,qBAAY,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,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,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;AAtBD,gCAsBC","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,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.testLocation = 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 schema_1 = require("@tsed/schema");
8
+ let LocationCtrl = class LocationCtrl {
9
+ testScenario1() {
10
+ return "Hello";
11
+ }
12
+ };
13
+ tslib_1.__decorate([
14
+ (0, common_1.Get)("/scenario-1"),
15
+ (0, schema_1.Location)("/test"),
16
+ tslib_1.__metadata("design:type", Function),
17
+ tslib_1.__metadata("design:paramtypes", []),
18
+ tslib_1.__metadata("design:returntype", void 0)
19
+ ], LocationCtrl.prototype, "testScenario1", null);
20
+ LocationCtrl = tslib_1.__decorate([
21
+ (0, common_1.Controller)("/location")
22
+ ], LocationCtrl);
23
+ function testLocation(options) {
24
+ let request;
25
+ beforeAll(common_1.PlatformTest.bootstrap(options.server, {
26
+ ...options,
27
+ mount: {
28
+ "/rest": [LocationCtrl]
29
+ }
30
+ }));
31
+ beforeAll(() => {
32
+ request = (0, supertest_1.default)(common_1.PlatformTest.callback());
33
+ });
34
+ afterAll(common_1.PlatformTest.reset);
35
+ it("Scenario1: GET /rest/location/scenario-1", async () => {
36
+ const response = await request.get("/rest/location/scenario-1").expect(200);
37
+ expect(response.text).toEqual("Hello");
38
+ expect(response.header.location).toEqual("/test");
39
+ });
40
+ }
41
+ exports.testLocation = testLocation;
42
+ //# sourceMappingURL=testLocation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testLocation.js","sourceRoot":"","sources":["../../../src/tests/testLocation.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAC3D,kEAAkC;AAClC,yCAAsC;AAItC,IAAM,YAAY,GAAlB,MAAM,YAAY;IAGhB,aAAa;QACX,OAAO,OAAO,CAAC;IACjB,CAAC;CACF,CAAA;AAHC;IAFC,IAAA,YAAG,EAAC,aAAa,CAAC;IAClB,IAAA,iBAAQ,EAAC,OAAO,CAAC;;;;iDAGjB;AALG,YAAY;IADjB,IAAA,mBAAU,EAAC,WAAW,CAAC;GAClB,YAAY,CAMjB;AAED,SAAgB,YAAY,CAAC,OAA+B;IAC1D,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;KACF,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,EAAE,CAAC,0CAA0C,EAAE,KAAK,IAAI,EAAE;QACxD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAE5E,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACvC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;AACL,CAAC;AAtBD,oCAsBC","sourcesContent":["import {Controller, Get, PlatformTest} from \"@tsed/common\";\nimport SuperTest from \"supertest\";\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,210 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.testMiddlewares = exports.CatchErrorMiddleware = void 0;
4
+ const tslib_1 = require("tslib");
5
+ require("@tsed/ajv");
6
+ const common_1 = require("@tsed/common");
7
+ const exceptions_1 = require("@tsed/exceptions");
8
+ const supertest_1 = tslib_1.__importDefault(require("supertest"));
9
+ let BeforeCustomMiddleware = class BeforeCustomMiddleware {
10
+ use(ctx) {
11
+ ctx.set("stacks", ["UseBefore - Ctrl"]);
12
+ }
13
+ };
14
+ tslib_1.__decorate([
15
+ tslib_1.__param(0, (0, common_1.Context)()),
16
+ tslib_1.__metadata("design:type", Function),
17
+ tslib_1.__metadata("design:paramtypes", [Object]),
18
+ tslib_1.__metadata("design:returntype", void 0)
19
+ ], BeforeCustomMiddleware.prototype, "use", null);
20
+ BeforeCustomMiddleware = tslib_1.__decorate([
21
+ (0, common_1.Middleware)()
22
+ ], BeforeCustomMiddleware);
23
+ let BeforeEndpointCustomMiddleware = class BeforeEndpointCustomMiddleware {
24
+ use(ctx) {
25
+ ctx.get("stacks").push("UseBefore - endpoint");
26
+ }
27
+ };
28
+ tslib_1.__decorate([
29
+ tslib_1.__param(0, (0, common_1.Context)()),
30
+ tslib_1.__metadata("design:type", Function),
31
+ tslib_1.__metadata("design:paramtypes", [Object]),
32
+ tslib_1.__metadata("design:returntype", void 0)
33
+ ], BeforeEndpointCustomMiddleware.prototype, "use", null);
34
+ BeforeEndpointCustomMiddleware = tslib_1.__decorate([
35
+ (0, common_1.Middleware)()
36
+ ], BeforeEndpointCustomMiddleware);
37
+ let AfterCustomMiddleware = class AfterCustomMiddleware {
38
+ use(ctx) {
39
+ ctx.get("stacks").push("UseAfter - Ctrl");
40
+ }
41
+ };
42
+ tslib_1.__decorate([
43
+ tslib_1.__param(0, (0, common_1.Context)()),
44
+ tslib_1.__metadata("design:type", Function),
45
+ tslib_1.__metadata("design:paramtypes", [Object]),
46
+ tslib_1.__metadata("design:returntype", void 0)
47
+ ], AfterCustomMiddleware.prototype, "use", null);
48
+ AfterCustomMiddleware = tslib_1.__decorate([
49
+ (0, common_1.Middleware)()
50
+ ], AfterCustomMiddleware);
51
+ let UseCustomMiddleware = class UseCustomMiddleware {
52
+ use(ctx) {
53
+ ctx.get("stacks").push("Use - Ctrl");
54
+ }
55
+ };
56
+ tslib_1.__decorate([
57
+ tslib_1.__param(0, (0, common_1.Context)()),
58
+ tslib_1.__metadata("design:type", Function),
59
+ tslib_1.__metadata("design:paramtypes", [Object]),
60
+ tslib_1.__metadata("design:returntype", void 0)
61
+ ], UseCustomMiddleware.prototype, "use", null);
62
+ UseCustomMiddleware = tslib_1.__decorate([
63
+ (0, common_1.Middleware)()
64
+ ], UseCustomMiddleware);
65
+ let AfterEndpointCustomMiddleware = class AfterEndpointCustomMiddleware {
66
+ use(ctx) {
67
+ ctx.get("stacks").push("UseAfter - endpoint");
68
+ }
69
+ };
70
+ tslib_1.__decorate([
71
+ tslib_1.__param(0, (0, common_1.Context)()),
72
+ tslib_1.__metadata("design:type", Function),
73
+ tslib_1.__metadata("design:paramtypes", [Object]),
74
+ tslib_1.__metadata("design:returntype", void 0)
75
+ ], AfterEndpointCustomMiddleware.prototype, "use", null);
76
+ AfterEndpointCustomMiddleware = tslib_1.__decorate([
77
+ (0, common_1.Middleware)()
78
+ ], AfterEndpointCustomMiddleware);
79
+ let UseMiddleware = class UseMiddleware {
80
+ use(ctx) {
81
+ ctx.get("stacks").push("Use - Ctrl");
82
+ }
83
+ };
84
+ tslib_1.__decorate([
85
+ tslib_1.__param(0, (0, common_1.Context)()),
86
+ tslib_1.__metadata("design:type", Function),
87
+ tslib_1.__metadata("design:paramtypes", [Object]),
88
+ tslib_1.__metadata("design:returntype", void 0)
89
+ ], UseMiddleware.prototype, "use", null);
90
+ UseMiddleware = tslib_1.__decorate([
91
+ (0, common_1.Middleware)()
92
+ ], UseMiddleware);
93
+ let UseEndpointMiddleware = class UseEndpointMiddleware {
94
+ use(ctx) {
95
+ ctx.get("stacks").push("Use - endpoint");
96
+ }
97
+ };
98
+ tslib_1.__decorate([
99
+ tslib_1.__param(0, (0, common_1.Context)()),
100
+ tslib_1.__metadata("design:type", Function),
101
+ tslib_1.__metadata("design:paramtypes", [Object]),
102
+ tslib_1.__metadata("design:returntype", void 0)
103
+ ], UseEndpointMiddleware.prototype, "use", null);
104
+ UseEndpointMiddleware = tslib_1.__decorate([
105
+ (0, common_1.Middleware)()
106
+ ], UseEndpointMiddleware);
107
+ let CatchErrorMiddleware = class CatchErrorMiddleware {
108
+ use(err) {
109
+ if ([401].includes(err.status)) {
110
+ throw new exceptions_1.BadRequest("Bad format");
111
+ }
112
+ throw err;
113
+ }
114
+ };
115
+ tslib_1.__decorate([
116
+ tslib_1.__param(0, (0, common_1.Err)()),
117
+ tslib_1.__metadata("design:type", Function),
118
+ tslib_1.__metadata("design:paramtypes", [exceptions_1.Exception]),
119
+ tslib_1.__metadata("design:returntype", void 0)
120
+ ], CatchErrorMiddleware.prototype, "use", null);
121
+ CatchErrorMiddleware = tslib_1.__decorate([
122
+ (0, common_1.Middleware)()
123
+ ], CatchErrorMiddleware);
124
+ exports.CatchErrorMiddleware = CatchErrorMiddleware;
125
+ let TestMiddlewaresCtrl = class TestMiddlewaresCtrl {
126
+ scenario1(context) {
127
+ context.get("stacks").push("endpoint");
128
+ return { stacks: context.get("stacks") };
129
+ }
130
+ scenario2(test) {
131
+ if (test === "error") {
132
+ throw new exceptions_1.Unauthorized("Unauthorized");
133
+ }
134
+ return {
135
+ hello: "world"
136
+ };
137
+ }
138
+ };
139
+ tslib_1.__decorate([
140
+ (0, common_1.Get)("/scenario-1"),
141
+ (0, common_1.UseBefore)(BeforeEndpointCustomMiddleware),
142
+ (0, common_1.UseAfter)(AfterEndpointCustomMiddleware),
143
+ (0, common_1.Use)(UseEndpointMiddleware),
144
+ tslib_1.__param(0, (0, common_1.Context)()),
145
+ tslib_1.__metadata("design:type", Function),
146
+ tslib_1.__metadata("design:paramtypes", [Object]),
147
+ tslib_1.__metadata("design:returntype", void 0)
148
+ ], TestMiddlewaresCtrl.prototype, "scenario1", null);
149
+ tslib_1.__decorate([
150
+ (0, common_1.Get)("/scenario-2"),
151
+ tslib_1.__param(0, (0, common_1.QueryParams)("test")),
152
+ tslib_1.__metadata("design:type", Function),
153
+ tslib_1.__metadata("design:paramtypes", [String]),
154
+ tslib_1.__metadata("design:returntype", void 0)
155
+ ], TestMiddlewaresCtrl.prototype, "scenario2", null);
156
+ TestMiddlewaresCtrl = tslib_1.__decorate([
157
+ (0, common_1.Controller)("/middlewares"),
158
+ (0, common_1.UseBefore)(BeforeCustomMiddleware),
159
+ (0, common_1.UseAfter)(AfterCustomMiddleware),
160
+ (0, common_1.UseAfter)(CatchErrorMiddleware),
161
+ (0, common_1.Use)(UseCustomMiddleware)
162
+ ], TestMiddlewaresCtrl);
163
+ function testMiddlewares(options) {
164
+ let request;
165
+ beforeAll(common_1.PlatformTest.bootstrap(options.server, {
166
+ ...options,
167
+ mount: {
168
+ "/rest": [TestMiddlewaresCtrl]
169
+ }
170
+ }));
171
+ beforeAll(() => {
172
+ request = (0, supertest_1.default)(common_1.PlatformTest.callback());
173
+ });
174
+ afterAll(common_1.PlatformTest.reset);
175
+ describe("Scenario 1: GET /rest/middlewares/scenario-1", () => {
176
+ it("should call all middlewares", async () => {
177
+ const response = await request.get("/rest/middlewares/scenario-1").expect(200);
178
+ expect(response.body).toEqual({
179
+ stacks: [
180
+ "UseBefore - Ctrl",
181
+ "UseBefore - endpoint",
182
+ "Use - Ctrl",
183
+ "Use - endpoint",
184
+ "endpoint",
185
+ "UseAfter - endpoint",
186
+ "UseAfter - Ctrl"
187
+ ]
188
+ });
189
+ });
190
+ });
191
+ describe("Scenario 2: GET /rest/middlewares/scenario-2", () => {
192
+ it("should call the endpoint without triggering middleware", async () => {
193
+ const response = await request.get("/rest/middlewares/scenario-2").expect(200);
194
+ expect(response.body).toEqual({
195
+ hello: "world"
196
+ });
197
+ });
198
+ it("should call the endpoint, throw an error and transform the error by calling the error middleware", async () => {
199
+ const response = await request.get("/rest/middlewares/scenario-2?test=error").expect(400);
200
+ expect(response.body).toEqual({
201
+ errors: [],
202
+ message: "Bad format",
203
+ name: "BAD_REQUEST",
204
+ status: 400
205
+ });
206
+ });
207
+ });
208
+ }
209
+ exports.testMiddlewares = testMiddlewares;
210
+ //# sourceMappingURL=testMiddlewares.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testMiddlewares.js","sourceRoot":"","sources":["../../../src/tests/testMiddlewares.ts"],"names":[],"mappings":";;;;AAAA,qBAAmB;AACnB,yCAYsB;AACtB,iDAAqE;AACrE,kEAAkC;AAIlC,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IAC1B,GAAG,CAAY,GAAY;QACzB,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,kBAAkB,CAAC,CAAC,CAAC;IAC1C,CAAC;CACF,CAAA;AAHC;IAAK,mBAAA,IAAA,gBAAO,GAAE,CAAA;;;;iDAEb;AAHG,sBAAsB;IAD3B,IAAA,mBAAU,GAAE;GACP,sBAAsB,CAI3B;AAGD,IAAM,8BAA8B,GAApC,MAA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AAC,CAAC,OAAO,CAAC;gBAC5B,MAAM,EAAE;oBACN,kBAAkB;oBAClB,sBAAsB;oBACtB,YAAY;oBACZ,gBAAgB;oBAChB,UAAU;oBACV,qBAAqB;oBACrB,iBAAiB;iBAClB;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,QAAQ,CAAC,8CAA8C,EAAE,GAAG,EAAE;QAC5D,EAAE,CAAC,wDAAwD,EAAE,KAAK,IAAI,EAAE;YACtE,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAE/E,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC;gBAC5B,KAAK,EAAE,OAAO;aACf,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,kGAAkG,EAAE,KAAK,IAAI,EAAE;YAChH,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAE1F,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC;gBAC5B,MAAM,EAAE,EAAE;gBACV,OAAO,EAAE,YAAY;gBACrB,IAAI,EAAE,aAAa;gBACnB,MAAM,EAAE,GAAG;aACZ,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AApDD,0CAoDC","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"]}