@venok/http 1.0.1-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (254) hide show
  1. package/adapter/adapter.d.ts +57 -0
  2. package/adapter/adapter.js +58 -0
  3. package/adapter/host.d.ts +27 -0
  4. package/adapter/host.js +33 -0
  5. package/application/application.d.ts +18 -0
  6. package/application/application.js +51 -0
  7. package/application/config.d.ts +16 -0
  8. package/application/config.js +47 -0
  9. package/application/http.module-defenition.d.ts +8 -0
  10. package/application/http.module-defenition.js +6 -0
  11. package/application/http.module.d.ts +3 -0
  12. package/application/http.module.js +21 -0
  13. package/application/http.service.d.ts +11 -0
  14. package/application/http.service.js +43 -0
  15. package/application/starter.d.ts +41 -0
  16. package/application/starter.js +140 -0
  17. package/constants.d.ts +12 -0
  18. package/constants.js +15 -0
  19. package/context/context.d.ts +56 -0
  20. package/context/context.js +102 -0
  21. package/context/response.controller.d.ts +30 -0
  22. package/context/response.controller.js +86 -0
  23. package/decorators/controller.decorator.d.ts +82 -0
  24. package/decorators/controller.decorator.js +53 -0
  25. package/decorators/header.decorator.d.ts +12 -0
  26. package/decorators/header.decorator.js +23 -0
  27. package/decorators/http-code.decorator.d.ts +9 -0
  28. package/decorators/http-code.decorator.js +19 -0
  29. package/decorators/index.d.ts +9 -0
  30. package/decorators/index.js +25 -0
  31. package/decorators/redirect.decorator.d.ts +6 -0
  32. package/decorators/redirect.decorator.js +16 -0
  33. package/decorators/render.decorator.d.ts +10 -0
  34. package/decorators/render.decorator.js +20 -0
  35. package/decorators/request-mapping.decorator.d.ts +78 -0
  36. package/decorators/request-mapping.decorator.js +98 -0
  37. package/decorators/route-params.decorator.d.ts +378 -0
  38. package/decorators/route-params.decorator.js +227 -0
  39. package/decorators/sse.decorator.d.ts +6 -0
  40. package/decorators/sse.decorator.js +20 -0
  41. package/decorators/version.decorator.d.ts +7 -0
  42. package/decorators/version.decorator.js +20 -0
  43. package/enums/http-status.enum.d.ts +53 -0
  44. package/enums/http-status.enum.js +57 -0
  45. package/enums/index.d.ts +4 -0
  46. package/enums/index.js +20 -0
  47. package/enums/request-method.enum.d.ts +11 -0
  48. package/enums/request-method.enum.js +15 -0
  49. package/enums/route-paramtypes.enum.d.ts +14 -0
  50. package/enums/route-paramtypes.enum.js +18 -0
  51. package/enums/version-type.enum.d.ts +9 -0
  52. package/enums/version-type.enum.js +13 -0
  53. package/errors/bad-gateway.exception.d.ts +33 -0
  54. package/errors/bad-gateway.exception.js +41 -0
  55. package/errors/bad-request.exception.d.ts +33 -0
  56. package/errors/bad-request.exception.js +41 -0
  57. package/errors/conflict.exception.d.ts +33 -0
  58. package/errors/conflict.exception.js +41 -0
  59. package/errors/forbidden.exception.d.ts +33 -0
  60. package/errors/forbidden.exception.js +41 -0
  61. package/errors/gateway-timeout.exception.d.ts +33 -0
  62. package/errors/gateway-timeout.exception.js +41 -0
  63. package/errors/gone.exception.d.ts +33 -0
  64. package/errors/gone.exception.js +41 -0
  65. package/errors/http-version-not-supported.exception.d.ts +33 -0
  66. package/errors/http-version-not-supported.exception.js +41 -0
  67. package/errors/http.exception.d.ts +79 -0
  68. package/errors/http.exception.js +123 -0
  69. package/errors/im-a-teapot.exception.d.ts +36 -0
  70. package/errors/im-a-teapot.exception.js +44 -0
  71. package/errors/index.d.ts +11 -0
  72. package/errors/index.js +27 -0
  73. package/errors/internal-server-error.exception.d.ts +33 -0
  74. package/errors/internal-server-error.exception.js +41 -0
  75. package/errors/invalid-middleware-configuration.exception.d.ts +4 -0
  76. package/errors/invalid-middleware-configuration.exception.js +11 -0
  77. package/errors/invalid-middleware.exception.d.ts +4 -0
  78. package/errors/invalid-middleware.exception.js +11 -0
  79. package/errors/not-found.exception.d.ts +33 -0
  80. package/errors/not-found.exception.js +41 -0
  81. package/errors/unknown-request-mapping.exception.d.ts +5 -0
  82. package/errors/unknown-request-mapping.exception.js +11 -0
  83. package/exceptions/messages.d.ts +4 -0
  84. package/exceptions/messages.js +13 -0
  85. package/explorers/path.explorer.d.ts +8 -0
  86. package/explorers/path.explorer.js +38 -0
  87. package/explorers/router.explorer.d.ts +51 -0
  88. package/explorers/router.explorer.js +195 -0
  89. package/factory/context-id.factory.d.ts +41 -0
  90. package/factory/context-id.factory.js +52 -0
  91. package/factory/index.d.ts +4 -0
  92. package/factory/index.js +20 -0
  93. package/factory/method.factory.d.ts +5 -0
  94. package/factory/method.factory.js +30 -0
  95. package/factory/params.factory.d.ts +5 -0
  96. package/factory/params.factory.js +39 -0
  97. package/factory/path.factory.d.ts +13 -0
  98. package/factory/path.factory.js +95 -0
  99. package/filters/context.d.ts +9 -0
  100. package/filters/context.js +15 -0
  101. package/filters/filter.d.ts +22 -0
  102. package/filters/filter.js +78 -0
  103. package/helpers/adapter.helper.d.ts +27 -0
  104. package/helpers/adapter.helper.js +37 -0
  105. package/helpers/exclude-route.helper.d.ts +4 -0
  106. package/helpers/exclude-route.helper.js +18 -0
  107. package/helpers/flatten-routes.helper.d.ts +5 -0
  108. package/helpers/flatten-routes.helper.js +27 -0
  109. package/helpers/index.d.ts +6 -0
  110. package/helpers/index.js +22 -0
  111. package/helpers/messages.helper.d.ts +6 -0
  112. package/helpers/messages.helper.js +25 -0
  113. package/helpers/path.helper.d.ts +3 -0
  114. package/helpers/path.helper.js +13 -0
  115. package/helpers/sse.helper.d.ts +45 -0
  116. package/helpers/sse.helper.js +83 -0
  117. package/index.d.ts +1 -0
  118. package/index.js +3 -0
  119. package/interfaces/http/cors.interface.d.ts +58 -0
  120. package/interfaces/http/cors.interface.js +2 -0
  121. package/interfaces/http/exception.interface.d.ts +6 -0
  122. package/interfaces/http/exception.interface.js +2 -0
  123. package/interfaces/http/exclude-route.interface.d.ts +15 -0
  124. package/interfaces/http/exclude-route.interface.js +2 -0
  125. package/interfaces/http/index.d.ts +10 -0
  126. package/interfaces/http/index.js +26 -0
  127. package/interfaces/http/message-event.interface.d.ts +6 -0
  128. package/interfaces/http/message-event.interface.js +2 -0
  129. package/interfaces/http/module.inteface.d.ts +5 -0
  130. package/interfaces/http/module.inteface.js +2 -0
  131. package/interfaces/http/options.interface.d.ts +127 -0
  132. package/interfaces/http/options.interface.js +2 -0
  133. package/interfaces/http/path-metadata.interface.d.ts +31 -0
  134. package/interfaces/http/path-metadata.interface.js +2 -0
  135. package/interfaces/http/prefix-options.interface.d.ts +7 -0
  136. package/interfaces/http/prefix-options.interface.js +2 -0
  137. package/interfaces/http/raw-request.d.ts +4 -0
  138. package/interfaces/http/raw-request.js +2 -0
  139. package/interfaces/http/routes.interface.d.ts +7 -0
  140. package/interfaces/http/routes.interface.js +2 -0
  141. package/interfaces/http/server.interface.d.ts +54 -0
  142. package/interfaces/http/server.interface.js +2 -0
  143. package/interfaces/index.d.ts +3 -0
  144. package/interfaces/index.js +19 -0
  145. package/interfaces/middleware/config-proxy.interface.d.ts +23 -0
  146. package/interfaces/middleware/config-proxy.interface.js +2 -0
  147. package/interfaces/middleware/configuration.interface.d.ts +12 -0
  148. package/interfaces/middleware/configuration.interface.js +2 -0
  149. package/interfaces/middleware/consumer.interface.d.ts +16 -0
  150. package/interfaces/middleware/consumer.interface.js +2 -0
  151. package/interfaces/middleware/index.d.ts +4 -0
  152. package/interfaces/middleware/index.js +20 -0
  153. package/interfaces/middleware/middleware.interface.d.ts +7 -0
  154. package/interfaces/middleware/middleware.interface.js +2 -0
  155. package/interfaces/router/callback-paramtypes.interface.d.ts +1 -0
  156. package/interfaces/router/callback-paramtypes.interface.js +2 -0
  157. package/interfaces/router/definition.interface.d.ts +10 -0
  158. package/interfaces/router/definition.interface.js +2 -0
  159. package/interfaces/router/index.d.ts +3 -0
  160. package/interfaces/router/index.js +19 -0
  161. package/interfaces/router/version-options.interface.d.ts +92 -0
  162. package/interfaces/router/version-options.interface.js +9 -0
  163. package/middleware/builder.d.ts +15 -0
  164. package/middleware/builder.js +78 -0
  165. package/middleware/container.d.ts +13 -0
  166. package/middleware/container.js +50 -0
  167. package/middleware/extractor.d.ts +15 -0
  168. package/middleware/extractor.js +50 -0
  169. package/middleware/index.d.ts +1 -0
  170. package/middleware/index.js +17 -0
  171. package/middleware/module.d.ts +33 -0
  172. package/middleware/module.js +180 -0
  173. package/middleware/resolver.d.ts +10 -0
  174. package/middleware/resolver.js +27 -0
  175. package/middleware/routes-mapper.d.ts +19 -0
  176. package/middleware/routes-mapper.js +111 -0
  177. package/middleware/utils.d.ts +8 -0
  178. package/middleware/utils.js +86 -0
  179. package/package.json +41 -0
  180. package/router/module.d.ts +18 -0
  181. package/router/module.js +88 -0
  182. package/router/resolver.d.ts +31 -0
  183. package/router/resolver.js +128 -0
  184. package/storage/http-instance.storage.d.ts +9 -0
  185. package/storage/http-instance.storage.js +19 -0
  186. package/stream/index.d.ts +1 -0
  187. package/stream/index.js +17 -0
  188. package/stream/interfaces/index.d.ts +2 -0
  189. package/stream/interfaces/index.js +18 -0
  190. package/stream/interfaces/streamable-handler-response.interface.d.ts +12 -0
  191. package/stream/interfaces/streamable-handler-response.interface.js +2 -0
  192. package/stream/interfaces/streamable-options.interface.d.ts +10 -0
  193. package/stream/interfaces/streamable-options.interface.js +2 -0
  194. package/stream/streamable-file.d.ts +22 -0
  195. package/stream/streamable-file.js +55 -0
  196. package/test/context/response.controller.spec.d.ts +1 -0
  197. package/test/context/response.controller.spec.js +328 -0
  198. package/test/decorators/controller.decorator.spec.d.ts +1 -0
  199. package/test/decorators/controller.decorator.spec.js +113 -0
  200. package/test/decorators/header.decorator.spec.d.ts +1 -0
  201. package/test/decorators/header.decorator.spec.js +33 -0
  202. package/test/decorators/http-code.decorator.spec.d.ts +1 -0
  203. package/test/decorators/http-code.decorator.spec.js +30 -0
  204. package/test/decorators/redirect.decorator.spec.d.ts +1 -0
  205. package/test/decorators/redirect.decorator.spec.js +36 -0
  206. package/test/decorators/render.decorator.spec.d.ts +1 -0
  207. package/test/decorators/render.decorator.spec.js +30 -0
  208. package/test/decorators/request-mapping.decorator.spec.d.ts +1 -0
  209. package/test/decorators/request-mapping.decorator.spec.js +85 -0
  210. package/test/decorators/route-params.decorator.spec.d.ts +1 -0
  211. package/test/decorators/route-params.decorator.spec.js +493 -0
  212. package/test/decorators/sse.decorator.spec.d.ts +1 -0
  213. package/test/decorators/sse.decorator.spec.js +35 -0
  214. package/test/decorators/version.decorator.spec.d.ts +1 -0
  215. package/test/decorators/version.decorator.spec.js +43 -0
  216. package/test/exceptions/handler.spec.d.ts +1 -0
  217. package/test/exceptions/handler.spec.js +145 -0
  218. package/test/exceptions/proxy.spec.d.ts +1 -0
  219. package/test/exceptions/proxy.spec.js +74 -0
  220. package/test/explorers/path.explorer.spec.d.ts +1 -0
  221. package/test/explorers/path.explorer.spec.js +190 -0
  222. package/test/explorers/router.explorer.spec.d.ts +1 -0
  223. package/test/explorers/router.explorer.spec.js +206 -0
  224. package/test/factory/method.factory.spec.d.ts +1 -0
  225. package/test/factory/method.factory.spec.js +33 -0
  226. package/test/factory/params.factory.spec.d.ts +1 -0
  227. package/test/factory/params.factory.spec.js +104 -0
  228. package/test/factory/path.factory.spec.d.ts +1 -0
  229. package/test/factory/path.factory.spec.js +260 -0
  230. package/test/filters/context.spec.d.ts +1 -0
  231. package/test/filters/context.spec.js +96 -0
  232. package/test/filters/filter.spec.d.ts +1 -0
  233. package/test/filters/filter.spec.js +96 -0
  234. package/test/helpers/flatten-routes.helper.spec.d.ts +1 -0
  235. package/test/helpers/flatten-routes.helper.spec.js +131 -0
  236. package/test/helpers/sse.helper.spec.d.ts +1 -0
  237. package/test/helpers/sse.helper.spec.js +132 -0
  238. package/test/middleware/builder.spec.d.ts +1 -0
  239. package/test/middleware/builder.spec.js +235 -0
  240. package/test/middleware/container.spec.d.ts +1 -0
  241. package/test/middleware/container.spec.js +81 -0
  242. package/test/middleware/module.spec.d.ts +1 -0
  243. package/test/middleware/module.spec.js +206 -0
  244. package/test/middleware/route-info-path-extractor.spec.d.ts +1 -0
  245. package/test/middleware/route-info-path-extractor.spec.js +123 -0
  246. package/test/middleware/routes-mapper.spec.d.ts +1 -0
  247. package/test/middleware/routes-mapper.spec.js +162 -0
  248. package/test/middleware/utils.spec.d.ts +1 -0
  249. package/test/middleware/utils.spec.js +132 -0
  250. package/test/router/module.spec.d.ts +1 -0
  251. package/test/router/module.spec.js +40 -0
  252. package/test/router/resolver.spec.d.ts +1 -0
  253. package/test/router/resolver.spec.js +326 -0
  254. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,145 @@
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 http_errors_1 = __importDefault(require("http-errors"));
8
+ const sinon_1 = __importDefault(require("sinon"));
9
+ const adapter_helper_1 = require("@venok/http/helpers/adapter.helper");
10
+ const execution_host_1 = require("../../../core/context/execution-host");
11
+ const invalid_exception_filter_exception_1 = require("../../../core/errors/exceptions/invalid-exception-filter.exception");
12
+ const shared_helper_1 = require("../../../core/helpers/shared.helper");
13
+ const errors_1 = require("../../errors");
14
+ const filter_1 = require("../../filters/filter");
15
+ const handler_1 = require("../../../core/exceptions/handler");
16
+ describe("VenokExceptionsHandler", () => {
17
+ let adapter;
18
+ let handler;
19
+ let statusStub;
20
+ let jsonStub;
21
+ let response;
22
+ beforeEach(() => {
23
+ adapter = new adapter_helper_1.NoopHttpAdapter({});
24
+ handler = new handler_1.VenokExceptionsHandler(new filter_1.HttpExceptionFilter(adapter));
25
+ statusStub = sinon_1.default.stub();
26
+ jsonStub = sinon_1.default.stub();
27
+ response = {
28
+ status: statusStub,
29
+ json: jsonStub,
30
+ };
31
+ response.status.returns(response);
32
+ response.json.returns(response);
33
+ });
34
+ describe("next", () => {
35
+ beforeEach(() => {
36
+ sinon_1.default.stub(adapter, "reply").callsFake((responseRef, body, statusCode) => {
37
+ if (statusCode)
38
+ responseRef.status(statusCode);
39
+ if ((0, shared_helper_1.isNull)(body))
40
+ return responseRef.send();
41
+ return (0, shared_helper_1.isObject)(body) ? responseRef.json(body) : responseRef.send(String(body));
42
+ });
43
+ });
44
+ it("should send expected response status code and message when exception is unknown", () => {
45
+ handler.next(new Error(), new execution_host_1.ExecutionContextHost([0, response]));
46
+ (0, chai_1.expect)(statusStub.calledWith(500)).to.be.true;
47
+ (0, chai_1.expect)(jsonStub.calledWith({
48
+ statusCode: 500,
49
+ message: "Internal server error",
50
+ })).to.be.true;
51
+ });
52
+ describe('when exception is instantiated by "http-errors" library', () => {
53
+ it("should send expected response status code and message", () => {
54
+ const error = new http_errors_1.default.NotFound("User does not exist");
55
+ handler.next(error, new execution_host_1.ExecutionContextHost([0, response]));
56
+ (0, chai_1.expect)(statusStub.calledWith(404)).to.be.true;
57
+ (0, chai_1.expect)(jsonStub.calledWith({
58
+ statusCode: 404,
59
+ message: "User does not exist",
60
+ })).to.be.true;
61
+ });
62
+ });
63
+ describe("when exception is an instance of HttpException", () => {
64
+ it("should send expected response status code and json object", () => {
65
+ const status = 401;
66
+ const message = {
67
+ custom: "Unauthorized",
68
+ };
69
+ handler.next(new errors_1.HttpException(message, status), new execution_host_1.ExecutionContextHost([0, response]));
70
+ (0, chai_1.expect)(statusStub.calledWith(status)).to.be.true;
71
+ (0, chai_1.expect)(jsonStub.calledWith(message)).to.be.true;
72
+ });
73
+ it("should send expected response status code and transform message to json", () => {
74
+ const status = 401;
75
+ const message = "Unauthorized";
76
+ handler.next(new errors_1.HttpException(message, status), new execution_host_1.ExecutionContextHost([0, response]));
77
+ (0, chai_1.expect)(statusStub.calledWith(status)).to.be.true;
78
+ (0, chai_1.expect)(jsonStub.calledWith({ message, statusCode: status })).to.be.true;
79
+ });
80
+ });
81
+ describe('when "invokeCustomFilters" returns true', () => {
82
+ beforeEach(() => {
83
+ sinon_1.default.stub(handler, "invokeCustomFilters").returns(true);
84
+ });
85
+ it("should do nothing", () => {
86
+ handler.next(new Error(), sinon_1.default.createStubInstance(execution_host_1.ExecutionContextHost));
87
+ (0, chai_1.expect)(statusStub.notCalled).to.be.true;
88
+ (0, chai_1.expect)(jsonStub.notCalled).to.be.true;
89
+ });
90
+ });
91
+ });
92
+ describe("setCustomFilters", () => {
93
+ const filters = ["test", "test2"];
94
+ it("should set custom filters", () => {
95
+ handler.setCustomFilters(filters);
96
+ (0, chai_1.expect)(handler.filters).to.be.eql(filters);
97
+ });
98
+ it("should throw exception when passed argument is not an array", () => {
99
+ (0, chai_1.expect)(() => handler.setCustomFilters(null)).to.throws(invalid_exception_filter_exception_1.InvalidExceptionFilterException);
100
+ });
101
+ });
102
+ describe("invokeCustomFilters", () => {
103
+ describe("when filters array is empty", () => {
104
+ it("should return false", () => {
105
+ (0, chai_1.expect)(handler.invokeCustomFilters(null, null)).to.be.false;
106
+ });
107
+ });
108
+ describe("when filters array is not empty", () => {
109
+ let filters, funcSpy;
110
+ class TestException {
111
+ }
112
+ beforeEach(() => {
113
+ funcSpy = sinon_1.default.spy();
114
+ });
115
+ describe("when filter exists in filters array", () => {
116
+ beforeEach(() => {
117
+ filters = [{ exceptionMetatypes: [TestException], func: funcSpy }];
118
+ handler.filters = filters;
119
+ });
120
+ it("should call funcSpy", () => {
121
+ handler.invokeCustomFilters(new TestException(), null);
122
+ (0, chai_1.expect)(funcSpy.notCalled).to.be.false;
123
+ });
124
+ it("should call funcSpy with exception and response passed as an arguments", () => {
125
+ const exception = new TestException();
126
+ const res = { foo: "bar" };
127
+ handler.invokeCustomFilters(exception, res);
128
+ (0, chai_1.expect)(funcSpy.calledWith(exception, res)).to.be.true;
129
+ });
130
+ it("should return true", () => {
131
+ (0, chai_1.expect)(handler.invokeCustomFilters(new TestException(), null)).to.be.true;
132
+ });
133
+ });
134
+ describe("when filter does not exists in filters array", () => {
135
+ it("should not call funcSpy", () => {
136
+ handler.invokeCustomFilters(new TestException(), null);
137
+ (0, chai_1.expect)(funcSpy.notCalled).to.be.true;
138
+ });
139
+ it("should return false", () => {
140
+ (0, chai_1.expect)(handler.invokeCustomFilters(new TestException(), null)).to.be.false;
141
+ });
142
+ });
143
+ });
144
+ });
145
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,74 @@
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 sinon_1 = __importDefault(require("sinon"));
8
+ const adapter_helper_1 = require("@venok/http/helpers/adapter.helper");
9
+ const execution_host_1 = require("../../../core/context/execution-host");
10
+ const errors_1 = require("../../errors");
11
+ const filter_1 = require("../../filters/filter");
12
+ const context_1 = require("../../../core/context");
13
+ const handler_1 = require("../../../core/exceptions/handler");
14
+ describe("RouterProxy", () => {
15
+ let routerProxy;
16
+ let handler;
17
+ const httpException = new errors_1.HttpException("test", 500);
18
+ let nextStub;
19
+ beforeEach(() => {
20
+ handler = new handler_1.VenokExceptionsHandler(new filter_1.HttpExceptionFilter(new adapter_helper_1.NoopHttpAdapter({})));
21
+ nextStub = sinon_1.default.stub(handler, "next");
22
+ routerProxy = new context_1.VenokProxy();
23
+ });
24
+ describe("createProxy", () => {
25
+ it("should method return thunk", () => {
26
+ const proxy = routerProxy.createProxy(() => { }, handler);
27
+ (0, chai_1.expect)(typeof proxy === "function").to.be.true;
28
+ });
29
+ it("should method encapsulate callback passed as argument", () => {
30
+ const proxy = routerProxy.createProxy((req, res, next) => {
31
+ throw httpException;
32
+ }, handler);
33
+ proxy(null, null, null);
34
+ (0, chai_1.expect)(nextStub.calledOnce).to.be.true;
35
+ (0, chai_1.expect)(nextStub.calledWith(httpException, new execution_host_1.ExecutionContextHost([null, null, null]))).to.be.true;
36
+ });
37
+ it("should method encapsulate async callback passed as argument", (done) => {
38
+ const proxy = routerProxy.createProxy(async (req, res, next) => {
39
+ throw httpException;
40
+ }, handler);
41
+ proxy(null, null, null);
42
+ setTimeout(() => {
43
+ (0, chai_1.expect)(nextStub.calledOnce).to.be.true;
44
+ (0, chai_1.expect)(nextStub.calledWith(httpException, new execution_host_1.ExecutionContextHost([null, null, null]))).to.be.true;
45
+ done();
46
+ }, 0);
47
+ });
48
+ });
49
+ describe("createExceptionLayerProxy", () => {
50
+ it("should method return thunk", () => {
51
+ const proxy = routerProxy.createProxy(() => { }, handler);
52
+ (0, chai_1.expect)(typeof proxy === "function").to.be.true;
53
+ });
54
+ it("should method encapsulate callback passed as argument", () => {
55
+ const proxy = routerProxy.createExceptionLayerProxy((err, req, res, next) => {
56
+ throw httpException;
57
+ }, handler);
58
+ proxy(null, null, null, null);
59
+ (0, chai_1.expect)(nextStub.calledOnce).to.be.true;
60
+ (0, chai_1.expect)(nextStub.calledWith(httpException, new execution_host_1.ExecutionContextHost([null, null, null]))).to.be.true;
61
+ });
62
+ it("should method encapsulate async callback passed as argument", (done) => {
63
+ const proxy = routerProxy.createExceptionLayerProxy(async (err, req, res, next) => {
64
+ throw httpException;
65
+ }, handler);
66
+ proxy(null, null, null, null);
67
+ setTimeout(() => {
68
+ (0, chai_1.expect)(nextStub.calledOnce).to.be.true;
69
+ (0, chai_1.expect)(nextStub.calledWith(httpException, new execution_host_1.ExecutionContextHost([null, null, null]))).to.be.true;
70
+ done();
71
+ }, 0);
72
+ });
73
+ });
74
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,190 @@
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 chai_1 = require("chai");
13
+ const decorators_1 = require("../../decorators");
14
+ const path_explorer_1 = require("../../explorers/path.explorer");
15
+ const core_1 = require("../../../core/index.ts");
16
+ const enums_1 = require("../../enums");
17
+ describe("PathExplorer", () => {
18
+ let TestRoute = class TestRoute {
19
+ getTest() { }
20
+ postTest() { }
21
+ anotherTest() { }
22
+ getTestUsingArray() { }
23
+ };
24
+ __decorate([
25
+ (0, decorators_1.Get)("test"),
26
+ __metadata("design:type", Function),
27
+ __metadata("design:paramtypes", []),
28
+ __metadata("design:returntype", void 0)
29
+ ], TestRoute.prototype, "getTest", null);
30
+ __decorate([
31
+ (0, decorators_1.Post)("test"),
32
+ __metadata("design:type", Function),
33
+ __metadata("design:paramtypes", []),
34
+ __metadata("design:returntype", void 0)
35
+ ], TestRoute.prototype, "postTest", null);
36
+ __decorate([
37
+ (0, decorators_1.All)("another-test"),
38
+ __metadata("design:type", Function),
39
+ __metadata("design:paramtypes", []),
40
+ __metadata("design:returntype", void 0)
41
+ ], TestRoute.prototype, "anotherTest", null);
42
+ __decorate([
43
+ (0, decorators_1.Get)(["foo", "bar"]),
44
+ __metadata("design:type", Function),
45
+ __metadata("design:paramtypes", []),
46
+ __metadata("design:returntype", void 0)
47
+ ], TestRoute.prototype, "getTestUsingArray", null);
48
+ TestRoute = __decorate([
49
+ (0, decorators_1.Controller)("global")
50
+ ], TestRoute);
51
+ let TestRouteAlias = class TestRouteAlias {
52
+ getTest() { }
53
+ postTest() { }
54
+ anotherTest() { }
55
+ getTestUsingArray() { }
56
+ };
57
+ __decorate([
58
+ (0, decorators_1.Get)("test"),
59
+ __metadata("design:type", Function),
60
+ __metadata("design:paramtypes", []),
61
+ __metadata("design:returntype", void 0)
62
+ ], TestRouteAlias.prototype, "getTest", null);
63
+ __decorate([
64
+ (0, decorators_1.Post)("test"),
65
+ __metadata("design:type", Function),
66
+ __metadata("design:paramtypes", []),
67
+ __metadata("design:returntype", void 0)
68
+ ], TestRouteAlias.prototype, "postTest", null);
69
+ __decorate([
70
+ (0, decorators_1.All)("another-test"),
71
+ __metadata("design:type", Function),
72
+ __metadata("design:paramtypes", []),
73
+ __metadata("design:returntype", void 0)
74
+ ], TestRouteAlias.prototype, "anotherTest", null);
75
+ __decorate([
76
+ (0, decorators_1.Get)(["foo", "bar"]),
77
+ __metadata("design:type", Function),
78
+ __metadata("design:paramtypes", []),
79
+ __metadata("design:returntype", void 0)
80
+ ], TestRouteAlias.prototype, "getTestUsingArray", null);
81
+ TestRouteAlias = __decorate([
82
+ (0, decorators_1.Controller)(["global", "global-alias"])
83
+ ], TestRouteAlias);
84
+ let pathsExplorer;
85
+ beforeEach(() => {
86
+ pathsExplorer = new path_explorer_1.PathsExplorer(new core_1.MetadataScanner());
87
+ });
88
+ describe("scanForPaths", () => {
89
+ it("should method return expected list of route paths", () => {
90
+ const paths = pathsExplorer.scanForPaths(new TestRoute());
91
+ (0, chai_1.expect)(paths).to.have.length(4);
92
+ (0, chai_1.expect)(paths[0].path).to.eql(["/test"]);
93
+ (0, chai_1.expect)(paths[1].path).to.eql(["/test"]);
94
+ (0, chai_1.expect)(paths[2].path).to.eql(["/another-test"]);
95
+ (0, chai_1.expect)(paths[3].path).to.eql(["/foo", "/bar"]);
96
+ (0, chai_1.expect)(paths[0].requestMethod).to.eql(enums_1.RequestMethod.GET);
97
+ (0, chai_1.expect)(paths[1].requestMethod).to.eql(enums_1.RequestMethod.POST);
98
+ (0, chai_1.expect)(paths[2].requestMethod).to.eql(enums_1.RequestMethod.ALL);
99
+ (0, chai_1.expect)(paths[3].requestMethod).to.eql(enums_1.RequestMethod.GET);
100
+ });
101
+ it("should method return expected list of route paths alias", () => {
102
+ const paths = pathsExplorer.scanForPaths(new TestRouteAlias());
103
+ (0, chai_1.expect)(paths).to.have.length(4);
104
+ (0, chai_1.expect)(paths[0].path).to.eql(["/test"]);
105
+ (0, chai_1.expect)(paths[1].path).to.eql(["/test"]);
106
+ (0, chai_1.expect)(paths[2].path).to.eql(["/another-test"]);
107
+ (0, chai_1.expect)(paths[3].path).to.eql(["/foo", "/bar"]);
108
+ (0, chai_1.expect)(paths[0].requestMethod).to.eql(enums_1.RequestMethod.GET);
109
+ (0, chai_1.expect)(paths[1].requestMethod).to.eql(enums_1.RequestMethod.POST);
110
+ (0, chai_1.expect)(paths[2].requestMethod).to.eql(enums_1.RequestMethod.ALL);
111
+ (0, chai_1.expect)(paths[3].requestMethod).to.eql(enums_1.RequestMethod.GET);
112
+ });
113
+ });
114
+ describe("exploreMethodMetadata", () => {
115
+ it("should method return expected object which represent single route", () => {
116
+ const instance = new TestRoute();
117
+ const instanceProto = Object.getPrototypeOf(instance);
118
+ const route = pathsExplorer.exploreMethodMetadata(instance, instanceProto, "getTest");
119
+ (0, chai_1.expect)(route.path).to.eql(["/test"]);
120
+ (0, chai_1.expect)(route.requestMethod).to.eql(enums_1.RequestMethod.GET);
121
+ (0, chai_1.expect)(route.targetCallback).to.eq(instance.getTest);
122
+ });
123
+ it("should method return expected object which represent single route with alias", () => {
124
+ const instance = new TestRouteAlias();
125
+ const instanceProto = Object.getPrototypeOf(instance);
126
+ const route = pathsExplorer.exploreMethodMetadata(instance, instanceProto, "getTest");
127
+ (0, chai_1.expect)(route.path).to.eql(["/test"]);
128
+ (0, chai_1.expect)(route.requestMethod).to.eql(enums_1.RequestMethod.GET);
129
+ (0, chai_1.expect)(route.targetCallback).to.eq(instance.getTest);
130
+ });
131
+ it("should method return expected object which represent multiple routes", () => {
132
+ const instance = new TestRoute();
133
+ const instanceProto = Object.getPrototypeOf(instance);
134
+ const route = pathsExplorer.exploreMethodMetadata(instance, instanceProto, "getTestUsingArray");
135
+ (0, chai_1.expect)(route.path).to.eql(["/foo", "/bar"]);
136
+ (0, chai_1.expect)(route.requestMethod).to.eql(enums_1.RequestMethod.GET);
137
+ (0, chai_1.expect)(route.targetCallback).to.eq(instance.getTestUsingArray);
138
+ });
139
+ it("should method return expected object which represent multiple routes with alias", () => {
140
+ const instance = new TestRouteAlias();
141
+ const instanceProto = Object.getPrototypeOf(instance);
142
+ const route = pathsExplorer.exploreMethodMetadata(instance, instanceProto, "getTestUsingArray");
143
+ (0, chai_1.expect)(route.path).to.eql(["/foo", "/bar"]);
144
+ (0, chai_1.expect)(route.requestMethod).to.eql(enums_1.RequestMethod.GET);
145
+ (0, chai_1.expect)(route.targetCallback).to.eq(instance.getTestUsingArray);
146
+ });
147
+ describe("when new implementation is injected into router", () => {
148
+ it("should method return changed impl of single route", () => {
149
+ const instance = new TestRoute();
150
+ const instanceProto = Object.getPrototypeOf(instance);
151
+ const newImpl = function () { };
152
+ instance.getTest = newImpl;
153
+ const route = pathsExplorer.exploreMethodMetadata(instance, instanceProto, "getTest");
154
+ (0, chai_1.expect)(route.targetCallback).to.eq(newImpl);
155
+ (0, chai_1.expect)(route.path).to.eql(["/test"]);
156
+ (0, chai_1.expect)(route.requestMethod).to.eql(enums_1.RequestMethod.GET);
157
+ });
158
+ it("should method return changed impl of single route which alias applied", () => {
159
+ const instance = new TestRouteAlias();
160
+ const instanceProto = Object.getPrototypeOf(instance);
161
+ const newImpl = function () { };
162
+ instance.getTest = newImpl;
163
+ const route = pathsExplorer.exploreMethodMetadata(instance, instanceProto, "getTest");
164
+ (0, chai_1.expect)(route.targetCallback).to.eq(newImpl);
165
+ (0, chai_1.expect)(route.path).to.eql(["/test"]);
166
+ (0, chai_1.expect)(route.requestMethod).to.eql(enums_1.RequestMethod.GET);
167
+ });
168
+ it("should method return changed impl of multiple routes", () => {
169
+ const instance = new TestRoute();
170
+ const instanceProto = Object.getPrototypeOf(instance);
171
+ const newImpl = function () { };
172
+ instance.getTestUsingArray = newImpl;
173
+ const route = pathsExplorer.exploreMethodMetadata(instance, instanceProto, "getTestUsingArray");
174
+ (0, chai_1.expect)(route.targetCallback).to.eq(newImpl);
175
+ (0, chai_1.expect)(route.path).to.eql(["/foo", "/bar"]);
176
+ (0, chai_1.expect)(route.requestMethod).to.eql(enums_1.RequestMethod.GET);
177
+ });
178
+ it("should method return changed impl of multiple routes which alias applied", () => {
179
+ const instance = new TestRouteAlias();
180
+ const instanceProto = Object.getPrototypeOf(instance);
181
+ const newImpl = function () { };
182
+ instance.getTestUsingArray = newImpl;
183
+ const route = pathsExplorer.exploreMethodMetadata(instance, instanceProto, "getTestUsingArray");
184
+ (0, chai_1.expect)(route.targetCallback).to.eq(newImpl);
185
+ (0, chai_1.expect)(route.path).to.eql(["/foo", "/bar"]);
186
+ (0, chai_1.expect)(route.requestMethod).to.eql(enums_1.RequestMethod.GET);
187
+ });
188
+ });
189
+ });
190
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,206 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const chai_1 = require("chai");
16
+ const sinon_1 = __importDefault(require("sinon"));
17
+ const decorators_1 = require("../../decorators");
18
+ const router_explorer_1 = require("../../explorers/router.explorer");
19
+ const injector_1 = require("../../../core/injector/injector");
20
+ const context_1 = require("../../filters/context");
21
+ const core_1 = require("../../../core/index.ts");
22
+ const factory_1 = require("../../factory");
23
+ const graph_inspector_1 = require("../../../core/inspector/graph-inspector");
24
+ const config_1 = require("../../application/config");
25
+ const enums_1 = require("../../enums");
26
+ const wrapper_1 = require("../../../core/injector/instance/wrapper");
27
+ const execution_host_1 = require("../../../core/context/execution-host");
28
+ const helpers_1 = require("../../helpers");
29
+ describe("RouterExplorer", () => {
30
+ let TestRoute = class TestRoute {
31
+ getTest() { }
32
+ postTest() { }
33
+ anotherTest() { }
34
+ getTestUsingArray() { }
35
+ };
36
+ __decorate([
37
+ (0, decorators_1.Get)("test"),
38
+ __metadata("design:type", Function),
39
+ __metadata("design:paramtypes", []),
40
+ __metadata("design:returntype", void 0)
41
+ ], TestRoute.prototype, "getTest", null);
42
+ __decorate([
43
+ (0, decorators_1.Post)("test"),
44
+ __metadata("design:type", Function),
45
+ __metadata("design:paramtypes", []),
46
+ __metadata("design:returntype", void 0)
47
+ ], TestRoute.prototype, "postTest", null);
48
+ __decorate([
49
+ (0, decorators_1.All)("another-test"),
50
+ __metadata("design:type", Function),
51
+ __metadata("design:paramtypes", []),
52
+ __metadata("design:returntype", void 0)
53
+ ], TestRoute.prototype, "anotherTest", null);
54
+ __decorate([
55
+ (0, decorators_1.Get)(["foo", "bar"]),
56
+ __metadata("design:type", Function),
57
+ __metadata("design:paramtypes", []),
58
+ __metadata("design:returntype", void 0)
59
+ ], TestRoute.prototype, "getTestUsingArray", null);
60
+ TestRoute = __decorate([
61
+ (0, decorators_1.Controller)("global")
62
+ ], TestRoute);
63
+ let TestRouteAlias = class TestRouteAlias {
64
+ getTest() { }
65
+ postTest() { }
66
+ anotherTest() { }
67
+ getTestUsingArray() { }
68
+ };
69
+ __decorate([
70
+ (0, decorators_1.Get)("test"),
71
+ __metadata("design:type", Function),
72
+ __metadata("design:paramtypes", []),
73
+ __metadata("design:returntype", void 0)
74
+ ], TestRouteAlias.prototype, "getTest", null);
75
+ __decorate([
76
+ (0, decorators_1.Post)("test"),
77
+ __metadata("design:type", Function),
78
+ __metadata("design:paramtypes", []),
79
+ __metadata("design:returntype", void 0)
80
+ ], TestRouteAlias.prototype, "postTest", null);
81
+ __decorate([
82
+ (0, decorators_1.All)("another-test"),
83
+ __metadata("design:type", Function),
84
+ __metadata("design:paramtypes", []),
85
+ __metadata("design:returntype", void 0)
86
+ ], TestRouteAlias.prototype, "anotherTest", null);
87
+ __decorate([
88
+ (0, decorators_1.Get)(["foo", "bar"]),
89
+ __metadata("design:type", Function),
90
+ __metadata("design:paramtypes", []),
91
+ __metadata("design:returntype", void 0)
92
+ ], TestRouteAlias.prototype, "getTestUsingArray", null);
93
+ TestRouteAlias = __decorate([
94
+ (0, decorators_1.Controller)(["global", "global-alias"])
95
+ ], TestRouteAlias);
96
+ class ClassWithMissingControllerDecorator {
97
+ }
98
+ let routerBuilder;
99
+ let injector;
100
+ let exceptionsFilter;
101
+ let applicationConfig;
102
+ let httpConfig;
103
+ let routePathFactory;
104
+ let graphInspector;
105
+ beforeEach(() => {
106
+ const container = new core_1.VenokContainer();
107
+ httpConfig = new config_1.HttpConfig();
108
+ applicationConfig = new core_1.ApplicationConfig();
109
+ injector = new injector_1.Injector();
110
+ routePathFactory = new factory_1.RoutePathFactory(httpConfig);
111
+ graphInspector = new graph_inspector_1.GraphInspector(container);
112
+ exceptionsFilter = new context_1.RouterExceptionFiltersContext(container, applicationConfig, null);
113
+ routerBuilder = new router_explorer_1.RouterExplorer(new core_1.MetadataScanner(), container, injector, null, exceptionsFilter, applicationConfig, routePathFactory, graphInspector, httpConfig.getHttpAdapterRef());
114
+ });
115
+ describe("applyPathsToRouterProxy", () => {
116
+ it("should method return expected object which represent single route", () => {
117
+ const bindStub = sinon_1.default.stub(routerBuilder, "applyCallbackToRouter");
118
+ const paths = [
119
+ { path: [""], requestMethod: enums_1.RequestMethod.GET },
120
+ { path: ["test"], requestMethod: enums_1.RequestMethod.GET },
121
+ { path: ["foo", "bar"], requestMethod: enums_1.RequestMethod.GET },
122
+ ];
123
+ routerBuilder.applyPathsToRouterProxy(null, paths, null, "", {}, "");
124
+ (0, chai_1.expect)(bindStub.calledWith(null, paths[0], null)).to.be.true;
125
+ (0, chai_1.expect)(bindStub.callCount).to.be.eql(paths.length);
126
+ });
127
+ it("should method return expected object which represents a single versioned route", () => {
128
+ const bindStub = sinon_1.default.stub(routerBuilder, "applyCallbackToRouter");
129
+ const paths = [
130
+ { path: [""], requestMethod: enums_1.RequestMethod.GET },
131
+ { path: ["test"], requestMethod: enums_1.RequestMethod.GET },
132
+ { path: ["foo", "bar"], requestMethod: enums_1.RequestMethod.GET },
133
+ ];
134
+ const routePathMetadata = {
135
+ versioningOptions: { type: enums_1.VersioningType.URI },
136
+ };
137
+ routerBuilder.applyPathsToRouterProxy(null, paths, null, "", routePathMetadata, "1");
138
+ (0, chai_1.expect)(bindStub.calledWith(null, paths[0], null, "", routePathMetadata, "1")).to.be.true;
139
+ (0, chai_1.expect)(bindStub.callCount).to.be.eql(paths.length);
140
+ });
141
+ });
142
+ describe("extractRouterPath", () => {
143
+ it("should return expected path", () => {
144
+ (0, chai_1.expect)(routerBuilder.extractRouterPath(TestRoute)).to.be.eql(["/global"]);
145
+ });
146
+ it("should return expected path with alias", () => {
147
+ (0, chai_1.expect)(routerBuilder.extractRouterPath(TestRouteAlias)).to.be.eql(["/global", "/global-alias"]);
148
+ });
149
+ it("should return [] when missing the `@Controller()` decorator in the class, displaying class's name", () => {
150
+ (0, chai_1.expect)(routerBuilder.extractRouterPath(ClassWithMissingControllerDecorator)).to.be.eql([]);
151
+ });
152
+ });
153
+ describe("createRequestScopedHandler", () => {
154
+ let nextSpy;
155
+ beforeEach(() => {
156
+ sinon_1.default.stub(injector, "loadPerContext").callsFake(() => {
157
+ throw new Error();
158
+ });
159
+ nextSpy = sinon_1.default.spy();
160
+ sinon_1.default.stub(exceptionsFilter, "create").callsFake(() => ({
161
+ next: nextSpy,
162
+ }));
163
+ });
164
+ describe('when "loadPerContext" throws', () => {
165
+ const moduleKey = "moduleKey";
166
+ const methodKey = "methodKey";
167
+ const module = {
168
+ controllers: new Map(),
169
+ };
170
+ const wrapper = new wrapper_1.InstanceWrapper({
171
+ instance: { [methodKey]: {} },
172
+ });
173
+ it("should delegate error to exception filters", async () => {
174
+ const handler = routerBuilder.createRequestScopedHandler(wrapper, enums_1.RequestMethod.ALL, module, moduleKey, methodKey);
175
+ await handler(null, null, null);
176
+ (0, chai_1.expect)(nextSpy.called).to.be.true;
177
+ (0, chai_1.expect)(nextSpy.getCall(0).args[0]).to.be.instanceOf(Error);
178
+ (0, chai_1.expect)(nextSpy.getCall(0).args[1]).to.be.instanceOf(execution_host_1.ExecutionContextHost);
179
+ });
180
+ });
181
+ });
182
+ describe("applyVersionFilter", () => {
183
+ it("should call and return the `applyVersionFilter` from the underlying http server", () => {
184
+ const router = sinon_1.default.spy(new helpers_1.NoopHttpAdapter({}));
185
+ const routePathMetadata = {
186
+ methodVersion: sinon_1.default.fake(),
187
+ versioningOptions: sinon_1.default.fake(),
188
+ };
189
+ const handler = sinon_1.default.stub();
190
+ // We're using type assertion here because `applyVersionFilter` is private
191
+ const versionFilter = routerBuilder.applyVersionFilter(router, routePathMetadata, handler);
192
+ (0, chai_1.expect)(router.applyVersionFilter.calledOnceWithExactly(handler, routePathMetadata.methodVersion, routePathMetadata.versioningOptions)).to.be.true;
193
+ (0, chai_1.expect)(router.applyVersionFilter.returnValues[0]).to.be.equal(versionFilter);
194
+ });
195
+ });
196
+ describe("copyMetadataToCallback", () => {
197
+ it("should then copy the metadata from the original callback to the target callback", () => {
198
+ const originalCallback = () => { };
199
+ Reflect.defineMetadata("test_metadata_key", "test_metadata_value", originalCallback);
200
+ const targetCallback = () => { };
201
+ // We're using type assertion here because `copyMetadataToCallback` is private
202
+ routerBuilder.copyMetadataToCallback(originalCallback, targetCallback);
203
+ (0, chai_1.expect)(Reflect.getMetadata("test_metadata_key", targetCallback)).to.be.equal("test_metadata_value");
204
+ });
205
+ });
206
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const chai_1 = require("chai");
4
+ const factory_1 = require("../../factory");
5
+ const enums_1 = require("../../enums");
6
+ describe("RouterMethodFactory", () => {
7
+ let factory;
8
+ const target = {
9
+ get: () => { },
10
+ post: () => { },
11
+ use: () => { },
12
+ delete: () => { },
13
+ put: () => { },
14
+ patch: () => { },
15
+ options: () => { },
16
+ head: () => { },
17
+ all: () => { },
18
+ };
19
+ beforeEach(() => {
20
+ factory = new factory_1.RouterMethodFactory();
21
+ });
22
+ it("should return proper method", () => {
23
+ (0, chai_1.expect)(factory.get(target, enums_1.RequestMethod.DELETE)).to.equal(target.delete);
24
+ (0, chai_1.expect)(factory.get(target, enums_1.RequestMethod.POST)).to.equal(target.post);
25
+ (0, chai_1.expect)(factory.get(target, enums_1.RequestMethod.ALL)).to.equal(target.all);
26
+ (0, chai_1.expect)(factory.get(target, enums_1.RequestMethod.PUT)).to.equal(target.put);
27
+ (0, chai_1.expect)(factory.get(target, enums_1.RequestMethod.GET)).to.equal(target.get);
28
+ (0, chai_1.expect)(factory.get(target, enums_1.RequestMethod.PATCH)).to.equal(target.patch);
29
+ (0, chai_1.expect)(factory.get(target, enums_1.RequestMethod.OPTIONS)).to.equal(target.options);
30
+ (0, chai_1.expect)(factory.get(target, enums_1.RequestMethod.HEAD)).to.equal(target.head);
31
+ (0, chai_1.expect)(factory.get(target, -1)).to.equal(target.use);
32
+ });
33
+ });