@deepkit/http 1.0.1-alpha.71 → 1.0.1-alpha.72
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/dist/cjs/src/decorator.d.ts +8 -6
- package/dist/cjs/src/decorator.js +49 -12
- package/dist/cjs/src/decorator.js.map +1 -1
- package/dist/cjs/src/filter.d.ts +3 -3
- package/dist/cjs/src/filter.js +3 -3
- package/dist/cjs/src/filter.js.map +1 -1
- package/dist/cjs/src/http.d.ts +49 -11
- package/dist/cjs/src/http.js +129 -38
- package/dist/cjs/src/http.js.map +1 -1
- package/dist/cjs/src/kernel.d.ts +3 -3
- package/dist/cjs/src/kernel.js +1 -1
- package/dist/cjs/src/kernel.js.map +1 -1
- package/dist/cjs/src/model.d.ts +11 -3
- package/dist/cjs/src/model.js +58 -26
- package/dist/cjs/src/model.js.map +1 -1
- package/dist/cjs/src/module.js +5 -3
- package/dist/cjs/src/module.js.map +1 -1
- package/dist/cjs/src/router.d.ts +84 -11
- package/dist/cjs/src/router.js +280 -94
- package/dist/cjs/src/router.js.map +1 -1
- package/dist/cjs/src/static-serving.js +15 -8
- package/dist/cjs/src/static-serving.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/src/decorator.d.ts +8 -6
- package/dist/esm/src/decorator.js +47 -11
- package/dist/esm/src/decorator.js.map +1 -1
- package/dist/esm/src/filter.d.ts +3 -3
- package/dist/esm/src/filter.js +4 -4
- package/dist/esm/src/filter.js.map +1 -1
- package/dist/esm/src/http.d.ts +49 -11
- package/dist/esm/src/http.js +102 -24
- package/dist/esm/src/http.js.map +1 -1
- package/dist/esm/src/kernel.d.ts +3 -3
- package/dist/esm/src/kernel.js +2 -2
- package/dist/esm/src/kernel.js.map +1 -1
- package/dist/esm/src/model.d.ts +11 -3
- package/dist/esm/src/model.js +47 -15
- package/dist/esm/src/model.js.map +1 -1
- package/dist/esm/src/module.js +5 -3
- package/dist/esm/src/module.js.map +1 -1
- package/dist/esm/src/router.d.ts +84 -11
- package/dist/esm/src/router.js +278 -94
- package/dist/esm/src/router.js.map +1 -1
- package/dist/esm/src/static-serving.js +16 -9
- package/dist/esm/src/static-serving.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +17 -14
- package/src/decorator.ts +9 -6
- package/src/filter.ts +4 -4
- package/src/http.ts +88 -15
- package/src/kernel.ts +2 -2
- package/src/model.ts +35 -6
- package/src/module.ts +5 -3
- package/src/router.ts +286 -73
- package/src/static-serving.ts +6 -3
- package/coverage/clover.xml +0 -1086
- package/coverage/coverage-final.json +0 -12
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -79
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -126
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -170
- package/coverage/lcov-report/src/controllers.ts.html +0 -113
- package/coverage/lcov-report/src/decorator.ts.html +0 -1280
- package/coverage/lcov-report/src/filter.ts.html +0 -734
- package/coverage/lcov-report/src/http.ts.html +0 -2192
- package/coverage/lcov-report/src/index.html +0 -246
- package/coverage/lcov-report/src/kernel.ts.html +0 -260
- package/coverage/lcov-report/src/middleware.ts.html +0 -428
- package/coverage/lcov-report/src/model.ts.html +0 -937
- package/coverage/lcov-report/src/module.config.ts.html +0 -89
- package/coverage/lcov-report/src/module.ts.html +0 -245
- package/coverage/lcov-report/src/router.ts.html +0 -2318
- package/coverage/lcov-report/tests/index.html +0 -111
- package/coverage/lcov-report/tests/utils.ts.html +0 -176
- package/coverage/lcov.info +0 -2225
- package/dist/cjs/tests/filter.spec.d.ts +0 -1
- package/dist/cjs/tests/filter.spec.js +0 -251
- package/dist/cjs/tests/filter.spec.js.map +0 -1
- package/dist/cjs/tests/middleware.spec.d.ts +0 -1
- package/dist/cjs/tests/middleware.spec.js +0 -471
- package/dist/cjs/tests/middleware.spec.js.map +0 -1
- package/dist/cjs/tests/model.spec.d.ts +0 -1
- package/dist/cjs/tests/model.spec.js +0 -23
- package/dist/cjs/tests/model.spec.js.map +0 -1
- package/dist/cjs/tests/module.spec.d.ts +0 -1
- package/dist/cjs/tests/module.spec.js +0 -46
- package/dist/cjs/tests/module.spec.js.map +0 -1
- package/dist/cjs/tests/router.spec.d.ts +0 -1
- package/dist/cjs/tests/router.spec.js +0 -987
- package/dist/cjs/tests/router.spec.js.map +0 -1
- package/dist/cjs/tests/utils.d.ts +0 -8
- package/dist/cjs/tests/utils.js +0 -30
- package/dist/cjs/tests/utils.js.map +0 -1
- package/dist/esm/tests/filter.spec.d.ts +0 -1
- package/dist/esm/tests/filter.spec.js +0 -249
- package/dist/esm/tests/filter.spec.js.map +0 -1
- package/dist/esm/tests/middleware.spec.d.ts +0 -1
- package/dist/esm/tests/middleware.spec.js +0 -469
- package/dist/esm/tests/middleware.spec.js.map +0 -1
- package/dist/esm/tests/model.spec.d.ts +0 -1
- package/dist/esm/tests/model.spec.js +0 -21
- package/dist/esm/tests/model.spec.js.map +0 -1
- package/dist/esm/tests/module.spec.d.ts +0 -1
- package/dist/esm/tests/module.spec.js +0 -44
- package/dist/esm/tests/module.spec.js.map +0 -1
- package/dist/esm/tests/router.spec.d.ts +0 -1
- package/dist/esm/tests/router.spec.js +0 -985
- package/dist/esm/tests/router.spec.js.map +0 -1
- package/dist/esm/tests/utils.d.ts +0 -8
- package/dist/esm/tests/utils.js +0 -26
- package/dist/esm/tests/utils.js.map +0 -1
- package/tests/filter.spec.ts +0 -181
- package/tests/middleware.spec.ts +0 -440
- package/tests/model.spec.ts +0 -26
- package/tests/module.spec.ts +0 -32
- package/tests/router.spec.ts +0 -781
- package/tests/utils.ts +0 -32
|
@@ -1,987 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const { __ΩHttpRegExp } = require('../src/model');
|
|
13
|
-
const { __ΩRouteParameterResolverContext } = require('../src/router');
|
|
14
|
-
const { __ΩHttpBody } = require('../src/model');
|
|
15
|
-
const { __ΩHttpQuery } = require('../src/model');
|
|
16
|
-
const { __ΩHttpQueries } = require('../src/model');
|
|
17
|
-
const { __ΩGroup } = require('@deepkit/type');
|
|
18
|
-
const { __ΩMinLength } = require('@deepkit/type');
|
|
19
|
-
const { __ΩHttpBodyValidation } = require('../src/model');
|
|
20
|
-
const globals_1 = require("@jest/globals");
|
|
21
|
-
const router_1 = require("../src/router");
|
|
22
|
-
const decorator_1 = require("../src/decorator");
|
|
23
|
-
const http_1 = require("../src/http");
|
|
24
|
-
const event_1 = require("@deepkit/event");
|
|
25
|
-
const model_1 = require("../src/model");
|
|
26
|
-
const core_1 = require("@deepkit/core");
|
|
27
|
-
const utils_1 = require("./utils");
|
|
28
|
-
(0, globals_1.test)('router', async () => {
|
|
29
|
-
var _a, _b, _c;
|
|
30
|
-
class Controller {
|
|
31
|
-
helloWorld() {
|
|
32
|
-
}
|
|
33
|
-
hello(name) {
|
|
34
|
-
}
|
|
35
|
-
userStatic(id) {
|
|
36
|
-
}
|
|
37
|
-
userStatic2(id, id2) {
|
|
38
|
-
}
|
|
39
|
-
any() {
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
Controller.__type = ['helloWorld', 'name', 'hello', 'id', 'userStatic', 'id2', 'userStatic2', 'any', 'P"0!P&2""0#P&2$"0%P&2$&2&"0\'P"0(5'];
|
|
43
|
-
__decorate([
|
|
44
|
-
decorator_1.http.GET(),
|
|
45
|
-
__metadata("design:type", Function),
|
|
46
|
-
__metadata("design:paramtypes", []),
|
|
47
|
-
__metadata("design:returntype", void 0)
|
|
48
|
-
], Controller.prototype, "helloWorld", null);
|
|
49
|
-
__decorate([
|
|
50
|
-
decorator_1.http.GET(':name'),
|
|
51
|
-
__metadata("design:type", Function),
|
|
52
|
-
__metadata("design:paramtypes", [String]),
|
|
53
|
-
__metadata("design:returntype", void 0)
|
|
54
|
-
], Controller.prototype, "hello", null);
|
|
55
|
-
__decorate([
|
|
56
|
-
decorator_1.http.GET('/user/:id/static'),
|
|
57
|
-
__metadata("design:type", Function),
|
|
58
|
-
__metadata("design:paramtypes", [String]),
|
|
59
|
-
__metadata("design:returntype", void 0)
|
|
60
|
-
], Controller.prototype, "userStatic", null);
|
|
61
|
-
__decorate([
|
|
62
|
-
decorator_1.http.GET('/user2/:id/static/:id2'),
|
|
63
|
-
__metadata("design:type", Function),
|
|
64
|
-
__metadata("design:paramtypes", [String, String]),
|
|
65
|
-
__metadata("design:returntype", void 0)
|
|
66
|
-
], Controller.prototype, "userStatic2", null);
|
|
67
|
-
__decorate([
|
|
68
|
-
decorator_1.http.ANY('/any'),
|
|
69
|
-
__metadata("design:type", Function),
|
|
70
|
-
__metadata("design:paramtypes", []),
|
|
71
|
-
__metadata("design:returntype", void 0)
|
|
72
|
-
], Controller.prototype, "any", null);
|
|
73
|
-
const router = router_1.Router.forControllers([Controller]);
|
|
74
|
-
(0, globals_1.expect)((_a = (await router.resolve('GET', '/'))) === null || _a === void 0 ? void 0 : _a.routeConfig.action).toMatchObject({ controller: Controller, methodName: 'helloWorld' });
|
|
75
|
-
(0, globals_1.expect)((_b = (await router.resolve('GET', '/peter'))) === null || _b === void 0 ? void 0 : _b.routeConfig.action).toMatchObject({ controller: Controller, methodName: 'hello' });
|
|
76
|
-
(0, globals_1.expect)((_c = (await router.resolve('GET', '/peter'))) === null || _c === void 0 ? void 0 : _c.parameters(undefined)).toEqual(['peter']);
|
|
77
|
-
const userStatic = await router.resolve('GET', '/user/1233/static');
|
|
78
|
-
(0, globals_1.expect)(userStatic === null || userStatic === void 0 ? void 0 : userStatic.routeConfig.action).toMatchObject({ controller: Controller, methodName: 'userStatic' });
|
|
79
|
-
(0, globals_1.expect)(userStatic === null || userStatic === void 0 ? void 0 : userStatic.parameters(undefined)).toEqual(['1233']);
|
|
80
|
-
const userStatic2 = await router.resolve('GET', '/user2/1233/static/123');
|
|
81
|
-
(0, globals_1.expect)(userStatic2 === null || userStatic2 === void 0 ? void 0 : userStatic2.routeConfig.action).toMatchObject({ controller: Controller, methodName: 'userStatic2' });
|
|
82
|
-
(0, globals_1.expect)(userStatic2 === null || userStatic2 === void 0 ? void 0 : userStatic2.parameters(undefined)).toEqual(['1233', '123']);
|
|
83
|
-
});
|
|
84
|
-
(0, globals_1.test)('any', async () => {
|
|
85
|
-
class Controller {
|
|
86
|
-
any() {
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
Controller.__type = ['any', 'P"0!5'];
|
|
90
|
-
__decorate([
|
|
91
|
-
decorator_1.http.ANY('/any'),
|
|
92
|
-
__metadata("design:type", Function),
|
|
93
|
-
__metadata("design:paramtypes", []),
|
|
94
|
-
__metadata("design:returntype", void 0)
|
|
95
|
-
], Controller.prototype, "any", null);
|
|
96
|
-
const router = router_1.Router.forControllers([Controller]);
|
|
97
|
-
(0, globals_1.expect)((await router.resolve('GET', '/any')).routeConfig.action.methodName).toEqual('any');
|
|
98
|
-
(0, globals_1.expect)((await router.resolve('POST', '/any')).routeConfig.action.methodName).toEqual('any');
|
|
99
|
-
(0, globals_1.expect)((await router.resolve('OPTIONS', '/any')).routeConfig.action.methodName).toEqual('any');
|
|
100
|
-
});
|
|
101
|
-
(0, globals_1.test)('router parameters', async () => {
|
|
102
|
-
var _a;
|
|
103
|
-
class Controller {
|
|
104
|
-
string(name) {
|
|
105
|
-
return new http_1.JSONResponse(name);
|
|
106
|
-
}
|
|
107
|
-
number(id) {
|
|
108
|
-
return new http_1.JSONResponse(id);
|
|
109
|
-
}
|
|
110
|
-
boolean(yes) {
|
|
111
|
-
return new http_1.JSONResponse(yes);
|
|
112
|
-
}
|
|
113
|
-
any(path) {
|
|
114
|
-
return new http_1.JSONResponse(path);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
Controller.__type = ['name', 'string', 'id', 'number', 'yes', 'boolean', () => __ΩHttpRegExp, ".*", 'path', 'any', 'P&2!"0"P\'2#"0$P)2%"0&P&.(o\'#2)"0*5'];
|
|
118
|
-
__decorate([
|
|
119
|
-
decorator_1.http.GET('/user/:name'),
|
|
120
|
-
__metadata("design:type", Function),
|
|
121
|
-
__metadata("design:paramtypes", [String]),
|
|
122
|
-
__metadata("design:returntype", void 0)
|
|
123
|
-
], Controller.prototype, "string", null);
|
|
124
|
-
__decorate([
|
|
125
|
-
decorator_1.http.GET('/user-id/:id'),
|
|
126
|
-
__metadata("design:type", Function),
|
|
127
|
-
__metadata("design:paramtypes", [Number]),
|
|
128
|
-
__metadata("design:returntype", void 0)
|
|
129
|
-
], Controller.prototype, "number", null);
|
|
130
|
-
__decorate([
|
|
131
|
-
decorator_1.http.GET('/boolean/:yes'),
|
|
132
|
-
__metadata("design:type", Function),
|
|
133
|
-
__metadata("design:paramtypes", [Boolean]),
|
|
134
|
-
__metadata("design:returntype", void 0)
|
|
135
|
-
], Controller.prototype, "boolean", null);
|
|
136
|
-
__decorate([
|
|
137
|
-
decorator_1.http.GET(':path'),
|
|
138
|
-
__metadata("design:type", Function),
|
|
139
|
-
__metadata("design:paramtypes", [Object]),
|
|
140
|
-
__metadata("design:returntype", void 0)
|
|
141
|
-
], Controller.prototype, "any", null);
|
|
142
|
-
const router = router_1.Router.forControllers([Controller]);
|
|
143
|
-
(0, globals_1.expect)((_a = (await router.resolve('GET', '/user/peter'))) === null || _a === void 0 ? void 0 : _a.routeConfig.action).toMatchObject({ controller: Controller, methodName: 'string' });
|
|
144
|
-
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
145
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/user/peter'))).json).toBe('peter');
|
|
146
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/user-id/123'))).json).toBe(123);
|
|
147
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/user-id/asd'))).json).toMatchObject({ message: 'Validation error:\nid(type): Cannot convert asd to number' });
|
|
148
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/boolean/1'))).json).toBe(true);
|
|
149
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/boolean/false'))).json).toBe(false);
|
|
150
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/any'))).json).toBe('any');
|
|
151
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/any/path'))).json).toBe('any/path');
|
|
152
|
-
});
|
|
153
|
-
(0, globals_1.test)('router HttpRequest', async () => {
|
|
154
|
-
class Controller {
|
|
155
|
-
anyReq(req, path) {
|
|
156
|
-
return [req.url, path];
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
Controller.__type = [() => model_1.HttpRequest, 'req', () => __ΩHttpRegExp, ".*", 'path', 'anyReq', 'PP7!2"&.$o##2%"0&5'];
|
|
160
|
-
__decorate([
|
|
161
|
-
decorator_1.http.GET(':path'),
|
|
162
|
-
__metadata("design:type", Function),
|
|
163
|
-
__metadata("design:paramtypes", [model_1.HttpRequest, Object]),
|
|
164
|
-
__metadata("design:returntype", void 0)
|
|
165
|
-
], Controller.prototype, "anyReq", null);
|
|
166
|
-
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
167
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/req/any/path'))).json).toEqual(['/req/any/path', 'req/any/path']);
|
|
168
|
-
});
|
|
169
|
-
(0, globals_1.test)('router parameter resolver by class', async () => {
|
|
170
|
-
class User {
|
|
171
|
-
constructor(username) {
|
|
172
|
-
this.username = username;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
User.__type = ['username', 'constructor', 'P&2!:"0"5'];
|
|
176
|
-
class Group {
|
|
177
|
-
constructor(name) {
|
|
178
|
-
this.name = name;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
Group.__type = ['name', 'constructor', 'P&2!:"0"5'];
|
|
182
|
-
class UserResolver {
|
|
183
|
-
resolve(context) {
|
|
184
|
-
const value = context.value || context.parameters.username;
|
|
185
|
-
if (!value)
|
|
186
|
-
throw new Error('No value specified');
|
|
187
|
-
return new User(value);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
UserResolver.__type = [() => __ΩRouteParameterResolverContext, 'context', 'resolve', 'Pn!2"P""`J0#5'];
|
|
191
|
-
class GroupResolver {
|
|
192
|
-
resolve(context) {
|
|
193
|
-
if (!context.value)
|
|
194
|
-
throw new Error('No value specified');
|
|
195
|
-
return new Group(context.value);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
GroupResolver.__type = [() => __ΩRouteParameterResolverContext, 'context', 'resolve', 'Pn!2"P""`J0#5'];
|
|
199
|
-
let Controller = class Controller {
|
|
200
|
-
route1(user) {
|
|
201
|
-
return [user.username];
|
|
202
|
-
}
|
|
203
|
-
route2(user) {
|
|
204
|
-
return [user.username];
|
|
205
|
-
}
|
|
206
|
-
route3(user, group) {
|
|
207
|
-
return [user.username, group.name];
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
Controller.__type = [() => User, 'user', 'route1', () => User, 'route2', () => User, () => Group, 'group', 'route3', 'PP7!2""0#PP7$2""0%PP7&2"P7\'2("0)5'];
|
|
211
|
-
__decorate([
|
|
212
|
-
decorator_1.http.GET('user/:username'),
|
|
213
|
-
__metadata("design:type", Function),
|
|
214
|
-
__metadata("design:paramtypes", [User]),
|
|
215
|
-
__metadata("design:returntype", void 0)
|
|
216
|
-
], Controller.prototype, "route1", null);
|
|
217
|
-
__decorate([
|
|
218
|
-
decorator_1.http.GET('invalid'),
|
|
219
|
-
__metadata("design:type", Function),
|
|
220
|
-
__metadata("design:paramtypes", [User]),
|
|
221
|
-
__metadata("design:returntype", void 0)
|
|
222
|
-
], Controller.prototype, "route2", null);
|
|
223
|
-
__decorate([
|
|
224
|
-
decorator_1.http.GET('user/:user/group/:group').resolveParameter(Group, GroupResolver),
|
|
225
|
-
__metadata("design:type", Function),
|
|
226
|
-
__metadata("design:paramtypes", [User, Group]),
|
|
227
|
-
__metadata("design:returntype", void 0)
|
|
228
|
-
], Controller.prototype, "route3", null);
|
|
229
|
-
Controller = __decorate([
|
|
230
|
-
decorator_1.http.resolveParameter(User, UserResolver)
|
|
231
|
-
], Controller);
|
|
232
|
-
const data = decorator_1.httpClass._fetch(Controller);
|
|
233
|
-
(0, globals_1.expect)(data.getActions().size).toBe(3);
|
|
234
|
-
(0, globals_1.expect)(data.resolverForToken.get(User)).toBe(UserResolver);
|
|
235
|
-
(0, globals_1.expect)(data.resolverForToken.get(User)).toBe(UserResolver);
|
|
236
|
-
(0, globals_1.expect)(data.getAction('route3').resolverForToken.get(Group)).toBe(GroupResolver);
|
|
237
|
-
const httpKernel = (0, utils_1.createHttpKernel)([Controller], [UserResolver, GroupResolver]);
|
|
238
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/user/peter'))).json).toEqual(['peter']);
|
|
239
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/user/peter/group/a'))).json).toEqual(['peter', 'a']);
|
|
240
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/invalid'))).bodyString).toEqual('Internal error');
|
|
241
|
-
});
|
|
242
|
-
(0, globals_1.test)('router parameter resolver by name', async () => {
|
|
243
|
-
class User {
|
|
244
|
-
constructor(username) {
|
|
245
|
-
this.username = username;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
User.__type = ['username', 'constructor', 'P&2!:"0"5'];
|
|
249
|
-
class Group {
|
|
250
|
-
constructor(name) {
|
|
251
|
-
this.name = name;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
Group.__type = ['name', 'constructor', 'P&2!:"0"5'];
|
|
255
|
-
class UserResolver {
|
|
256
|
-
resolve(context) {
|
|
257
|
-
const value = context.value || context.parameters.username;
|
|
258
|
-
if (!value) {
|
|
259
|
-
throw new Error('No value specified');
|
|
260
|
-
}
|
|
261
|
-
return new User(value);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
UserResolver.__type = [() => __ΩRouteParameterResolverContext, 'context', 'resolve', 'Pn!2"P""`J0#5'];
|
|
265
|
-
class GroupResolver {
|
|
266
|
-
resolve(context) {
|
|
267
|
-
if (!context.value)
|
|
268
|
-
throw new Error('No value specified');
|
|
269
|
-
return new Group(context.value);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
GroupResolver.__type = [() => __ΩRouteParameterResolverContext, 'context', 'resolve', 'Pn!2"P""`J0#5'];
|
|
273
|
-
class MyAuth {
|
|
274
|
-
constructor(name) {
|
|
275
|
-
this.name = name;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
MyAuth.__type = ['name', 'constructor', 'P&2!:"0"5'];
|
|
279
|
-
class AuthResolver {
|
|
280
|
-
resolve(context) {
|
|
281
|
-
return new MyAuth('auth');
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
AuthResolver.__type = [() => __ΩRouteParameterResolverContext, 'context', 'resolve', 'Pn!2"P""`J0#5'];
|
|
285
|
-
let Controller = class Controller {
|
|
286
|
-
route1(user) {
|
|
287
|
-
return [user.username];
|
|
288
|
-
}
|
|
289
|
-
route2(user) {
|
|
290
|
-
return [user.username];
|
|
291
|
-
}
|
|
292
|
-
route3(user, group) {
|
|
293
|
-
return [user.username, group.name];
|
|
294
|
-
}
|
|
295
|
-
nonClass(auth) {
|
|
296
|
-
return [auth.name, (0, core_1.getClassName)(auth)];
|
|
297
|
-
}
|
|
298
|
-
};
|
|
299
|
-
Controller.__type = [() => User, 'user', 'route1', () => User, 'route2', () => User, () => Group, 'group', 'route3', 'auth', 'nonClass', 'PP7!2""0#PP7$2""0%PP7&2"P7\'2("0)P"2*"0+5'];
|
|
300
|
-
__decorate([
|
|
301
|
-
decorator_1.http.GET('user/:username'),
|
|
302
|
-
__metadata("design:type", Function),
|
|
303
|
-
__metadata("design:paramtypes", [User]),
|
|
304
|
-
__metadata("design:returntype", void 0)
|
|
305
|
-
], Controller.prototype, "route1", null);
|
|
306
|
-
__decorate([
|
|
307
|
-
decorator_1.http.GET('invalid'),
|
|
308
|
-
__metadata("design:type", Function),
|
|
309
|
-
__metadata("design:paramtypes", [User]),
|
|
310
|
-
__metadata("design:returntype", void 0)
|
|
311
|
-
], Controller.prototype, "route2", null);
|
|
312
|
-
__decorate([
|
|
313
|
-
decorator_1.http.GET('user/:user/group/:group').resolveParameterByName('group', GroupResolver),
|
|
314
|
-
__metadata("design:type", Function),
|
|
315
|
-
__metadata("design:paramtypes", [User, Group]),
|
|
316
|
-
__metadata("design:returntype", void 0)
|
|
317
|
-
], Controller.prototype, "route3", null);
|
|
318
|
-
__decorate([
|
|
319
|
-
decorator_1.http.GET('nonClass').resolveParameterByName('auth', AuthResolver),
|
|
320
|
-
__metadata("design:type", Function),
|
|
321
|
-
__metadata("design:paramtypes", [Object]),
|
|
322
|
-
__metadata("design:returntype", void 0)
|
|
323
|
-
], Controller.prototype, "nonClass", null);
|
|
324
|
-
Controller = __decorate([
|
|
325
|
-
decorator_1.http.resolveParameterByName('user', UserResolver)
|
|
326
|
-
], Controller);
|
|
327
|
-
const data = decorator_1.httpClass._fetch(Controller);
|
|
328
|
-
(0, globals_1.expect)(data.getActions().size).toBe(4);
|
|
329
|
-
(0, globals_1.expect)(data.resolverForParameterName.get('user')).toBe(UserResolver);
|
|
330
|
-
(0, globals_1.expect)(data.getAction('route3').resolverForParameterName.get('group')).toBe(GroupResolver);
|
|
331
|
-
const httpKernel = (0, utils_1.createHttpKernel)([Controller], [UserResolver, GroupResolver, AuthResolver]);
|
|
332
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/user/peter'))).json).toEqual(['peter']);
|
|
333
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/user/peter/group/a'))).json).toEqual(['peter', 'a']);
|
|
334
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/invalid'))).bodyString).toEqual('Internal error');
|
|
335
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/nonClass'))).json).toEqual(['auth', 'MyAuth']);
|
|
336
|
-
});
|
|
337
|
-
(0, globals_1.test)('router body class', async () => {
|
|
338
|
-
class Body {
|
|
339
|
-
}
|
|
340
|
-
Body.__type = ['username', '&3!5'];
|
|
341
|
-
class Controller {
|
|
342
|
-
anyReq(body, req) {
|
|
343
|
-
return [body.username, body instanceof Body, req.url];
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
Controller.__type = [() => __ΩHttpBody, () => Body, 'body', () => model_1.HttpRequest, 'req', 'anyReq', 'PP7"o!"2#P7$2%"0&5'];
|
|
347
|
-
__decorate([
|
|
348
|
-
decorator_1.http.POST(),
|
|
349
|
-
__metadata("design:type", Function),
|
|
350
|
-
__metadata("design:paramtypes", [Object, model_1.HttpRequest]),
|
|
351
|
-
__metadata("design:returntype", void 0)
|
|
352
|
-
], Controller.prototype, "anyReq", null);
|
|
353
|
-
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
354
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.POST('/').json({ username: 'Peter' }))).json).toEqual(['Peter', true, '/']);
|
|
355
|
-
});
|
|
356
|
-
(0, globals_1.test)('router body is safe for simultaneous requests', async () => {
|
|
357
|
-
class Body {
|
|
358
|
-
}
|
|
359
|
-
Body.__type = ['username', '&3!5'];
|
|
360
|
-
class Controller {
|
|
361
|
-
anyReq(body, req) {
|
|
362
|
-
return [body.username, body instanceof Body, req.url];
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
Controller.__type = [() => __ΩHttpBody, () => Body, 'body', () => model_1.HttpRequest, 'req', 'anyReq', 'PP7"o!"2#P7$2%"0&5'];
|
|
366
|
-
__decorate([
|
|
367
|
-
decorator_1.http.POST(),
|
|
368
|
-
__metadata("design:type", Function),
|
|
369
|
-
__metadata("design:paramtypes", [Object, model_1.HttpRequest]),
|
|
370
|
-
__metadata("design:returntype", void 0)
|
|
371
|
-
], Controller.prototype, "anyReq", null);
|
|
372
|
-
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
373
|
-
const makeReq = () => httpKernel.request(model_1.HttpRequest.POST('/').json({ username: 'Peter' }));
|
|
374
|
-
const results = await Promise.all([...new Array(100)].map(() => makeReq().then(Object.assign(res => res.json, { __type: ['res', '', 'P"2!"/"'] }))));
|
|
375
|
-
(0, globals_1.expect)(results).toEqual(results.map(() => ['Peter', true, '/']));
|
|
376
|
-
});
|
|
377
|
-
(0, globals_1.test)('router body interface', async () => {
|
|
378
|
-
const __ΩBody = ['username', 'P&4!M'];
|
|
379
|
-
class Controller {
|
|
380
|
-
anyReq(body, req) {
|
|
381
|
-
return [body.username, typeof body.username, req.url];
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
Controller.__type = [() => __ΩHttpBody, () => __ΩBody, 'body', () => model_1.HttpRequest, 'req', 'anyReq', 'Pn"o!"2#P7$2%"0&5'];
|
|
385
|
-
__decorate([
|
|
386
|
-
decorator_1.http.POST(),
|
|
387
|
-
__metadata("design:type", Function),
|
|
388
|
-
__metadata("design:paramtypes", [Object, model_1.HttpRequest]),
|
|
389
|
-
__metadata("design:returntype", void 0)
|
|
390
|
-
], Controller.prototype, "anyReq", null);
|
|
391
|
-
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
392
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.POST('/').json({ username: 'Peter' }))).json).toEqual(['Peter', 'string', '/']);
|
|
393
|
-
});
|
|
394
|
-
(0, globals_1.test)('router body double', async () => {
|
|
395
|
-
class Body {
|
|
396
|
-
}
|
|
397
|
-
Body.__type = ['username', '&3!5'];
|
|
398
|
-
class Controller {
|
|
399
|
-
anyReq(body, body2, req) {
|
|
400
|
-
return [body2.username, body2 instanceof Body && body instanceof Body, req.url];
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
Controller.__type = [() => __ΩHttpBody, () => Body, 'body', () => __ΩHttpBody, () => Body, 'body2', () => model_1.HttpRequest, 'req', 'anyReq', 'PP7"o!"2#P7%o$"2&P7\'2("0)5'];
|
|
404
|
-
__decorate([
|
|
405
|
-
decorator_1.http.POST(),
|
|
406
|
-
__metadata("design:type", Function),
|
|
407
|
-
__metadata("design:paramtypes", [Object, Object, model_1.HttpRequest]),
|
|
408
|
-
__metadata("design:returntype", void 0)
|
|
409
|
-
], Controller.prototype, "anyReq", null);
|
|
410
|
-
const httpData = decorator_1.httpClass._fetch(Controller);
|
|
411
|
-
if (!httpData)
|
|
412
|
-
throw new Error('httpClass undefined');
|
|
413
|
-
const action = [...httpData.getActions()][0];
|
|
414
|
-
(0, globals_1.expect)(action.methodName).toBe('anyReq');
|
|
415
|
-
(0, globals_1.expect)(action.httpMethods).toEqual(['POST']);
|
|
416
|
-
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
417
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.POST('/').json({ username: 'Peter' }))).json).toEqual(['Peter', true, '/']);
|
|
418
|
-
});
|
|
419
|
-
(0, globals_1.test)('router groups', async () => {
|
|
420
|
-
{
|
|
421
|
-
class Controller {
|
|
422
|
-
a() {
|
|
423
|
-
}
|
|
424
|
-
b() {
|
|
425
|
-
}
|
|
426
|
-
c() {
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
Controller.__type = ['a', 'b', 'c', 'P"0!P"0"P"0#5'];
|
|
430
|
-
__decorate([
|
|
431
|
-
decorator_1.http.GET('a').group('a'),
|
|
432
|
-
__metadata("design:type", Function),
|
|
433
|
-
__metadata("design:paramtypes", []),
|
|
434
|
-
__metadata("design:returntype", void 0)
|
|
435
|
-
], Controller.prototype, "a", null);
|
|
436
|
-
__decorate([
|
|
437
|
-
decorator_1.http.GET('b'),
|
|
438
|
-
__metadata("design:type", Function),
|
|
439
|
-
__metadata("design:paramtypes", []),
|
|
440
|
-
__metadata("design:returntype", void 0)
|
|
441
|
-
], Controller.prototype, "b", null);
|
|
442
|
-
__decorate([
|
|
443
|
-
decorator_1.http.GET('c').group('c'),
|
|
444
|
-
__metadata("design:type", Function),
|
|
445
|
-
__metadata("design:paramtypes", []),
|
|
446
|
-
__metadata("design:returntype", void 0)
|
|
447
|
-
], Controller.prototype, "c", null);
|
|
448
|
-
const httpData = decorator_1.httpClass._fetch(Controller);
|
|
449
|
-
if (!httpData)
|
|
450
|
-
throw new Error('httpClass undefined');
|
|
451
|
-
(0, globals_1.expect)(httpData.getAction('a').groups).toEqual(['a']);
|
|
452
|
-
(0, globals_1.expect)(httpData.getAction('b').groups).toEqual([]);
|
|
453
|
-
(0, globals_1.expect)(httpData.getAction('c').groups).toEqual(['c']);
|
|
454
|
-
}
|
|
455
|
-
{
|
|
456
|
-
let Controller = class Controller {
|
|
457
|
-
a() {
|
|
458
|
-
}
|
|
459
|
-
b() {
|
|
460
|
-
}
|
|
461
|
-
c() {
|
|
462
|
-
}
|
|
463
|
-
};
|
|
464
|
-
Controller.__type = ['a', 'b', 'c', 'P"0!P"0"P"0#5'];
|
|
465
|
-
__decorate([
|
|
466
|
-
decorator_1.http.GET('a').group('a'),
|
|
467
|
-
__metadata("design:type", Function),
|
|
468
|
-
__metadata("design:paramtypes", []),
|
|
469
|
-
__metadata("design:returntype", void 0)
|
|
470
|
-
], Controller.prototype, "a", null);
|
|
471
|
-
__decorate([
|
|
472
|
-
decorator_1.http.GET('b'),
|
|
473
|
-
__metadata("design:type", Function),
|
|
474
|
-
__metadata("design:paramtypes", []),
|
|
475
|
-
__metadata("design:returntype", void 0)
|
|
476
|
-
], Controller.prototype, "b", null);
|
|
477
|
-
__decorate([
|
|
478
|
-
decorator_1.http.GET('c').group('c'),
|
|
479
|
-
__metadata("design:type", Function),
|
|
480
|
-
__metadata("design:paramtypes", []),
|
|
481
|
-
__metadata("design:returntype", void 0)
|
|
482
|
-
], Controller.prototype, "c", null);
|
|
483
|
-
Controller = __decorate([
|
|
484
|
-
decorator_1.http.group('all')
|
|
485
|
-
], Controller);
|
|
486
|
-
const httpData = decorator_1.httpClass._fetch(Controller);
|
|
487
|
-
if (!httpData)
|
|
488
|
-
throw new Error('httpClass undefined');
|
|
489
|
-
(0, globals_1.expect)(httpData.getAction('a').groups).toEqual(['a', 'all']);
|
|
490
|
-
(0, globals_1.expect)(httpData.getAction('b').groups).toEqual(['all']);
|
|
491
|
-
(0, globals_1.expect)(httpData.getAction('c').groups).toEqual(['c', 'all']);
|
|
492
|
-
}
|
|
493
|
-
});
|
|
494
|
-
(0, globals_1.test)('router query', async () => {
|
|
495
|
-
class Controller {
|
|
496
|
-
anyReq(test) {
|
|
497
|
-
return test;
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
Controller.__type = [() => __ΩHttpQuery, 'test', 'anyReq', 'P\'o!"2"8"0#5'];
|
|
501
|
-
__decorate([
|
|
502
|
-
decorator_1.http.GET('my-action'),
|
|
503
|
-
__metadata("design:type", Function),
|
|
504
|
-
__metadata("design:paramtypes", [Object]),
|
|
505
|
-
__metadata("design:returntype", void 0)
|
|
506
|
-
], Controller.prototype, "anyReq", null);
|
|
507
|
-
const httpData = decorator_1.httpClass._fetch(Controller);
|
|
508
|
-
if (!httpData)
|
|
509
|
-
throw new Error('httpClass undefined');
|
|
510
|
-
const action = [...httpData.getActions()][0];
|
|
511
|
-
(0, globals_1.expect)(action.methodName).toBe('anyReq');
|
|
512
|
-
(0, globals_1.expect)(action.httpMethods).toEqual(['GET']);
|
|
513
|
-
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
514
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/my-action?test=123'))).json).toEqual(123);
|
|
515
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/my-action'))).bodyString).toEqual('');
|
|
516
|
-
});
|
|
517
|
-
(0, globals_1.test)('router query all', async () => {
|
|
518
|
-
class AnyReqQuery {
|
|
519
|
-
}
|
|
520
|
-
AnyReqQuery.__type = ['test', 'filter', 'page', '&3!8&3"8\'3#85'];
|
|
521
|
-
class Controller {
|
|
522
|
-
anyReq(anyReqQuery) {
|
|
523
|
-
return anyReqQuery;
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
Controller.__type = [() => __ΩHttpQueries, () => AnyReqQuery, 'anyReqQuery', 'anyReq', 'PP7"o!"2#"0$5'];
|
|
527
|
-
__decorate([
|
|
528
|
-
decorator_1.http.GET('my-action'),
|
|
529
|
-
__metadata("design:type", Function),
|
|
530
|
-
__metadata("design:paramtypes", [Object]),
|
|
531
|
-
__metadata("design:returntype", void 0)
|
|
532
|
-
], Controller.prototype, "anyReq", null);
|
|
533
|
-
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
534
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/my-action?test=123'))).json).toEqual({ test: '123' });
|
|
535
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/my-action'))).json).toEqual({});
|
|
536
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/my-action?filter=page&page=5'))).json).toEqual({ filter: 'page', page: 5 });
|
|
537
|
-
});
|
|
538
|
-
(0, globals_1.test)('serializer options', async () => {
|
|
539
|
-
class User {
|
|
540
|
-
}
|
|
541
|
-
User.__type = ['username', () => __ΩGroup, "sensitive", 'password', '&3!P&.#o""K3$5'];
|
|
542
|
-
class Controller {
|
|
543
|
-
anyReq() {
|
|
544
|
-
return { username: 'Peter', password: 'secret' };
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
Controller.__type = [() => User, 'anyReq', 'PP7!0"5'];
|
|
548
|
-
__decorate([
|
|
549
|
-
decorator_1.http.GET().serialization({ groupsExclude: ['sensitive'] }),
|
|
550
|
-
__metadata("design:type", Function),
|
|
551
|
-
__metadata("design:paramtypes", []),
|
|
552
|
-
__metadata("design:returntype", User)
|
|
553
|
-
], Controller.prototype, "anyReq", null);
|
|
554
|
-
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
555
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/'))).json).toEqual({ username: 'Peter' });
|
|
556
|
-
});
|
|
557
|
-
(0, globals_1.test)('hook after serializer', async () => {
|
|
558
|
-
class User {
|
|
559
|
-
}
|
|
560
|
-
User.__type = ['username', () => __ΩGroup, "sensitive", 'password', '&3!P&.#o""K3$5'];
|
|
561
|
-
class Controller {
|
|
562
|
-
async anyReq() {
|
|
563
|
-
await (0, core_1.sleep)(0.1);
|
|
564
|
-
return { username: 'Peter', password: 'secret' };
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
Controller.__type = [() => User, 'anyReq', 'PP7!`0"5'];
|
|
568
|
-
__decorate([
|
|
569
|
-
decorator_1.http.GET().serialization({ groupsExclude: ['sensitive'] }),
|
|
570
|
-
__metadata("design:type", Function),
|
|
571
|
-
__metadata("design:paramtypes", []),
|
|
572
|
-
__metadata("design:returntype", Promise)
|
|
573
|
-
], Controller.prototype, "anyReq", null);
|
|
574
|
-
class Listener {
|
|
575
|
-
onResponse(event) {
|
|
576
|
-
event.result = { processingTime: event.controllerActionTime, data: event.result };
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
Listener.__type = [() => http_1.httpWorkflow.onResponse.event, 'event', 'onResponse', 'Pi!2""0#5'];
|
|
580
|
-
__decorate([
|
|
581
|
-
event_1.eventDispatcher.listen(http_1.httpWorkflow.onResponse),
|
|
582
|
-
__metadata("design:type", Function),
|
|
583
|
-
__metadata("design:paramtypes", [Object]),
|
|
584
|
-
__metadata("design:returntype", void 0)
|
|
585
|
-
], Listener.prototype, "onResponse", null);
|
|
586
|
-
const httpKernel = (0, utils_1.createHttpKernel)([Controller], [], [Listener]);
|
|
587
|
-
const result = (await httpKernel.request(model_1.HttpRequest.GET('/'))).json;
|
|
588
|
-
(0, globals_1.expect)(result.data).toEqual({ username: 'Peter' });
|
|
589
|
-
(0, globals_1.expect)(result.processingTime).toBeGreaterThanOrEqual(99);
|
|
590
|
-
});
|
|
591
|
-
(0, globals_1.test)('invalid route definition', async () => {
|
|
592
|
-
class Controller {
|
|
593
|
-
doIt(user) {
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
Controller.__type = ['user', 'doIt', 'P"2!"0"5'];
|
|
597
|
-
__decorate([
|
|
598
|
-
decorator_1.http.GET(),
|
|
599
|
-
__metadata("design:type", Function),
|
|
600
|
-
__metadata("design:paramtypes", [Object]),
|
|
601
|
-
__metadata("design:returntype", void 0)
|
|
602
|
-
], Controller.prototype, "doIt", null);
|
|
603
|
-
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
604
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/'))).bodyString).toEqual('Internal error');
|
|
605
|
-
});
|
|
606
|
-
(0, globals_1.test)('inject request storage ClassType', async () => {
|
|
607
|
-
class User {
|
|
608
|
-
constructor(username) {
|
|
609
|
-
this.username = username;
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
User.__type = ['username', 'constructor', 'P&2!:"0"5'];
|
|
613
|
-
class Controller {
|
|
614
|
-
doIt(user) {
|
|
615
|
-
return { isUser: user instanceof User, username: user.username };
|
|
616
|
-
}
|
|
617
|
-
doItOptional(user) {
|
|
618
|
-
return { isUser: user instanceof User };
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
Controller.__type = [() => User, 'user', 'doIt', () => User, 'doItOptional', 'PP7!2""0#PP7$2"8"0%5'];
|
|
622
|
-
__decorate([
|
|
623
|
-
decorator_1.http.GET(),
|
|
624
|
-
__metadata("design:type", Function),
|
|
625
|
-
__metadata("design:paramtypes", [User]),
|
|
626
|
-
__metadata("design:returntype", void 0)
|
|
627
|
-
], Controller.prototype, "doIt", null);
|
|
628
|
-
__decorate([
|
|
629
|
-
decorator_1.http.GET('optional'),
|
|
630
|
-
__metadata("design:type", Function),
|
|
631
|
-
__metadata("design:paramtypes", [User]),
|
|
632
|
-
__metadata("design:returntype", void 0)
|
|
633
|
-
], Controller.prototype, "doItOptional", null);
|
|
634
|
-
class Listener {
|
|
635
|
-
onAuth(event) {
|
|
636
|
-
if (event.request.headers.authorization === 'yes') {
|
|
637
|
-
event.request.store.user = new User('bar');
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
Listener.__type = [() => http_1.httpWorkflow.onAuth.event, 'event', 'onAuth', 'Pi!2""0#5'];
|
|
642
|
-
__decorate([
|
|
643
|
-
event_1.eventDispatcher.listen(http_1.httpWorkflow.onAuth),
|
|
644
|
-
__metadata("design:type", Function),
|
|
645
|
-
__metadata("design:paramtypes", [Object]),
|
|
646
|
-
__metadata("design:returntype", void 0)
|
|
647
|
-
], Listener.prototype, "onAuth", null);
|
|
648
|
-
const httpKernel = (0, utils_1.createHttpKernel)([Controller], [
|
|
649
|
-
{
|
|
650
|
-
provide: User, scope: 'http',
|
|
651
|
-
useFactory: Object.assign(function useFactory(request) {
|
|
652
|
-
return request.store.user;
|
|
653
|
-
}, { __type: [() => model_1.HttpRequest, 'request', 'useFactory', 'PP7!2""/#'] })
|
|
654
|
-
}
|
|
655
|
-
], [Listener]);
|
|
656
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/').headers({ authorization: 'yes' }))).json).toEqual({ isUser: true, username: 'bar' });
|
|
657
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/').headers({ authorization: 'no' }))).bodyString).toEqual('Internal error');
|
|
658
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/optional').headers({ authorization: 'no' }))).json).toEqual({ isUser: false });
|
|
659
|
-
});
|
|
660
|
-
(0, globals_1.test)('custom request handling', async () => {
|
|
661
|
-
class Listener {
|
|
662
|
-
onRouteNotFound(event) {
|
|
663
|
-
//CORS requirement for example
|
|
664
|
-
if (event.request.method === 'OPTIONS')
|
|
665
|
-
event.send(new http_1.JSONResponse(true, 200));
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
Listener.__type = [() => http_1.httpWorkflow.onRouteNotFound.event, 'event', 'onRouteNotFound', 'Pi!2""0#5'];
|
|
669
|
-
__decorate([
|
|
670
|
-
event_1.eventDispatcher.listen(http_1.httpWorkflow.onRouteNotFound),
|
|
671
|
-
__metadata("design:type", Function),
|
|
672
|
-
__metadata("design:paramtypes", [Object]),
|
|
673
|
-
__metadata("design:returntype", void 0)
|
|
674
|
-
], Listener.prototype, "onRouteNotFound", null);
|
|
675
|
-
const httpKernel = (0, utils_1.createHttpKernel)([], [], [Listener]);
|
|
676
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.OPTIONS('/'))).json).toBe(true);
|
|
677
|
-
});
|
|
678
|
-
(0, globals_1.test)('race condition', async () => {
|
|
679
|
-
let call = 0;
|
|
680
|
-
class Listener {
|
|
681
|
-
async onRouteNotFound(event) {
|
|
682
|
-
if (call === 0) {
|
|
683
|
-
await (0, core_1.sleep)(0.1);
|
|
684
|
-
}
|
|
685
|
-
call++;
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
Listener.__type = [() => http_1.httpWorkflow.onRouteNotFound.event, 'event', 'onRouteNotFound', 'Pi!2""0#5'];
|
|
689
|
-
__decorate([
|
|
690
|
-
event_1.eventDispatcher.listen(http_1.httpWorkflow.onAuth),
|
|
691
|
-
__metadata("design:type", Function),
|
|
692
|
-
__metadata("design:paramtypes", [Object]),
|
|
693
|
-
__metadata("design:returntype", Promise)
|
|
694
|
-
], Listener.prototype, "onRouteNotFound", null);
|
|
695
|
-
class Controller {
|
|
696
|
-
one(param1) {
|
|
697
|
-
return param1;
|
|
698
|
-
}
|
|
699
|
-
second(param2) {
|
|
700
|
-
return param2;
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
Controller.__type = ['param1', 'one', 'param2', 'second', 'P&2!"0"P&2#"0$5'];
|
|
704
|
-
__decorate([
|
|
705
|
-
decorator_1.http.GET('/one/:param1'),
|
|
706
|
-
__metadata("design:type", Function),
|
|
707
|
-
__metadata("design:paramtypes", [String]),
|
|
708
|
-
__metadata("design:returntype", void 0)
|
|
709
|
-
], Controller.prototype, "one", null);
|
|
710
|
-
__decorate([
|
|
711
|
-
decorator_1.http.GET('/second/:param2'),
|
|
712
|
-
__metadata("design:type", Function),
|
|
713
|
-
__metadata("design:paramtypes", [String]),
|
|
714
|
-
__metadata("design:returntype", void 0)
|
|
715
|
-
], Controller.prototype, "second", null);
|
|
716
|
-
const httpKernel = (0, utils_1.createHttpKernel)([Controller], [], [Listener]);
|
|
717
|
-
const [a, b] = await Promise.all([
|
|
718
|
-
httpKernel.request(model_1.HttpRequest.GET('/one/a')),
|
|
719
|
-
httpKernel.request(model_1.HttpRequest.GET('/second/b')),
|
|
720
|
-
]);
|
|
721
|
-
(0, globals_1.expect)(a.json).toBe('a');
|
|
722
|
-
(0, globals_1.expect)(b.json).toBe('b');
|
|
723
|
-
});
|
|
724
|
-
(0, globals_1.test)('multiple methods', async () => {
|
|
725
|
-
class Controller {
|
|
726
|
-
one() {
|
|
727
|
-
return true;
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
Controller.__type = ['one', 'P"0!5'];
|
|
731
|
-
__decorate([
|
|
732
|
-
decorator_1.http.GET('/one').POST(),
|
|
733
|
-
__metadata("design:type", Function),
|
|
734
|
-
__metadata("design:paramtypes", []),
|
|
735
|
-
__metadata("design:returntype", void 0)
|
|
736
|
-
], Controller.prototype, "one", null);
|
|
737
|
-
const httpKernel = (0, utils_1.createHttpKernel)([Controller], [], []);
|
|
738
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/one'))).json).toBe(true);
|
|
739
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.POST('/one'))).json).toBe(true);
|
|
740
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.PATCH('/one'))).bodyString).toBe('Not found');
|
|
741
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.PUT('/one'))).bodyString).toBe('Not found');
|
|
742
|
-
});
|
|
743
|
-
(0, globals_1.test)('promise serializer', async () => {
|
|
744
|
-
class Controller {
|
|
745
|
-
async anyReq1() {
|
|
746
|
-
return 'test';
|
|
747
|
-
}
|
|
748
|
-
async anyReq2() {
|
|
749
|
-
return 1;
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
Controller.__type = ['anyReq1', 'anyReq2', 'P"0!P&`0"5'];
|
|
753
|
-
__decorate([
|
|
754
|
-
decorator_1.http.GET('1'),
|
|
755
|
-
__metadata("design:type", Function),
|
|
756
|
-
__metadata("design:paramtypes", []),
|
|
757
|
-
__metadata("design:returntype", Promise)
|
|
758
|
-
], Controller.prototype, "anyReq1", null);
|
|
759
|
-
__decorate([
|
|
760
|
-
decorator_1.http.GET('2'),
|
|
761
|
-
__metadata("design:type", Function),
|
|
762
|
-
__metadata("design:paramtypes", []),
|
|
763
|
-
__metadata("design:returntype", Promise)
|
|
764
|
-
], Controller.prototype, "anyReq2", null);
|
|
765
|
-
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
766
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/1'))).json).toBe('test');
|
|
767
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/2'))).json).toBe('1');
|
|
768
|
-
});
|
|
769
|
-
(0, globals_1.test)('unions', async () => {
|
|
770
|
-
class Controller {
|
|
771
|
-
list(page) {
|
|
772
|
-
return page;
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
Controller.__type = [() => __ΩHttpQuery, 'page', 'list', 'PP\')Jo!"2""0#5'];
|
|
776
|
-
__decorate([
|
|
777
|
-
decorator_1.http.GET('/list'),
|
|
778
|
-
__metadata("design:type", Function),
|
|
779
|
-
__metadata("design:paramtypes", [Object]),
|
|
780
|
-
__metadata("design:returntype", void 0)
|
|
781
|
-
], Controller.prototype, "list", null);
|
|
782
|
-
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
783
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/list?page=0'))).json).toEqual(0);
|
|
784
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/list?page=1'))).json).toEqual(1);
|
|
785
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/list?page=2222'))).json).toEqual(2222);
|
|
786
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/list?page=false'))).json).toEqual(false);
|
|
787
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/list?page=true'))).json).toEqual(true);
|
|
788
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/list?page=asdasdc'))).json).toMatchObject({
|
|
789
|
-
'errors': [
|
|
790
|
-
{
|
|
791
|
-
'code': 'type',
|
|
792
|
-
'message': 'No value given',
|
|
793
|
-
'path': 'page'
|
|
794
|
-
}
|
|
795
|
-
],
|
|
796
|
-
});
|
|
797
|
-
});
|
|
798
|
-
(0, globals_1.test)('router dotToUrlPath', () => {
|
|
799
|
-
(0, globals_1.expect)((0, router_1.dotToUrlPath)('peter')).toBe('peter');
|
|
800
|
-
(0, globals_1.expect)((0, router_1.dotToUrlPath)('foo.bar')).toBe('foo[bar]');
|
|
801
|
-
(0, globals_1.expect)((0, router_1.dotToUrlPath)('foo.bar.deep')).toBe('foo[bar][deep]');
|
|
802
|
-
(0, globals_1.expect)((0, router_1.dotToUrlPath)('foo.bar.deep.very')).toBe('foo[bar][deep][very]');
|
|
803
|
-
});
|
|
804
|
-
(0, globals_1.test)('router url resolve', async () => {
|
|
805
|
-
class AnyReqQuery {
|
|
806
|
-
}
|
|
807
|
-
AnyReqQuery.__type = ['test', 'filter', 'page', '&3!8&3"8\'3#85'];
|
|
808
|
-
class Controller {
|
|
809
|
-
first() {
|
|
810
|
-
return '';
|
|
811
|
-
}
|
|
812
|
-
second(peter) {
|
|
813
|
-
return '';
|
|
814
|
-
}
|
|
815
|
-
secondQuery(peter) {
|
|
816
|
-
return '';
|
|
817
|
-
}
|
|
818
|
-
secondQuery2(peter) {
|
|
819
|
-
return '';
|
|
820
|
-
}
|
|
821
|
-
third(params) {
|
|
822
|
-
return params;
|
|
823
|
-
}
|
|
824
|
-
third2(params) {
|
|
825
|
-
return params;
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
Controller.__type = ['first', 'peter', 'second', () => __ΩHttpQuery, 'secondQuery', () => __ΩHttpQuery, "changed", 'name', 'secondQuery2', () => __ΩHttpQueries, () => AnyReqQuery, 'params', 'third', () => __ΩHttpQueries, () => AnyReqQuery, "deep", 'third2', 'P"0!P&2""0#P&o$"2""0%P&P.\'4(Mo""0)PP7+o*"2,"0-PP7/P.04(Mo.#2,"015'];
|
|
829
|
-
__decorate([
|
|
830
|
-
decorator_1.http.GET('').name('first'),
|
|
831
|
-
__metadata("design:type", Function),
|
|
832
|
-
__metadata("design:paramtypes", []),
|
|
833
|
-
__metadata("design:returntype", void 0)
|
|
834
|
-
], Controller.prototype, "first", null);
|
|
835
|
-
__decorate([
|
|
836
|
-
decorator_1.http.GET(':peter').name('second'),
|
|
837
|
-
__metadata("design:type", Function),
|
|
838
|
-
__metadata("design:paramtypes", [String]),
|
|
839
|
-
__metadata("design:returntype", void 0)
|
|
840
|
-
], Controller.prototype, "second", null);
|
|
841
|
-
__decorate([
|
|
842
|
-
decorator_1.http.GET('').name('secondQuery'),
|
|
843
|
-
__metadata("design:type", Function),
|
|
844
|
-
__metadata("design:paramtypes", [Object]),
|
|
845
|
-
__metadata("design:returntype", void 0)
|
|
846
|
-
], Controller.prototype, "secondQuery", null);
|
|
847
|
-
__decorate([
|
|
848
|
-
decorator_1.http.GET('').name('secondQuery2'),
|
|
849
|
-
__metadata("design:type", Function),
|
|
850
|
-
__metadata("design:paramtypes", [Object]),
|
|
851
|
-
__metadata("design:returntype", void 0)
|
|
852
|
-
], Controller.prototype, "secondQuery2", null);
|
|
853
|
-
__decorate([
|
|
854
|
-
decorator_1.http.GET('third').name('third'),
|
|
855
|
-
__metadata("design:type", Function),
|
|
856
|
-
__metadata("design:paramtypes", [Object]),
|
|
857
|
-
__metadata("design:returntype", void 0)
|
|
858
|
-
], Controller.prototype, "third", null);
|
|
859
|
-
__decorate([
|
|
860
|
-
decorator_1.http.GET('third2').name('third2'),
|
|
861
|
-
__metadata("design:type", Function),
|
|
862
|
-
__metadata("design:paramtypes", [Object]),
|
|
863
|
-
__metadata("design:returntype", void 0)
|
|
864
|
-
], Controller.prototype, "third2", null);
|
|
865
|
-
const router = router_1.Router.forControllers([Controller]);
|
|
866
|
-
(0, globals_1.expect)(router.resolveUrl('first')).toBe('/');
|
|
867
|
-
(0, globals_1.expect)(router.resolveUrl('second', { peter: 'foo' })).toBe('/foo');
|
|
868
|
-
(0, globals_1.expect)(router.resolveUrl('secondQuery', { peter: 'foo' })).toBe('/?peter=foo');
|
|
869
|
-
(0, globals_1.expect)(router.resolveUrl('secondQuery2', { peter: 'foo' })).toBe('/?changed=foo');
|
|
870
|
-
(0, globals_1.expect)(router.resolveUrl('third', {})).toBe('/third');
|
|
871
|
-
(0, globals_1.expect)(router.resolveUrl('third', { params: { test: 123 } })).toBe('/third?test=123');
|
|
872
|
-
(0, globals_1.expect)(router.resolveUrl('third', { params: { test: 123, filter: 'peter' } })).toBe('/third?test=123&filter=peter');
|
|
873
|
-
(0, globals_1.expect)(router.resolveUrl('third2', {})).toBe('/third2');
|
|
874
|
-
(0, globals_1.expect)(router.resolveUrl('third2', { params: { test: 123 } })).toBe('/third2?deep[test]=123');
|
|
875
|
-
(0, globals_1.expect)(router.resolveUrl('third2', { params: { test: 123, filter: 'peter' } })).toBe('/third2?deep[test]=123&deep[filter]=peter');
|
|
876
|
-
});
|
|
877
|
-
(0, globals_1.test)('destructing params', async () => {
|
|
878
|
-
const __ΩDTO = ['name', 'title', 'P&4!&4"M'];
|
|
879
|
-
class Controller {
|
|
880
|
-
first({ name, title }) {
|
|
881
|
-
return [name, title];
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
Controller.__type = [() => __ΩHttpBody, () => __ΩDTO, 'param0', 'first', 'Pn"o!"2#"0$5'];
|
|
885
|
-
__decorate([
|
|
886
|
-
decorator_1.http.GET(''),
|
|
887
|
-
__metadata("design:type", Function),
|
|
888
|
-
__metadata("design:paramtypes", [Object]),
|
|
889
|
-
__metadata("design:returntype", void 0)
|
|
890
|
-
], Controller.prototype, "first", null);
|
|
891
|
-
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
892
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/').json({ name: 'Peter', title: 'CTO' }))).json).toEqual(['Peter', 'CTO']);
|
|
893
|
-
});
|
|
894
|
-
(0, globals_1.test)('use http.response for serialization', async () => {
|
|
895
|
-
const __ΩDefaultResponse = ['title', 'P&4!M'];
|
|
896
|
-
const __ΩErrorResponse = ['message', 'P&4!M'];
|
|
897
|
-
class Controller {
|
|
898
|
-
action1() {
|
|
899
|
-
return [{ title: 'a' }, { title: '1' }];
|
|
900
|
-
}
|
|
901
|
-
action2() {
|
|
902
|
-
return [{ title: 'a' }, { title: 1 }];
|
|
903
|
-
}
|
|
904
|
-
action3() {
|
|
905
|
-
return new http_1.JSONResponse([{ message: 'error' }, { message: 1 }]).status(400);
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
Controller.__type = [() => __ΩDefaultResponse, 'action1', 'action2', 'action3', 'Pn!F0"P"0#P"0$5'];
|
|
909
|
-
__decorate([
|
|
910
|
-
decorator_1.http.GET('/action1'),
|
|
911
|
-
__metadata("design:type", Function),
|
|
912
|
-
__metadata("design:paramtypes", []),
|
|
913
|
-
__metadata("design:returntype", Array)
|
|
914
|
-
], Controller.prototype, "action1", null);
|
|
915
|
-
__decorate([
|
|
916
|
-
decorator_1.http.GET('/action2').response(200, `List`, [() => __ΩDefaultResponse, 'n!F']),
|
|
917
|
-
__metadata("design:type", Function),
|
|
918
|
-
__metadata("design:paramtypes", []),
|
|
919
|
-
__metadata("design:returntype", void 0)
|
|
920
|
-
], Controller.prototype, "action2", null);
|
|
921
|
-
__decorate([
|
|
922
|
-
decorator_1.http.GET('/action3')
|
|
923
|
-
.response(200, `List`, [() => __ΩDefaultResponse, 'n!F'])
|
|
924
|
-
.response(400, `Error`, [() => __ΩErrorResponse, 'n!F']),
|
|
925
|
-
__metadata("design:type", Function),
|
|
926
|
-
__metadata("design:paramtypes", []),
|
|
927
|
-
__metadata("design:returntype", void 0)
|
|
928
|
-
], Controller.prototype, "action3", null);
|
|
929
|
-
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
930
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/action1'))).json).toEqual([{ title: 'a' }, { title: '1' }]);
|
|
931
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/action2'))).json).toEqual([{ title: 'a' }, { title: '1' }]);
|
|
932
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/action3'))).json).toEqual([{ message: 'error' }, { message: '1' }]);
|
|
933
|
-
});
|
|
934
|
-
(0, globals_1.test)('BodyValidation', async () => {
|
|
935
|
-
class User {
|
|
936
|
-
}
|
|
937
|
-
User.__type = [() => __ΩMinLength, 3, 'username', 'P&."o!"K3#5'];
|
|
938
|
-
class AddUserDto extends User {
|
|
939
|
-
}
|
|
940
|
-
AddUserDto.__type = [() => router_1.UploadedFile, 'imageUpload', 'P7!3"85'];
|
|
941
|
-
class Controller {
|
|
942
|
-
action1(user) {
|
|
943
|
-
return user;
|
|
944
|
-
}
|
|
945
|
-
action2(user) {
|
|
946
|
-
if (user.valid()) {
|
|
947
|
-
return user.value;
|
|
948
|
-
}
|
|
949
|
-
throw new http_1.HttpBadRequestError('Invalid: ' + user.error.getErrorMessageForPath('username'));
|
|
950
|
-
}
|
|
951
|
-
action3(user) {
|
|
952
|
-
if (user.valid()) {
|
|
953
|
-
return user.value;
|
|
954
|
-
}
|
|
955
|
-
throw new http_1.HttpBadRequestError('Invalid: ' + user.error.getErrorMessageForPath('username'));
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
Controller.__type = [() => __ΩHttpBody, () => User, 'user', 'action1', () => __ΩHttpBodyValidation, () => User, () => User, 'action2', () => __ΩHttpBodyValidation, () => AddUserDto, () => User, 'action3', 'PP7"o!"2#"0$PP7&o%"2#P7\'0(PP7*o)"2#P7+0,5'];
|
|
959
|
-
__decorate([
|
|
960
|
-
decorator_1.http.POST('/action1'),
|
|
961
|
-
__metadata("design:type", Function),
|
|
962
|
-
__metadata("design:paramtypes", [Object]),
|
|
963
|
-
__metadata("design:returntype", Object)
|
|
964
|
-
], Controller.prototype, "action1", null);
|
|
965
|
-
__decorate([
|
|
966
|
-
decorator_1.http.POST('/action2'),
|
|
967
|
-
__metadata("design:type", Function),
|
|
968
|
-
__metadata("design:paramtypes", [Object]),
|
|
969
|
-
__metadata("design:returntype", User)
|
|
970
|
-
], Controller.prototype, "action2", null);
|
|
971
|
-
__decorate([
|
|
972
|
-
decorator_1.http.POST('/action3'),
|
|
973
|
-
__metadata("design:type", Function),
|
|
974
|
-
__metadata("design:paramtypes", [Object]),
|
|
975
|
-
__metadata("design:returntype", User)
|
|
976
|
-
], Controller.prototype, "action3", null);
|
|
977
|
-
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
978
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.POST('/action1').json({ username: 'Peter' }))).json).toEqual({ username: 'Peter' });
|
|
979
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.POST('/action1').json({ username: 'Pe' }))).json).toEqual({
|
|
980
|
-
errors: [{ code: 'minLength', message: 'Min length is 3', path: 'username' }], message: 'Validation error:\nusername(minLength): Min length is 3'
|
|
981
|
-
});
|
|
982
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.POST('/action2').json({ username: 'Peter' }))).json).toEqual({ username: 'Peter' });
|
|
983
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.POST('/action2').json({ username: 'Pe' }))).bodyString).toEqual(`{"message":"Invalid: Min length is 3"}`);
|
|
984
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.POST('/action3').json({ username: 'Peter' }))).json).toEqual({ username: 'Peter' });
|
|
985
|
-
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.POST('/action3').json({ username: 'Pe' }))).bodyString).toEqual(`{"message":"Invalid: Min length is 3"}`);
|
|
986
|
-
});
|
|
987
|
-
//# sourceMappingURL=router.spec.js.map
|