@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,615 @@
1
+ import { __decorate, __metadata, __param } from "tslib";
2
+ import { Context, Controller, Get, getContext, PathParams, PlatformResponse, PlatformTest, Post, Res } from "@tsed/common";
3
+ import { CollectionOf, ContentType, Enum, ForwardGroups, Groups, Ignore, Name, Property, Required, Returns, Status } from "@tsed/schema";
4
+ import axios from "axios";
5
+ import { createReadStream } from "fs";
6
+ import { join } from "path";
7
+ import { of } from "rxjs";
8
+ import { agent } from "superagent";
9
+ import SuperTest from "supertest";
10
+ class Base {
11
+ ignoreMeBase;
12
+ fooBase;
13
+ }
14
+ __decorate([
15
+ Ignore(),
16
+ __metadata("design:type", String)
17
+ ], Base.prototype, "ignoreMeBase", void 0);
18
+ __decorate([
19
+ Property(),
20
+ __metadata("design:type", String)
21
+ ], Base.prototype, "fooBase", void 0);
22
+ class MyModel extends Base {
23
+ foo;
24
+ ignoreMe;
25
+ ignoreMe2;
26
+ }
27
+ __decorate([
28
+ Property(),
29
+ __metadata("design:type", String)
30
+ ], MyModel.prototype, "foo", void 0);
31
+ __decorate([
32
+ Ignore(),
33
+ __metadata("design:type", String)
34
+ ], MyModel.prototype, "ignoreMe", void 0);
35
+ __decorate([
36
+ Ignore((value, ctx) => ctx.endpoint),
37
+ __metadata("design:type", String)
38
+ ], MyModel.prototype, "ignoreMe2", void 0);
39
+ class EmptyModel {
40
+ raw;
41
+ affected;
42
+ }
43
+ export var EnumValue;
44
+ (function (EnumValue) {
45
+ EnumValue["One"] = "one";
46
+ EnumValue["Two"] = "two";
47
+ })(EnumValue || (EnumValue = {}));
48
+ export class NestedEnum {
49
+ value;
50
+ }
51
+ __decorate([
52
+ Required(),
53
+ Enum(EnumValue),
54
+ __metadata("design:type", String)
55
+ ], NestedEnum.prototype, "value", void 0);
56
+ export class TestNestedEnum {
57
+ nested;
58
+ }
59
+ __decorate([
60
+ Property(),
61
+ __metadata("design:type", NestedEnum)
62
+ ], TestNestedEnum.prototype, "nested", void 0);
63
+ export class ModelGroup {
64
+ id;
65
+ groups;
66
+ }
67
+ __decorate([
68
+ Property(),
69
+ __metadata("design:type", String)
70
+ ], ModelGroup.prototype, "id", void 0);
71
+ __decorate([
72
+ Groups("!creation"),
73
+ __metadata("design:type", String)
74
+ ], ModelGroup.prototype, "groups", void 0);
75
+ class TeamModel {
76
+ name;
77
+ }
78
+ __decorate([
79
+ Required(),
80
+ Name("teamName"),
81
+ __metadata("design:type", String)
82
+ ], TeamModel.prototype, "name", void 0);
83
+ class TeamsModel {
84
+ teams;
85
+ }
86
+ __decorate([
87
+ Required(),
88
+ CollectionOf(TeamModel),
89
+ ForwardGroups(),
90
+ __metadata("design:type", Array)
91
+ ], TeamsModel.prototype, "teams", void 0);
92
+ class AllowedModel {
93
+ id;
94
+ description;
95
+ prop1; // not display by default
96
+ prop2; // not display by default
97
+ sensitiveProp; // not displayed because it's a sensitive props
98
+ }
99
+ __decorate([
100
+ Property(),
101
+ __metadata("design:type", String)
102
+ ], AllowedModel.prototype, "id", void 0);
103
+ __decorate([
104
+ Property(),
105
+ __metadata("design:type", String)
106
+ ], AllowedModel.prototype, "description", void 0);
107
+ __decorate([
108
+ Groups("summary"),
109
+ __metadata("design:type", String)
110
+ ], AllowedModel.prototype, "prop1", void 0);
111
+ __decorate([
112
+ Groups("details"),
113
+ __metadata("design:type", String)
114
+ ], AllowedModel.prototype, "prop2", void 0);
115
+ __decorate([
116
+ Groups("admin"),
117
+ __metadata("design:type", String)
118
+ ], AllowedModel.prototype, "sensitiveProp", void 0);
119
+ let TestResponseParamsCtrl = class TestResponseParamsCtrl {
120
+ testScenario1Get(id) {
121
+ return `hello-${id}`;
122
+ }
123
+ testScenario3EmptyResponse(id, ctx) {
124
+ if (id) {
125
+ return;
126
+ }
127
+ ctx.response.status(201);
128
+ return {
129
+ id: 1
130
+ };
131
+ }
132
+ async testScenario5Promise() {
133
+ await new Promise((resolve) => {
134
+ resolve(undefined);
135
+ });
136
+ return {
137
+ id: 1
138
+ };
139
+ }
140
+ testScenario6Observable() {
141
+ return of({ id: 1 });
142
+ }
143
+ async testScenario6bObservable() {
144
+ return of({ id: 1 });
145
+ }
146
+ testScenario7Stream() {
147
+ return createReadStream(join(__dirname, "../data/response.data.json"));
148
+ }
149
+ async testScenario7bStream() {
150
+ return createReadStream(join(__dirname, "../data/response.data.json"));
151
+ }
152
+ testScenario9Get() {
153
+ return "value";
154
+ }
155
+ testScenario9WithDynamicParam(id) {
156
+ return "value" + id;
157
+ }
158
+ testScenario10() {
159
+ const model = new MyModel();
160
+ model.foo = "foo";
161
+ model.ignoreMe = "ignoreMe";
162
+ model.ignoreMe2 = "ignoreMe2";
163
+ model.fooBase = "fooBase";
164
+ model.ignoreMeBase = "ignoreMeBase";
165
+ return model;
166
+ }
167
+ testScenario11() {
168
+ const t = new EmptyModel();
169
+ t.raw = 1;
170
+ t.affected = 1;
171
+ return t;
172
+ }
173
+ testScenario12(res) {
174
+ res.attachment("filename");
175
+ return Buffer.from("Hello");
176
+ }
177
+ async testScenario13(res) {
178
+ const http = agent();
179
+ const image_res = await http.get("https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png");
180
+ res.setHeader("Content-Disposition", "inline;filename=googlelogo_color_272x92dp.png;");
181
+ res.setHeader("X-Content-Type-Options", "nosniff");
182
+ res.setHeader("Content-Type", "image/png");
183
+ return image_res.body;
184
+ }
185
+ scenario14() {
186
+ return {
187
+ jsonexample: 1
188
+ };
189
+ }
190
+ testScenario15a() {
191
+ return axios.get(`https://tsed.io/api.json`, {
192
+ responseType: "json"
193
+ });
194
+ }
195
+ async testScenario15b() {
196
+ return axios.get(`https://api.tsed.io/rest/github/typed/test`, {
197
+ responseType: "json"
198
+ });
199
+ }
200
+ async testScenario16() {
201
+ const test = new TestNestedEnum();
202
+ const nested = new NestedEnum();
203
+ nested.value = EnumValue.One;
204
+ test.nested = nested;
205
+ return test;
206
+ }
207
+ async testScenario17() {
208
+ const model = new ModelGroup();
209
+ model.id = "id";
210
+ model.groups = "groups";
211
+ return model;
212
+ }
213
+ testScenario18() {
214
+ const data = new TeamsModel();
215
+ const team = {};
216
+ team.name = "name";
217
+ data.teams = [team];
218
+ return data;
219
+ }
220
+ async testScenario19() {
221
+ const model = new AllowedModel();
222
+ model.id = "id";
223
+ model.prop1 = "prop1";
224
+ model.description = "description";
225
+ model.prop2 = "prop2";
226
+ model.sensitiveProp = "sensitiveProp";
227
+ return model;
228
+ }
229
+ async testScenario20() {
230
+ const $ctx = getContext();
231
+ return { id: $ctx?.request.query.id };
232
+ }
233
+ };
234
+ __decorate([
235
+ Get("/scenario1/:id"),
236
+ __param(0, PathParams("id")),
237
+ __metadata("design:type", Function),
238
+ __metadata("design:paramtypes", [Number]),
239
+ __metadata("design:returntype", void 0)
240
+ ], TestResponseParamsCtrl.prototype, "testScenario1Get", null);
241
+ __decorate([
242
+ Post("/scenario3/:id?"),
243
+ Status(204),
244
+ __param(0, PathParams("id")),
245
+ __param(1, Context()),
246
+ __metadata("design:type", Function),
247
+ __metadata("design:paramtypes", [Number, Object]),
248
+ __metadata("design:returntype", void 0)
249
+ ], TestResponseParamsCtrl.prototype, "testScenario3EmptyResponse", null);
250
+ __decorate([
251
+ Get("/scenario5"),
252
+ __metadata("design:type", Function),
253
+ __metadata("design:paramtypes", []),
254
+ __metadata("design:returntype", Promise)
255
+ ], TestResponseParamsCtrl.prototype, "testScenario5Promise", null);
256
+ __decorate([
257
+ Get("/scenario6"),
258
+ __metadata("design:type", Function),
259
+ __metadata("design:paramtypes", []),
260
+ __metadata("design:returntype", void 0)
261
+ ], TestResponseParamsCtrl.prototype, "testScenario6Observable", null);
262
+ __decorate([
263
+ Get("/scenario6b"),
264
+ __metadata("design:type", Function),
265
+ __metadata("design:paramtypes", []),
266
+ __metadata("design:returntype", Promise)
267
+ ], TestResponseParamsCtrl.prototype, "testScenario6bObservable", null);
268
+ __decorate([
269
+ Get("/scenario7"),
270
+ ContentType("application/json"),
271
+ __metadata("design:type", Function),
272
+ __metadata("design:paramtypes", []),
273
+ __metadata("design:returntype", void 0)
274
+ ], TestResponseParamsCtrl.prototype, "testScenario7Stream", null);
275
+ __decorate([
276
+ Get("/scenario7b"),
277
+ ContentType("application/json"),
278
+ __metadata("design:type", Function),
279
+ __metadata("design:paramtypes", []),
280
+ __metadata("design:returntype", Promise)
281
+ ], TestResponseParamsCtrl.prototype, "testScenario7bStream", null);
282
+ __decorate([
283
+ Get("/scenario9/static"),
284
+ __metadata("design:type", Function),
285
+ __metadata("design:paramtypes", []),
286
+ __metadata("design:returntype", String)
287
+ ], TestResponseParamsCtrl.prototype, "testScenario9Get", null);
288
+ __decorate([
289
+ Get("/scenario9/:id"),
290
+ __param(0, PathParams("id")),
291
+ __metadata("design:type", Function),
292
+ __metadata("design:paramtypes", [Number]),
293
+ __metadata("design:returntype", String)
294
+ ], TestResponseParamsCtrl.prototype, "testScenario9WithDynamicParam", null);
295
+ __decorate([
296
+ Get("/scenario10"),
297
+ __metadata("design:type", Function),
298
+ __metadata("design:paramtypes", []),
299
+ __metadata("design:returntype", void 0)
300
+ ], TestResponseParamsCtrl.prototype, "testScenario10", null);
301
+ __decorate([
302
+ Get("/scenario11"),
303
+ __metadata("design:type", Function),
304
+ __metadata("design:paramtypes", []),
305
+ __metadata("design:returntype", void 0)
306
+ ], TestResponseParamsCtrl.prototype, "testScenario11", null);
307
+ __decorate([
308
+ Get("/scenario12"),
309
+ __param(0, Res()),
310
+ __metadata("design:type", Function),
311
+ __metadata("design:paramtypes", [PlatformResponse]),
312
+ __metadata("design:returntype", void 0)
313
+ ], TestResponseParamsCtrl.prototype, "testScenario12", null);
314
+ __decorate([
315
+ Get("/scenario13"),
316
+ __param(0, Res()),
317
+ __metadata("design:type", Function),
318
+ __metadata("design:paramtypes", [PlatformResponse]),
319
+ __metadata("design:returntype", Promise)
320
+ ], TestResponseParamsCtrl.prototype, "testScenario13", null);
321
+ __decorate([
322
+ Get("/scenario14"),
323
+ __metadata("design:type", Function),
324
+ __metadata("design:paramtypes", []),
325
+ __metadata("design:returntype", void 0)
326
+ ], TestResponseParamsCtrl.prototype, "scenario14", null);
327
+ __decorate([
328
+ Get("/scenario15a"),
329
+ __metadata("design:type", Function),
330
+ __metadata("design:paramtypes", []),
331
+ __metadata("design:returntype", void 0)
332
+ ], TestResponseParamsCtrl.prototype, "testScenario15a", null);
333
+ __decorate([
334
+ Get("/scenario15b"),
335
+ __metadata("design:type", Function),
336
+ __metadata("design:paramtypes", []),
337
+ __metadata("design:returntype", Promise)
338
+ ], TestResponseParamsCtrl.prototype, "testScenario15b", null);
339
+ __decorate([
340
+ Get("/scenario16"),
341
+ __metadata("design:type", Function),
342
+ __metadata("design:paramtypes", []),
343
+ __metadata("design:returntype", Promise)
344
+ ], TestResponseParamsCtrl.prototype, "testScenario16", null);
345
+ __decorate([
346
+ Get("/scenario17"),
347
+ Returns(201, ModelGroup).Groups("creation"),
348
+ __metadata("design:type", Function),
349
+ __metadata("design:paramtypes", []),
350
+ __metadata("design:returntype", Promise)
351
+ ], TestResponseParamsCtrl.prototype, "testScenario17", null);
352
+ __decorate([
353
+ Get("/scenario18"),
354
+ Returns(200, TeamsModel),
355
+ __metadata("design:type", Function),
356
+ __metadata("design:paramtypes", []),
357
+ __metadata("design:returntype", void 0)
358
+ ], TestResponseParamsCtrl.prototype, "testScenario18", null);
359
+ __decorate([
360
+ Get("/scenario19"),
361
+ Returns(200, AllowedModel).Groups("!admin").AllowedGroups("summary", "details"),
362
+ __metadata("design:type", Function),
363
+ __metadata("design:paramtypes", []),
364
+ __metadata("design:returntype", Promise)
365
+ ], TestResponseParamsCtrl.prototype, "testScenario19", null);
366
+ __decorate([
367
+ Get("/scenario20"),
368
+ __metadata("design:type", Function),
369
+ __metadata("design:paramtypes", []),
370
+ __metadata("design:returntype", Promise)
371
+ ], TestResponseParamsCtrl.prototype, "testScenario20", null);
372
+ TestResponseParamsCtrl = __decorate([
373
+ Controller("/response")
374
+ ], TestResponseParamsCtrl);
375
+ export function testResponse(options) {
376
+ let request;
377
+ beforeAll(PlatformTest.bootstrap(options.server, {
378
+ ...options,
379
+ mount: {
380
+ "/rest": [TestResponseParamsCtrl]
381
+ }
382
+ }));
383
+ beforeAll(() => {
384
+ request = SuperTest(PlatformTest.callback());
385
+ });
386
+ afterAll(PlatformTest.reset);
387
+ describe("Scenario1: return the id (classic)", () => {
388
+ describe("GET /rest/response/scenario1/:id", () => {
389
+ it("should return the id + test", async () => {
390
+ const response = await request.get("/rest/response/scenario1/10").expect(200);
391
+ expect(response.text).toEqual("hello-10");
392
+ });
393
+ });
394
+ });
395
+ describe("Scenario3: when response is empty or created", () => {
396
+ describe("GET /rest/response/scenario3/:id?", () => {
397
+ it("should return nothing with a 204 status", async () => {
398
+ const response = await request.post("/rest/response/scenario3/10").expect(204);
399
+ expect(response.text).toEqual("");
400
+ });
401
+ it("should return a body", async () => {
402
+ const response = await request.post("/rest/response/scenario3").expect(201);
403
+ expect(response.body).toEqual({ id: 1 });
404
+ });
405
+ });
406
+ });
407
+ describe("Scenario5: when endpoint response from promise", () => {
408
+ describe("GET /rest/response/scenario5", () => {
409
+ it("should return a body", async () => {
410
+ const response = await request.get("/rest/response/scenario5");
411
+ expect(response.body).toEqual({ id: 1 });
412
+ });
413
+ });
414
+ });
415
+ describe("Scenario6: when endpoint return an observable", () => {
416
+ describe("GET /rest/response/scenario6", () => {
417
+ it("should return a body", async () => {
418
+ const response = await request.get("/rest/response/scenario6");
419
+ expect(response.body).toEqual({ id: 1 });
420
+ });
421
+ });
422
+ describe("GET /rest/response/scenario6b", () => {
423
+ it("should return a body", async () => {
424
+ const response = await request.get("/rest/response/scenario6b");
425
+ expect(response.body).toEqual({ id: 1 });
426
+ });
427
+ });
428
+ });
429
+ describe("Scenario7: when endpoint return a stream", () => {
430
+ describe("GET /rest/response/scenario7", () => {
431
+ it("should return a body", async () => {
432
+ const response = await request.get("/rest/response/scenario7");
433
+ expect(response.body).toEqual({ id: "1" });
434
+ });
435
+ });
436
+ describe("GET /rest/response/scenario7b", () => {
437
+ it("should return a body", async () => {
438
+ const response = await request.get("/rest/response/scenario7b");
439
+ expect(response.body).toEqual({ id: "1" });
440
+ });
441
+ });
442
+ });
443
+ describe("Scenario9: routes without parameters must be defined first", () => {
444
+ describe("GET /rest/response/scenario9/static", () => {
445
+ it("should return the test", async () => {
446
+ const response = await request.get("/rest/response/scenario9/static").expect(200);
447
+ expect(response.text).toEqual("value");
448
+ });
449
+ });
450
+ describe("GET /rest/response/scenario9/:dynamic", () => {
451
+ it("should return the test + id", async () => {
452
+ const response = await request.get("/rest/response/scenario9/10").expect(200);
453
+ expect(response.text).toEqual("value10");
454
+ });
455
+ });
456
+ describe("GET /rest/response/scenario9/:dynamic", () => {
457
+ it("should throw a badRequest when path params isn't set as number", async () => {
458
+ const response = await request.get("/rest/response/scenario9/kkk").expect(400);
459
+ expect(response.body).toEqual({
460
+ errors: [
461
+ {
462
+ data: "kkk",
463
+ dataPath: "",
464
+ instancePath: "",
465
+ keyword: "type",
466
+ message: "must be number",
467
+ params: {
468
+ type: "number"
469
+ },
470
+ schemaPath: "#/type"
471
+ }
472
+ ],
473
+ message: 'Bad request on parameter "request.path.id".\nValue must be number. Given value: "kkk"',
474
+ name: "AJV_VALIDATION_ERROR",
475
+ status: 400
476
+ });
477
+ });
478
+ });
479
+ });
480
+ describe("Scenario10: return a model with ignored props", () => {
481
+ it("should return a body", async () => {
482
+ const response = await request.get("/rest/response/scenario10");
483
+ expect(response.body).toEqual({
484
+ foo: "foo",
485
+ fooBase: "fooBase"
486
+ });
487
+ });
488
+ });
489
+ describe("Scenario11: return models without props", () => {
490
+ it("should return a body", async () => {
491
+ const response = await request.get("/rest/response/scenario11");
492
+ expect(response.body).toEqual({
493
+ affected: 1,
494
+ raw: 1
495
+ });
496
+ });
497
+ });
498
+ describe("Scenario12: Return buffer", () => {
499
+ it("should return a body", async () => {
500
+ const response = await request.get("/rest/response/scenario12");
501
+ expect(response.headers["content-disposition"]).toEqual('attachment; filename="filename"');
502
+ expect(response.headers["content-type"]).toContain("application/octet-stream");
503
+ expect(response.headers["content-length"]).toEqual("5");
504
+ expect(response.body.toString()).toEqual("Hello");
505
+ });
506
+ });
507
+ describe("Scenario13: Return buffer", () => {
508
+ it("should return image", async () => {
509
+ const response = await request.get("/rest/response/scenario13");
510
+ expect(response.headers["content-disposition"]).toEqual("inline;filename=googlelogo_color_272x92dp.png;");
511
+ expect(response.headers["content-type"]).toContain("image/png");
512
+ expect(response.headers["content-length"]).toEqual("5969");
513
+ });
514
+ });
515
+ describe("Scenario14: Return application/json when Accept is */*", () => {
516
+ it("should return a */* content-type", async () => {
517
+ const response = await request
518
+ .get("/rest/response/scenario14")
519
+ .set("Accept", "*/*")
520
+ .set("Content-Type", "application/json")
521
+ .expect(200);
522
+ expect(response.headers["content-type"]).toEqual("application/json; charset=utf-8");
523
+ expect(response.body).toEqual({
524
+ jsonexample: 1
525
+ });
526
+ });
527
+ });
528
+ describe("Scenario15: Use axios as proxy", () => {
529
+ it("should return the response (200)", async () => {
530
+ const response = await request.get("/rest/response/scenario15a").expect(200);
531
+ expect(response.headers["content-type"]).toEqual("application/json; charset=utf-8");
532
+ });
533
+ it("should return the response (401)", async () => {
534
+ const response = await request.get("/rest/response/scenario15b").expect(401);
535
+ expect(response.headers["content-type"]).toEqual("application/json; charset=utf-8");
536
+ });
537
+ });
538
+ describe("Scenario16: Return response with nested enum", () => {
539
+ it("should return the response (200)", async () => {
540
+ const response = await request.get("/rest/response/scenario16").expect(200);
541
+ expect(response.body).toEqual({ nested: { value: "one" } });
542
+ });
543
+ });
544
+ describe("Scenario17: Return response with groups on 201", () => {
545
+ it("should return the response (200)", async () => {
546
+ const response = await request.get("/rest/response/scenario17").expect(201);
547
+ expect(response.body).toEqual({ id: "id" });
548
+ });
549
+ });
550
+ describe("Scenario18: Return data with alias", () => {
551
+ it("should return the response (200)", async () => {
552
+ const response = await request.get("/rest/response/scenario18").expect(200);
553
+ expect(response.body).toEqual({
554
+ teams: [
555
+ {
556
+ teamName: "name"
557
+ }
558
+ ]
559
+ });
560
+ });
561
+ });
562
+ describe("Scenario19: includes options", () => {
563
+ it("should return the response (200)", async () => {
564
+ const response = await request.get("/rest/response/scenario19").expect(200);
565
+ expect(response.body).toEqual({
566
+ description: "description",
567
+ id: "id",
568
+ prop1: "prop1",
569
+ prop2: "prop2"
570
+ });
571
+ });
572
+ it("should return the response (200 + [summary])", async () => {
573
+ const response = await request.get("/rest/response/scenario19?includes=summary").expect(200);
574
+ expect(response.body).toEqual({
575
+ description: "description",
576
+ id: "id",
577
+ prop1: "prop1"
578
+ });
579
+ });
580
+ it("should return the response (200 + [summary, details])", async () => {
581
+ const response = await request.get("/rest/response/scenario19?includes=summary&includes=details").expect(200);
582
+ expect(response.body).toEqual({
583
+ description: "description",
584
+ id: "id",
585
+ prop2: "prop2",
586
+ prop1: "prop1"
587
+ });
588
+ });
589
+ it("should return the response (200 + [summary, details, admin])", async () => {
590
+ const response = await request.get("/rest/response/scenario19?includes=summary&includes=details&includes=admin").expect(200);
591
+ expect(response.body).toEqual({
592
+ description: "description",
593
+ id: "id",
594
+ prop2: "prop2",
595
+ prop1: "prop1"
596
+ });
597
+ });
598
+ it("should return the response (200 + 'summary,details,admin')", async () => {
599
+ const response = await request.get("/rest/response/scenario19?includes=summary,details,admin").expect(200);
600
+ expect(response.body).toEqual({
601
+ description: "description",
602
+ id: "id",
603
+ prop2: "prop2",
604
+ prop1: "prop1"
605
+ });
606
+ });
607
+ });
608
+ describe("Scenario20: should return query data from Context", () => {
609
+ it("should return the response (200)", async () => {
610
+ const response = await request.get("/rest/response/scenario20?id=id").expect(200);
611
+ expect(response.body).toEqual({ id: "id" });
612
+ });
613
+ });
614
+ }
615
+ //# sourceMappingURL=testResponse.js.map