@venok/http 1.1.0 → 2.0.1-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.js +33 -0
- package/dist/decorators/controller.decorator.js +45 -0
- package/dist/decorators/header.decorator.js +28 -0
- package/dist/decorators/http-code.decorator.js +22 -0
- package/dist/decorators/http-params.decorator.js +63 -0
- package/dist/decorators/method.decorator.js +57 -0
- package/dist/decorators/redirect.decorator.js +28 -0
- package/dist/decorators/version.decorator.js +31 -0
- package/dist/enums/method.enum.js +32 -0
- package/dist/enums/paramtypes.enum.js +33 -0
- package/dist/enums/status.enum.js +71 -0
- package/dist/enums/version-type.enum.js +27 -0
- package/dist/exceptions/bad-gateway.exception.js +29 -0
- package/dist/exceptions/bad-request.exception.js +29 -0
- package/dist/exceptions/conflict.exception.js +29 -0
- package/dist/exceptions/expectation-failed.exception.js +29 -0
- package/dist/exceptions/failed-dependency.exception.js +29 -0
- package/dist/exceptions/forbidden.exception.js +29 -0
- package/dist/exceptions/gateway-timeout.exception.js +29 -0
- package/dist/exceptions/gone.exception.js +29 -0
- package/dist/exceptions/http-version-not-supported.exception.js +29 -0
- package/dist/exceptions/http.exception.js +94 -0
- package/dist/exceptions/im-a-teapot.exception.js +29 -0
- package/dist/exceptions/internal-server-error.exception.js +29 -0
- package/dist/exceptions/length-required.exception.js +29 -0
- package/dist/exceptions/method-not-allowed.exception.js +29 -0
- package/dist/exceptions/misdirected.exception.js +29 -0
- package/dist/exceptions/not-acceptable.exception.js +29 -0
- package/dist/exceptions/not-found.exception.js +29 -0
- package/dist/exceptions/not-implemented.exception.js +29 -0
- package/dist/exceptions/payload-too-large.exception.js +29 -0
- package/dist/exceptions/payment-required.exception.js +29 -0
- package/dist/exceptions/precondition-failed.exception.js +29 -0
- package/dist/exceptions/precondition-required.exception.js +29 -0
- package/dist/exceptions/proxy-authentication-required.exception.js +29 -0
- package/dist/exceptions/request-timeout.exception.js +29 -0
- package/dist/exceptions/requested-range-not-satisfiable.exception.js +29 -0
- package/dist/exceptions/service-unavailable.exception.js +29 -0
- package/dist/exceptions/too-many-requests.exception.js +29 -0
- package/dist/exceptions/unauthorized.exception.js +29 -0
- package/dist/exceptions/unprocessable-entity.exception.js +29 -0
- package/dist/exceptions/unsupported-media-type.exception.js +29 -0
- package/dist/exceptions/uri-too-long.exception.js +29 -0
- package/dist/filters/context.js +28 -0
- package/dist/filters/filter.js +56 -0
- package/dist/helpers/discovery.helper.js +69 -0
- package/dist/helpers/messages.helper.js +41 -0
- package/dist/helpers/middleware.helper.js +69 -0
- package/dist/helpers/path.helper.js +53 -0
- package/dist/helpers/route.helper.js +54 -0
- package/dist/http/adapter.js +294 -0
- package/dist/http/config.js +67 -0
- package/dist/http/configurable-module.js +26 -0
- package/dist/http/context.js +117 -0
- package/dist/http/explorer.js +133 -0
- package/dist/http/module.js +35 -0
- package/dist/http/starter-module.js +85 -0
- package/dist/index.d.ts +2117 -0
- package/dist/index.js +82 -0
- package/dist/interfaces/adapter.interface.js +0 -0
- package/dist/interfaces/exception.interface.js +0 -0
- package/dist/interfaces/index.js +7 -0
- package/dist/interfaces/middleware/config-proxy.interface.js +0 -0
- package/dist/interfaces/middleware/consumer.interface.js +0 -0
- package/dist/interfaces/middleware/index.js +3 -0
- package/dist/interfaces/options.interface.js +0 -0
- package/dist/interfaces/prefix.interface.js +0 -0
- package/dist/interfaces/router/definition.interface.js +0 -0
- package/dist/interfaces/router/exclude-route.interface.js +0 -0
- package/dist/interfaces/router/index.js +7 -0
- package/dist/interfaces/router/info.interface.js +0 -0
- package/dist/interfaces/router/path-metadata.interface.js +0 -0
- package/dist/interfaces/router/tree.interface.js +0 -0
- package/dist/interfaces/router/version.interface.js +21 -0
- package/dist/middleware/builder.js +96 -0
- package/dist/middleware/module.js +22 -0
- package/dist/middleware/routes-mapper.js +107 -0
- package/dist/middleware/service.js +48 -0
- package/dist/middleware/tree.js +91 -0
- package/dist/router/finder.js +64 -0
- package/dist/router/module.js +89 -0
- package/dist/router/path-factory.js +110 -0
- package/dist/symbols.js +33 -0
- package/package.json +41 -46
- package/adapter/adapter.d.ts +0 -57
- package/adapter/adapter.js +0 -58
- package/adapter/host.d.ts +0 -27
- package/adapter/host.js +0 -33
- package/application/application.d.ts +0 -18
- package/application/application.js +0 -51
- package/application/config.d.ts +0 -16
- package/application/config.js +0 -47
- package/application/http.module-defenition.d.ts +0 -8
- package/application/http.module-defenition.js +0 -6
- package/application/http.module.d.ts +0 -3
- package/application/http.module.js +0 -21
- package/application/http.service.d.ts +0 -11
- package/application/http.service.js +0 -43
- package/application/starter.d.ts +0 -41
- package/application/starter.js +0 -140
- package/constants.d.ts +0 -12
- package/constants.js +0 -15
- package/context/context.d.ts +0 -56
- package/context/context.js +0 -102
- package/context/response.controller.d.ts +0 -30
- package/context/response.controller.js +0 -86
- package/decorators/controller.decorator.d.ts +0 -82
- package/decorators/controller.decorator.js +0 -53
- package/decorators/header.decorator.d.ts +0 -12
- package/decorators/header.decorator.js +0 -23
- package/decorators/http-code.decorator.d.ts +0 -9
- package/decorators/http-code.decorator.js +0 -19
- package/decorators/index.d.ts +0 -9
- package/decorators/index.js +0 -25
- package/decorators/redirect.decorator.d.ts +0 -6
- package/decorators/redirect.decorator.js +0 -16
- package/decorators/render.decorator.d.ts +0 -10
- package/decorators/render.decorator.js +0 -20
- package/decorators/request-mapping.decorator.d.ts +0 -78
- package/decorators/request-mapping.decorator.js +0 -98
- package/decorators/route-params.decorator.d.ts +0 -378
- package/decorators/route-params.decorator.js +0 -227
- package/decorators/sse.decorator.d.ts +0 -6
- package/decorators/sse.decorator.js +0 -20
- package/decorators/version.decorator.d.ts +0 -7
- package/decorators/version.decorator.js +0 -20
- package/enums/http-status.enum.d.ts +0 -53
- package/enums/http-status.enum.js +0 -57
- package/enums/index.d.ts +0 -4
- package/enums/index.js +0 -20
- package/enums/request-method.enum.d.ts +0 -11
- package/enums/request-method.enum.js +0 -15
- package/enums/route-paramtypes.enum.d.ts +0 -14
- package/enums/route-paramtypes.enum.js +0 -18
- package/enums/version-type.enum.d.ts +0 -9
- package/enums/version-type.enum.js +0 -13
- package/errors/bad-gateway.exception.d.ts +0 -33
- package/errors/bad-gateway.exception.js +0 -41
- package/errors/bad-request.exception.d.ts +0 -33
- package/errors/bad-request.exception.js +0 -41
- package/errors/conflict.exception.d.ts +0 -33
- package/errors/conflict.exception.js +0 -41
- package/errors/forbidden.exception.d.ts +0 -33
- package/errors/forbidden.exception.js +0 -41
- package/errors/gateway-timeout.exception.d.ts +0 -33
- package/errors/gateway-timeout.exception.js +0 -41
- package/errors/gone.exception.d.ts +0 -33
- package/errors/gone.exception.js +0 -41
- package/errors/http-version-not-supported.exception.d.ts +0 -33
- package/errors/http-version-not-supported.exception.js +0 -41
- package/errors/http.exception.d.ts +0 -79
- package/errors/http.exception.js +0 -123
- package/errors/im-a-teapot.exception.d.ts +0 -36
- package/errors/im-a-teapot.exception.js +0 -44
- package/errors/index.d.ts +0 -11
- package/errors/index.js +0 -27
- package/errors/internal-server-error.exception.d.ts +0 -33
- package/errors/internal-server-error.exception.js +0 -41
- package/errors/invalid-middleware-configuration.exception.d.ts +0 -4
- package/errors/invalid-middleware-configuration.exception.js +0 -11
- package/errors/invalid-middleware.exception.d.ts +0 -4
- package/errors/invalid-middleware.exception.js +0 -11
- package/errors/not-found.exception.d.ts +0 -33
- package/errors/not-found.exception.js +0 -41
- package/errors/unknown-request-mapping.exception.d.ts +0 -5
- package/errors/unknown-request-mapping.exception.js +0 -11
- package/exceptions/messages.d.ts +0 -4
- package/exceptions/messages.js +0 -13
- package/explorers/path.explorer.d.ts +0 -8
- package/explorers/path.explorer.js +0 -38
- package/explorers/router.explorer.d.ts +0 -51
- package/explorers/router.explorer.js +0 -195
- package/factory/context-id.factory.d.ts +0 -41
- package/factory/context-id.factory.js +0 -52
- package/factory/index.d.ts +0 -4
- package/factory/index.js +0 -20
- package/factory/method.factory.d.ts +0 -5
- package/factory/method.factory.js +0 -30
- package/factory/params.factory.d.ts +0 -5
- package/factory/params.factory.js +0 -39
- package/factory/path.factory.d.ts +0 -13
- package/factory/path.factory.js +0 -95
- package/filters/context.d.ts +0 -9
- package/filters/context.js +0 -15
- package/filters/filter.d.ts +0 -22
- package/filters/filter.js +0 -78
- package/helpers/adapter.helper.d.ts +0 -27
- package/helpers/adapter.helper.js +0 -37
- package/helpers/exclude-route.helper.d.ts +0 -4
- package/helpers/exclude-route.helper.js +0 -18
- package/helpers/flatten-routes.helper.d.ts +0 -5
- package/helpers/flatten-routes.helper.js +0 -27
- package/helpers/index.d.ts +0 -6
- package/helpers/index.js +0 -22
- package/helpers/messages.helper.d.ts +0 -6
- package/helpers/messages.helper.js +0 -25
- package/helpers/path.helper.d.ts +0 -3
- package/helpers/path.helper.js +0 -13
- package/helpers/sse.helper.d.ts +0 -45
- package/helpers/sse.helper.js +0 -83
- package/index.d.ts +0 -1
- package/index.js +0 -3
- package/interfaces/http/cors.interface.d.ts +0 -58
- package/interfaces/http/cors.interface.js +0 -2
- package/interfaces/http/exception.interface.d.ts +0 -6
- package/interfaces/http/exception.interface.js +0 -2
- package/interfaces/http/exclude-route.interface.d.ts +0 -15
- package/interfaces/http/exclude-route.interface.js +0 -2
- package/interfaces/http/index.d.ts +0 -10
- package/interfaces/http/index.js +0 -26
- package/interfaces/http/message-event.interface.d.ts +0 -6
- package/interfaces/http/message-event.interface.js +0 -2
- package/interfaces/http/module.inteface.d.ts +0 -5
- package/interfaces/http/module.inteface.js +0 -2
- package/interfaces/http/options.interface.d.ts +0 -127
- package/interfaces/http/options.interface.js +0 -2
- package/interfaces/http/path-metadata.interface.d.ts +0 -31
- package/interfaces/http/path-metadata.interface.js +0 -2
- package/interfaces/http/prefix-options.interface.d.ts +0 -7
- package/interfaces/http/prefix-options.interface.js +0 -2
- package/interfaces/http/raw-request.d.ts +0 -4
- package/interfaces/http/raw-request.js +0 -2
- package/interfaces/http/routes.interface.d.ts +0 -7
- package/interfaces/http/routes.interface.js +0 -2
- package/interfaces/http/server.interface.d.ts +0 -54
- package/interfaces/http/server.interface.js +0 -2
- package/interfaces/index.d.ts +0 -3
- package/interfaces/index.js +0 -19
- package/interfaces/middleware/config-proxy.interface.d.ts +0 -23
- package/interfaces/middleware/config-proxy.interface.js +0 -2
- package/interfaces/middleware/configuration.interface.d.ts +0 -12
- package/interfaces/middleware/configuration.interface.js +0 -2
- package/interfaces/middleware/consumer.interface.d.ts +0 -16
- package/interfaces/middleware/consumer.interface.js +0 -2
- package/interfaces/middleware/index.d.ts +0 -4
- package/interfaces/middleware/index.js +0 -20
- package/interfaces/middleware/middleware.interface.d.ts +0 -7
- package/interfaces/middleware/middleware.interface.js +0 -2
- package/interfaces/router/callback-paramtypes.interface.d.ts +0 -1
- package/interfaces/router/callback-paramtypes.interface.js +0 -2
- package/interfaces/router/definition.interface.d.ts +0 -10
- package/interfaces/router/definition.interface.js +0 -2
- package/interfaces/router/index.d.ts +0 -3
- package/interfaces/router/index.js +0 -19
- package/interfaces/router/version-options.interface.d.ts +0 -92
- package/interfaces/router/version-options.interface.js +0 -9
- package/middleware/builder.d.ts +0 -15
- package/middleware/builder.js +0 -78
- package/middleware/container.d.ts +0 -13
- package/middleware/container.js +0 -50
- package/middleware/extractor.d.ts +0 -15
- package/middleware/extractor.js +0 -50
- package/middleware/index.d.ts +0 -1
- package/middleware/index.js +0 -17
- package/middleware/module.d.ts +0 -33
- package/middleware/module.js +0 -180
- package/middleware/resolver.d.ts +0 -10
- package/middleware/resolver.js +0 -27
- package/middleware/routes-mapper.d.ts +0 -19
- package/middleware/routes-mapper.js +0 -111
- package/middleware/utils.d.ts +0 -8
- package/middleware/utils.js +0 -86
- package/router/module.d.ts +0 -18
- package/router/module.js +0 -88
- package/router/resolver.d.ts +0 -31
- package/router/resolver.js +0 -128
- package/storage/http-instance.storage.d.ts +0 -9
- package/storage/http-instance.storage.js +0 -19
- package/stream/index.d.ts +0 -1
- package/stream/index.js +0 -17
- package/stream/interfaces/index.d.ts +0 -2
- package/stream/interfaces/index.js +0 -18
- package/stream/interfaces/streamable-handler-response.interface.d.ts +0 -12
- package/stream/interfaces/streamable-handler-response.interface.js +0 -2
- package/stream/interfaces/streamable-options.interface.d.ts +0 -10
- package/stream/interfaces/streamable-options.interface.js +0 -2
- package/stream/streamable-file.d.ts +0 -22
- package/stream/streamable-file.js +0 -55
- package/test/context/response.controller.spec.d.ts +0 -1
- package/test/context/response.controller.spec.js +0 -328
- package/test/decorators/controller.decorator.spec.d.ts +0 -1
- package/test/decorators/controller.decorator.spec.js +0 -113
- package/test/decorators/header.decorator.spec.d.ts +0 -1
- package/test/decorators/header.decorator.spec.js +0 -33
- package/test/decorators/http-code.decorator.spec.d.ts +0 -1
- package/test/decorators/http-code.decorator.spec.js +0 -30
- package/test/decorators/redirect.decorator.spec.d.ts +0 -1
- package/test/decorators/redirect.decorator.spec.js +0 -36
- package/test/decorators/render.decorator.spec.d.ts +0 -1
- package/test/decorators/render.decorator.spec.js +0 -30
- package/test/decorators/request-mapping.decorator.spec.d.ts +0 -1
- package/test/decorators/request-mapping.decorator.spec.js +0 -85
- package/test/decorators/route-params.decorator.spec.d.ts +0 -1
- package/test/decorators/route-params.decorator.spec.js +0 -493
- package/test/decorators/sse.decorator.spec.d.ts +0 -1
- package/test/decorators/sse.decorator.spec.js +0 -35
- package/test/decorators/version.decorator.spec.d.ts +0 -1
- package/test/decorators/version.decorator.spec.js +0 -43
- package/test/exceptions/handler.spec.d.ts +0 -1
- package/test/exceptions/handler.spec.js +0 -145
- package/test/exceptions/proxy.spec.d.ts +0 -1
- package/test/exceptions/proxy.spec.js +0 -74
- package/test/explorers/path.explorer.spec.d.ts +0 -1
- package/test/explorers/path.explorer.spec.js +0 -190
- package/test/explorers/router.explorer.spec.d.ts +0 -1
- package/test/explorers/router.explorer.spec.js +0 -206
- package/test/factory/method.factory.spec.d.ts +0 -1
- package/test/factory/method.factory.spec.js +0 -33
- package/test/factory/params.factory.spec.d.ts +0 -1
- package/test/factory/params.factory.spec.js +0 -104
- package/test/factory/path.factory.spec.d.ts +0 -1
- package/test/factory/path.factory.spec.js +0 -260
- package/test/filters/context.spec.d.ts +0 -1
- package/test/filters/context.spec.js +0 -96
- package/test/filters/filter.spec.d.ts +0 -1
- package/test/filters/filter.spec.js +0 -96
- package/test/helpers/flatten-routes.helper.spec.d.ts +0 -1
- package/test/helpers/flatten-routes.helper.spec.js +0 -131
- package/test/helpers/sse.helper.spec.d.ts +0 -1
- package/test/helpers/sse.helper.spec.js +0 -132
- package/test/middleware/builder.spec.d.ts +0 -1
- package/test/middleware/builder.spec.js +0 -235
- package/test/middleware/container.spec.d.ts +0 -1
- package/test/middleware/container.spec.js +0 -81
- package/test/middleware/module.spec.d.ts +0 -1
- package/test/middleware/module.spec.js +0 -206
- package/test/middleware/route-info-path-extractor.spec.d.ts +0 -1
- package/test/middleware/route-info-path-extractor.spec.js +0 -123
- package/test/middleware/routes-mapper.spec.d.ts +0 -1
- package/test/middleware/routes-mapper.spec.js +0 -162
- package/test/middleware/utils.spec.d.ts +0 -1
- package/test/middleware/utils.spec.js +0 -132
- package/test/router/module.spec.d.ts +0 -1
- package/test/router/module.spec.js +0 -40
- package/test/router/resolver.spec.d.ts +0 -1
- package/test/router/resolver.spec.js +0 -326
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const chai_1 = require("chai");
|
|
4
|
-
const params_factory_1 = require("@venok/http/factory/params.factory");
|
|
5
|
-
const enums_1 = require("@venok/http/enums");
|
|
6
|
-
describe("RouteParamsFactory", () => {
|
|
7
|
-
let factory;
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
factory = new params_factory_1.RouteParamsFactory();
|
|
10
|
-
});
|
|
11
|
-
describe("exchangeKeyForValue", () => {
|
|
12
|
-
const res = {};
|
|
13
|
-
const next = () => ({});
|
|
14
|
-
const req = {
|
|
15
|
-
ip: "ip",
|
|
16
|
-
session: null,
|
|
17
|
-
body: {
|
|
18
|
-
foo: "bar",
|
|
19
|
-
},
|
|
20
|
-
headers: {
|
|
21
|
-
foo: "bar",
|
|
22
|
-
},
|
|
23
|
-
params: {
|
|
24
|
-
foo: "bar",
|
|
25
|
-
},
|
|
26
|
-
hosts: {
|
|
27
|
-
foo: "bar",
|
|
28
|
-
},
|
|
29
|
-
query: {
|
|
30
|
-
foo: "bar",
|
|
31
|
-
},
|
|
32
|
-
file: "file",
|
|
33
|
-
files: "files",
|
|
34
|
-
};
|
|
35
|
-
describe("when key is", () => {
|
|
36
|
-
const args = [null, [req, res, next]];
|
|
37
|
-
describe(`RouteParamtypes.NEXT`, () => {
|
|
38
|
-
it("should return next object", () => {
|
|
39
|
-
(0, chai_1.expect)(factory.exchangeKeyForValue(enums_1.RouteParamtypes.NEXT, ...args)).to.be.eql(next);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
describe(`RouteParamtypes.RESPONSE`, () => {
|
|
43
|
-
it("should return response object", () => {
|
|
44
|
-
(0, chai_1.expect)(factory.exchangeKeyForValue(enums_1.RouteParamtypes.RESPONSE, ...args)).to.be.eql(res);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
describe(`RouteParamtypes.REQUEST`, () => {
|
|
48
|
-
it("should return request object", () => {
|
|
49
|
-
(0, chai_1.expect)(factory.exchangeKeyForValue(enums_1.RouteParamtypes.REQUEST, ...args)).to.be.eql(req);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
describe(`RouteParamtypes.BODY`, () => {
|
|
53
|
-
it("should return body object", () => {
|
|
54
|
-
(0, chai_1.expect)(factory.exchangeKeyForValue(enums_1.RouteParamtypes.BODY, ...args)).to.be.eql(req.body);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
describe(`RouteParamtypes.HEADERS`, () => {
|
|
58
|
-
it("should return headers object", () => {
|
|
59
|
-
(0, chai_1.expect)(factory.exchangeKeyForValue(enums_1.RouteParamtypes.HEADERS, ...args)).to.be.eql(req.headers);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
describe(`RouteParamtypes.IP`, () => {
|
|
63
|
-
it("should return ip property", () => {
|
|
64
|
-
(0, chai_1.expect)(factory.exchangeKeyForValue(enums_1.RouteParamtypes.IP, ...args)).to.be.equal(req.ip);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
describe(`RouteParamtypes.SESSION`, () => {
|
|
68
|
-
it("should return session object", () => {
|
|
69
|
-
(0, chai_1.expect)(factory.exchangeKeyForValue(enums_1.RouteParamtypes.SESSION, ...args)).to.be.eql(req.session);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
describe(`RouteParamtypes.QUERY`, () => {
|
|
73
|
-
it("should return query object", () => {
|
|
74
|
-
(0, chai_1.expect)(factory.exchangeKeyForValue(enums_1.RouteParamtypes.QUERY, ...args)).to.be.eql(req.query);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
describe(`RouteParamtypes.PARAM`, () => {
|
|
78
|
-
it("should return params object", () => {
|
|
79
|
-
(0, chai_1.expect)(factory.exchangeKeyForValue(enums_1.RouteParamtypes.PARAM, ...args)).to.be.eql(req.params);
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
describe(`RouteParamtypes.HOST`, () => {
|
|
83
|
-
it("should return hosts object", () => {
|
|
84
|
-
(0, chai_1.expect)(factory.exchangeKeyForValue(enums_1.RouteParamtypes.HOST, ...args)).to.be.eql(req.hosts);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
describe(`RouteParamtypes.FILE`, () => {
|
|
88
|
-
it("should return file object", () => {
|
|
89
|
-
(0, chai_1.expect)(factory.exchangeKeyForValue(enums_1.RouteParamtypes.FILE, ...args)).to.be.eql(req.file);
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
describe(`RouteParamtypes.FILES`, () => {
|
|
93
|
-
it("should return files object", () => {
|
|
94
|
-
(0, chai_1.expect)(factory.exchangeKeyForValue(enums_1.RouteParamtypes.FILES, ...args)).to.be.eql(req.files);
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
describe("not available", () => {
|
|
98
|
-
it("should return null", () => {
|
|
99
|
-
(0, chai_1.expect)(factory.exchangeKeyForValue(-1, ...args)).to.be.eql(null);
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const chai_1 = require("chai");
|
|
7
|
-
const path_to_regexp_1 = require("path-to-regexp");
|
|
8
|
-
const sinon_1 = __importDefault(require("sinon"));
|
|
9
|
-
const factory_1 = require("../../factory");
|
|
10
|
-
const enums_1 = require("../../enums");
|
|
11
|
-
const interfaces_1 = require("../../interfaces");
|
|
12
|
-
const config_1 = require("../../application/config");
|
|
13
|
-
describe("RoutePathFactory", () => {
|
|
14
|
-
let routePathFactory;
|
|
15
|
-
let httpConfig;
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
httpConfig = new config_1.HttpConfig();
|
|
18
|
-
routePathFactory = new factory_1.RoutePathFactory(httpConfig);
|
|
19
|
-
});
|
|
20
|
-
describe("create", () => {
|
|
21
|
-
it("should return valid, concatenated paths (various combinations)", () => {
|
|
22
|
-
(0, chai_1.expect)(routePathFactory.create({
|
|
23
|
-
ctrlPath: "ctrlPath/",
|
|
24
|
-
methodPath: "",
|
|
25
|
-
})).to.deep.equal(["/ctrlPath"]);
|
|
26
|
-
(0, chai_1.expect)(routePathFactory.create({
|
|
27
|
-
ctrlPath: "/ctrlPath",
|
|
28
|
-
methodPath: "",
|
|
29
|
-
})).to.deep.equal(["/ctrlPath"]);
|
|
30
|
-
(0, chai_1.expect)(routePathFactory.create({
|
|
31
|
-
ctrlPath: "/ctrlPath/",
|
|
32
|
-
methodPath: "/methodPath",
|
|
33
|
-
})).to.deep.equal(["/ctrlPath/methodPath"]);
|
|
34
|
-
(0, chai_1.expect)(routePathFactory.create({
|
|
35
|
-
ctrlPath: "ctrlPath/",
|
|
36
|
-
methodPath: "methodPath/",
|
|
37
|
-
})).to.deep.equal(["/ctrlPath/methodPath"]);
|
|
38
|
-
(0, chai_1.expect)(routePathFactory.create({
|
|
39
|
-
ctrlPath: "ctrlPath/",
|
|
40
|
-
methodPath: "methodPath",
|
|
41
|
-
modulePath: "modulePath",
|
|
42
|
-
})).to.deep.equal(["/modulePath/ctrlPath/methodPath"]);
|
|
43
|
-
(0, chai_1.expect)(routePathFactory.create({
|
|
44
|
-
ctrlPath: "ctrlPath/",
|
|
45
|
-
methodPath: "methodPath",
|
|
46
|
-
modulePath: "/modulePath",
|
|
47
|
-
})).to.deep.equal(["/modulePath/ctrlPath/methodPath"]);
|
|
48
|
-
(0, chai_1.expect)(routePathFactory.create({
|
|
49
|
-
ctrlPath: "/ctrlPath/",
|
|
50
|
-
methodPath: "/methodPath/",
|
|
51
|
-
modulePath: "/modulePath/",
|
|
52
|
-
})).to.deep.equal(["/modulePath/ctrlPath/methodPath"]);
|
|
53
|
-
(0, chai_1.expect)(routePathFactory.create({
|
|
54
|
-
ctrlPath: "/ctrlPath/",
|
|
55
|
-
methodPath: "/methodPath/",
|
|
56
|
-
modulePath: "/modulePath/",
|
|
57
|
-
globalPrefix: "api",
|
|
58
|
-
})).to.deep.equal(["/api/modulePath/ctrlPath/methodPath"]);
|
|
59
|
-
(0, chai_1.expect)(routePathFactory.create({
|
|
60
|
-
ctrlPath: "/ctrlPath/",
|
|
61
|
-
methodPath: "/methodPath/",
|
|
62
|
-
modulePath: "/modulePath/",
|
|
63
|
-
globalPrefix: "/api",
|
|
64
|
-
})).to.deep.equal(["/api/modulePath/ctrlPath/methodPath"]);
|
|
65
|
-
(0, chai_1.expect)(routePathFactory.create({
|
|
66
|
-
ctrlPath: "/ctrlPath/",
|
|
67
|
-
methodPath: "/methodPath/",
|
|
68
|
-
modulePath: "/modulePath/",
|
|
69
|
-
globalPrefix: "/api",
|
|
70
|
-
versioningOptions: {
|
|
71
|
-
type: enums_1.VersioningType.HEADER,
|
|
72
|
-
header: "x",
|
|
73
|
-
},
|
|
74
|
-
methodVersion: "1.0.0",
|
|
75
|
-
controllerVersion: "1.1.1",
|
|
76
|
-
})).to.deep.equal(["/api/modulePath/ctrlPath/methodPath"]);
|
|
77
|
-
(0, chai_1.expect)(routePathFactory.create({
|
|
78
|
-
ctrlPath: "/ctrlPath/",
|
|
79
|
-
methodPath: "/methodPath/",
|
|
80
|
-
modulePath: "/modulePath/",
|
|
81
|
-
globalPrefix: "/api/",
|
|
82
|
-
versioningOptions: {
|
|
83
|
-
type: enums_1.VersioningType.URI,
|
|
84
|
-
},
|
|
85
|
-
methodVersion: "1.0.0",
|
|
86
|
-
controllerVersion: "1.1.1",
|
|
87
|
-
})).to.deep.equal(["/api/v1.0.0/modulePath/ctrlPath/methodPath"]);
|
|
88
|
-
(0, chai_1.expect)(routePathFactory.create({
|
|
89
|
-
ctrlPath: "/ctrlPath/",
|
|
90
|
-
methodPath: "/methodPath/",
|
|
91
|
-
modulePath: "/modulePath/",
|
|
92
|
-
versioningOptions: {
|
|
93
|
-
type: enums_1.VersioningType.URI,
|
|
94
|
-
},
|
|
95
|
-
methodVersion: "1.0.0",
|
|
96
|
-
controllerVersion: "1.1.1",
|
|
97
|
-
})).to.deep.equal(["/v1.0.0/modulePath/ctrlPath/methodPath"]);
|
|
98
|
-
(0, chai_1.expect)(routePathFactory.create({
|
|
99
|
-
ctrlPath: "/ctrlPath/",
|
|
100
|
-
methodPath: "/methodPath/",
|
|
101
|
-
globalPrefix: "/api",
|
|
102
|
-
versioningOptions: {
|
|
103
|
-
type: enums_1.VersioningType.URI,
|
|
104
|
-
},
|
|
105
|
-
methodVersion: "1.0.0",
|
|
106
|
-
controllerVersion: "1.1.1",
|
|
107
|
-
})).to.deep.equal(["/api/v1.0.0/ctrlPath/methodPath"]);
|
|
108
|
-
(0, chai_1.expect)(routePathFactory.create({
|
|
109
|
-
ctrlPath: "/ctrlPath/",
|
|
110
|
-
methodPath: "/methodPath/",
|
|
111
|
-
globalPrefix: "/api",
|
|
112
|
-
versioningOptions: {
|
|
113
|
-
type: enums_1.VersioningType.URI,
|
|
114
|
-
},
|
|
115
|
-
controllerVersion: "1.1.1",
|
|
116
|
-
})).to.deep.equal(["/api/v1.1.1/ctrlPath/methodPath"]);
|
|
117
|
-
(0, chai_1.expect)(routePathFactory.create({
|
|
118
|
-
ctrlPath: "/ctrlPath/",
|
|
119
|
-
methodPath: "/methodPath/",
|
|
120
|
-
globalPrefix: "/api",
|
|
121
|
-
versioningOptions: {
|
|
122
|
-
type: enums_1.VersioningType.URI,
|
|
123
|
-
},
|
|
124
|
-
controllerVersion: ["1.1.1", "1.2.3"],
|
|
125
|
-
})).to.deep.equal(["/api/v1.1.1/ctrlPath/methodPath", "/api/v1.2.3/ctrlPath/methodPath"]);
|
|
126
|
-
(0, chai_1.expect)(routePathFactory.create({
|
|
127
|
-
ctrlPath: "",
|
|
128
|
-
methodPath: "",
|
|
129
|
-
globalPrefix: "/api",
|
|
130
|
-
versioningOptions: {
|
|
131
|
-
type: enums_1.VersioningType.URI,
|
|
132
|
-
},
|
|
133
|
-
controllerVersion: ["1.1.1", "1.2.3"],
|
|
134
|
-
})).to.deep.equal(["/api/v1.1.1", "/api/v1.2.3"]);
|
|
135
|
-
(0, chai_1.expect)(routePathFactory.create({
|
|
136
|
-
ctrlPath: "",
|
|
137
|
-
methodPath: "",
|
|
138
|
-
globalPrefix: "",
|
|
139
|
-
controllerVersion: interfaces_1.VERSION_NEUTRAL,
|
|
140
|
-
versioningOptions: {
|
|
141
|
-
type: enums_1.VersioningType.URI,
|
|
142
|
-
defaultVersion: interfaces_1.VERSION_NEUTRAL,
|
|
143
|
-
},
|
|
144
|
-
})).to.deep.equal(["/"]);
|
|
145
|
-
(0, chai_1.expect)(routePathFactory.create({
|
|
146
|
-
ctrlPath: "",
|
|
147
|
-
methodPath: "",
|
|
148
|
-
globalPrefix: "",
|
|
149
|
-
controllerVersion: ["1", interfaces_1.VERSION_NEUTRAL],
|
|
150
|
-
versioningOptions: {
|
|
151
|
-
type: enums_1.VersioningType.URI,
|
|
152
|
-
defaultVersion: ["1", interfaces_1.VERSION_NEUTRAL],
|
|
153
|
-
},
|
|
154
|
-
})).to.deep.equal(["/v1", "/"]);
|
|
155
|
-
(0, chai_1.expect)(routePathFactory.create({
|
|
156
|
-
ctrlPath: "",
|
|
157
|
-
methodPath: "",
|
|
158
|
-
globalPrefix: "",
|
|
159
|
-
})).to.deep.equal(["/"]);
|
|
160
|
-
sinon_1.default.stub(routePathFactory, "isExcludedFromGlobalPrefix").returns(true);
|
|
161
|
-
(0, chai_1.expect)(routePathFactory.create({
|
|
162
|
-
ctrlPath: "/ctrlPath/",
|
|
163
|
-
methodPath: "/",
|
|
164
|
-
modulePath: "/",
|
|
165
|
-
globalPrefix: "/api",
|
|
166
|
-
})).to.deep.equal(["/ctrlPath"]);
|
|
167
|
-
sinon_1.default.restore();
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
describe("isExcludedFromGlobalPrefix", () => {
|
|
171
|
-
describe("when there is no exclude configuration", () => {
|
|
172
|
-
it("should return false", () => {
|
|
173
|
-
sinon_1.default.stub(httpConfig, "getGlobalPrefixOptions").returns({
|
|
174
|
-
exclude: undefined,
|
|
175
|
-
});
|
|
176
|
-
(0, chai_1.expect)(routePathFactory.isExcludedFromGlobalPrefix("/cats", enums_1.RequestMethod.GET)).to.be.false;
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
describe("otherwise", () => {
|
|
180
|
-
describe("when route is not excluded", () => {
|
|
181
|
-
it("should return false", () => {
|
|
182
|
-
sinon_1.default.stub(httpConfig, "getGlobalPrefixOptions").returns({
|
|
183
|
-
exclude: [
|
|
184
|
-
{
|
|
185
|
-
path: "/random",
|
|
186
|
-
pathRegex: (0, path_to_regexp_1.pathToRegexp)("/random"),
|
|
187
|
-
requestMethod: enums_1.RequestMethod.ALL,
|
|
188
|
-
},
|
|
189
|
-
],
|
|
190
|
-
});
|
|
191
|
-
(0, chai_1.expect)(routePathFactory.isExcludedFromGlobalPrefix("/cats", enums_1.RequestMethod.GET)).to.be.false;
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
describe("when route is excluded (by path)", () => {
|
|
195
|
-
it("should return true", () => {
|
|
196
|
-
sinon_1.default.stub(httpConfig, "getGlobalPrefixOptions").returns({
|
|
197
|
-
exclude: [
|
|
198
|
-
{
|
|
199
|
-
path: "/cats",
|
|
200
|
-
pathRegex: (0, path_to_regexp_1.pathToRegexp)("/cats"),
|
|
201
|
-
requestMethod: enums_1.RequestMethod.ALL,
|
|
202
|
-
},
|
|
203
|
-
],
|
|
204
|
-
});
|
|
205
|
-
(0, chai_1.expect)(routePathFactory.isExcludedFromGlobalPrefix("/cats", enums_1.RequestMethod.GET)).to.be.true;
|
|
206
|
-
});
|
|
207
|
-
describe("when route is excluded (by method and path)", () => {
|
|
208
|
-
it("should return true", () => {
|
|
209
|
-
sinon_1.default.stub(httpConfig, "getGlobalPrefixOptions").returns({
|
|
210
|
-
exclude: [
|
|
211
|
-
{
|
|
212
|
-
path: "/cats",
|
|
213
|
-
pathRegex: (0, path_to_regexp_1.pathToRegexp)("/cats"),
|
|
214
|
-
requestMethod: enums_1.RequestMethod.GET,
|
|
215
|
-
},
|
|
216
|
-
],
|
|
217
|
-
});
|
|
218
|
-
(0, chai_1.expect)(routePathFactory.isExcludedFromGlobalPrefix("/cats", enums_1.RequestMethod.GET)).to.be.true;
|
|
219
|
-
(0, chai_1.expect)(routePathFactory.isExcludedFromGlobalPrefix("/cats", enums_1.RequestMethod.POST)).to.be.false;
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
describe("getVersionPrefix", () => {
|
|
226
|
-
describe("when URI versioning is enabled", () => {
|
|
227
|
-
describe("and prefix is disabled", () => {
|
|
228
|
-
it("should return empty string", () => {
|
|
229
|
-
(0, chai_1.expect)(routePathFactory.getVersionPrefix({
|
|
230
|
-
type: enums_1.VersioningType.URI,
|
|
231
|
-
prefix: false,
|
|
232
|
-
})).to.equal("");
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
describe("and prefix is undefined", () => {
|
|
236
|
-
it("should return the default prefix", () => {
|
|
237
|
-
(0, chai_1.expect)(routePathFactory.getVersionPrefix({
|
|
238
|
-
type: enums_1.VersioningType.URI,
|
|
239
|
-
})).to.equal("v");
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
describe("and prefix is specified", () => {
|
|
243
|
-
it("should return it", () => {
|
|
244
|
-
(0, chai_1.expect)(routePathFactory.getVersionPrefix({
|
|
245
|
-
type: enums_1.VersioningType.URI,
|
|
246
|
-
prefix: "test",
|
|
247
|
-
})).to.equal("test");
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
describe("when URI versioning is disabled", () => {
|
|
252
|
-
it("should return default prefix", () => {
|
|
253
|
-
(0, chai_1.expect)(routePathFactory.getVersionPrefix({
|
|
254
|
-
type: enums_1.VersioningType.HEADER,
|
|
255
|
-
header: "X",
|
|
256
|
-
})).to.equal("v");
|
|
257
|
-
});
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,96 +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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const chai_1 = require("chai");
|
|
13
|
-
const sinon_1 = __importDefault(require("sinon"));
|
|
14
|
-
const core_1 = require("../../../core");
|
|
15
|
-
const context_1 = require("../../filters/context");
|
|
16
|
-
const helpers_1 = require("../../helpers");
|
|
17
|
-
const wrapper_1 = require("../../../core/injector/instance/wrapper");
|
|
18
|
-
const filter_1 = require("../../filters/filter");
|
|
19
|
-
describe("RouterExceptionFiltersContext", () => {
|
|
20
|
-
let applicationConfig;
|
|
21
|
-
let exceptionFilter;
|
|
22
|
-
class CustomException {
|
|
23
|
-
}
|
|
24
|
-
let ExceptionFilter = class ExceptionFilter {
|
|
25
|
-
catch(exc, res) { }
|
|
26
|
-
};
|
|
27
|
-
ExceptionFilter = __decorate([
|
|
28
|
-
(0, core_1.Catch)(CustomException)
|
|
29
|
-
], ExceptionFilter);
|
|
30
|
-
beforeEach(() => {
|
|
31
|
-
applicationConfig = new core_1.ApplicationConfig();
|
|
32
|
-
exceptionFilter = new context_1.RouterExceptionFiltersContext(new core_1.VenokContainer(), applicationConfig,
|
|
33
|
-
// new HttpConfig(),
|
|
34
|
-
new helpers_1.NoopHttpAdapter({}));
|
|
35
|
-
});
|
|
36
|
-
describe("create", () => {
|
|
37
|
-
describe("when filters metadata is empty", () => {
|
|
38
|
-
class EmptyMetadata {
|
|
39
|
-
}
|
|
40
|
-
beforeEach(() => {
|
|
41
|
-
sinon_1.default.stub(exceptionFilter, "createContext").returns([]);
|
|
42
|
-
});
|
|
43
|
-
it("should return plain ExceptionHandler object", () => {
|
|
44
|
-
const filter = exceptionFilter.create(new EmptyMetadata(), () => ({}), undefined);
|
|
45
|
-
(0, chai_1.expect)(filter.filters).to.be.empty;
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
describe("when filters metadata is not empty", () => {
|
|
49
|
-
let WithMetadata = class WithMetadata {
|
|
50
|
-
};
|
|
51
|
-
WithMetadata = __decorate([
|
|
52
|
-
(0, core_1.UseFilters)(new filter_1.HttpExceptionFilter())
|
|
53
|
-
], WithMetadata);
|
|
54
|
-
it("should return ExceptionHandler object with exception filters", () => {
|
|
55
|
-
const filter = exceptionFilter.create(new WithMetadata(), () => ({}), undefined);
|
|
56
|
-
(0, chai_1.expect)(filter.filters).to.not.be.empty;
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
describe("reflectCatchExceptions", () => {
|
|
61
|
-
it("should return FILTER_CATCH_EXCEPTIONS metadata", () => {
|
|
62
|
-
(0, chai_1.expect)(exceptionFilter.reflectCatchExceptions(new ExceptionFilter())).to.be.eql([CustomException]);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
describe("createConcreteContext", () => {
|
|
66
|
-
class InvalidFilter {
|
|
67
|
-
}
|
|
68
|
-
const filters = [new ExceptionFilter(), new InvalidFilter(), "test"];
|
|
69
|
-
it("should return expected exception filters metadata", () => {
|
|
70
|
-
const resolved = exceptionFilter.createConcreteContext(filters);
|
|
71
|
-
(0, chai_1.expect)(resolved).to.have.length(1);
|
|
72
|
-
(0, chai_1.expect)(resolved[0].exceptionMetatypes).to.be.deep.equal([CustomException]);
|
|
73
|
-
(0, chai_1.expect)(resolved[0].func).to.be.a("function");
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
describe("getGlobalMetadata", () => {
|
|
77
|
-
describe("when contextId is static and inquirerId is nil", () => {
|
|
78
|
-
it("should return global filters", () => {
|
|
79
|
-
const expectedResult = applicationConfig.getGlobalFilters();
|
|
80
|
-
(0, chai_1.expect)(exceptionFilter.getGlobalMetadata()).to.be.equal(expectedResult);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
describe("otherwise", () => {
|
|
84
|
-
it("should merge static global with request/transient scoped filters", () => {
|
|
85
|
-
const globalFilters = ["test"];
|
|
86
|
-
const instanceWrapper = new wrapper_1.InstanceWrapper();
|
|
87
|
-
const instance = "request-scoped";
|
|
88
|
-
const scopedFilterWrappers = [instanceWrapper];
|
|
89
|
-
sinon_1.default.stub(applicationConfig, "getGlobalFilters").callsFake(() => globalFilters);
|
|
90
|
-
sinon_1.default.stub(applicationConfig, "getGlobalRequestFilters").callsFake(() => scopedFilterWrappers);
|
|
91
|
-
sinon_1.default.stub(instanceWrapper, "getInstanceByContextId").callsFake(() => ({ instance }));
|
|
92
|
-
(0, chai_1.expect)(exceptionFilter.getGlobalMetadata({ id: 3 })).to.contains(instance, ...globalFilters);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,96 +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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const chai_1 = require("chai");
|
|
13
|
-
const sinon_1 = __importDefault(require("sinon"));
|
|
14
|
-
const core_1 = require("../../../core");
|
|
15
|
-
const context_1 = require("../../filters/context");
|
|
16
|
-
const config_1 = require("../../application/config");
|
|
17
|
-
const helpers_1 = require("../../helpers");
|
|
18
|
-
const wrapper_1 = require("../../../core/injector/instance/wrapper");
|
|
19
|
-
describe("RouterExceptionFiltersContext", () => {
|
|
20
|
-
let applicationConfig;
|
|
21
|
-
let httpConfig;
|
|
22
|
-
let exceptionFilter;
|
|
23
|
-
class CustomException {
|
|
24
|
-
}
|
|
25
|
-
let ExceptionFilter = class ExceptionFilter {
|
|
26
|
-
catch(exc, res) { }
|
|
27
|
-
};
|
|
28
|
-
ExceptionFilter = __decorate([
|
|
29
|
-
(0, core_1.Catch)(CustomException)
|
|
30
|
-
], ExceptionFilter);
|
|
31
|
-
beforeEach(() => {
|
|
32
|
-
applicationConfig = new core_1.ApplicationConfig();
|
|
33
|
-
httpConfig = new config_1.HttpConfig();
|
|
34
|
-
exceptionFilter = new context_1.RouterExceptionFiltersContext(new core_1.VenokContainer(), applicationConfig, new helpers_1.NoopHttpAdapter({}));
|
|
35
|
-
});
|
|
36
|
-
describe("create", () => {
|
|
37
|
-
describe("when filters metadata is empty", () => {
|
|
38
|
-
class EmptyMetadata {
|
|
39
|
-
}
|
|
40
|
-
beforeEach(() => {
|
|
41
|
-
sinon_1.default.stub(exceptionFilter, "createContext").returns([]);
|
|
42
|
-
});
|
|
43
|
-
it("should return plain ExceptionHandler object", () => {
|
|
44
|
-
const filter = exceptionFilter.create(new EmptyMetadata(), () => ({}), undefined);
|
|
45
|
-
(0, chai_1.expect)(filter.filters).to.be.empty;
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
describe("when filters metadata is not empty", () => {
|
|
49
|
-
let WithMetadata = class WithMetadata {
|
|
50
|
-
};
|
|
51
|
-
WithMetadata = __decorate([
|
|
52
|
-
(0, core_1.UseFilters)(new ExceptionFilter())
|
|
53
|
-
], WithMetadata);
|
|
54
|
-
it("should return ExceptionHandler object with exception filters", () => {
|
|
55
|
-
const filter = exceptionFilter.create(new WithMetadata(), () => ({}), undefined);
|
|
56
|
-
(0, chai_1.expect)(filter.filters).to.not.be.empty;
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
describe("reflectCatchExceptions", () => {
|
|
61
|
-
it("should return FILTER_CATCH_EXCEPTIONS metadata", () => {
|
|
62
|
-
(0, chai_1.expect)(exceptionFilter.reflectCatchExceptions(new ExceptionFilter())).to.be.eql([CustomException]);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
describe("createConcreteContext", () => {
|
|
66
|
-
class InvalidFilter {
|
|
67
|
-
}
|
|
68
|
-
const filters = [new ExceptionFilter(), new InvalidFilter(), "test"];
|
|
69
|
-
it("should return expected exception filters metadata", () => {
|
|
70
|
-
const resolved = exceptionFilter.createConcreteContext(filters);
|
|
71
|
-
(0, chai_1.expect)(resolved).to.have.length(1);
|
|
72
|
-
(0, chai_1.expect)(resolved[0].exceptionMetatypes).to.be.deep.equal([CustomException]);
|
|
73
|
-
(0, chai_1.expect)(resolved[0].func).to.be.a("function");
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
describe("getGlobalMetadata", () => {
|
|
77
|
-
describe("when contextId is static and inquirerId is nil", () => {
|
|
78
|
-
it("should return global filters", () => {
|
|
79
|
-
const expectedResult = applicationConfig.getGlobalFilters();
|
|
80
|
-
(0, chai_1.expect)(exceptionFilter.getGlobalMetadata()).to.be.equal(expectedResult);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
describe("otherwise", () => {
|
|
84
|
-
it("should merge static global with request/transient scoped filters", () => {
|
|
85
|
-
const globalFilters = ["test"];
|
|
86
|
-
const instanceWrapper = new wrapper_1.InstanceWrapper();
|
|
87
|
-
const instance = "request-scoped";
|
|
88
|
-
const scopedFilterWrappers = [instanceWrapper];
|
|
89
|
-
sinon_1.default.stub(applicationConfig, "getGlobalFilters").callsFake(() => globalFilters);
|
|
90
|
-
sinon_1.default.stub(applicationConfig, "getGlobalRequestFilters").callsFake(() => scopedFilterWrappers);
|
|
91
|
-
sinon_1.default.stub(instanceWrapper, "getInstanceByContextId").callsFake(() => ({ instance }));
|
|
92
|
-
(0, chai_1.expect)(exceptionFilter.getGlobalMetadata({ id: 3 })).to.contains(instance, ...globalFilters);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|