@tsed/platform-test-sdk 7.79.4 → 7.80.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.
- package/lib/cjs/tests/testHeaders.js +8 -24
- package/lib/cjs/tests/testHeaders.js.map +1 -1
- package/lib/cjs/tests/testInheritanceController.js +2 -1
- package/lib/cjs/tests/testInheritanceController.js.map +1 -1
- package/lib/cjs/tests/testMulter.js +5 -3
- package/lib/cjs/tests/testMulter.js.map +1 -1
- package/lib/cjs/tests/testRouting.js +4 -2
- package/lib/cjs/tests/testRouting.js.map +1 -1
- package/lib/cjs/tests/testStream.js +1 -1
- package/lib/esm/tests/testHeaders.js +8 -24
- package/lib/esm/tests/testHeaders.js.map +1 -1
- package/lib/esm/tests/testInheritanceController.js +2 -1
- package/lib/esm/tests/testInheritanceController.js.map +1 -1
- package/lib/esm/tests/testMulter.js +6 -4
- package/lib/esm/tests/testMulter.js.map +1 -1
- package/lib/esm/tests/testRouting.js +4 -2
- package/lib/esm/tests/testRouting.js.map +1 -1
- package/lib/esm/tests/testStream.js +1 -1
- package/lib/types-esm/components/PlatformTestSdk.d.ts +9 -0
- package/lib/types-esm/errors/CustomBadRequest.d.ts +8 -0
- package/lib/types-esm/errors/CustomInternalError.d.ts +8 -0
- package/lib/types-esm/interfaces/PlatformTestingSdkOpts.d.ts +8 -0
- package/lib/types-esm/modules/feature/FeatureModule.d.ts +2 -0
- package/lib/types-esm/modules/feature/controllers/FeatureController.d.ts +3 -0
- package/lib/types-esm/tests/exports.d.ts +2 -0
- package/lib/types-esm/tests/testAcceptMime.d.ts +2 -0
- package/lib/types-esm/tests/testAuth.d.ts +8 -0
- package/lib/types-esm/tests/testBodyParams.d.ts +3 -0
- package/lib/types-esm/tests/testCache.d.ts +2 -0
- package/lib/types-esm/tests/testChildrenControllers.d.ts +2 -0
- package/lib/types-esm/tests/testCookies.d.ts +11 -0
- package/lib/types-esm/tests/testCustom404.d.ts +2 -0
- package/lib/types-esm/tests/testDeepQueryParams.d.ts +3 -0
- package/lib/types-esm/tests/testErrors.d.ts +19 -0
- package/lib/types-esm/tests/testHandlers.d.ts +12 -0
- package/lib/types-esm/tests/testHeaderParams.d.ts +16 -0
- package/lib/types-esm/tests/testHeaders.d.ts +8 -0
- package/lib/types-esm/tests/testInheritanceController.d.ts +42 -0
- package/lib/types-esm/tests/testLocals.d.ts +2 -0
- package/lib/types-esm/tests/testLocation.d.ts +2 -0
- package/lib/types-esm/tests/testMiddlewares.d.ts +8 -0
- package/lib/types-esm/tests/testModule.d.ts +2 -0
- package/lib/types-esm/tests/testMulter.d.ts +21 -0
- package/lib/types-esm/tests/testPathParams.d.ts +2 -0
- package/lib/types-esm/tests/testQueryParams.d.ts +6 -0
- package/lib/types-esm/tests/testRedirect.d.ts +2 -0
- package/lib/types-esm/tests/testResponse.d.ts +16 -0
- package/lib/types-esm/tests/testResponseFilter.d.ts +2 -0
- package/lib/types-esm/tests/testRouting.d.ts +7 -0
- package/lib/types-esm/tests/testScopeRequest.d.ts +12 -0
- package/lib/types-esm/tests/testSession.d.ts +16 -0
- package/lib/types-esm/tests/testStatics.d.ts +2 -0
- package/lib/types-esm/tests/testStream.d.ts +2 -0
- package/lib/types-esm/tests/testView.d.ts +2 -0
- package/package.json +22 -20
- package/lib/cjs/package.json +0 -3
- package/lib/esm/package.json +0 -3
- package/lib/tsconfig.esm.tsbuildinfo +0 -1
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/src/components/PlatformTestSdk.ts +0 -29
- package/src/data/file.txt +0 -1
- package/src/data/response.data.json +0 -3
- package/src/data/swagger.json +0 -32
- package/src/errors/CustomBadRequest.ts +0 -16
- package/src/errors/CustomInternalError.ts +0 -16
- package/src/interfaces/PlatformTestingSdkOpts.ts +0 -10
- package/src/modules/feature/FeatureModule.ts +0 -9
- package/src/modules/feature/controllers/FeatureController.ts +0 -11
- package/src/tests/exports.ts +0 -71
- package/src/tests/testAcceptMime.ts +0 -95
- package/src/tests/testAuth.ts +0 -339
- package/src/tests/testBodyParams.ts +0 -483
- package/src/tests/testCache.ts +0 -279
- package/src/tests/testChildrenControllers.ts +0 -55
- package/src/tests/testCookies.ts +0 -36
- package/src/tests/testCustom404.ts +0 -33
- package/src/tests/testDeepQueryParams.ts +0 -120
- package/src/tests/testErrors.ts +0 -226
- package/src/tests/testHandlers.ts +0 -90
- package/src/tests/testHeaderParams.ts +0 -152
- package/src/tests/testHeaders.ts +0 -91
- package/src/tests/testInheritanceController.ts +0 -200
- package/src/tests/testLocals.ts +0 -46
- package/src/tests/testLocation.ts +0 -37
- package/src/tests/testMiddlewares.ts +0 -159
- package/src/tests/testModule.ts +0 -46
- package/src/tests/testMulter.ts +0 -151
- package/src/tests/testPathParams.ts +0 -123
- package/src/tests/testQueryParams.ts +0 -233
- package/src/tests/testRedirect.ts +0 -124
- package/src/tests/testResponse.ts +0 -528
- package/src/tests/testResponseFilter.ts +0 -101
- package/src/tests/testRouting.ts +0 -65
- package/src/tests/testScopeRequest.ts +0 -111
- package/src/tests/testSession.ts +0 -103
- package/src/tests/testStatics.ts +0 -61
- package/src/tests/testStream.ts +0 -59
- package/src/tests/testView.ts +0 -68
- package/tsconfig.esm.json +0 -63
- package/tsconfig.json +0 -63
- /package/{src/index.ts → lib/types-esm/index.d.ts} +0 -0
- /package/{src/interfaces/index.ts → lib/types-esm/interfaces/index.d.ts} +0 -0
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import {Context, Controller, Get, PathParams, PlatformTest, Post} from "@tsed/common";
|
|
2
|
-
import {Pattern} from "@tsed/schema";
|
|
3
|
-
import SuperTest from "supertest";
|
|
4
|
-
import {PlatformTestingSdkOpts} from "../interfaces/index.js";
|
|
5
|
-
|
|
6
|
-
@Controller("/path-params")
|
|
7
|
-
class TestPathParamsCtrl {
|
|
8
|
-
@Get("/scenario-1/:scope/:scopeId")
|
|
9
|
-
testScenario1(@PathParams("scope") scope: string) {
|
|
10
|
-
// Here scope will be {0: 'a', 1: 'b', 2: 'c'} instead of 'abc' in version 5.47.0
|
|
11
|
-
expect(scope).toEqual("abc");
|
|
12
|
-
|
|
13
|
-
return Promise.resolve(scope);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
@Get("/scenario-2/:scope/:scopeId")
|
|
17
|
-
testScenario2(@PathParams("scope") scope: any) {
|
|
18
|
-
// This way it works in version 5.47.0
|
|
19
|
-
expect(scope).toEqual("abc");
|
|
20
|
-
|
|
21
|
-
return scope;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
@Post("/scenario-3/:scope/:scopeId")
|
|
25
|
-
testScenario3(@PathParams("scope") scope: string): Promise<any[]> {
|
|
26
|
-
expect(scope).toEqual("abc");
|
|
27
|
-
|
|
28
|
-
// Here the function will return {0: 'a', 1: 'b', 2: 'c'} instead of ['a','b','c'] in version 5.44.13
|
|
29
|
-
return Promise.resolve(["a", "b", "c"]);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
@Post("/scenario-4/:scope/:scopeId")
|
|
33
|
-
testScenario4(@PathParams("scope") scope: string, @Context() ctx: Context) {
|
|
34
|
-
expect(scope).toEqual("abc");
|
|
35
|
-
|
|
36
|
-
// This way it works in version 5.44.13
|
|
37
|
-
ctx.response.body(["a", "b", "c"]);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
@Get("/scenario-5/:scopeId")
|
|
41
|
-
testScenario5(@PathParams("scopeId") @Pattern(/^[0-9a-fA-F]{24}$/) scopeId: string, @Context() ctx: Context) {
|
|
42
|
-
return "test";
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
@Get("/scenario-6/:id")
|
|
46
|
-
testScenario6(@PathParams("id") id: number) {
|
|
47
|
-
return {id};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function testPathParams(options: PlatformTestingSdkOpts) {
|
|
52
|
-
let request: SuperTest.Agent;
|
|
53
|
-
|
|
54
|
-
beforeAll(
|
|
55
|
-
PlatformTest.bootstrap(options.server, {
|
|
56
|
-
...options,
|
|
57
|
-
mount: {
|
|
58
|
-
"/rest": [TestPathParamsCtrl]
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
);
|
|
62
|
-
beforeAll(() => {
|
|
63
|
-
request = SuperTest(PlatformTest.callback());
|
|
64
|
-
});
|
|
65
|
-
afterAll(PlatformTest.reset);
|
|
66
|
-
|
|
67
|
-
it("Scenario 1: GET /rest/path-params/scenario-1/scope/scopeId", async () => {
|
|
68
|
-
const response = await request.get("/rest/path-params/scenario-1/abc/1").expect(200);
|
|
69
|
-
|
|
70
|
-
expect(response.text).toEqual("abc");
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("Scenario 2: GET /rest/path-params/scenario-2/scopeId", async () => {
|
|
74
|
-
const response = await request.get("/rest/path-params/scenario-2/abc/1").expect(200);
|
|
75
|
-
|
|
76
|
-
expect(response.text).toEqual("abc");
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it("Scenario 3: POST /rest/path-params/scenario-3/scope/scopeId", async () => {
|
|
80
|
-
const response = await request.post("/rest/path-params/scenario-3/abc/1").expect(200);
|
|
81
|
-
|
|
82
|
-
expect(response.body).toEqual(["a", "b", "c"]);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it("Scenario 4: POST /rest/path-params/scenario-4/scope/scopeId", async () => {
|
|
86
|
-
const response = await request.post("/rest/path-params/scenario-4/abc/1").expect(200);
|
|
87
|
-
|
|
88
|
-
expect(response.body).toEqual(["a", "b", "c"]);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("Scenario 5 a: GET /rest/path-params/scenario-5/scopeId", async () => {
|
|
92
|
-
const response = await request.get("/rest/path-params/scenario-5/1").expect(400);
|
|
93
|
-
|
|
94
|
-
expect(response.body).toEqual({
|
|
95
|
-
errors: [
|
|
96
|
-
{
|
|
97
|
-
data: "1",
|
|
98
|
-
requestPath: "path",
|
|
99
|
-
dataPath: ".scopeId",
|
|
100
|
-
instancePath: "",
|
|
101
|
-
keyword: "pattern",
|
|
102
|
-
message: 'must match pattern "^[0-9a-fA-F]{24}$"',
|
|
103
|
-
params: {
|
|
104
|
-
pattern: "^[0-9a-fA-F]{24}$"
|
|
105
|
-
},
|
|
106
|
-
schemaPath: "#/pattern"
|
|
107
|
-
}
|
|
108
|
-
],
|
|
109
|
-
message: 'Bad request on parameter "request.path.scopeId".\nValue must match pattern "^[0-9a-fA-F]{24}$". Given value: "1"',
|
|
110
|
-
name: "AJV_VALIDATION_ERROR",
|
|
111
|
-
status: 400
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
it("Scenario 5b: GET /rest/path-params/scenario-5/scopeId", async () => {
|
|
115
|
-
await request.get("/rest/path-params/scenario-5/5ce4ee471495836c5e2e4cb0").expect(200);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("Scenario 6: GET /rest/path-params/scenario-6/id", async () => {
|
|
119
|
-
const response = await request.get("/rest/path-params/scenario-6/1").expect(200);
|
|
120
|
-
|
|
121
|
-
expect(response.body).toEqual({id: 1});
|
|
122
|
-
});
|
|
123
|
-
}
|
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
import "@tsed/ajv";
|
|
2
|
-
import {Controller, Get, PlatformTest, QueryParams} from "@tsed/common";
|
|
3
|
-
import {Maximum, Minimum, Required} from "@tsed/schema";
|
|
4
|
-
import SuperTest from "supertest";
|
|
5
|
-
import {PlatformTestingSdkOpts} from "../interfaces/index.js";
|
|
6
|
-
|
|
7
|
-
export class RandomStringModel {
|
|
8
|
-
@Maximum(250)
|
|
9
|
-
@Minimum(1)
|
|
10
|
-
@Required()
|
|
11
|
-
length: number;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
@Controller("/query-params")
|
|
15
|
-
class TestQueryParamsCtrl {
|
|
16
|
-
@Get("/scenario-1")
|
|
17
|
-
testScenario1(@QueryParams("test") value: boolean): any {
|
|
18
|
-
return {value};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
@Get("/scenario-2")
|
|
22
|
-
testScenario2(@QueryParams("test") value: boolean = true): any {
|
|
23
|
-
return {value};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
@Get("/scenario-3")
|
|
27
|
-
testScenario3(@QueryParams("test") value: number): any {
|
|
28
|
-
return {value};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
@Get("/scenario-4")
|
|
32
|
-
testScenario4(@QueryParams("test") value: string): any {
|
|
33
|
-
return {value};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
@Get("/scenario-5")
|
|
37
|
-
testScenario5(@QueryParams() value: RandomStringModel): any {
|
|
38
|
-
return {value};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
@Get("/scenario-6")
|
|
42
|
-
testScenario8(@QueryParams("test", String) value: string[]): any {
|
|
43
|
-
return {value};
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function testQueryParams(options: PlatformTestingSdkOpts) {
|
|
48
|
-
let request: SuperTest.Agent;
|
|
49
|
-
|
|
50
|
-
beforeAll(
|
|
51
|
-
PlatformTest.bootstrap(options.server, {
|
|
52
|
-
...options,
|
|
53
|
-
ajv: {
|
|
54
|
-
verbose: false
|
|
55
|
-
},
|
|
56
|
-
mount: {
|
|
57
|
-
"/rest": [TestQueryParamsCtrl]
|
|
58
|
-
}
|
|
59
|
-
})
|
|
60
|
-
);
|
|
61
|
-
beforeAll(() => {
|
|
62
|
-
request = SuperTest(PlatformTest.callback());
|
|
63
|
-
});
|
|
64
|
-
afterAll(PlatformTest.reset);
|
|
65
|
-
describe("Scenario1: Boolean value", () => {
|
|
66
|
-
it("should return true when query is true", async () => {
|
|
67
|
-
const response = await request.get("/rest/query-params/scenario-1?test=true").expect(200);
|
|
68
|
-
|
|
69
|
-
expect(response.body).toEqual({value: true});
|
|
70
|
-
});
|
|
71
|
-
it("should return true when query is 1", async () => {
|
|
72
|
-
const response = await request.get("/rest/query-params/scenario-1?test=1").expect(200);
|
|
73
|
-
|
|
74
|
-
expect(response.body).toEqual({value: true});
|
|
75
|
-
});
|
|
76
|
-
it("should return false when query is false", async () => {
|
|
77
|
-
const response = await request.get("/rest/query-params/scenario-1?test=false").expect(200);
|
|
78
|
-
|
|
79
|
-
expect(response.body).toEqual({value: false});
|
|
80
|
-
});
|
|
81
|
-
it("should return false when query is 0", async () => {
|
|
82
|
-
const response = await request.get("/rest/query-params/scenario-1?test=0").expect(200);
|
|
83
|
-
|
|
84
|
-
expect(response.body).toEqual({value: false});
|
|
85
|
-
});
|
|
86
|
-
it("should return false when query is null", async () => {
|
|
87
|
-
const response = await request.get("/rest/query-params/scenario-1?test=null").expect(200);
|
|
88
|
-
|
|
89
|
-
expect(response.body).toEqual({value: null});
|
|
90
|
-
});
|
|
91
|
-
it("should return undefined when query is empty", async () => {
|
|
92
|
-
const response = await request.get("/rest/query-params/scenario-1?test=").expect(200);
|
|
93
|
-
|
|
94
|
-
expect(response.body).toEqual({});
|
|
95
|
-
});
|
|
96
|
-
it("should return undefined when no query", async () => {
|
|
97
|
-
const response = await request.get("/rest/query-params/scenario-1").expect(200);
|
|
98
|
-
|
|
99
|
-
expect(response.body).toEqual({});
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
describe("Scenario2: Boolean value with default value", () => {
|
|
103
|
-
it("should return true when query is true", async () => {
|
|
104
|
-
const response = await request.get("/rest/query-params/scenario-2?test=true").expect(200);
|
|
105
|
-
|
|
106
|
-
expect(response.body).toEqual({value: true});
|
|
107
|
-
});
|
|
108
|
-
it("should return true when query is 1", async () => {
|
|
109
|
-
const response = await request.get("/rest/query-params/scenario-2?test=1").expect(200);
|
|
110
|
-
|
|
111
|
-
expect(response.body).toEqual({value: true});
|
|
112
|
-
});
|
|
113
|
-
it("should return false when query is false", async () => {
|
|
114
|
-
const response = await request.get("/rest/query-params/scenario-2?test=false").expect(200);
|
|
115
|
-
|
|
116
|
-
expect(response.body).toEqual({value: false});
|
|
117
|
-
});
|
|
118
|
-
it("should return false when query is 0", async () => {
|
|
119
|
-
const response = await request.get("/rest/query-params/scenario-2?test=0").expect(200);
|
|
120
|
-
|
|
121
|
-
expect(response.body).toEqual({value: false});
|
|
122
|
-
});
|
|
123
|
-
it("should return false when query is null", async () => {
|
|
124
|
-
const response = await request.get("/rest/query-params/scenario-2?test=null").expect(200);
|
|
125
|
-
|
|
126
|
-
expect(response.body).toEqual({value: null});
|
|
127
|
-
});
|
|
128
|
-
it("should return undefined when query is empty", async () => {
|
|
129
|
-
const response = await request.get("/rest/query-params/scenario-2?test=").expect(200);
|
|
130
|
-
|
|
131
|
-
expect(response.body).toEqual({value: true});
|
|
132
|
-
});
|
|
133
|
-
it("should return undefined when no query", async () => {
|
|
134
|
-
const response = await request.get("/rest/query-params/scenario-2").expect(200);
|
|
135
|
-
|
|
136
|
-
expect(response.body).toEqual({value: true});
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
describe("Scenario3: Number value", () => {
|
|
140
|
-
const endpoint = "/rest/query-params/scenario-3";
|
|
141
|
-
it("should return 0 when query is 0", async () => {
|
|
142
|
-
const response = await request.get(`${endpoint}?test=0`).expect(200);
|
|
143
|
-
|
|
144
|
-
expect(response.body).toEqual({value: 0});
|
|
145
|
-
});
|
|
146
|
-
it("should return 1 when query is 1", async () => {
|
|
147
|
-
const response = await request.get(`${endpoint}?test=1`).expect(200);
|
|
148
|
-
|
|
149
|
-
expect(response.body).toEqual({value: 1});
|
|
150
|
-
});
|
|
151
|
-
it("should return 0.1 when query is 0.1", async () => {
|
|
152
|
-
const response = await request.get(`${endpoint}?test=0.1`).expect(200);
|
|
153
|
-
|
|
154
|
-
expect(response.body).toEqual({value: 0.1});
|
|
155
|
-
});
|
|
156
|
-
it("should throw bad request", async () => {
|
|
157
|
-
const response = await request.get(`${endpoint}?test=error`).expect(400);
|
|
158
|
-
expect(response.body).toEqual({
|
|
159
|
-
name: "AJV_VALIDATION_ERROR",
|
|
160
|
-
message: 'Bad request on parameter "request.query.test".\nValue must be number. Given value: "error"',
|
|
161
|
-
status: 400,
|
|
162
|
-
errors: [
|
|
163
|
-
{
|
|
164
|
-
keyword: "type",
|
|
165
|
-
requestPath: "query",
|
|
166
|
-
dataPath: ".test",
|
|
167
|
-
instancePath: "",
|
|
168
|
-
schemaPath: "#/type",
|
|
169
|
-
params: {type: "number"},
|
|
170
|
-
message: "must be number",
|
|
171
|
-
data: "error"
|
|
172
|
-
}
|
|
173
|
-
]
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
it("should return undefined when query is empty", async () => {
|
|
177
|
-
const response = await request.get(`${endpoint}?test=null`).expect(200);
|
|
178
|
-
|
|
179
|
-
expect(response.body).toEqual({value: null});
|
|
180
|
-
});
|
|
181
|
-
it("should return undefined when query is empty", async () => {
|
|
182
|
-
const response = await request.get(`${endpoint}?test=`).expect(200);
|
|
183
|
-
|
|
184
|
-
expect(response.body).toEqual({});
|
|
185
|
-
});
|
|
186
|
-
it("should return undefined when no query", async () => {
|
|
187
|
-
const response = await request.get(`${endpoint}`).expect(200);
|
|
188
|
-
|
|
189
|
-
expect(response.body).toEqual({});
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
describe("Scenario4: String value", () => {
|
|
193
|
-
const endpoint = "/rest/query-params/scenario-4";
|
|
194
|
-
it("should return 0 when query is 0", async () => {
|
|
195
|
-
const response = await request.get(`${endpoint}?test=0`).expect(200);
|
|
196
|
-
|
|
197
|
-
expect(response.body).toEqual({value: "0"});
|
|
198
|
-
});
|
|
199
|
-
it("should return 1 when query is 1", async () => {
|
|
200
|
-
const response = await request.get(`${endpoint}?test=1`).expect(200);
|
|
201
|
-
|
|
202
|
-
expect(response.body).toEqual({value: "1"});
|
|
203
|
-
});
|
|
204
|
-
it("should return 0.1 when query is 0.1", async () => {
|
|
205
|
-
const response = await request.get(`${endpoint}?test=0.1`).expect(200);
|
|
206
|
-
|
|
207
|
-
expect(response.body).toEqual({value: "0.1"});
|
|
208
|
-
});
|
|
209
|
-
it("should return undefined when query is empty", async () => {
|
|
210
|
-
const response = await request.get(`${endpoint}?test=`).expect(200);
|
|
211
|
-
|
|
212
|
-
expect(response.body).toEqual({value: ""});
|
|
213
|
-
});
|
|
214
|
-
it("should return undefined when no query", async () => {
|
|
215
|
-
const response = await request.get(`${endpoint}`).expect(200);
|
|
216
|
-
|
|
217
|
-
expect(response.body).toEqual({});
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
describe("Scenario6: String[] value", () => {
|
|
221
|
-
const endpoint = "/rest/query-params/scenario-6";
|
|
222
|
-
it("should return 0 when query is 0", async () => {
|
|
223
|
-
const response = await request.get(`${endpoint}?test=0`).expect(200);
|
|
224
|
-
|
|
225
|
-
expect(response.body).toEqual({value: ["0"]});
|
|
226
|
-
});
|
|
227
|
-
it("should return 1 when query is 1", async () => {
|
|
228
|
-
const response = await request.get(`${endpoint}?test=1&test=2`).expect(200);
|
|
229
|
-
|
|
230
|
-
expect(response.body).toEqual({value: ["1", "2"]});
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import {Context, Controller, Get, Location, PlatformTest, Redirect} from "@tsed/common";
|
|
2
|
-
import SuperTest from "supertest";
|
|
3
|
-
import {PlatformTestingSdkOpts} from "../interfaces/index.js";
|
|
4
|
-
|
|
5
|
-
@Controller("/redirect")
|
|
6
|
-
class RedirectCtrl {
|
|
7
|
-
@Get("/scenario-1")
|
|
8
|
-
@Redirect("/test")
|
|
9
|
-
testScenario1() {
|
|
10
|
-
return "Hello";
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
@Get("/scenario-2")
|
|
14
|
-
@Redirect(301, "/test")
|
|
15
|
-
testScenario2() {
|
|
16
|
-
return "Hello";
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
@Get("/scenario-3")
|
|
20
|
-
@Redirect(301, "/test")
|
|
21
|
-
testScenario3(@Context() ctx: Context) {
|
|
22
|
-
ctx.response.redirect(302, "/another/path");
|
|
23
|
-
|
|
24
|
-
return "Hello";
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
@Get("/scenario-4")
|
|
28
|
-
@Redirect("back")
|
|
29
|
-
testScenario4(@Context() ctx: Context) {
|
|
30
|
-
return "Hello";
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
@Get("/scenario-5")
|
|
34
|
-
@Location("back")
|
|
35
|
-
testScenario5(@Context() ctx: Context) {
|
|
36
|
-
return "Hello";
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
@Get("/scenario-6")
|
|
40
|
-
@Location("/path/to").Status(301)
|
|
41
|
-
testScenario6(@Context() ctx: Context) {
|
|
42
|
-
return "Hello";
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
@Get("/scenario-7")
|
|
46
|
-
@Location("/path/to")
|
|
47
|
-
testScenario7(@Context() ctx: Context) {
|
|
48
|
-
ctx.response.location("/another/path");
|
|
49
|
-
return "Hello";
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function testRedirect(options: PlatformTestingSdkOpts) {
|
|
54
|
-
let request: SuperTest.Agent;
|
|
55
|
-
|
|
56
|
-
beforeAll(
|
|
57
|
-
PlatformTest.bootstrap(options.server, {
|
|
58
|
-
...options,
|
|
59
|
-
mount: {
|
|
60
|
-
"/rest": [RedirectCtrl]
|
|
61
|
-
}
|
|
62
|
-
})
|
|
63
|
-
);
|
|
64
|
-
beforeAll(() => {
|
|
65
|
-
request = SuperTest(PlatformTest.callback());
|
|
66
|
-
});
|
|
67
|
-
afterAll(PlatformTest.reset);
|
|
68
|
-
|
|
69
|
-
it("Scenario1: GET /rest/redirect/scenario-1", async () => {
|
|
70
|
-
const response = await request.get("/rest/redirect/scenario-1").expect(302);
|
|
71
|
-
|
|
72
|
-
expect(response.text).toEqual("Found. Redirecting to /test");
|
|
73
|
-
expect(response.header.location).toEqual("/test");
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it("Scenario1: HEAD /rest/redirect/scenario-1", async () => {
|
|
77
|
-
const response = await request.head("/rest/redirect/scenario-1").expect(302);
|
|
78
|
-
|
|
79
|
-
expect(response.text).toBeUndefined();
|
|
80
|
-
expect(response.header.location).toEqual("/test");
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it("Scenario2: GET /rest/redirect/scenario-2", async () => {
|
|
84
|
-
const response = await request.get("/rest/redirect/scenario-2").expect(301);
|
|
85
|
-
|
|
86
|
-
expect(response.text).toEqual("Moved Permanently. Redirecting to /test");
|
|
87
|
-
expect(response.header.location).toEqual("/test");
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it("Scenario3: GET /rest/redirect/scenario-3", async () => {
|
|
91
|
-
const response = await request.get("/rest/redirect/scenario-3").expect(302);
|
|
92
|
-
|
|
93
|
-
expect(response.header.location).toEqual("/another/path");
|
|
94
|
-
expect(response.text).toEqual("Found. Redirecting to /another/path");
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it("Scenario4: GET /rest/redirect/scenario-4 with referer", async () => {
|
|
98
|
-
const response = await request.get("/rest/redirect/scenario-4").set("Referrer", "https://referrer.com").expect(302);
|
|
99
|
-
|
|
100
|
-
expect(response.text).toEqual("Found. Redirecting to https://referrer.com");
|
|
101
|
-
expect(response.header.location).toEqual("https://referrer.com");
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it("Scenario5: GET /rest/redirect/scenario-5", async () => {
|
|
105
|
-
const response = await request.get("/rest/redirect/scenario-5").set("Referrer", "https://referrer.com").expect(200);
|
|
106
|
-
|
|
107
|
-
expect(response.text).toEqual("Hello");
|
|
108
|
-
expect(response.header.location).toEqual("https://referrer.com");
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("Scenario6: GET /rest/redirect/scenario-6", async () => {
|
|
112
|
-
const response = await request.get("/rest/redirect/scenario-6").set("Referrer", "https://referrer.com").expect(301);
|
|
113
|
-
|
|
114
|
-
expect(response.text).toEqual("Hello");
|
|
115
|
-
expect(response.header.location).toEqual("/path/to");
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("Scenario7: GET /rest/redirect/scenario-7", async () => {
|
|
119
|
-
const response = await request.get("/rest/redirect/scenario-7").set("Referrer", "https://referrer.com").expect(200);
|
|
120
|
-
|
|
121
|
-
expect(response.text).toEqual("Hello");
|
|
122
|
-
expect(response.header.location).toEqual("/another/path");
|
|
123
|
-
});
|
|
124
|
-
}
|