@tsed/platform-test-sdk 7.62.1 → 7.62.3
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/index.js +2 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/tests/exports.js +4 -2
- package/lib/cjs/tests/exports.js.map +1 -1
- package/lib/cjs/tests/testBodyParams.js +22 -1
- package/lib/cjs/tests/testBodyParams.js.map +1 -1
- package/lib/cjs/tests/testCache.js +13 -3
- package/lib/cjs/tests/testCache.js.map +1 -1
- package/lib/cjs/tests/testDeepQueryParams.js +144 -0
- package/lib/cjs/tests/testDeepQueryParams.js.map +1 -0
- package/lib/cjs/tests/testErrors.js +1 -1
- package/lib/cjs/tests/testErrors.js.map +1 -1
- package/lib/cjs/tests/testHeaderParams.js +1 -0
- package/lib/cjs/tests/testHeaderParams.js.map +1 -1
- package/lib/cjs/tests/testInheritanceController.js +68 -3
- package/lib/cjs/tests/testInheritanceController.js.map +1 -1
- package/lib/cjs/tests/testQueryParams.js +1 -114
- package/lib/cjs/tests/testQueryParams.js.map +1 -1
- package/lib/cjs/tests/testResponse.js +0 -38
- package/lib/cjs/tests/testResponse.js.map +1 -1
- package/lib/cjs/tests/testStream.js +67 -0
- package/lib/cjs/tests/testStream.js.map +1 -0
- package/lib/esm/index.js +2 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/tests/exports.js +4 -2
- package/lib/esm/tests/exports.js.map +1 -1
- package/lib/esm/tests/testBodyParams.js +23 -2
- package/lib/esm/tests/testBodyParams.js.map +1 -1
- package/lib/esm/tests/testCache.js +13 -3
- package/lib/esm/tests/testCache.js.map +1 -1
- package/lib/esm/tests/testDeepQueryParams.js +140 -0
- package/lib/esm/tests/testDeepQueryParams.js.map +1 -0
- package/lib/esm/tests/testErrors.js +1 -1
- package/lib/esm/tests/testErrors.js.map +1 -1
- package/lib/esm/tests/testHeaderParams.js +1 -0
- package/lib/esm/tests/testHeaderParams.js.map +1 -1
- package/lib/esm/tests/testInheritanceController.js +67 -3
- package/lib/esm/tests/testInheritanceController.js.map +1 -1
- package/lib/esm/tests/testQueryParams.js +2 -115
- package/lib/esm/tests/testQueryParams.js.map +1 -1
- package/lib/esm/tests/testResponse.js +1 -39
- package/lib/esm/tests/testResponse.js.map +1 -1
- package/lib/esm/tests/testStream.js +63 -0
- package/lib/esm/tests/testStream.js.map +1 -0
- package/lib/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/index.d.ts +2 -1
- package/lib/types/tests/testDeepQueryParams.d.ts +3 -0
- package/lib/types/tests/testInheritanceController.d.ts +14 -0
- package/lib/types/tests/testStream.d.ts +2 -0
- package/package.json +13 -13
- package/src/index.ts +2 -1
- package/src/tests/exports.ts +4 -2
- package/src/tests/testBodyParams.ts +30 -7
- package/src/tests/testCache.ts +15 -6
- package/src/tests/testDeepQueryParams.ts +119 -0
- package/src/tests/testErrors.ts +1 -1
- package/src/tests/testHeaderParams.ts +1 -0
- package/src/tests/testInheritanceController.ts +47 -3
- package/src/tests/testQueryParams.ts +2 -93
- package/src/tests/testResponse.ts +2 -35
- package/src/tests/testStream.ts +60 -0
- package/lib/cjs/tests/testCtrlInheritance.js +0 -161
- package/lib/cjs/tests/testCtrlInheritance.js.map +0 -1
- package/lib/esm/tests/testCtrlInheritance.js +0 -156
- package/lib/esm/tests/testCtrlInheritance.js.map +0 -1
- package/lib/types/tests/testCtrlInheritance.d.ts +0 -18
- package/src/tests/testCtrlInheritance.ts +0 -140
package/lib/types/index.d.ts
CHANGED
|
@@ -14,8 +14,8 @@ export * from "./tests/testBodyParams";
|
|
|
14
14
|
export * from "./tests/testCache";
|
|
15
15
|
export * from "./tests/testChildrenControllers";
|
|
16
16
|
export * from "./tests/testCookies";
|
|
17
|
-
export * from "./tests/testCtrlInheritance";
|
|
18
17
|
export * from "./tests/testCustom404";
|
|
18
|
+
export * from "./tests/testDeepQueryParams";
|
|
19
19
|
export * from "./tests/testErrors";
|
|
20
20
|
export * from "./tests/testHandlers";
|
|
21
21
|
export * from "./tests/testHeaderParams";
|
|
@@ -35,4 +35,5 @@ export * from "./tests/testRouting";
|
|
|
35
35
|
export * from "./tests/testScopeRequest";
|
|
36
36
|
export * from "./tests/testSession";
|
|
37
37
|
export * from "./tests/testStatics";
|
|
38
|
+
export * from "./tests/testStream";
|
|
38
39
|
export * from "./tests/testView";
|
|
@@ -24,5 +24,19 @@ declare abstract class AttachmentController {
|
|
|
24
24
|
export declare class FindingsController extends AttachmentController {
|
|
25
25
|
get(): string;
|
|
26
26
|
}
|
|
27
|
+
export declare abstract class TestBaseController {
|
|
28
|
+
scenario3(search: string): {
|
|
29
|
+
search: string;
|
|
30
|
+
};
|
|
31
|
+
scenario5(q: string): {
|
|
32
|
+
data: string;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export declare class TestChildController extends TestBaseController {
|
|
36
|
+
scenario4(id: string): any;
|
|
37
|
+
scenario5(s: string): {
|
|
38
|
+
data: string;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
27
41
|
export declare function testInheritanceController(options: PlatformTestingSdkOpts): void;
|
|
28
42
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-test-sdk",
|
|
3
|
-
"version": "7.62.
|
|
3
|
+
"version": "7.62.3",
|
|
4
4
|
"description": "Package to test platform adapter integration with Ts.ED",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -25,24 +25,24 @@
|
|
|
25
25
|
"Adapter"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@tsed/ajv": "7.62.
|
|
29
|
-
"@tsed/common": "7.62.
|
|
30
|
-
"@tsed/core": "7.62.
|
|
31
|
-
"@tsed/di": "7.62.
|
|
32
|
-
"@tsed/json-mapper": "7.62.
|
|
28
|
+
"@tsed/ajv": "7.62.3",
|
|
29
|
+
"@tsed/common": "7.62.3",
|
|
30
|
+
"@tsed/core": "7.62.3",
|
|
31
|
+
"@tsed/di": "7.62.3",
|
|
32
|
+
"@tsed/json-mapper": "7.62.3",
|
|
33
33
|
"@tsed/logger": "6.6.3",
|
|
34
|
-
"@tsed/platform-cache": "7.62.
|
|
35
|
-
"@tsed/platform-params": "7.62.
|
|
36
|
-
"@tsed/platform-router": "7.62.
|
|
37
|
-
"@tsed/platform-views": "7.62.
|
|
38
|
-
"@tsed/schema": "7.62.
|
|
39
|
-
"@tsed/swagger": "7.62.
|
|
34
|
+
"@tsed/platform-cache": "7.62.3",
|
|
35
|
+
"@tsed/platform-params": "7.62.3",
|
|
36
|
+
"@tsed/platform-router": "7.62.3",
|
|
37
|
+
"@tsed/platform-views": "7.62.3",
|
|
38
|
+
"@tsed/schema": "7.62.3",
|
|
39
|
+
"@tsed/swagger": "7.62.3",
|
|
40
40
|
"ajv": "^8.12.0",
|
|
41
41
|
"axios": "1.6.7",
|
|
42
42
|
"read-pkg-up": "7.0.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@tsed/typescript": "7.62.
|
|
45
|
+
"@tsed/typescript": "7.62.3",
|
|
46
46
|
"barrelsby": "^2.8.1",
|
|
47
47
|
"eslint": "^8.12.0",
|
|
48
48
|
"jest": "^29.2.0"
|
package/src/index.ts
CHANGED
|
@@ -15,8 +15,8 @@ export * from "./tests/testBodyParams";
|
|
|
15
15
|
export * from "./tests/testCache";
|
|
16
16
|
export * from "./tests/testChildrenControllers";
|
|
17
17
|
export * from "./tests/testCookies";
|
|
18
|
-
export * from "./tests/testCtrlInheritance";
|
|
19
18
|
export * from "./tests/testCustom404";
|
|
19
|
+
export * from "./tests/testDeepQueryParams";
|
|
20
20
|
export * from "./tests/testErrors";
|
|
21
21
|
export * from "./tests/testHandlers";
|
|
22
22
|
export * from "./tests/testHeaderParams";
|
|
@@ -36,4 +36,5 @@ export * from "./tests/testRouting";
|
|
|
36
36
|
export * from "./tests/testScopeRequest";
|
|
37
37
|
export * from "./tests/testSession";
|
|
38
38
|
export * from "./tests/testStatics";
|
|
39
|
+
export * from "./tests/testStream";
|
|
39
40
|
export * from "./tests/testView";
|
package/src/tests/exports.ts
CHANGED
|
@@ -4,8 +4,8 @@ import {testAuth} from "./testAuth";
|
|
|
4
4
|
import {testBodyParams} from "./testBodyParams";
|
|
5
5
|
import {testChildrenControllers} from "./testChildrenControllers";
|
|
6
6
|
import {testCookies} from "./testCookies";
|
|
7
|
-
import {testCtrlInheritance} from "./testCtrlInheritance";
|
|
8
7
|
import {testCustom404} from "./testCustom404";
|
|
8
|
+
import {testDeepQueryParams} from "./testDeepQueryParams";
|
|
9
9
|
import {testErrors} from "./testErrors";
|
|
10
10
|
import {testHandlers} from "./testHandlers";
|
|
11
11
|
import {testHeaderParams} from "./testHeaderParams";
|
|
@@ -25,6 +25,7 @@ import {testRouting} from "./testRouting";
|
|
|
25
25
|
import {testScopeRequest} from "./testScopeRequest";
|
|
26
26
|
import {testSession} from "./testSession";
|
|
27
27
|
import {testStatics} from "./testStatics";
|
|
28
|
+
import {testStream} from "./testStream";
|
|
28
29
|
import {testView} from "./testView";
|
|
29
30
|
import {testCache} from "./testCache";
|
|
30
31
|
|
|
@@ -43,6 +44,7 @@ specsContainer.set("redirect", testRedirect);
|
|
|
43
44
|
specsContainer.set("view", testView);
|
|
44
45
|
specsContainer.set("errors", testErrors);
|
|
45
46
|
specsContainer.set("response", testResponse);
|
|
47
|
+
specsContainer.set("stream", testStream);
|
|
46
48
|
specsContainer.set("responseFilter", testResponseFilter);
|
|
47
49
|
specsContainer.set("custom404", testCustom404);
|
|
48
50
|
specsContainer.set("statics", testStatics);
|
|
@@ -55,13 +57,13 @@ specsContainer.set("headerParams", testHeaderParams);
|
|
|
55
57
|
specsContainer.set("bodyParams", testBodyParams);
|
|
56
58
|
specsContainer.set("pathParams", testPathParams);
|
|
57
59
|
specsContainer.set("queryParams", testQueryParams);
|
|
60
|
+
specsContainer.set("deepQueryParams", testDeepQueryParams);
|
|
58
61
|
specsContainer.set("locals", testLocals);
|
|
59
62
|
specsContainer.set("multer", testMulter);
|
|
60
63
|
|
|
61
64
|
// ROUTING
|
|
62
65
|
specsContainer.set("scopeRequest", testScopeRequest);
|
|
63
66
|
specsContainer.set("routing", testRouting);
|
|
64
|
-
specsContainer.set("inheritance", testCtrlInheritance);
|
|
65
67
|
|
|
66
68
|
// CODE ORGANIZATION
|
|
67
69
|
specsContainer.set("childrenControllers", testChildrenControllers);
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import "@tsed/ajv";
|
|
2
2
|
import {BodyParams, Context, Controller, HeaderParams, PlatformTest, RawBodyParams} from "@tsed/common";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
Post,
|
|
5
|
+
Default,
|
|
6
|
+
Description,
|
|
7
|
+
GenericOf,
|
|
8
|
+
Generics,
|
|
9
|
+
Maximum,
|
|
10
|
+
Minimum,
|
|
11
|
+
Nullable,
|
|
12
|
+
Property,
|
|
13
|
+
Required,
|
|
14
|
+
Status,
|
|
15
|
+
Consumes
|
|
16
|
+
} from "@tsed/schema";
|
|
4
17
|
import SuperTest from "supertest";
|
|
5
18
|
import {PlatformTestingSdkOpts} from "../interfaces";
|
|
6
19
|
|
|
@@ -134,6 +147,12 @@ class TestBodyParamsCtrl {
|
|
|
134
147
|
) {
|
|
135
148
|
return {param1, param2};
|
|
136
149
|
}
|
|
150
|
+
|
|
151
|
+
@Post("/scenario-11")
|
|
152
|
+
@Consumes("application/x-www-form-urlencoded")
|
|
153
|
+
testScenario11(@Required() @BodyParams("client_id") client_id: string) {
|
|
154
|
+
return {client_id};
|
|
155
|
+
}
|
|
137
156
|
}
|
|
138
157
|
|
|
139
158
|
export function testBodyParams(options: PlatformTestingSdkOpts) {
|
|
@@ -201,7 +220,7 @@ export function testBodyParams(options: PlatformTestingSdkOpts) {
|
|
|
201
220
|
expect(response.body).toEqual({value: ["value"]});
|
|
202
221
|
});
|
|
203
222
|
it("should return an empty array (1)", async () => {
|
|
204
|
-
const response = await request.post("/rest/body-params/scenario-3").send().expect(200);
|
|
223
|
+
const response = await request.post("/rest/body-params/scenario-3").send({}).expect(200);
|
|
205
224
|
|
|
206
225
|
expect(response.body).toEqual({value: [{}]});
|
|
207
226
|
});
|
|
@@ -235,7 +254,6 @@ export function testBodyParams(options: PlatformTestingSdkOpts) {
|
|
|
235
254
|
});
|
|
236
255
|
});
|
|
237
256
|
});
|
|
238
|
-
|
|
239
257
|
describe("Scenario4b: with expression required String", () => {
|
|
240
258
|
it("should return value", async () => {
|
|
241
259
|
const response = await request.post("/rest/body-params/scenario-4b").send({test: "value"}).expect(200);
|
|
@@ -321,7 +339,6 @@ export function testBodyParams(options: PlatformTestingSdkOpts) {
|
|
|
321
339
|
});
|
|
322
340
|
});
|
|
323
341
|
});
|
|
324
|
-
|
|
325
342
|
describe("Scenario6: Enum", () => {
|
|
326
343
|
it("should return value", async () => {
|
|
327
344
|
const response = await request.post("/rest/body-params/scenario-6").send({
|
|
@@ -333,7 +350,6 @@ export function testBodyParams(options: PlatformTestingSdkOpts) {
|
|
|
333
350
|
});
|
|
334
351
|
});
|
|
335
352
|
});
|
|
336
|
-
|
|
337
353
|
describe("Scenario7: payload with Null", () => {
|
|
338
354
|
it("should return value", async () => {
|
|
339
355
|
const response = await request.post("/rest/body-params/scenario-7").send({
|
|
@@ -345,7 +361,6 @@ export function testBodyParams(options: PlatformTestingSdkOpts) {
|
|
|
345
361
|
});
|
|
346
362
|
});
|
|
347
363
|
});
|
|
348
|
-
|
|
349
364
|
describe("Scenario8: payload with props to null", () => {
|
|
350
365
|
it("should return value with null value", async () => {
|
|
351
366
|
const response = await request.post("/rest/body-params/scenario-8").send({
|
|
@@ -365,7 +380,6 @@ export function testBodyParams(options: PlatformTestingSdkOpts) {
|
|
|
365
380
|
});
|
|
366
381
|
});
|
|
367
382
|
});
|
|
368
|
-
|
|
369
383
|
describe("Scenario9: payload with Generics", () => {
|
|
370
384
|
it("should return value", async () => {
|
|
371
385
|
const response = await request
|
|
@@ -452,4 +466,13 @@ export function testBodyParams(options: PlatformTestingSdkOpts) {
|
|
|
452
466
|
.expect(200);
|
|
453
467
|
});
|
|
454
468
|
});
|
|
469
|
+
describe("Scenario11: validate application/x-www-form-urlencoded body", () => {
|
|
470
|
+
it("should validate the body params", async () => {
|
|
471
|
+
await request
|
|
472
|
+
.post("/rest/body-params/scenario-11")
|
|
473
|
+
.set("Content-Type", "application/x-www-form-urlencoded")
|
|
474
|
+
.send("client_id=id&grant_type=grant")
|
|
475
|
+
.expect(200);
|
|
476
|
+
});
|
|
477
|
+
});
|
|
455
478
|
}
|
package/src/tests/testCache.ts
CHANGED
|
@@ -117,12 +117,21 @@ export function testCache(options: PlatformTestingSdkOpts) {
|
|
|
117
117
|
const platformCache = PlatformTest.get<PlatformCache>(PlatformCache);
|
|
118
118
|
|
|
119
119
|
const response = await request.get("/rest/caches/scenario-1").expect(200);
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
120
|
+
console.log(response.headers);
|
|
121
|
+
if (response.headers["etag"]) {
|
|
122
|
+
// platform koa doesn't support Etag
|
|
123
|
+
await request
|
|
124
|
+
.get("/rest/caches/scenario-1")
|
|
125
|
+
.set("if-none-match", response.headers["etag"] || "")
|
|
126
|
+
.expect(304);
|
|
127
|
+
|
|
128
|
+
await platformCache.reset();
|
|
129
|
+
|
|
130
|
+
await request
|
|
131
|
+
.get("/rest/caches/scenario-1")
|
|
132
|
+
.set("if-none-match", response.headers["etag"] || "")
|
|
133
|
+
.expect(200);
|
|
134
|
+
}
|
|
126
135
|
});
|
|
127
136
|
|
|
128
137
|
it("should return fresh data if cache-control is set to no-cache", async () => {
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import "@tsed/ajv";
|
|
2
|
+
import {Controller, Get, PlatformTest, QueryParams} from "@tsed/common";
|
|
3
|
+
import {Default, GenericOf, Generics, Maximum, Minimum, Property, Required} from "@tsed/schema";
|
|
4
|
+
import SuperTest from "supertest";
|
|
5
|
+
import {PlatformTestingSdkOpts} from "../interfaces";
|
|
6
|
+
|
|
7
|
+
class FindQuery {
|
|
8
|
+
@Property()
|
|
9
|
+
a?: number;
|
|
10
|
+
|
|
11
|
+
@Property()
|
|
12
|
+
b?: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@Generics("T")
|
|
16
|
+
class PaginationQuery<T> {
|
|
17
|
+
// things about pagination
|
|
18
|
+
@Minimum(0)
|
|
19
|
+
@Default(0)
|
|
20
|
+
offset?: number;
|
|
21
|
+
|
|
22
|
+
@Minimum(1)
|
|
23
|
+
@Maximum(1000)
|
|
24
|
+
@Default(50)
|
|
25
|
+
limit?: number;
|
|
26
|
+
|
|
27
|
+
@Property("T")
|
|
28
|
+
where?: T;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@Controller("/deep-query-params")
|
|
32
|
+
class TestDeepQueryParamsCtrl {
|
|
33
|
+
@Get("/scenario-1")
|
|
34
|
+
testScenario6(@QueryParams() @GenericOf(FindQuery) q: PaginationQuery<FindQuery>, @QueryParams() qs: any) {
|
|
35
|
+
return {q};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Get("/scenario-2")
|
|
39
|
+
testScenario7(@QueryParams("q") @GenericOf(FindQuery) q: PaginationQuery<FindQuery>) {
|
|
40
|
+
return {q};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function testDeepQueryParams(options: PlatformTestingSdkOpts) {
|
|
45
|
+
let request: SuperTest.Agent;
|
|
46
|
+
|
|
47
|
+
beforeAll(
|
|
48
|
+
PlatformTest.bootstrap(options.server, {
|
|
49
|
+
...options,
|
|
50
|
+
ajv: {
|
|
51
|
+
verbose: false
|
|
52
|
+
},
|
|
53
|
+
mount: {
|
|
54
|
+
"/rest": [TestDeepQueryParamsCtrl]
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
);
|
|
58
|
+
beforeAll(() => {
|
|
59
|
+
request = SuperTest(PlatformTest.callback());
|
|
60
|
+
});
|
|
61
|
+
afterAll(PlatformTest.reset);
|
|
62
|
+
describe("Scenario1: DeepObject", () => {
|
|
63
|
+
const endpoint = "/rest/deep-query-params/scenario-1";
|
|
64
|
+
it("should return 0 when query is 0", async () => {
|
|
65
|
+
const response = await request.get(`${endpoint}?offset=0&limit=10&where[a]=0&where[b]=1`).expect(200);
|
|
66
|
+
|
|
67
|
+
expect(response.body).toEqual({
|
|
68
|
+
q: {
|
|
69
|
+
limit: 10,
|
|
70
|
+
offset: 0,
|
|
71
|
+
where: {
|
|
72
|
+
a: 0,
|
|
73
|
+
b: 1
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
describe("Scenario2: DeepObject", () => {
|
|
80
|
+
const endpoint = "/rest/deep-query-params/scenario-2";
|
|
81
|
+
it("should return the query value", async () => {
|
|
82
|
+
const response = await request.get(`${endpoint}?q[offset]=0&q[limit]=10&q[where][a]=0&q[where][b]=1`).expect(200);
|
|
83
|
+
|
|
84
|
+
expect(response.body).toEqual({
|
|
85
|
+
q: {
|
|
86
|
+
limit: 10,
|
|
87
|
+
offset: 0,
|
|
88
|
+
where: {
|
|
89
|
+
a: 0,
|
|
90
|
+
b: 1
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
it("should throw a bad request", async () => {
|
|
96
|
+
const response = await request.get(`${endpoint}?q[offset]=0&q[limit]=10&q[where][a]=ca&q[where][b]=1`).expect(400);
|
|
97
|
+
|
|
98
|
+
expect(response.body).toEqual({
|
|
99
|
+
errors: [
|
|
100
|
+
{
|
|
101
|
+
data: "ca",
|
|
102
|
+
dataPath: ".where.a",
|
|
103
|
+
instancePath: "/where/a",
|
|
104
|
+
keyword: "type",
|
|
105
|
+
message: "must be number",
|
|
106
|
+
modelName: "PaginationQuery",
|
|
107
|
+
params: {
|
|
108
|
+
type: "number"
|
|
109
|
+
},
|
|
110
|
+
schemaPath: "#/properties/where/properties/a/type"
|
|
111
|
+
}
|
|
112
|
+
],
|
|
113
|
+
message: 'Bad request on parameter "request.query.q".\nPaginationQuery.where.a must be number. Given value: "ca"',
|
|
114
|
+
name: "AJV_VALIDATION_ERROR",
|
|
115
|
+
status: 400
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
}
|
package/src/tests/testErrors.ts
CHANGED
|
@@ -167,7 +167,7 @@ export function testErrors(options: PlatformTestingSdkOpts) {
|
|
|
167
167
|
});
|
|
168
168
|
|
|
169
169
|
it("Scenario 5: POST /rest/errors/scenario-5", async () => {
|
|
170
|
-
const response: any = await request.post("/rest/errors/scenario-5").expect(400);
|
|
170
|
+
const response: any = await request.post("/rest/errors/scenario-5").send({}).expect(400);
|
|
171
171
|
|
|
172
172
|
expect(response.body).toEqual({
|
|
173
173
|
errors: [
|
|
@@ -81,6 +81,7 @@ export function testHeaderParams(options: PlatformTestingSdkOpts) {
|
|
|
81
81
|
it("should return a response with the extracted contentType from the request headers", async () => {
|
|
82
82
|
const response = await request
|
|
83
83
|
.post("/rest/header-params/scenario-2")
|
|
84
|
+
.send({})
|
|
84
85
|
.set({
|
|
85
86
|
"Content-Type": "application/json"
|
|
86
87
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {BodyParams, Controller, Get, Middleware, PathParams, PlatformTest, Post, UseAuth} from "@tsed/common";
|
|
1
|
+
import {BodyParams, Controller, Get, Middleware, PathParams, PlatformTest, Post, QueryParams, UseAuth} from "@tsed/common";
|
|
2
2
|
import {NotFound} from "@tsed/exceptions";
|
|
3
3
|
import {Description, MaxLength, MinLength, Property, Returns, Summary} from "@tsed/schema";
|
|
4
4
|
import SuperTest from "supertest";
|
|
@@ -91,6 +91,33 @@ export class FindingsController extends AttachmentController {
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
export abstract class TestBaseController {
|
|
95
|
+
@Get("/")
|
|
96
|
+
scenario3(@QueryParams("search") search: string) {
|
|
97
|
+
return {
|
|
98
|
+
search
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@Get("/override")
|
|
103
|
+
scenario5(@QueryParams("q") q: string) {
|
|
104
|
+
return {data: q};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
@Controller("/test")
|
|
109
|
+
export class TestChildController extends TestBaseController {
|
|
110
|
+
@Get("/:id")
|
|
111
|
+
scenario4(@PathParams("id") id: string): any {
|
|
112
|
+
return {id};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
@Get("/override")
|
|
116
|
+
scenario5(@QueryParams("s") s: string) {
|
|
117
|
+
return {data: s};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
94
121
|
export function testInheritanceController(options: PlatformTestingSdkOpts) {
|
|
95
122
|
let request: SuperTest.Agent;
|
|
96
123
|
|
|
@@ -98,7 +125,7 @@ export function testInheritanceController(options: PlatformTestingSdkOpts) {
|
|
|
98
125
|
PlatformTest.bootstrap(options.server, {
|
|
99
126
|
...options,
|
|
100
127
|
mount: {
|
|
101
|
-
"/rest": [ResourcesCtrl, FindingsController]
|
|
128
|
+
"/rest": [ResourcesCtrl, FindingsController, TestChildController]
|
|
102
129
|
}
|
|
103
130
|
})
|
|
104
131
|
);
|
|
@@ -147,10 +174,27 @@ export function testInheritanceController(options: PlatformTestingSdkOpts) {
|
|
|
147
174
|
expect(text).toEqual("All attachments of 1");
|
|
148
175
|
});
|
|
149
176
|
|
|
150
|
-
it("should call /rest/findings
|
|
177
|
+
it("should call /rest/findings", async () => {
|
|
151
178
|
const {text} = await request.get("/rest/findings").expect(200);
|
|
152
179
|
|
|
153
180
|
expect(text).toEqual("hello Finding");
|
|
154
181
|
});
|
|
155
182
|
});
|
|
183
|
+
|
|
184
|
+
it("Scenario3: should call inherited method", async () => {
|
|
185
|
+
const {body} = await request.get("/rest/test?search=test").expect(200);
|
|
186
|
+
expect(body).toEqual({
|
|
187
|
+
search: "test"
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("Scenario4: should the Child method", async () => {
|
|
192
|
+
const {body} = await request.get("/rest/test/1").expect(200);
|
|
193
|
+
expect(body).toEqual({id: "1"});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("Scenario5: should call the Child method and not the base method", async () => {
|
|
197
|
+
const {body} = await request.get("/rest/test/1").expect(200);
|
|
198
|
+
expect(body).toEqual({id: "1"});
|
|
199
|
+
});
|
|
156
200
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "@tsed/ajv";
|
|
2
2
|
import {Controller, Get, PlatformTest, QueryParams} from "@tsed/common";
|
|
3
|
-
import {
|
|
3
|
+
import {Maximum, Minimum, Required} from "@tsed/schema";
|
|
4
4
|
import SuperTest from "supertest";
|
|
5
5
|
import {PlatformTestingSdkOpts} from "../interfaces";
|
|
6
6
|
|
|
@@ -11,30 +11,6 @@ export class RandomStringModel {
|
|
|
11
11
|
length: number;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
class FindQuery {
|
|
15
|
-
@Property()
|
|
16
|
-
a?: number;
|
|
17
|
-
|
|
18
|
-
@Property()
|
|
19
|
-
b?: number;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
@Generics("T")
|
|
23
|
-
class PaginationQuery<T> {
|
|
24
|
-
// things about pagination
|
|
25
|
-
@Minimum(0)
|
|
26
|
-
@Default(0)
|
|
27
|
-
offset?: number;
|
|
28
|
-
|
|
29
|
-
@Minimum(1)
|
|
30
|
-
@Maximum(1000)
|
|
31
|
-
@Default(50)
|
|
32
|
-
limit?: number;
|
|
33
|
-
|
|
34
|
-
@Property("T")
|
|
35
|
-
where?: T;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
14
|
@Controller("/query-params")
|
|
39
15
|
class TestQueryParamsCtrl {
|
|
40
16
|
@Get("/scenario-1")
|
|
@@ -63,16 +39,6 @@ class TestQueryParamsCtrl {
|
|
|
63
39
|
}
|
|
64
40
|
|
|
65
41
|
@Get("/scenario-6")
|
|
66
|
-
testScenario6(@QueryParams() @GenericOf(FindQuery) q: PaginationQuery<FindQuery>, @QueryParams() qs: any) {
|
|
67
|
-
return {q};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
@Get("/scenario-7")
|
|
71
|
-
testScenario7(@QueryParams("q") @GenericOf(FindQuery) q: PaginationQuery<FindQuery>) {
|
|
72
|
-
return {q};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
@Get("/scenario-8")
|
|
76
42
|
testScenario8(@QueryParams("test", String) value: string[]): any {
|
|
77
43
|
return {value};
|
|
78
44
|
}
|
|
@@ -250,65 +216,8 @@ export function testQueryParams(options: PlatformTestingSdkOpts) {
|
|
|
250
216
|
expect(response.body).toEqual({});
|
|
251
217
|
});
|
|
252
218
|
});
|
|
253
|
-
describe("Scenario6:
|
|
219
|
+
describe("Scenario6: String[] value", () => {
|
|
254
220
|
const endpoint = "/rest/query-params/scenario-6";
|
|
255
|
-
it("should return 0 when query is 0", async () => {
|
|
256
|
-
const response = await request.get(`${endpoint}?offset=0&limit=10&where[a]=0&where[b]=1`).expect(200);
|
|
257
|
-
|
|
258
|
-
expect(response.body).toEqual({
|
|
259
|
-
q: {
|
|
260
|
-
limit: 10,
|
|
261
|
-
offset: 0,
|
|
262
|
-
where: {
|
|
263
|
-
a: 0,
|
|
264
|
-
b: 1
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
});
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
describe("Scenario7: DeepObject", () => {
|
|
271
|
-
const endpoint = "/rest/query-params/scenario-7";
|
|
272
|
-
it("should return the query value", async () => {
|
|
273
|
-
const response = await request.get(`${endpoint}?q[offset]=0&q[limit]=10&q[where][a]=0&q[where][b]=1`).expect(200);
|
|
274
|
-
|
|
275
|
-
expect(response.body).toEqual({
|
|
276
|
-
q: {
|
|
277
|
-
limit: 10,
|
|
278
|
-
offset: 0,
|
|
279
|
-
where: {
|
|
280
|
-
a: 0,
|
|
281
|
-
b: 1
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
});
|
|
286
|
-
it("should throw a bad request", async () => {
|
|
287
|
-
const response = await request.get(`${endpoint}?q[offset]=0&q[limit]=10&q[where][a]=ca&q[where][b]=1`).expect(400);
|
|
288
|
-
|
|
289
|
-
expect(response.body).toEqual({
|
|
290
|
-
errors: [
|
|
291
|
-
{
|
|
292
|
-
data: "ca",
|
|
293
|
-
dataPath: ".where.a",
|
|
294
|
-
instancePath: "/where/a",
|
|
295
|
-
keyword: "type",
|
|
296
|
-
message: "must be number",
|
|
297
|
-
modelName: "PaginationQuery",
|
|
298
|
-
params: {
|
|
299
|
-
type: "number"
|
|
300
|
-
},
|
|
301
|
-
schemaPath: "#/properties/where/properties/a/type"
|
|
302
|
-
}
|
|
303
|
-
],
|
|
304
|
-
message: 'Bad request on parameter "request.query.q".\nPaginationQuery.where.a must be number. Given value: "ca"',
|
|
305
|
-
name: "AJV_VALIDATION_ERROR",
|
|
306
|
-
status: 400
|
|
307
|
-
});
|
|
308
|
-
});
|
|
309
|
-
});
|
|
310
|
-
describe("Scenario8: String[] value", () => {
|
|
311
|
-
const endpoint = "/rest/query-params/scenario-8";
|
|
312
221
|
it("should return 0 when query is 0", async () => {
|
|
313
222
|
const response = await request.get(`${endpoint}?test=0`).expect(200);
|
|
314
223
|
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import {Context, Controller, Get, getContext, PathParams, PlatformResponse, PlatformTest, Post, Res} from "@tsed/common";
|
|
2
|
-
import {CollectionOf,
|
|
2
|
+
import {CollectionOf, Enum, ForwardGroups, Groups, Ignore, Name, Property, Required, Returns, Status} from "@tsed/schema";
|
|
3
3
|
import axios from "axios";
|
|
4
|
-
import filedirname from "filedirname";
|
|
5
|
-
import {createReadStream} from "fs";
|
|
6
|
-
import {join} from "path";
|
|
7
4
|
import {of} from "rxjs";
|
|
8
5
|
import {agent, SuperAgentStatic} from "superagent";
|
|
9
6
|
import SuperTest from "supertest";
|
|
10
7
|
import {PlatformTestingSdkOpts} from "../interfaces";
|
|
8
|
+
|
|
11
9
|
// FIXME remove when esm is ready
|
|
12
|
-
const [, rootDir] = filedirname();
|
|
13
10
|
|
|
14
11
|
class Base {
|
|
15
12
|
@Ignore()
|
|
@@ -131,18 +128,6 @@ class TestResponseParamsCtrl {
|
|
|
131
128
|
return Promise.resolve(of({id: 1}));
|
|
132
129
|
}
|
|
133
130
|
|
|
134
|
-
@Get("/scenario7")
|
|
135
|
-
@ContentType("application/json")
|
|
136
|
-
testScenario7Stream() {
|
|
137
|
-
return createReadStream(join(rootDir, "../data/response.data.json"));
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
@Get("/scenario7b")
|
|
141
|
-
@ContentType("application/json")
|
|
142
|
-
testScenario7bStream() {
|
|
143
|
-
return Promise.resolve(createReadStream(join(rootDir, "../data/response.data.json")));
|
|
144
|
-
}
|
|
145
|
-
|
|
146
131
|
@Get("/scenario9/static")
|
|
147
132
|
public testScenario9Get(): string {
|
|
148
133
|
return "value";
|
|
@@ -338,24 +323,6 @@ export function testResponse(options: PlatformTestingSdkOpts) {
|
|
|
338
323
|
});
|
|
339
324
|
});
|
|
340
325
|
|
|
341
|
-
describe("Scenario7: when endpoint return a stream", () => {
|
|
342
|
-
describe("GET /rest/response/scenario7", () => {
|
|
343
|
-
it("should return a body", async () => {
|
|
344
|
-
const response = await request.get("/rest/response/scenario7");
|
|
345
|
-
|
|
346
|
-
expect(response.body).toEqual({id: "1"});
|
|
347
|
-
});
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
describe("GET /rest/response/scenario7b", () => {
|
|
351
|
-
it("should return a body", async () => {
|
|
352
|
-
const response = await request.get("/rest/response/scenario7b");
|
|
353
|
-
|
|
354
|
-
expect(response.body).toEqual({id: "1"});
|
|
355
|
-
});
|
|
356
|
-
});
|
|
357
|
-
});
|
|
358
|
-
|
|
359
326
|
describe("Scenario9: routes without parameters must be defined first", () => {
|
|
360
327
|
describe("GET /rest/response/scenario9/static", () => {
|
|
361
328
|
it("should return the test", async () => {
|