@tsed/platform-test-sdk 8.11.0 → 8.11.2-rc.1

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 (119) hide show
  1. package/lib/esm/components/PlatformTestSdk.js +0 -1
  2. package/lib/esm/errors/CustomBadRequest.js +0 -1
  3. package/lib/esm/errors/CustomInternalError.js +0 -1
  4. package/lib/esm/index.js +0 -1
  5. package/lib/esm/interfaces/PlatformTestingSdkOpts.js +0 -1
  6. package/lib/esm/interfaces/index.js +0 -1
  7. package/lib/esm/modules/feature/FeatureModule.js +0 -1
  8. package/lib/esm/modules/feature/controllers/FeatureController.js +0 -1
  9. package/lib/esm/tests/exports.js +0 -1
  10. package/lib/esm/tests/testAcceptMime.js +0 -1
  11. package/lib/esm/tests/testAuth.js +0 -1
  12. package/lib/esm/tests/testBodyParams.js +0 -1
  13. package/lib/esm/tests/testCache.js +0 -1
  14. package/lib/esm/tests/testChildrenControllers.js +0 -1
  15. package/lib/esm/tests/testCookies.js +0 -1
  16. package/lib/esm/tests/testCustom404.js +0 -1
  17. package/lib/esm/tests/testDeepQueryParams.js +0 -1
  18. package/lib/esm/tests/testErrors.js +0 -1
  19. package/lib/esm/tests/testHandlers.js +0 -1
  20. package/lib/esm/tests/testHeaderParams.js +0 -1
  21. package/lib/esm/tests/testHeaders.js +0 -1
  22. package/lib/esm/tests/testInheritanceController.js +0 -1
  23. package/lib/esm/tests/testLocals.js +0 -1
  24. package/lib/esm/tests/testLocation.js +0 -1
  25. package/lib/esm/tests/testMiddlewares.js +0 -1
  26. package/lib/esm/tests/testModule.js +0 -1
  27. package/lib/esm/tests/testMulter.js +0 -1
  28. package/lib/esm/tests/testPathParams.js +0 -1
  29. package/lib/esm/tests/testQueryParams.js +0 -1
  30. package/lib/esm/tests/testRedirect.js +0 -1
  31. package/lib/esm/tests/testResponse.js +0 -1
  32. package/lib/esm/tests/testResponseFilter.js +0 -1
  33. package/lib/esm/tests/testRouting.js +0 -1
  34. package/lib/esm/tests/testScopeRequest.js +0 -1
  35. package/lib/esm/tests/testSession.js +0 -1
  36. package/lib/esm/tests/testStatics.js +0 -1
  37. package/lib/esm/tests/testStream.js +0 -1
  38. package/lib/esm/tests/testView.js +0 -1
  39. package/package.json +18 -15
  40. package/.barrelsby.json +0 -5
  41. package/lib/esm/components/PlatformTestSdk.js.map +0 -1
  42. package/lib/esm/errors/CustomBadRequest.js.map +0 -1
  43. package/lib/esm/errors/CustomInternalError.js.map +0 -1
  44. package/lib/esm/index.js.map +0 -1
  45. package/lib/esm/interfaces/PlatformTestingSdkOpts.js.map +0 -1
  46. package/lib/esm/interfaces/index.js.map +0 -1
  47. package/lib/esm/modules/feature/FeatureModule.js.map +0 -1
  48. package/lib/esm/modules/feature/controllers/FeatureController.js.map +0 -1
  49. package/lib/esm/tests/exports.js.map +0 -1
  50. package/lib/esm/tests/testAcceptMime.js.map +0 -1
  51. package/lib/esm/tests/testAuth.js.map +0 -1
  52. package/lib/esm/tests/testBodyParams.js.map +0 -1
  53. package/lib/esm/tests/testCache.js.map +0 -1
  54. package/lib/esm/tests/testChildrenControllers.js.map +0 -1
  55. package/lib/esm/tests/testCookies.js.map +0 -1
  56. package/lib/esm/tests/testCustom404.js.map +0 -1
  57. package/lib/esm/tests/testDeepQueryParams.js.map +0 -1
  58. package/lib/esm/tests/testErrors.js.map +0 -1
  59. package/lib/esm/tests/testHandlers.js.map +0 -1
  60. package/lib/esm/tests/testHeaderParams.js.map +0 -1
  61. package/lib/esm/tests/testHeaders.js.map +0 -1
  62. package/lib/esm/tests/testInheritanceController.js.map +0 -1
  63. package/lib/esm/tests/testLocals.js.map +0 -1
  64. package/lib/esm/tests/testLocation.js.map +0 -1
  65. package/lib/esm/tests/testMiddlewares.js.map +0 -1
  66. package/lib/esm/tests/testModule.js.map +0 -1
  67. package/lib/esm/tests/testMulter.js.map +0 -1
  68. package/lib/esm/tests/testPathParams.js.map +0 -1
  69. package/lib/esm/tests/testQueryParams.js.map +0 -1
  70. package/lib/esm/tests/testRedirect.js.map +0 -1
  71. package/lib/esm/tests/testResponse.js.map +0 -1
  72. package/lib/esm/tests/testResponseFilter.js.map +0 -1
  73. package/lib/esm/tests/testRouting.js.map +0 -1
  74. package/lib/esm/tests/testScopeRequest.js.map +0 -1
  75. package/lib/esm/tests/testSession.js.map +0 -1
  76. package/lib/esm/tests/testStatics.js.map +0 -1
  77. package/lib/esm/tests/testStream.js.map +0 -1
  78. package/lib/esm/tests/testView.js.map +0 -1
  79. package/src/components/PlatformTestSdk.ts +0 -30
  80. package/src/data/file.txt +0 -1
  81. package/src/data/response.data.json +0 -3
  82. package/src/data/swagger.json +0 -32
  83. package/src/errors/CustomBadRequest.ts +0 -16
  84. package/src/errors/CustomInternalError.ts +0 -16
  85. package/src/index.ts +0 -40
  86. package/src/interfaces/PlatformTestingSdkOpts.ts +0 -10
  87. package/src/interfaces/index.ts +0 -4
  88. package/src/modules/feature/FeatureModule.ts +0 -10
  89. package/src/modules/feature/controllers/FeatureController.ts +0 -11
  90. package/src/tests/exports.ts +0 -71
  91. package/src/tests/testAcceptMime.ts +0 -99
  92. package/src/tests/testAuth.ts +0 -345
  93. package/src/tests/testBodyParams.ts +0 -525
  94. package/src/tests/testCache.ts +0 -283
  95. package/src/tests/testChildrenControllers.ts +0 -59
  96. package/src/tests/testCookies.ts +0 -41
  97. package/src/tests/testCustom404.ts +0 -35
  98. package/src/tests/testDeepQueryParams.ts +0 -125
  99. package/src/tests/testErrors.ts +0 -233
  100. package/src/tests/testHandlers.ts +0 -94
  101. package/src/tests/testHeaderParams.ts +0 -158
  102. package/src/tests/testHeaders.ts +0 -78
  103. package/src/tests/testInheritanceController.ts +0 -206
  104. package/src/tests/testLocals.ts +0 -53
  105. package/src/tests/testLocation.ts +0 -40
  106. package/src/tests/testMiddlewares.ts +0 -155
  107. package/src/tests/testModule.ts +0 -50
  108. package/src/tests/testMulter.ts +0 -186
  109. package/src/tests/testPathParams.ts +0 -127
  110. package/src/tests/testQueryParams.ts +0 -238
  111. package/src/tests/testRedirect.ts +0 -129
  112. package/src/tests/testResponse.ts +0 -573
  113. package/src/tests/testResponseFilter.ts +0 -106
  114. package/src/tests/testRouting.ts +0 -71
  115. package/src/tests/testScopeRequest.ts +0 -116
  116. package/src/tests/testSession.ts +0 -109
  117. package/src/tests/testStatics.ts +0 -64
  118. package/src/tests/testStream.ts +0 -63
  119. package/src/tests/testView.ts +0 -75
