@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,349 @@
1
+ import { __decorate, __metadata, __param } from "tslib";
2
+ import "@tsed/ajv";
3
+ import { Controller, Get, PlatformTest, QueryParams } from "@tsed/common";
4
+ import { Default, GenericOf, Generics, Maximum, Minimum, Property, Required } from "@tsed/schema";
5
+ import SuperTest from "supertest";
6
+ export class RandomStringModel {
7
+ length;
8
+ }
9
+ __decorate([
10
+ Maximum(250),
11
+ Minimum(1),
12
+ Required(),
13
+ __metadata("design:type", Number)
14
+ ], RandomStringModel.prototype, "length", void 0);
15
+ class FindQuery {
16
+ a;
17
+ b;
18
+ }
19
+ __decorate([
20
+ Property(),
21
+ __metadata("design:type", Number)
22
+ ], FindQuery.prototype, "a", void 0);
23
+ __decorate([
24
+ Property(),
25
+ __metadata("design:type", Number)
26
+ ], FindQuery.prototype, "b", void 0);
27
+ let PaginationQuery = class PaginationQuery {
28
+ // things about pagination
29
+ offset;
30
+ limit;
31
+ where;
32
+ };
33
+ __decorate([
34
+ Minimum(0),
35
+ Default(0),
36
+ __metadata("design:type", Number)
37
+ ], PaginationQuery.prototype, "offset", void 0);
38
+ __decorate([
39
+ Minimum(1),
40
+ Maximum(1000),
41
+ Default(50),
42
+ __metadata("design:type", Number)
43
+ ], PaginationQuery.prototype, "limit", void 0);
44
+ __decorate([
45
+ Property("T"),
46
+ __metadata("design:type", Object)
47
+ ], PaginationQuery.prototype, "where", void 0);
48
+ PaginationQuery = __decorate([
49
+ Generics("T")
50
+ ], PaginationQuery);
51
+ let TestQueryParamsCtrl = class TestQueryParamsCtrl {
52
+ testScenario1(value) {
53
+ return { value };
54
+ }
55
+ testScenario2(value = true) {
56
+ return { value };
57
+ }
58
+ testScenario3(value) {
59
+ return { value };
60
+ }
61
+ testScenario4(value) {
62
+ return { value };
63
+ }
64
+ testScenario5(value) {
65
+ return { value };
66
+ }
67
+ testScenario6(q, qs) {
68
+ return { q };
69
+ }
70
+ testScenario7(q) {
71
+ return { q };
72
+ }
73
+ testScenario8(value) {
74
+ return { value };
75
+ }
76
+ };
77
+ __decorate([
78
+ Get("/scenario-1"),
79
+ __param(0, QueryParams("test")),
80
+ __metadata("design:type", Function),
81
+ __metadata("design:paramtypes", [Boolean]),
82
+ __metadata("design:returntype", Object)
83
+ ], TestQueryParamsCtrl.prototype, "testScenario1", null);
84
+ __decorate([
85
+ Get("/scenario-2"),
86
+ __param(0, QueryParams("test")),
87
+ __metadata("design:type", Function),
88
+ __metadata("design:paramtypes", [Boolean]),
89
+ __metadata("design:returntype", Object)
90
+ ], TestQueryParamsCtrl.prototype, "testScenario2", null);
91
+ __decorate([
92
+ Get("/scenario-3"),
93
+ __param(0, QueryParams("test")),
94
+ __metadata("design:type", Function),
95
+ __metadata("design:paramtypes", [Number]),
96
+ __metadata("design:returntype", Object)
97
+ ], TestQueryParamsCtrl.prototype, "testScenario3", null);
98
+ __decorate([
99
+ Get("/scenario-4"),
100
+ __param(0, QueryParams("test")),
101
+ __metadata("design:type", Function),
102
+ __metadata("design:paramtypes", [String]),
103
+ __metadata("design:returntype", Object)
104
+ ], TestQueryParamsCtrl.prototype, "testScenario4", null);
105
+ __decorate([
106
+ Get("/scenario-5"),
107
+ __param(0, QueryParams()),
108
+ __metadata("design:type", Function),
109
+ __metadata("design:paramtypes", [RandomStringModel]),
110
+ __metadata("design:returntype", Object)
111
+ ], TestQueryParamsCtrl.prototype, "testScenario5", null);
112
+ __decorate([
113
+ Get("/scenario-6"),
114
+ __param(0, QueryParams()),
115
+ __param(0, GenericOf(FindQuery)),
116
+ __param(1, QueryParams()),
117
+ __metadata("design:type", Function),
118
+ __metadata("design:paramtypes", [PaginationQuery, Object]),
119
+ __metadata("design:returntype", void 0)
120
+ ], TestQueryParamsCtrl.prototype, "testScenario6", null);
121
+ __decorate([
122
+ Get("/scenario-7"),
123
+ __param(0, QueryParams("q")),
124
+ __param(0, GenericOf(FindQuery)),
125
+ __metadata("design:type", Function),
126
+ __metadata("design:paramtypes", [PaginationQuery]),
127
+ __metadata("design:returntype", void 0)
128
+ ], TestQueryParamsCtrl.prototype, "testScenario7", null);
129
+ __decorate([
130
+ Get("/scenario-8"),
131
+ __param(0, QueryParams("test", String)),
132
+ __metadata("design:type", Function),
133
+ __metadata("design:paramtypes", [Array]),
134
+ __metadata("design:returntype", Object)
135
+ ], TestQueryParamsCtrl.prototype, "testScenario8", null);
136
+ TestQueryParamsCtrl = __decorate([
137
+ Controller("/query-params")
138
+ ], TestQueryParamsCtrl);
139
+ export function testQueryParams(options) {
140
+ let request;
141
+ beforeAll(PlatformTest.bootstrap(options.server, {
142
+ ...options,
143
+ ajv: {
144
+ verbose: false
145
+ },
146
+ mount: {
147
+ "/rest": [TestQueryParamsCtrl]
148
+ }
149
+ }));
150
+ beforeAll(() => {
151
+ request = SuperTest(PlatformTest.callback());
152
+ });
153
+ afterAll(PlatformTest.reset);
154
+ describe("Scenario1: Boolean value", () => {
155
+ it("should return true when query is true", async () => {
156
+ const response = await request.get("/rest/query-params/scenario-1?test=true").expect(200);
157
+ expect(response.body).toEqual({ value: true });
158
+ });
159
+ it("should return true when query is 1", async () => {
160
+ const response = await request.get("/rest/query-params/scenario-1?test=1").expect(200);
161
+ expect(response.body).toEqual({ value: true });
162
+ });
163
+ it("should return false when query is false", async () => {
164
+ const response = await request.get("/rest/query-params/scenario-1?test=false").expect(200);
165
+ expect(response.body).toEqual({ value: false });
166
+ });
167
+ it("should return false when query is 0", async () => {
168
+ const response = await request.get("/rest/query-params/scenario-1?test=0").expect(200);
169
+ expect(response.body).toEqual({ value: false });
170
+ });
171
+ it("should return false when query is null", async () => {
172
+ const response = await request.get("/rest/query-params/scenario-1?test=null").expect(200);
173
+ expect(response.body).toEqual({ value: null });
174
+ });
175
+ it("should return undefined when query is empty", async () => {
176
+ const response = await request.get("/rest/query-params/scenario-1?test=").expect(200);
177
+ expect(response.body).toEqual({});
178
+ });
179
+ it("should return undefined when no query", async () => {
180
+ const response = await request.get("/rest/query-params/scenario-1").expect(200);
181
+ expect(response.body).toEqual({});
182
+ });
183
+ });
184
+ describe("Scenario2: Boolean value with default value", () => {
185
+ it("should return true when query is true", async () => {
186
+ const response = await request.get("/rest/query-params/scenario-2?test=true").expect(200);
187
+ expect(response.body).toEqual({ value: true });
188
+ });
189
+ it("should return true when query is 1", async () => {
190
+ const response = await request.get("/rest/query-params/scenario-2?test=1").expect(200);
191
+ expect(response.body).toEqual({ value: true });
192
+ });
193
+ it("should return false when query is false", async () => {
194
+ const response = await request.get("/rest/query-params/scenario-2?test=false").expect(200);
195
+ expect(response.body).toEqual({ value: false });
196
+ });
197
+ it("should return false when query is 0", async () => {
198
+ const response = await request.get("/rest/query-params/scenario-2?test=0").expect(200);
199
+ expect(response.body).toEqual({ value: false });
200
+ });
201
+ it("should return false when query is null", async () => {
202
+ const response = await request.get("/rest/query-params/scenario-2?test=null").expect(200);
203
+ expect(response.body).toEqual({ value: null });
204
+ });
205
+ it("should return undefined when query is empty", async () => {
206
+ const response = await request.get("/rest/query-params/scenario-2?test=").expect(200);
207
+ expect(response.body).toEqual({ value: true });
208
+ });
209
+ it("should return undefined when no query", async () => {
210
+ const response = await request.get("/rest/query-params/scenario-2").expect(200);
211
+ expect(response.body).toEqual({ value: true });
212
+ });
213
+ });
214
+ describe("Scenario3: Number value", () => {
215
+ const endpoint = "/rest/query-params/scenario-3";
216
+ it("should return 0 when query is 0", async () => {
217
+ const response = await request.get(`${endpoint}?test=0`).expect(200);
218
+ expect(response.body).toEqual({ value: 0 });
219
+ });
220
+ it("should return 1 when query is 1", async () => {
221
+ const response = await request.get(`${endpoint}?test=1`).expect(200);
222
+ expect(response.body).toEqual({ value: 1 });
223
+ });
224
+ it("should return 0.1 when query is 0.1", async () => {
225
+ const response = await request.get(`${endpoint}?test=0.1`).expect(200);
226
+ expect(response.body).toEqual({ value: 0.1 });
227
+ });
228
+ it("should throw bad request", async () => {
229
+ const response = await request.get(`${endpoint}?test=error`).expect(400);
230
+ expect(response.body).toEqual({
231
+ name: "AJV_VALIDATION_ERROR",
232
+ message: 'Bad request on parameter "request.query.test".\nValue must be number. Given value: "error"',
233
+ status: 400,
234
+ errors: [
235
+ {
236
+ keyword: "type",
237
+ dataPath: "",
238
+ instancePath: "",
239
+ schemaPath: "#/type",
240
+ params: { type: "number" },
241
+ message: "must be number",
242
+ data: "error"
243
+ }
244
+ ]
245
+ });
246
+ });
247
+ it("should return undefined when query is empty", async () => {
248
+ const response = await request.get(`${endpoint}?test=null`).expect(200);
249
+ expect(response.body).toEqual({ value: null });
250
+ });
251
+ it("should return undefined when query is empty", async () => {
252
+ const response = await request.get(`${endpoint}?test=`).expect(200);
253
+ expect(response.body).toEqual({});
254
+ });
255
+ it("should return undefined when no query", async () => {
256
+ const response = await request.get(`${endpoint}`).expect(200);
257
+ expect(response.body).toEqual({});
258
+ });
259
+ });
260
+ describe("Scenario4: String value", () => {
261
+ const endpoint = "/rest/query-params/scenario-4";
262
+ it("should return 0 when query is 0", async () => {
263
+ const response = await request.get(`${endpoint}?test=0`).expect(200);
264
+ expect(response.body).toEqual({ value: "0" });
265
+ });
266
+ it("should return 1 when query is 1", async () => {
267
+ const response = await request.get(`${endpoint}?test=1`).expect(200);
268
+ expect(response.body).toEqual({ value: "1" });
269
+ });
270
+ it("should return 0.1 when query is 0.1", async () => {
271
+ const response = await request.get(`${endpoint}?test=0.1`).expect(200);
272
+ expect(response.body).toEqual({ value: "0.1" });
273
+ });
274
+ it("should return undefined when query is empty", async () => {
275
+ const response = await request.get(`${endpoint}?test=`).expect(200);
276
+ expect(response.body).toEqual({ value: "" });
277
+ });
278
+ it("should return undefined when no query", async () => {
279
+ const response = await request.get(`${endpoint}`).expect(200);
280
+ expect(response.body).toEqual({});
281
+ });
282
+ });
283
+ describe("Scenario6: DeepObject", () => {
284
+ const endpoint = "/rest/query-params/scenario-6";
285
+ it("should return 0 when query is 0", async () => {
286
+ const response = await request.get(`${endpoint}?offset=0&limit=10&where[a]=0&where[b]=1`).expect(200);
287
+ expect(response.body).toEqual({
288
+ q: {
289
+ limit: 10,
290
+ offset: 0,
291
+ where: {
292
+ a: 0,
293
+ b: 1
294
+ }
295
+ }
296
+ });
297
+ });
298
+ });
299
+ describe("Scenario7: DeepObject", () => {
300
+ const endpoint = "/rest/query-params/scenario-7";
301
+ it("should return the query value", async () => {
302
+ const response = await request.get(`${endpoint}?q[offset]=0&q[limit]=10&q[where][a]=0&q[where][b]=1`).expect(200);
303
+ expect(response.body).toEqual({
304
+ q: {
305
+ limit: 10,
306
+ offset: 0,
307
+ where: {
308
+ a: 0,
309
+ b: 1
310
+ }
311
+ }
312
+ });
313
+ });
314
+ it("should throw a bad request", async () => {
315
+ const response = await request.get(`${endpoint}?q[offset]=0&q[limit]=10&q[where][a]=ca&q[where][b]=1`).expect(400);
316
+ expect(response.body).toEqual({
317
+ errors: [
318
+ {
319
+ data: "ca",
320
+ dataPath: ".where.a",
321
+ instancePath: "/where/a",
322
+ keyword: "type",
323
+ message: "must be number",
324
+ modelName: "PaginationQuery",
325
+ params: {
326
+ type: "number"
327
+ },
328
+ schemaPath: "#/properties/where/properties/a/type"
329
+ }
330
+ ],
331
+ message: 'Bad request on parameter "request.query.q".\nPaginationQuery.where.a must be number. Given value: "ca"',
332
+ name: "AJV_VALIDATION_ERROR",
333
+ status: 400
334
+ });
335
+ });
336
+ });
337
+ describe("Scenario8: String[] value", () => {
338
+ const endpoint = "/rest/query-params/scenario-8";
339
+ it("should return 0 when query is 0", async () => {
340
+ const response = await request.get(`${endpoint}?test=0`).expect(200);
341
+ expect(response.body).toEqual({ value: ["0"] });
342
+ });
343
+ it("should return 1 when query is 1", async () => {
344
+ const response = await request.get(`${endpoint}?test=1&test=2`).expect(200);
345
+ expect(response.body).toEqual({ value: ["1", "2"] });
346
+ });
347
+ });
348
+ }
349
+ //# sourceMappingURL=testQueryParams.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testQueryParams.js","sourceRoot":"","sources":["../../../src/tests/testQueryParams.ts"],"names":[],"mappings":";AAAA,OAAO,WAAW,CAAC;AACnB,OAAO,EAAC,UAAU,EAAE,GAAG,EAAE,YAAY,EAAE,WAAW,EAAC,MAAM,cAAc,CAAC;AACxE,OAAO,EAAC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAC,MAAM,cAAc,CAAC;AAChG,OAAO,SAAS,MAAM,WAAW,CAAC;AAGlC,MAAM,OAAO,iBAAiB;IAI5B,MAAM,CAAS;CAChB;AADC;IAHC,OAAO,CAAC,GAAG,CAAC;IACZ,OAAO,CAAC,CAAC,CAAC;IACV,QAAQ,EAAE;;iDACI;AAGjB,MAAM,SAAS;IAEb,CAAC,CAAU;IAGX,CAAC,CAAU;CACZ;AAJC;IADC,QAAQ,EAAE;;oCACA;AAGX;IADC,QAAQ,EAAE;;oCACA;AAIb,IAAM,eAAe,GAArB,MAAM,eAAe;IACnB,0BAA0B;IAG1B,MAAM,CAAU;IAKhB,KAAK,CAAU;IAGf,KAAK,CAAK;CACX,CAAA;AATC;IAFC,OAAO,CAAC,CAAC,CAAC;IACV,OAAO,CAAC,CAAC,CAAC;;+CACK;AAKhB;IAHC,OAA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,CAAC,EAAC,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,iCAAiC,EAAE,KAAK,IAAI,EAAE;YAC/C,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,QAAQ,gBAAgB,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAE5E,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,EAAC,KAAK,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,EAAC,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import \"@tsed/ajv\";\nimport {Controller, Get, PlatformTest, QueryParams} from \"@tsed/common\";\nimport {Default, GenericOf, Generics, Maximum, Minimum, Property, Required} from \"@tsed/schema\";\nimport SuperTest from \"supertest\";\nimport {PlatformTestingSdkOpts} from \"../interfaces\";\n\nexport class RandomStringModel {\n @Maximum(250)\n @Minimum(1)\n @Required()\n length: number;\n}\n\nclass FindQuery {\n @Property()\n a?: number;\n\n @Property()\n b?: number;\n}\n\n@Generics(\"T\")\nclass PaginationQuery<T> {\n // things about pagination\n @Minimum(0)\n @Default(0)\n offset?: number;\n\n @Minimum(1)\n @Maximum(1000)\n @Default(50)\n limit?: number;\n\n @Property(\"T\")\n where?: T;\n}\n\n@Controller(\"/query-params\")\nclass TestQueryParamsCtrl {\n @Get(\"/scenario-1\")\n testScenario1(@QueryParams(\"test\") value: boolean): any {\n return {value};\n }\n\n @Get(\"/scenario-2\")\n testScenario2(@QueryParams(\"test\") value: boolean = true): any {\n return {value};\n }\n\n @Get(\"/scenario-3\")\n testScenario3(@QueryParams(\"test\") value: number): any {\n return {value};\n }\n\n @Get(\"/scenario-4\")\n testScenario4(@QueryParams(\"test\") value: string): any {\n return {value};\n }\n\n @Get(\"/scenario-5\")\n testScenario5(@QueryParams() value: RandomStringModel): any {\n return {value};\n }\n\n @Get(\"/scenario-6\")\n testScenario6(@QueryParams() @GenericOf(FindQuery) q: PaginationQuery<FindQuery>, @QueryParams() qs: any) {\n return {q};\n }\n\n @Get(\"/scenario-7\")\n testScenario7(@QueryParams(\"q\") @GenericOf(FindQuery) q: PaginationQuery<FindQuery>) {\n return {q};\n }\n\n @Get(\"/scenario-8\")\n testScenario8(@QueryParams(\"test\", String) value: string[]): any {\n return {value};\n }\n}\n\nexport function testQueryParams(options: PlatformTestingSdkOpts) {\n let request: SuperTest.SuperTest<SuperTest.Test>;\n\n beforeAll(\n PlatformTest.bootstrap(options.server, {\n ...options,\n ajv: {\n verbose: false\n },\n mount: {\n \"/rest\": [TestQueryParamsCtrl]\n }\n })\n );\n beforeAll(() => {\n request = SuperTest(PlatformTest.callback());\n });\n afterAll(PlatformTest.reset);\n describe(\"Scenario1: Boolean value\", () => {\n it(\"should return true when query is true\", async () => {\n const response = await request.get(\"/rest/query-params/scenario-1?test=true\").expect(200);\n\n expect(response.body).toEqual({value: true});\n });\n it(\"should return true when query is 1\", async () => {\n const response = await request.get(\"/rest/query-params/scenario-1?test=1\").expect(200);\n\n expect(response.body).toEqual({value: true});\n });\n it(\"should return false when query is false\", async () => {\n const response = await request.get(\"/rest/query-params/scenario-1?test=false\").expect(200);\n\n expect(response.body).toEqual({value: false});\n });\n it(\"should return false when query is 0\", async () => {\n const response = await request.get(\"/rest/query-params/scenario-1?test=0\").expect(200);\n\n expect(response.body).toEqual({value: false});\n });\n it(\"should return false when query is null\", async () => {\n const response = await request.get(\"/rest/query-params/scenario-1?test=null\").expect(200);\n\n expect(response.body).toEqual({value: null});\n });\n it(\"should return undefined when query is empty\", async () => {\n const response = await request.get(\"/rest/query-params/scenario-1?test=\").expect(200);\n\n expect(response.body).toEqual({});\n });\n it(\"should return undefined when no query\", async () => {\n const response = await request.get(\"/rest/query-params/scenario-1\").expect(200);\n\n expect(response.body).toEqual({});\n });\n });\n describe(\"Scenario2: Boolean value with default value\", () => {\n it(\"should return true when query is true\", async () => {\n const response = await request.get(\"/rest/query-params/scenario-2?test=true\").expect(200);\n\n expect(response.body).toEqual({value: true});\n });\n it(\"should return true when query is 1\", async () => {\n const response = await request.get(\"/rest/query-params/scenario-2?test=1\").expect(200);\n\n expect(response.body).toEqual({value: true});\n });\n it(\"should return false when query is false\", async () => {\n const response = await request.get(\"/rest/query-params/scenario-2?test=false\").expect(200);\n\n expect(response.body).toEqual({value: false});\n });\n it(\"should return false when query is 0\", async () => {\n const response = await request.get(\"/rest/query-params/scenario-2?test=0\").expect(200);\n\n expect(response.body).toEqual({value: false});\n });\n it(\"should return false when query is null\", async () => {\n const response = await request.get(\"/rest/query-params/scenario-2?test=null\").expect(200);\n\n expect(response.body).toEqual({value: null});\n });\n it(\"should return undefined when query is empty\", async () => {\n const response = await request.get(\"/rest/query-params/scenario-2?test=\").expect(200);\n\n expect(response.body).toEqual({value: true});\n });\n it(\"should return undefined when no query\", async () => {\n const response = await request.get(\"/rest/query-params/scenario-2\").expect(200);\n\n expect(response.body).toEqual({value: true});\n });\n });\n describe(\"Scenario3: Number value\", () => {\n const endpoint = \"/rest/query-params/scenario-3\";\n it(\"should return 0 when query is 0\", async () => {\n const response = await request.get(`${endpoint}?test=0`).expect(200);\n\n expect(response.body).toEqual({value: 0});\n });\n it(\"should return 1 when query is 1\", async () => {\n const response = await request.get(`${endpoint}?test=1`).expect(200);\n\n expect(response.body).toEqual({value: 1});\n });\n it(\"should return 0.1 when query is 0.1\", async () => {\n const response = await request.get(`${endpoint}?test=0.1`).expect(200);\n\n expect(response.body).toEqual({value: 0.1});\n });\n it(\"should throw bad request\", async () => {\n const response = await request.get(`${endpoint}?test=error`).expect(400);\n expect(response.body).toEqual({\n name: \"AJV_VALIDATION_ERROR\",\n message: 'Bad request on parameter \"request.query.test\".\\nValue must be number. Given value: \"error\"',\n status: 400,\n errors: [\n {\n keyword: \"type\",\n dataPath: \"\",\n instancePath: \"\",\n schemaPath: \"#/type\",\n params: {type: \"number\"},\n message: \"must be number\",\n data: \"error\"\n }\n ]\n });\n });\n it(\"should return undefined when query is empty\", async () => {\n const response = await request.get(`${endpoint}?test=null`).expect(200);\n\n expect(response.body).toEqual({value: null});\n });\n it(\"should return undefined when query is empty\", async () => {\n const response = await request.get(`${endpoint}?test=`).expect(200);\n\n expect(response.body).toEqual({});\n });\n it(\"should return undefined when no query\", async () => {\n const response = await request.get(`${endpoint}`).expect(200);\n\n expect(response.body).toEqual({});\n });\n });\n describe(\"Scenario4: String value\", () => {\n const endpoint = \"/rest/query-params/scenario-4\";\n it(\"should return 0 when query is 0\", async () => {\n const response = await request.get(`${endpoint}?test=0`).expect(200);\n\n expect(response.body).toEqual({value: \"0\"});\n });\n it(\"should return 1 when query is 1\", async () => {\n const response = await request.get(`${endpoint}?test=1`).expect(200);\n\n expect(response.body).toEqual({value: \"1\"});\n });\n it(\"should return 0.1 when query is 0.1\", async () => {\n const response = await request.get(`${endpoint}?test=0.1`).expect(200);\n\n expect(response.body).toEqual({value: \"0.1\"});\n });\n it(\"should return undefined when query is empty\", async () => {\n const response = await request.get(`${endpoint}?test=`).expect(200);\n\n expect(response.body).toEqual({value: \"\"});\n });\n it(\"should return undefined when no query\", async () => {\n const response = await request.get(`${endpoint}`).expect(200);\n\n expect(response.body).toEqual({});\n });\n });\n describe(\"Scenario6: DeepObject\", () => {\n const endpoint = \"/rest/query-params/scenario-6\";\n it(\"should return 0 when query is 0\", async () => {\n const response = await request.get(`${endpoint}?offset=0&limit=10&where[a]=0&where[b]=1`).expect(200);\n\n expect(response.body).toEqual({\n q: {\n limit: 10,\n offset: 0,\n where: {\n a: 0,\n b: 1\n }\n }\n });\n });\n });\n describe(\"Scenario7: DeepObject\", () => {\n const endpoint = \"/rest/query-params/scenario-7\";\n it(\"should return the query value\", async () => {\n const response = await request.get(`${endpoint}?q[offset]=0&q[limit]=10&q[where][a]=0&q[where][b]=1`).expect(200);\n\n expect(response.body).toEqual({\n q: {\n limit: 10,\n offset: 0,\n where: {\n a: 0,\n b: 1\n }\n }\n });\n });\n it(\"should throw a bad request\", async () => {\n const response = await request.get(`${endpoint}?q[offset]=0&q[limit]=10&q[where][a]=ca&q[where][b]=1`).expect(400);\n\n expect(response.body).toEqual({\n errors: [\n {\n data: \"ca\",\n dataPath: \".where.a\",\n instancePath: \"/where/a\",\n keyword: \"type\",\n message: \"must be number\",\n modelName: \"PaginationQuery\",\n params: {\n type: \"number\"\n },\n schemaPath: \"#/properties/where/properties/a/type\"\n }\n ],\n message: 'Bad request on parameter \"request.query.q\".\\nPaginationQuery.where.a must be number. Given value: \"ca\"',\n name: \"AJV_VALIDATION_ERROR\",\n status: 400\n });\n });\n });\n describe(\"Scenario8: String[] value\", () => {\n const endpoint = \"/rest/query-params/scenario-8\";\n it(\"should return 0 when query is 0\", async () => {\n const response = await request.get(`${endpoint}?test=0`).expect(200);\n\n expect(response.body).toEqual({value: [\"0\"]});\n });\n it(\"should return 1 when query is 1\", async () => {\n const response = await request.get(`${endpoint}?test=1&test=2`).expect(200);\n\n expect(response.body).toEqual({value: [\"1\", \"2\"]});\n });\n });\n}\n"]}
@@ -0,0 +1,139 @@
1
+ import { __decorate, __metadata, __param } from "tslib";
2
+ import { Context, Controller, Get, Location, PlatformTest, Redirect } from "@tsed/common";
3
+ import SuperTest from "supertest";
4
+ let RedirectCtrl = class RedirectCtrl {
5
+ testScenario1() {
6
+ return "Hello";
7
+ }
8
+ testScenario2() {
9
+ return "Hello";
10
+ }
11
+ testScenario3(ctx) {
12
+ ctx.response.redirect(302, "/another/path");
13
+ return "Hello";
14
+ }
15
+ testScenario4(ctx) {
16
+ return "Hello";
17
+ }
18
+ testScenario5(ctx) {
19
+ return "Hello";
20
+ }
21
+ testScenario6(ctx) {
22
+ return "Hello";
23
+ }
24
+ testScenario7(ctx) {
25
+ ctx.response.location("/another/path");
26
+ return "Hello";
27
+ }
28
+ };
29
+ __decorate([
30
+ Get("/scenario-1"),
31
+ Redirect("/test"),
32
+ __metadata("design:type", Function),
33
+ __metadata("design:paramtypes", []),
34
+ __metadata("design:returntype", void 0)
35
+ ], RedirectCtrl.prototype, "testScenario1", null);
36
+ __decorate([
37
+ Get("/scenario-2"),
38
+ Redirect(301, "/test"),
39
+ __metadata("design:type", Function),
40
+ __metadata("design:paramtypes", []),
41
+ __metadata("design:returntype", void 0)
42
+ ], RedirectCtrl.prototype, "testScenario2", null);
43
+ __decorate([
44
+ Get("/scenario-3"),
45
+ Redirect(301, "/test"),
46
+ __param(0, Context()),
47
+ __metadata("design:type", Function),
48
+ __metadata("design:paramtypes", [Object]),
49
+ __metadata("design:returntype", void 0)
50
+ ], RedirectCtrl.prototype, "testScenario3", null);
51
+ __decorate([
52
+ Get("/scenario-4"),
53
+ Redirect("back"),
54
+ __param(0, Context()),
55
+ __metadata("design:type", Function),
56
+ __metadata("design:paramtypes", [Object]),
57
+ __metadata("design:returntype", void 0)
58
+ ], RedirectCtrl.prototype, "testScenario4", null);
59
+ __decorate([
60
+ Get("/scenario-5"),
61
+ Location("back"),
62
+ __param(0, Context()),
63
+ __metadata("design:type", Function),
64
+ __metadata("design:paramtypes", [Object]),
65
+ __metadata("design:returntype", void 0)
66
+ ], RedirectCtrl.prototype, "testScenario5", null);
67
+ __decorate([
68
+ Get("/scenario-6"),
69
+ Location("/path/to").Status(301),
70
+ __param(0, Context()),
71
+ __metadata("design:type", Function),
72
+ __metadata("design:paramtypes", [Object]),
73
+ __metadata("design:returntype", void 0)
74
+ ], RedirectCtrl.prototype, "testScenario6", null);
75
+ __decorate([
76
+ Get("/scenario-7"),
77
+ Location("/path/to"),
78
+ __param(0, Context()),
79
+ __metadata("design:type", Function),
80
+ __metadata("design:paramtypes", [Object]),
81
+ __metadata("design:returntype", void 0)
82
+ ], RedirectCtrl.prototype, "testScenario7", null);
83
+ RedirectCtrl = __decorate([
84
+ Controller("/redirect")
85
+ ], RedirectCtrl);
86
+ export function testRedirect(options) {
87
+ let request;
88
+ beforeAll(PlatformTest.bootstrap(options.server, {
89
+ ...options,
90
+ mount: {
91
+ "/rest": [RedirectCtrl]
92
+ }
93
+ }));
94
+ beforeAll(() => {
95
+ request = SuperTest(PlatformTest.callback());
96
+ });
97
+ afterAll(PlatformTest.reset);
98
+ it("Scenario1: GET /rest/redirect/scenario-1", async () => {
99
+ const response = await request.get("/rest/redirect/scenario-1").expect(302);
100
+ expect(response.text).toEqual("Found. Redirecting to /test");
101
+ expect(response.header.location).toEqual("/test");
102
+ });
103
+ it("Scenario1: HEAD /rest/redirect/scenario-1", async () => {
104
+ const response = await request.head("/rest/redirect/scenario-1").expect(302);
105
+ expect(response.text).toBeUndefined();
106
+ expect(response.header.location).toEqual("/test");
107
+ });
108
+ it("Scenario2: GET /rest/redirect/scenario-2", async () => {
109
+ const response = await request.get("/rest/redirect/scenario-2").expect(301);
110
+ expect(response.text).toEqual("Moved Permanently. Redirecting to /test");
111
+ expect(response.header.location).toEqual("/test");
112
+ });
113
+ it("Scenario3: GET /rest/redirect/scenario-3", async () => {
114
+ const response = await request.get("/rest/redirect/scenario-3").expect(302);
115
+ expect(response.header.location).toEqual("/another/path");
116
+ expect(response.text).toEqual("Found. Redirecting to /another/path");
117
+ });
118
+ it("Scenario4: GET /rest/redirect/scenario-4 with referer", async () => {
119
+ const response = await request.get("/rest/redirect/scenario-4").set("Referrer", "https://referrer.com").expect(302);
120
+ expect(response.text).toEqual("Found. Redirecting to https://referrer.com");
121
+ expect(response.header.location).toEqual("https://referrer.com");
122
+ });
123
+ it("Scenario5: GET /rest/redirect/scenario-5", async () => {
124
+ const response = await request.get("/rest/redirect/scenario-5").set("Referrer", "https://referrer.com").expect(200);
125
+ expect(response.text).toEqual("Hello");
126
+ expect(response.header.location).toEqual("https://referrer.com");
127
+ });
128
+ it("Scenario6: GET /rest/redirect/scenario-6", async () => {
129
+ const response = await request.get("/rest/redirect/scenario-6").set("Referrer", "https://referrer.com").expect(301);
130
+ expect(response.text).toEqual("Hello");
131
+ expect(response.header.location).toEqual("/path/to");
132
+ });
133
+ it("Scenario7: GET /rest/redirect/scenario-7", async () => {
134
+ const response = await request.get("/rest/redirect/scenario-7").set("Referrer", "https://referrer.com").expect(200);
135
+ expect(response.text).toEqual("Hello");
136
+ expect(response.header.location).toEqual("/another/path");
137
+ });
138
+ }
139
+ //# sourceMappingURL=testRedirect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testRedirect.js","sourceRoot":"","sources":["../../../src/tests/testRedirect.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAC,MAAM,cAAc,CAAC;AACxF,OAAO,SAAS,MAAM,WAAW,CAAC;AAIlC,IAAM,YAAY,GAAlB,MAAM,YAAY;IAGhB,aAAa;QACX,OAAO,OAAO,CAAC;IACjB,CAAC;IAID,aAAa;QACX,OAAO,OAAO,CAAC;IACjB,CAAC;IAID,aAAa,CAAY,GAAY;QACnC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;QAE5C,OAAO,OAAO,CAAC;IACjB,CAAC;IAID,aAAa,CAAY,GAAY;QACnC,OAAO,OAAO,CAAC;IACjB,CAAC;IAID,aAAa,CAAY,GAAY;QACnC,OAAO,OAAO,CAAC;IACjB,CAAC;IAID,aAAa,CAAY,GAAY;QACnC,OAAO,OAAO,CAAC;IACjB,CAAC;IAID,aAAa,CAAY,GAAY;QACnC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;QACvC,OAAO,OAAO,CAAC;IACjB,CAAC;CACF,CAAA;AA1CC;IAFC,GAAG,CAAC,aAAa,CAAC;IAClB,QAAQ,CAAC,OAAO,CAAC;;;;iDAGjB;AAID;IAFC,GAAG,CAAC,aAAa,CAAC;IAClB,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;;;;iDAGtB;AAID;IAFC,GAAG,CAAC,aAAa,CAAC;IAClB,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;IACR,WA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AAG,CAAC,UAAU,EAAE,sBAAsB,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAEpH,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACvC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {Context, Controller, Get, Location, PlatformTest, Redirect} from \"@tsed/common\";\nimport SuperTest from \"supertest\";\nimport {PlatformTestingSdkOpts} from \"../interfaces\";\n\n@Controller(\"/redirect\")\nclass RedirectCtrl {\n @Get(\"/scenario-1\")\n @Redirect(\"/test\")\n testScenario1() {\n return \"Hello\";\n }\n\n @Get(\"/scenario-2\")\n @Redirect(301, \"/test\")\n testScenario2() {\n return \"Hello\";\n }\n\n @Get(\"/scenario-3\")\n @Redirect(301, \"/test\")\n testScenario3(@Context() ctx: Context) {\n ctx.response.redirect(302, \"/another/path\");\n\n return \"Hello\";\n }\n\n @Get(\"/scenario-4\")\n @Redirect(\"back\")\n testScenario4(@Context() ctx: Context) {\n return \"Hello\";\n }\n\n @Get(\"/scenario-5\")\n @Location(\"back\")\n testScenario5(@Context() ctx: Context) {\n return \"Hello\";\n }\n\n @Get(\"/scenario-6\")\n @Location(\"/path/to\").Status(301)\n testScenario6(@Context() ctx: Context) {\n return \"Hello\";\n }\n\n @Get(\"/scenario-7\")\n @Location(\"/path/to\")\n testScenario7(@Context() ctx: Context) {\n ctx.response.location(\"/another/path\");\n return \"Hello\";\n }\n}\n\nexport function testRedirect(options: PlatformTestingSdkOpts) {\n let request: SuperTest.SuperTest<SuperTest.Test>;\n\n beforeAll(\n PlatformTest.bootstrap(options.server, {\n ...options,\n mount: {\n \"/rest\": [RedirectCtrl]\n }\n })\n );\n beforeAll(() => {\n request = SuperTest(PlatformTest.callback());\n });\n afterAll(PlatformTest.reset);\n\n it(\"Scenario1: GET /rest/redirect/scenario-1\", async () => {\n const response = await request.get(\"/rest/redirect/scenario-1\").expect(302);\n\n expect(response.text).toEqual(\"Found. Redirecting to /test\");\n expect(response.header.location).toEqual(\"/test\");\n });\n\n it(\"Scenario1: HEAD /rest/redirect/scenario-1\", async () => {\n const response = await request.head(\"/rest/redirect/scenario-1\").expect(302);\n\n expect(response.text).toBeUndefined();\n expect(response.header.location).toEqual(\"/test\");\n });\n\n it(\"Scenario2: GET /rest/redirect/scenario-2\", async () => {\n const response = await request.get(\"/rest/redirect/scenario-2\").expect(301);\n\n expect(response.text).toEqual(\"Moved Permanently. Redirecting to /test\");\n expect(response.header.location).toEqual(\"/test\");\n });\n\n it(\"Scenario3: GET /rest/redirect/scenario-3\", async () => {\n const response = await request.get(\"/rest/redirect/scenario-3\").expect(302);\n\n expect(response.header.location).toEqual(\"/another/path\");\n expect(response.text).toEqual(\"Found. Redirecting to /another/path\");\n });\n\n it(\"Scenario4: GET /rest/redirect/scenario-4 with referer\", async () => {\n const response = await request.get(\"/rest/redirect/scenario-4\").set(\"Referrer\", \"https://referrer.com\").expect(302);\n\n expect(response.text).toEqual(\"Found. Redirecting to https://referrer.com\");\n expect(response.header.location).toEqual(\"https://referrer.com\");\n });\n\n it(\"Scenario5: GET /rest/redirect/scenario-5\", async () => {\n const response = await request.get(\"/rest/redirect/scenario-5\").set(\"Referrer\", \"https://referrer.com\").expect(200);\n\n expect(response.text).toEqual(\"Hello\");\n expect(response.header.location).toEqual(\"https://referrer.com\");\n });\n\n it(\"Scenario6: GET /rest/redirect/scenario-6\", async () => {\n const response = await request.get(\"/rest/redirect/scenario-6\").set(\"Referrer\", \"https://referrer.com\").expect(301);\n\n expect(response.text).toEqual(\"Hello\");\n expect(response.header.location).toEqual(\"/path/to\");\n });\n\n it(\"Scenario7: GET /rest/redirect/scenario-7\", async () => {\n const response = await request.get(\"/rest/redirect/scenario-7\").set(\"Referrer\", \"https://referrer.com\").expect(200);\n\n expect(response.text).toEqual(\"Hello\");\n expect(response.header.location).toEqual(\"/another/path\");\n });\n}\n"]}