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