@@ -1,233 +0,0 @@
1
- import "@tsed/ajv";
2
-
3
- import {Env} from "@tsed/core";
4
- import {Controller} from "@tsed/di";
5
- import {BadRequest, InternalServerError} from "@tsed/exceptions";
6
- import {Err} from "@tsed/platform-http";
7
- import {PlatformTest} from "@tsed/platform-http/testing";
8
- import {Middleware, UseAfter} from "@tsed/platform-middlewares";
9
- import {BodyParams} from "@tsed/platform-params";
10
- import {Description, Get, Name, Post, Required, Returns, Summary} from "@tsed/schema";
11
- import SuperTest from "supertest";
12
- import {afterAll, beforeAll, expect, it} from "vitest";
13
-
14
- import {CustomBadRequest} from "../errors/CustomBadRequest.js";
15
- import {CustomInternalError} from "../errors/CustomInternalError.js";
16
- import {PlatformTestingSdkOpts} from "../interfaces/index.js";
17
-
18
- class CustomModel {
19
- @Required() name: string;
20
- }
21
-
22
- class CustomPropModel {
23
- @Name("role_item")
24
- @Required()
25
- roleItem: string;
26
- }
27
-
28
- @Middleware()
29
- class ErrorMiddleware {
30
- use(@Err() error: any) {
31
- return {
32
- message: "no error"
33
- };
34
- }
35
- }
36
-
37
- @Middleware()
38
- class FakeMiddleware {
39
- use() {
40
- return {
41
- message: "should not be called by the platform when endpoint throw an error"
42
- };
43
- }
44
- }
45
-
46
- @Controller("/errors")
47
- export class ErrorsCtrl {
48
- @Get("/scenario-1")
49
- @(Returns(500, InternalServerError).Description("Custom Bad Request"))
50
- public scenario1() {
51
- throw new CustomBadRequest("Custom Bad Request");
52
- }
53
-
54
- @Get("/scenario-2")
55
- @(Returns(500).Description("Internal Server Error"))
56
- public scenario2() {
57
- throw new Error("My error");
58
- }
59
-
60
- @Get("/scenario-3")
61
- @(Returns(400, CustomInternalError).Description("Bad request"))
62
- public scenario3() {
63
- throw new CustomInternalError("My custom error");
64
- }
65
-
66
- @Post("/scenario-4")
67
- @Returns(400)
68
- public scenario4(@Required() @BodyParams("name") name: string) {
69
- return name;
70
- }
71
-
72
- @Post("/scenario-5")
73
- @(Returns(400, BadRequest).Description("Bad request"))
74
- public scenario5(
75
- @Required()
76
- @BodyParams()
77
- model: CustomModel
78
- ) {
79
- return model;
80
- }
81
-
82
- @Post("/scenario-6")
83
- @Summary("Throw a Required prop if prop name is required")
84
- @Description(`Return a required error`)
85
- @(Returns(400).Description("Bad request"))
86
- public scenario6(
87
- @Required()
88
- @BodyParams()
89
- model: CustomPropModel
90
- ) {
91
- return model;
92
- }
93
-
94
- @Get("/scenario-7")
95
- @(Returns(400).Description("Bad request"))
96
- @UseAfter(FakeMiddleware)
97
- @UseAfter(ErrorMiddleware)
98
- public scenario7() {
99
- throw new CustomInternalError("My custom error");
100
- }
101
- }
102
-
103
- export function testErrors(options: PlatformTestingSdkOpts) {
104
- let request: SuperTest.Agent;
105
- beforeAll(
106
- PlatformTest.bootstrap(options.server, {
107
- ...options,
108
- env: Env.TEST,
109
- mount: {
110
- "/rest": [ErrorsCtrl]
111
- }
112
- })
113
- );
114
- beforeAll(() => {
115
- request = SuperTest(PlatformTest.callback());
116
- });
117
- afterAll(PlatformTest.reset);
118
-
119
- it("Scenario 1: GET /rest/errors/scenario-1", async () => {
120
- const response: any = await request.get("/rest/errors/scenario-1").expect(400);
121
-
122
- expect(response.headers["x-header-error"]).toEqual("deny");
123
- expect(response.body).toEqual({
124
- name: "CUSTOM_BAD_REQUEST",
125
- message: "Custom Bad Request",
126
- status: 400,
127
- errors: ["test"]
128
- });
129
- });
130
-
131
- it("Scenario 2: GET /rest/errors/scenario-2", async () => {
132
- const response: any = await request.get("/rest/errors/scenario-2").expect(500);
133
-
134
- expect(response.body).toEqual({
135
- errors: [],
136
- message: "My error",
137
- name: "Error",
138
- status: 500
139
- });
140
- });
141
-
142
- it("Scenario 3: GET /rest/errors/scenario-3", async () => {
143
- const response: any = await request.get("/rest/errors/scenario-3").expect(500);
144
-
145
- expect(response.headers["x-header-error"]).toEqual("deny");
146
- expect(response.body).toEqual({
147
- name: "CUSTOM_INTERNAL_SERVER_ERROR",
148
- message: "My custom error",
149
- status: 500,
150
- errors: ["test"]
151
- });
152
- });
153
-
154
- it("Scenario 4: POST /rest/errors/scenario-4", async () => {
155
- const response: any = await request.post("/rest/errors/scenario-4").expect(400);
156
-
157
- expect(response.body).toEqual({
158
- errors: [
159
- {
160
- dataPath: ".name",
161
- requestPath: "body",
162
- keyword: "required",
163
- message: "It should have required parameter 'name'",
164
- modelName: "body",
165
- params: {
166
- missingProperty: "name"
167
- },
168
- schemaPath: "#/required"
169
- }
170
- ],
171
- message: "Bad request on parameter \"request.body.name\".\nIt should have required parameter 'name'",
172
- name: "REQUIRED_VALIDATION_ERROR",
173
- status: 400
174
- });
175
- });
176
-
177
- it("Scenario 5: POST /rest/errors/scenario-5", async () => {
178
- const response: any = await request.post("/rest/errors/scenario-5").send({}).expect(400);
179
-
180
- expect(response.body).toEqual({
181
- errors: [
182
- {
183
- dataPath: ".name",
184
- requestPath: "body",
185
- instancePath: "",
186
- keyword: "required",
187
- message: "must have required property 'name'",
188
- modelName: "CustomModel",
189
- params: {
190
- missingProperty: "name"
191
- },
192
- schemaPath: "#/required"
193
- }
194
- ],
195
- message: 'Bad request on parameter "request.body".\nCustomModel must have required property \'name\'. Given value: "undefined"',
196
- name: "AJV_VALIDATION_ERROR",
197
- status: 400
198
- });
199
- });
200
-
201
- it("Scenario 6: POST /rest/errors/scenario-6", async () => {
202
- const response: any = await request.post(`/rest/errors/scenario-6`).send({}).expect(400);
203
-
204
- expect(response.body).toEqual({
205
- errors: [
206
- {
207
- dataPath: ".role_item",
208
- requestPath: "body",
209
- instancePath: "",
210
- keyword: "required",
211
- message: "must have required property 'role_item'",
212
- modelName: "CustomPropModel",
213
- params: {
214
- missingProperty: "role_item"
215
- },
216
- schemaPath: "#/required"
217
- }
218
- ],
219
- message:
220
- 'Bad request on parameter "request.body".\nCustomPropModel must have required property \'role_item\'. Given value: "undefined"',
221
- name: "AJV_VALIDATION_ERROR",
222
- status: 400
223
- });
224
- });
225
-
226
- it("Scenario 7: GET /rest/errors/scenario-7", async () => {
227
- const response: any = await request.get("/rest/errors/scenario-7").expect(200);
228
-
229
- expect(response.body).toEqual({
230
- message: "no error"
231
- });
232
- });
233
- }
@@ -1,94 +0,0 @@
1
- import {Controller} from "@tsed/di";
2
- import {PlatformTest} from "@tsed/platform-http/testing";
3
- import {Context, PathParams} from "@tsed/platform-params";
4
- import {Get, Property, Required, Title} from "@tsed/schema";
5
- import SuperTest from "supertest";
6
- import {afterAll, beforeAll, expect, it} from "vitest";
7
-
8
- import {PlatformTestingSdkOpts} from "../interfaces/index.js";
9
-
10
- export class MyModel {
11
- @Title("ID")
12
- @Property()
13
- public id: string;
14
-
15
- @Property()
16
- @Required()
17
- public name: string;
18
- }
19
-
20
- @Controller("/handlers")
21
- export class HandlersCtrl {
22
- @Get("/scenario-1/:id") // Express style
23
- public scenario1(@PathParams("id") id: string): MyModel {
24
- const model = new MyModel();
25
- model.id = id;
26
- model.name = "test";
27
-
28
- return model;
29
- }
30
-
31
- @Get("/scenario-2/:id") // Ts.ED style with response injection
32
- public scenario2(
33
- @Context() ctx: Context,
34
- @PathParams("id")
35
- @Required()
36
- id: string
37
- ): void {
38
- const model = new MyModel();
39
- model.id = "1";
40
- model.name = "test";
41
-
42
- try {
43
- ctx.response.status(202).body(model);
44
- } catch (er) {
45
- console.log(er);
46
- }
47
- }
48
-
49
- @Get("/scenario-3/:id") // Ts.ED style
50
- public scenario3(@PathParams("id") id: string): Promise<any> {
51
- const model = new MyModel();
52
- model.id = id;
53
- model.name = "test";
54
-
55
- return Promise.resolve(model);
56
- }
57
- }
58
-
59
- export function testHandlers(options: PlatformTestingSdkOpts) {
60
- let request: SuperTest.Agent;
61
- beforeAll(
62
- PlatformTest.bootstrap(options.server, {
63
- ...options,
64
- logger: {},
65
- mount: {
66
- "/rest": [HandlersCtrl]
67
- }
68
- })
69
- );
70
- beforeAll(() => {
71
- request = SuperTest(PlatformTest.callback());
72
- });
73
- afterAll(PlatformTest.reset);
74
- it("Scenario 1: GET /rest/handlers/scenario-1/:id", async () => {
75
- const {body}: any = await request.get("/rest/handlers/scenario-1/1").expect(200);
76
-
77
- expect(body.id).toEqual("1");
78
- expect(body.name).toEqual("test");
79
- });
80
-
81
- it("Scenario 2: GET /rest/handlers/scenario-2/:id", async () => {
82
- const {body}: any = await request.get("/rest/handlers/scenario-2/1").expect(202);
83
-
84
- expect(body.id).toEqual("1");
85
- expect(body.name).toEqual("test");
86
- });
87
-
88
- it("Scenario 3: GET /rest/handlers/scenario-3/:id", async () => {
89
- const {body}: any = await request.get("/rest/handlers/scenario-3/1").expect(200);
90
-
91
- expect(body.id).toEqual("1");
92
- expect(body.name).toEqual("test");
93
- });
94
- }
@@ -1,158 +0,0 @@
1
- import {Controller} from "@tsed/di";
2
- import {Req} from "@tsed/platform-http";
3
- import {PlatformTest} from "@tsed/platform-http/testing";
4
- import {Middleware, Use} from "@tsed/platform-middlewares";
5
- import {Context, HeaderParams, Locals} from "@tsed/platform-params";
6
- import {Enum, Get, Post, Required} from "@tsed/schema";
7
- import SuperTest from "supertest";
8
- import {afterAll, beforeAll, describe, expect, it} from "vitest";
9
-
10
- import {PlatformTestingSdkOpts} from "../interfaces/index.js";
11
-
12
- @Middleware()
13
- class SetId {
14
- use(@Req() request: any, @Locals() locals: any, @Context() $ctx: Context) {
15
- request["user"] = 1;
16
- locals.id = "local-10909";
17
- $ctx.set("uid", "ctx-10909");
18
- }
19
- }
20
-
21
- @Controller("/header-params")
22
- export class HeaderParamsCtrl {
23
- /**
24
- * Handle request with a raw middleware + handler
25
- * Get Authorization from header
26
- * @param request
27
- * @param auth
28
- */
29
- @Get("/scenario-1")
30
- @Use(SetId)
31
- public scenario1(@Req() request: Req, @HeaderParams("authorization") auth: string): any {
32
- return {
33
- user: (request as any).user,
34
- token: auth
35
- };
36
- }
37
-
38
- @Post("/scenario-2")
39
- scenario2(@HeaderParams("Content-type") contentType: string) {
40
- return {contentType};
41
- }
42
-
43
- @Get("/scenario-3")
44
- testScenario3(
45
- @HeaderParams({
46
- expression: "x-token",
47
- useValidation: true
48
- })
49
- @Required()
50
- @Enum("test", "gcp")
51
- token: string
52
- ): any {
53
- return {token};
54
- }
55
- }
56
-
57
- export function testHeaderParams(options: PlatformTestingSdkOpts) {
58
- let request: SuperTest.Agent;
59
- beforeAll(
60
- PlatformTest.bootstrap(options.server, {
61
- ...options,
62
- mount: {
63
- "/rest": [HeaderParamsCtrl]
64
- }
65
- })
66
- );
67
- beforeAll(() => {
68
- request = SuperTest(PlatformTest.callback());
69
- });
70
- afterAll(PlatformTest.reset);
71
-
72
- describe("Scenario 1: GET /rest/header-params/scenario-1", () => {
73
- it("should return a response with the extracted authorization from the request headers", async () => {
74
- const {body}: any = await request
75
- .get("/rest/header-params/scenario-1")
76
- .set({
77
- Authorization: "tokenauth"
78
- })
79
- .expect(200);
80
-
81
- expect(body.user).toEqual(1);
82
- expect(body.token).toEqual("tokenauth");
83
- });
84
- });
85
-
86
- describe("Scenario 2: POST with contentType", () => {
87
- it("should return a response with the extracted contentType from the request headers", async () => {
88
- const response = await request
89
- .post("/rest/header-params/scenario-2")
90
- .send({})
91
- .set({
92
- "Content-Type": "application/json"
93
- })
94
- .expect(200);
95
-
96
- expect(response.body).toEqual({
97
- contentType: "application/json"
98
- });
99
- });
100
- });
101
- describe("Scenario3: GET /rest/headers/scenario-3", () => {
102
- it("should accept the header", async () => {
103
- const response = await request.get("/rest/header-params/scenario-3").set("x-token", "test").expect(200);
104
-
105
- expect(response.body).toEqual({
106
- token: "test"
107
- });
108
- });
109
-
110
- it("should not validate the header", async () => {
111
- const response = await request.get("/rest/header-params/scenario-3").expect(400);
112
-
113
- expect(response.body).toEqual({
114
- errors: [
115
- {
116
- requestPath: "header",
117
- dataPath: ".x-token",
118
- keyword: "required",
119
- message: "It should have required parameter 'x-token'",
120
- modelName: "header",
121
- params: {
122
- missingProperty: "x-token"
123
- },
124
- schemaPath: "#/required"
125
- }
126
- ],
127
- message: "Bad request on parameter \"request.header.x-token\".\nIt should have required parameter 'x-token'",
128
- name: "REQUIRED_VALIDATION_ERROR",
129
- status: 400
130
- });
131
- });
132
-
133
- it("should not validate the header - enum", async () => {
134
- const response = await request.get("/rest/header-params/scenario-3").set("x-token", "invalid").expect(400);
135
-
136
- expect(response.body).toEqual({
137
- errors: [
138
- {
139
- data: "invalid",
140
- requestPath: "header",
141
- dataPath: ".x-token",
142
- instancePath: "",
143
- keyword: "enum",
144
- message: "must be equal to one of the allowed values",
145
- params: {
146
- allowedValues: ["test", "gcp"]
147
- },
148
- schemaPath: "#/enum"
149
- }
150
- ],
151
- message:
152
- 'Bad request on parameter "request.header.x-token".\nValue must be equal to one of the allowed values. Given value: "invalid"',
153
- name: "AJV_VALIDATION_ERROR",
154
- status: 400
155
- });
156
- });
157
- });
158
- }
@@ -1,78 +0,0 @@
1
- import {Controller} from "@tsed/di";
2
- import {PlatformResponse, Res} from "@tsed/platform-http";
3
- import {PlatformTest} from "@tsed/platform-http/testing";
4
- import {BodyParams} from "@tsed/platform-params";
5
- import {Get, Returns} from "@tsed/schema";
6
- import SuperTest from "supertest";
7
- import {afterAll, beforeAll, expect, it} from "vitest";
8
-
9
- import {PlatformTestingSdkOpts} from "../interfaces/index.js";
10
-
11
- @Controller("/headers")
12
- export class HeadersCtrl {
13
- @Get("/scenario-1")
14
- @(Returns(200, String).Header("test", "x-token"))
15
- testScenario1(@BodyParams("test") value: string[]): any {
16
- return "hello";
17
- }
18
-
19
- @Get("/scenario-2")
20
- @(Returns(200, String).Header("x-token-test", "test").Header("x-token-test-2", "test2").ContentType("application/xml"))
21
- testScenario2() {
22
- return "<xml></xml>";
23
- }
24
-
25
- @Get("/scenario-3")
26
- @(Returns(200, String).Headers({
27
- Location: {
28
- description: "URL to the new xxx",
29
- type: "string",
30
- value: "/v1/location/header"
31
- }
32
- }))
33
- testScenario3(@Res() response: PlatformResponse) {
34
- response.setHeader("Location", `/v1/location`);
35
- return "Hello";
36
- }
37
- }
38
-
39
- export function testHeaders(options: PlatformTestingSdkOpts) {
40
- let request: SuperTest.Agent;
41
-
42
- beforeAll(
43
- PlatformTest.bootstrap(options.server, {
44
- ...options,
45
- logger: {
46
- level: "off"
47
- },
48
- mount: {
49
- "/rest": [HeadersCtrl]
50
- }
51
- })
52
- );
53
- beforeAll(() => {
54
- request = SuperTest(PlatformTest.callback());
55
- });
56
- afterAll(PlatformTest.reset);
57
-
58
- it("Scenario1: GET /rest/headers/scenario-1", async () => {
59
- const response = await request.get("/rest/headers/scenario-1").expect(200);
60
-
61
- expect(response.text).toEqual("hello");
62
- expect(response.header["test"]).toEqual("x-token");
63
- });
64
-
65
- it("Scenario2: GET /rest/headers/scenario-2", async () => {
66
- const response = await request.get("/rest/headers/scenario-2").expect(200);
67
-
68
- expect(response.headers["x-token-test"]).toEqual("test");
69
- expect(response.headers["x-token-test-2"]).toEqual("test2");
70
- expect(response.headers["content-type"]).toContain("application/xml");
71
- });
72
-
73
- it("Scenario3: GET /rest/headers/scenario-3", async () => {
74
- const response = await request.get("/rest/headers/scenario-3").expect(200);
75
-
76
- expect(response.headers["location"]).toEqual("/v1/location");
77
- });
78
- }