@tsed/platform-test-sdk 7.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/components/PlatformTestSdk.js +31 -0
- package/lib/cjs/components/PlatformTestSdk.js.map +1 -0
- package/lib/cjs/data/swagger.json +32 -0
- package/lib/cjs/errors/CustomBadRequest.js +18 -0
- package/lib/cjs/errors/CustomBadRequest.js.map +1 -0
- package/lib/cjs/errors/CustomInternalError.js +18 -0
- package/lib/cjs/errors/CustomInternalError.js.map +1 -0
- package/lib/cjs/index.js +42 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/interfaces/PlatformTestingSdkOpts.js +3 -0
- package/lib/cjs/interfaces/PlatformTestingSdkOpts.js.map +1 -0
- package/lib/cjs/interfaces/index.js +8 -0
- package/lib/cjs/interfaces/index.js.map +1 -0
- package/lib/cjs/modules/feature/FeatureModule.js +17 -0
- package/lib/cjs/modules/feature/FeatureModule.js.map +1 -0
- package/lib/cjs/modules/feature/controllers/FeatureController.js +23 -0
- package/lib/cjs/modules/feature/controllers/FeatureController.js.map +1 -0
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/tests/exports.js +66 -0
- package/lib/cjs/tests/exports.js.map +1 -0
- package/lib/cjs/tests/testAcceptMime.js +103 -0
- package/lib/cjs/tests/testAcceptMime.js.map +1 -0
- package/lib/cjs/tests/testAuth.js +343 -0
- package/lib/cjs/tests/testAuth.js.map +1 -0
- package/lib/cjs/tests/testBodyParams.js +526 -0
- package/lib/cjs/tests/testBodyParams.js.map +1 -0
- package/lib/cjs/tests/testCache.js +292 -0
- package/lib/cjs/tests/testCache.js.map +1 -0
- package/lib/cjs/tests/testChildrenControllers.js +64 -0
- package/lib/cjs/tests/testChildrenControllers.js.map +1 -0
- package/lib/cjs/tests/testCookies.js +45 -0
- package/lib/cjs/tests/testCookies.js.map +1 -0
- package/lib/cjs/tests/testCtrlInheritance.js +161 -0
- package/lib/cjs/tests/testCtrlInheritance.js.map +1 -0
- package/lib/cjs/tests/testCustom404.js +32 -0
- package/lib/cjs/tests/testCustom404.js.map +1 -0
- package/lib/cjs/tests/testErrors.js +252 -0
- package/lib/cjs/tests/testErrors.js.map +1 -0
- package/lib/cjs/tests/testHandlers.js +110 -0
- package/lib/cjs/tests/testHandlers.js.map +1 -0
- package/lib/cjs/tests/testHeaderParams.js +166 -0
- package/lib/cjs/tests/testHeaderParams.js.map +1 -0
- package/lib/cjs/tests/testHeaders.js +101 -0
- package/lib/cjs/tests/testHeaders.js.map +1 -0
- package/lib/cjs/tests/testInheritanceController.js +173 -0
- package/lib/cjs/tests/testInheritanceController.js.map +1 -0
- package/lib/cjs/tests/testLocals.js +63 -0
- package/lib/cjs/tests/testLocals.js.map +1 -0
- package/lib/cjs/tests/testLocation.js +42 -0
- package/lib/cjs/tests/testLocation.js.map +1 -0
- package/lib/cjs/tests/testMiddlewares.js +210 -0
- package/lib/cjs/tests/testMiddlewares.js.map +1 -0
- package/lib/cjs/tests/testModule.js +49 -0
- package/lib/cjs/tests/testModule.js.map +1 -0
- package/lib/cjs/tests/testMulter.js +162 -0
- package/lib/cjs/tests/testMulter.js.map +1 -0
- package/lib/cjs/tests/testPathParams.js +142 -0
- package/lib/cjs/tests/testPathParams.js.map +1 -0
- package/lib/cjs/tests/testQueryParams.js +354 -0
- package/lib/cjs/tests/testQueryParams.js.map +1 -0
- package/lib/cjs/tests/testRedirect.js +143 -0
- package/lib/cjs/tests/testRedirect.js.map +1 -0
- package/lib/cjs/tests/testResponse.js +622 -0
- package/lib/cjs/tests/testResponse.js.map +1 -0
- package/lib/cjs/tests/testResponseFilter.js +107 -0
- package/lib/cjs/tests/testResponseFilter.js.map +1 -0
- package/lib/cjs/tests/testRouting.js +75 -0
- package/lib/cjs/tests/testRouting.js.map +1 -0
- package/lib/cjs/tests/testScopeRequest.js +116 -0
- package/lib/cjs/tests/testScopeRequest.js.map +1 -0
- package/lib/cjs/tests/testSession.js +128 -0
- package/lib/cjs/tests/testSession.js.map +1 -0
- package/lib/cjs/tests/testStatics.js +58 -0
- package/lib/cjs/tests/testStatics.js.map +1 -0
- package/lib/cjs/tests/testView.js +83 -0
- package/lib/cjs/tests/testView.js.map +1 -0
- package/lib/esm/components/PlatformTestSdk.js +27 -0
- package/lib/esm/components/PlatformTestSdk.js.map +1 -0
- package/lib/esm/data/swagger.json +32 -0
- package/lib/esm/errors/CustomBadRequest.js +14 -0
- package/lib/esm/errors/CustomBadRequest.js.map +1 -0
- package/lib/esm/errors/CustomInternalError.js +14 -0
- package/lib/esm/errors/CustomInternalError.js.map +1 -0
- package/lib/esm/index.js +39 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/interfaces/PlatformTestingSdkOpts.js +2 -0
- package/lib/esm/interfaces/PlatformTestingSdkOpts.js.map +1 -0
- package/lib/esm/interfaces/index.js +5 -0
- package/lib/esm/interfaces/index.js.map +1 -0
- package/lib/esm/modules/feature/FeatureModule.js +14 -0
- package/lib/esm/modules/feature/FeatureModule.js.map +1 -0
- package/lib/esm/modules/feature/controllers/FeatureController.js +20 -0
- package/lib/esm/modules/feature/controllers/FeatureController.js.map +1 -0
- package/lib/esm/package.json +3 -0
- package/lib/esm/tests/exports.js +63 -0
- package/lib/esm/tests/exports.js.map +1 -0
- package/lib/esm/tests/testAcceptMime.js +99 -0
- package/lib/esm/tests/testAcceptMime.js.map +1 -0
- package/lib/esm/tests/testAuth.js +338 -0
- package/lib/esm/tests/testAuth.js.map +1 -0
- package/lib/esm/tests/testBodyParams.js +522 -0
- package/lib/esm/tests/testBodyParams.js.map +1 -0
- package/lib/esm/tests/testCache.js +288 -0
- package/lib/esm/tests/testCache.js.map +1 -0
- package/lib/esm/tests/testChildrenControllers.js +60 -0
- package/lib/esm/tests/testChildrenControllers.js.map +1 -0
- package/lib/esm/tests/testCookies.js +41 -0
- package/lib/esm/tests/testCookies.js.map +1 -0
- package/lib/esm/tests/testCtrlInheritance.js +156 -0
- package/lib/esm/tests/testCtrlInheritance.js.map +1 -0
- package/lib/esm/tests/testCustom404.js +27 -0
- package/lib/esm/tests/testCustom404.js.map +1 -0
- package/lib/esm/tests/testErrors.js +248 -0
- package/lib/esm/tests/testErrors.js.map +1 -0
- package/lib/esm/tests/testHandlers.js +105 -0
- package/lib/esm/tests/testHandlers.js.map +1 -0
- package/lib/esm/tests/testHeaderParams.js +162 -0
- package/lib/esm/tests/testHeaderParams.js.map +1 -0
- package/lib/esm/tests/testHeaders.js +97 -0
- package/lib/esm/tests/testHeaders.js.map +1 -0
- package/lib/esm/tests/testInheritanceController.js +167 -0
- package/lib/esm/tests/testInheritanceController.js.map +1 -0
- package/lib/esm/tests/testLocals.js +59 -0
- package/lib/esm/tests/testLocals.js.map +1 -0
- package/lib/esm/tests/testLocation.js +38 -0
- package/lib/esm/tests/testLocation.js.map +1 -0
- package/lib/esm/tests/testMiddlewares.js +206 -0
- package/lib/esm/tests/testMiddlewares.js.map +1 -0
- package/lib/esm/tests/testModule.js +45 -0
- package/lib/esm/tests/testModule.js.map +1 -0
- package/lib/esm/tests/testMulter.js +156 -0
- package/lib/esm/tests/testMulter.js.map +1 -0
- package/lib/esm/tests/testPathParams.js +138 -0
- package/lib/esm/tests/testPathParams.js.map +1 -0
- package/lib/esm/tests/testQueryParams.js +349 -0
- package/lib/esm/tests/testQueryParams.js.map +1 -0
- package/lib/esm/tests/testRedirect.js +139 -0
- package/lib/esm/tests/testRedirect.js.map +1 -0
- package/lib/esm/tests/testResponse.js +615 -0
- package/lib/esm/tests/testResponse.js.map +1 -0
- package/lib/esm/tests/testResponseFilter.js +103 -0
- package/lib/esm/tests/testResponseFilter.js.map +1 -0
- package/lib/esm/tests/testRouting.js +71 -0
- package/lib/esm/tests/testRouting.js.map +1 -0
- package/lib/esm/tests/testScopeRequest.js +112 -0
- package/lib/esm/tests/testScopeRequest.js.map +1 -0
- package/lib/esm/tests/testSession.js +122 -0
- package/lib/esm/tests/testSession.js.map +1 -0
- package/lib/esm/tests/testStatics.js +54 -0
- package/lib/esm/tests/testStatics.js.map +1 -0
- package/lib/esm/tests/testView.js +79 -0
- package/lib/esm/tests/testView.js.map +1 -0
- package/lib/types/components/PlatformTestSdk.d.ts +9 -0
- package/lib/types/errors/CustomBadRequest.d.ts +8 -0
- package/lib/types/errors/CustomInternalError.d.ts +8 -0
- package/lib/types/index.d.ts +38 -0
- package/lib/types/interfaces/PlatformTestingSdkOpts.d.ts +8 -0
- package/lib/types/interfaces/index.d.ts +4 -0
- package/lib/types/modules/feature/FeatureModule.d.ts +2 -0
- package/lib/types/modules/feature/controllers/FeatureController.d.ts +3 -0
- package/lib/types/tests/exports.d.ts +2 -0
- package/lib/types/tests/testAcceptMime.d.ts +2 -0
- package/lib/types/tests/testAuth.d.ts +8 -0
- package/lib/types/tests/testBodyParams.d.ts +3 -0
- package/lib/types/tests/testCache.d.ts +2 -0
- package/lib/types/tests/testChildrenControllers.d.ts +2 -0
- package/lib/types/tests/testCookies.d.ts +11 -0
- package/lib/types/tests/testCtrlInheritance.d.ts +18 -0
- package/lib/types/tests/testCustom404.d.ts +2 -0
- package/lib/types/tests/testErrors.d.ts +19 -0
- package/lib/types/tests/testHandlers.d.ts +12 -0
- package/lib/types/tests/testHeaderParams.d.ts +16 -0
- package/lib/types/tests/testHeaders.d.ts +8 -0
- package/lib/types/tests/testInheritanceController.d.ts +28 -0
- package/lib/types/tests/testLocals.d.ts +2 -0
- package/lib/types/tests/testLocation.d.ts +2 -0
- package/lib/types/tests/testMiddlewares.d.ts +8 -0
- package/lib/types/tests/testModule.d.ts +2 -0
- package/lib/types/tests/testMulter.d.ts +21 -0
- package/lib/types/tests/testPathParams.d.ts +2 -0
- package/lib/types/tests/testQueryParams.d.ts +6 -0
- package/lib/types/tests/testRedirect.d.ts +2 -0
- package/lib/types/tests/testResponse.d.ts +16 -0
- package/lib/types/tests/testResponseFilter.d.ts +2 -0
- package/lib/types/tests/testRouting.d.ts +7 -0
- package/lib/types/tests/testScopeRequest.d.ts +12 -0
- package/lib/types/tests/testSession.d.ts +16 -0
- package/lib/types/tests/testStatics.d.ts +2 -0
- package/lib/types/tests/testView.d.ts +2 -0
- package/package.json +44 -0
- package/src/components/PlatformTestSdk.ts +29 -0
- package/src/data/file.txt +1 -0
- package/src/data/response.data.json +3 -0
- package/src/data/swagger.json +32 -0
- package/src/errors/CustomBadRequest.ts +16 -0
- package/src/errors/CustomInternalError.ts +16 -0
- package/src/index.ts +39 -0
- package/src/interfaces/PlatformTestingSdkOpts.ts +10 -0
- package/src/interfaces/index.ts +5 -0
- package/src/modules/feature/FeatureModule.ts +9 -0
- package/src/modules/feature/controllers/FeatureController.ts +11 -0
- package/src/tests/exports.ts +69 -0
- package/src/tests/testAcceptMime.ts +95 -0
- package/src/tests/testAuth.ts +339 -0
- package/src/tests/testBodyParams.ts +455 -0
- package/src/tests/testCache.ts +270 -0
- package/src/tests/testChildrenControllers.ts +55 -0
- package/src/tests/testCookies.ts +36 -0
- package/src/tests/testCtrlInheritance.ts +140 -0
- package/src/tests/testCustom404.ts +33 -0
- package/src/tests/testErrors.ts +223 -0
- package/src/tests/testHandlers.ts +92 -0
- package/src/tests/testHeaderParams.ts +149 -0
- package/src/tests/testHeaders.ts +91 -0
- package/src/tests/testInheritanceController.ts +156 -0
- package/src/tests/testLocals.ts +46 -0
- package/src/tests/testLocation.ts +37 -0
- package/src/tests/testMiddlewares.ts +159 -0
- package/src/tests/testModule.ts +46 -0
- package/src/tests/testMulter.ts +140 -0
- package/src/tests/testPathParams.ts +122 -0
- package/src/tests/testQueryParams.ts +323 -0
- package/src/tests/testRedirect.ts +124 -0
- package/src/tests/testResponse.ts +558 -0
- package/src/tests/testResponseFilter.ts +101 -0
- package/src/tests/testRouting.ts +65 -0
- package/src/tests/testScopeRequest.ts +111 -0
- package/src/tests/testSession.ts +104 -0
- package/src/tests/testStatics.ts +61 -0
- package/src/tests/testView.ts +68 -0
- package/tsconfig.compile.esm.json +12 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.testView = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@tsed/common");
|
|
6
|
+
const os_1 = require("os");
|
|
7
|
+
const supertest_1 = tslib_1.__importDefault(require("supertest"));
|
|
8
|
+
const platform_views_1 = require("@tsed/platform-views");
|
|
9
|
+
let LocalsMiddleware = class LocalsMiddleware {
|
|
10
|
+
use(locals) {
|
|
11
|
+
locals.localID = "local-10909";
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
tslib_1.__decorate([
|
|
15
|
+
tslib_1.__param(0, (0, common_1.Locals)()),
|
|
16
|
+
tslib_1.__metadata("design:type", Function),
|
|
17
|
+
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
18
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
19
|
+
], LocalsMiddleware.prototype, "use", null);
|
|
20
|
+
LocalsMiddleware = tslib_1.__decorate([
|
|
21
|
+
(0, common_1.Middleware)()
|
|
22
|
+
], LocalsMiddleware);
|
|
23
|
+
let ViewCtrl = class ViewCtrl {
|
|
24
|
+
testScenario1() {
|
|
25
|
+
return {
|
|
26
|
+
world: "world"
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
testScenario2() {
|
|
30
|
+
return {
|
|
31
|
+
world: "world"
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
tslib_1.__decorate([
|
|
36
|
+
(0, common_1.Get)("/scenario-1"),
|
|
37
|
+
(0, common_1.UseBefore)(LocalsMiddleware),
|
|
38
|
+
(0, platform_views_1.View)("view.ejs", { opts: "opts" }),
|
|
39
|
+
tslib_1.__metadata("design:type", Function),
|
|
40
|
+
tslib_1.__metadata("design:paramtypes", []),
|
|
41
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
42
|
+
], ViewCtrl.prototype, "testScenario1", null);
|
|
43
|
+
tslib_1.__decorate([
|
|
44
|
+
(0, common_1.Get)("/scenario-2"),
|
|
45
|
+
(0, platform_views_1.View)("view", { opts: "opts" }) // missing extension
|
|
46
|
+
,
|
|
47
|
+
tslib_1.__metadata("design:type", Function),
|
|
48
|
+
tslib_1.__metadata("design:paramtypes", []),
|
|
49
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
50
|
+
], ViewCtrl.prototype, "testScenario2", null);
|
|
51
|
+
ViewCtrl = tslib_1.__decorate([
|
|
52
|
+
(0, common_1.Controller)("/views")
|
|
53
|
+
], ViewCtrl);
|
|
54
|
+
function testView(options) {
|
|
55
|
+
let request;
|
|
56
|
+
beforeAll(common_1.PlatformTest.bootstrap(options.server, {
|
|
57
|
+
...options,
|
|
58
|
+
mount: {
|
|
59
|
+
"/rest": [ViewCtrl]
|
|
60
|
+
}
|
|
61
|
+
}));
|
|
62
|
+
beforeAll(() => {
|
|
63
|
+
request = (0, supertest_1.default)(common_1.PlatformTest.callback());
|
|
64
|
+
});
|
|
65
|
+
afterAll(common_1.PlatformTest.reset);
|
|
66
|
+
describe("Scenario1: GET /rest/views/scenario-1", () => {
|
|
67
|
+
it("should render a view", async () => {
|
|
68
|
+
const response = await request.get("/rest/views/scenario-1").expect(200);
|
|
69
|
+
expect(response.headers["content-type"]).toEqual("text/html; charset=utf-8");
|
|
70
|
+
expect(response.text).toEqual(`<p>Hello world with opts and ID local-10909</p>${os_1.EOL}`);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
describe("Scenario2: GET /rest/views/scenario-2", () => {
|
|
74
|
+
it("should throw an error when extension is not defined", async () => {
|
|
75
|
+
const response = await request.get("/rest/views/scenario-2").expect(500);
|
|
76
|
+
expect(response.body.name).toEqual("TEMPLATE_RENDER_ERROR");
|
|
77
|
+
expect(response.body.message).toContain("Template rendering error: ViewCtrl.testScenario2()");
|
|
78
|
+
expect(response.body.status).toEqual(500);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
exports.testView = testView;
|
|
83
|
+
//# sourceMappingURL=testView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testView.js","sourceRoot":"","sources":["../../../src/tests/testView.ts"],"names":[],"mappings":";;;;AAAA,yCAA0F;AAC1F,2BAAuB;AACvB,kEAAkC;AAClC,yDAA0C;AAI1C,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IACpB,GAAG,CAAW,MAAW;QACvB,MAAM,CAAC,OAAO,GAAG,aAAa,CAAC;IACjC,CAAC;CACF,CAAA;AAHC;IAAK,mBAAA,IAAA,eAAM,GAAE,CAAA;;;;2CAEZ;AAHG,gBAAgB;IADrB,IAAA,mBAAU,GAAE;GACP,gBAAgB,CAIrB;AAGD,IAAM,QAAQ,GAAd,MAAM,QAAQ;IAIZ,aAAa;QACX,OAAO;YACL,KAAK,EAAE,OAAO;SACf,CAAC;IACJ,CAAC;IAID,aAAa;QACX,OAAO;YACL,KAAK,EAAE,OAAO;SACf,CAAC;IACJ,CAAC;CACF,CAAA;AAbC;IAHC,IAAA,YAAG,EAAC,aAAa,CAAC;IAClB,IAAA,kBAAS,EAAC,gBAAgB,CAAC;IAC3B,IAAA,qBAAI,EAAC,UAAU,EAAE,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;;;;6CAKhC;AAID;IAFC,IAAA,YAAG,EAAC,aAAa,CAAC;IAClB,IAAA,qBAAI,EAAC,MAAM,EAAE,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC,CAAC,oBAAoB;;;;;6CAKjD;AAhBG,QAAQ;IADb,IAAA,mBAAU,EAAC,QAAQ,CAAC;GACf,QAAQ,CAiBb;AAED,SAAgB,QAAQ,CAAC,OAA+B;IACtD,IAAI,OAA4C,CAAC;IAEjD,SAAS,CACP,qBAAY,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE;QACrC,GAAG,OAAO;QACV,KAAK,EAAE;YACL,OAAO,EAAE,CAAC,QAAQ,CAAC;SACpB;KACF,CAAC,CACH,CAA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} from \"@tsed/common\";\nimport {EOL} from \"os\";\nimport SuperTest from \"supertest\";\nimport {View} from \"@tsed/platform-views\";\nimport {PlatformTestingSdkOpts} from \"../interfaces\";\n\n@Middleware()\nclass LocalsMiddleware {\n use(@Locals() locals: any) {\n locals.localID = \"local-10909\";\n }\n}\n\n@Controller(\"/views\")\nclass ViewCtrl {\n @Get(\"/scenario-1\")\n @UseBefore(LocalsMiddleware)\n @View(\"view.ejs\", {opts: \"opts\"})\n testScenario1() {\n return {\n world: \"world\"\n };\n }\n\n @Get(\"/scenario-2\")\n @View(\"view\", {opts: \"opts\"}) // missing extension\n testScenario2() {\n return {\n world: \"world\"\n };\n }\n}\n\nexport function testView(options: PlatformTestingSdkOpts) {\n let request: SuperTest.SuperTest<SuperTest.Test>;\n\n beforeAll(\n PlatformTest.bootstrap(options.server, {\n ...options,\n mount: {\n \"/rest\": [ViewCtrl]\n }\n })\n );\n beforeAll(() => {\n request = SuperTest(PlatformTest.callback());\n });\n afterAll(PlatformTest.reset);\n\n describe(\"Scenario1: GET /rest/views/scenario-1\", () => {\n it(\"should render a view\", async () => {\n const response = await request.get(\"/rest/views/scenario-1\").expect(200);\n\n expect(response.headers[\"content-type\"]).toEqual(\"text/html; charset=utf-8\");\n expect(response.text).toEqual(`<p>Hello world with opts and ID local-10909</p>${EOL}`);\n });\n });\n\n describe(\"Scenario2: GET /rest/views/scenario-2\", () => {\n it(\"should throw an error when extension is not defined\", async () => {\n const response = await request.get(\"/rest/views/scenario-2\").expect(500);\n\n expect(response.body.name).toEqual(\"TEMPLATE_RENDER_ERROR\");\n expect(response.body.message).toContain(\"Template rendering error: ViewCtrl.testScenario2()\");\n expect(response.body.status).toEqual(500);\n });\n });\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { PlatformTest } from "@tsed/common";
|
|
2
|
+
import { specsContainer } from "../tests/exports.js";
|
|
3
|
+
export class PlatformTestSdk {
|
|
4
|
+
options;
|
|
5
|
+
constructor(options) {
|
|
6
|
+
this.options = options;
|
|
7
|
+
}
|
|
8
|
+
static create(options) {
|
|
9
|
+
return new PlatformTestSdk(options);
|
|
10
|
+
}
|
|
11
|
+
test(name, options = {}) {
|
|
12
|
+
specsContainer.get(name)({
|
|
13
|
+
...this.options,
|
|
14
|
+
...options
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
bootstrap(options = {}) {
|
|
18
|
+
return PlatformTest.bootstrap(this.options.server, {
|
|
19
|
+
...this.options,
|
|
20
|
+
...options
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
reset() {
|
|
24
|
+
return PlatformTest.reset;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=PlatformTestSdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlatformTestSdk.js","sourceRoot":"","sources":["../../../src/components/PlatformTestSdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEhD,MAAM,OAAO,eAAe;IACI;IAA9B,YAA8B,OAA+B;QAA/B,YAAO,GAAP,OAAO,CAAwB;IAAG,CAAC;IAEjE,MAAM,CAAC,MAAM,CAAC,OAA+B;QAC3C,OAAO,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;IAED,IAAI,CAAC,IAAY,EAAE,UAAe,EAAE;QAClC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC;YACxB,GAAG,IAAI,CAAC,OAAO;YACf,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC;IAED,SAAS,CAAC,UAAe,EAAE;QACzB,OAAO,YAAY,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YACjD,GAAG,IAAI,CAAC,OAAO;YACf,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC;IAED,KAAK;QACH,OAAO,YAAY,CAAC,KAAK,CAAC;IAC5B,CAAC;CACF","sourcesContent":["import {PlatformTest} from \"@tsed/common\";\nimport {PlatformTestingSdkOpts} from \"../interfaces/index\";\nimport {specsContainer} from \"../tests/exports\";\n\nexport class PlatformTestSdk {\n protected constructor(private options: PlatformTestingSdkOpts) {}\n\n static create(options: PlatformTestingSdkOpts) {\n return new PlatformTestSdk(options);\n }\n\n test(name: string, options: any = {}) {\n specsContainer.get(name)!({\n ...this.options,\n ...options\n });\n }\n\n bootstrap(options: any = {}) {\n return PlatformTest.bootstrap(this.options.server, {\n ...this.options,\n ...options\n });\n }\n\n reset() {\n return PlatformTest.reset;\n }\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"openapi": "3.0.1",
|
|
3
|
+
"info": {
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"description": "Swagger description",
|
|
6
|
+
"title": "Swagger Title",
|
|
7
|
+
"termsOfService": "http://swagger.io/terms/",
|
|
8
|
+
"contact": {
|
|
9
|
+
"email": "apiteam@swagger.io"
|
|
10
|
+
},
|
|
11
|
+
"license": {
|
|
12
|
+
"name": "Apache 2.0",
|
|
13
|
+
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"components": {
|
|
17
|
+
"securitySchemes": {
|
|
18
|
+
"global_auth": {
|
|
19
|
+
"type": "oauth2",
|
|
20
|
+
"flows": {
|
|
21
|
+
"implicit": {
|
|
22
|
+
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
|
|
23
|
+
"scopes": {
|
|
24
|
+
"admin": "Admin access"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"paths": {}
|
|
32
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BadRequest } from "@tsed/exceptions";
|
|
2
|
+
export class CustomBadRequest extends BadRequest {
|
|
3
|
+
name = "CUSTOM_BAD_REQUEST";
|
|
4
|
+
errors;
|
|
5
|
+
headers = {};
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.errors = ["test"];
|
|
9
|
+
this.headers = {
|
|
10
|
+
"X-HEADER-ERROR": "deny"
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=CustomBadRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomBadRequest.js","sourceRoot":"","sources":["../../../src/errors/CustomBadRequest.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAE5C,MAAM,OAAO,gBAAiB,SAAQ,UAAU;IAC9C,IAAI,GAAG,oBAAoB,CAAC;IAC5B,MAAM,CAAQ;IACd,OAAO,GAAG,EAAE,CAAC;IAEb,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,CAAC,MAAM,CAAC,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG;YACb,gBAAgB,EAAE,MAAM;SACzB,CAAC;IACJ,CAAC;CACF","sourcesContent":["import {ResponseErrorObject} from \"@tsed/common\";\nimport {BadRequest} from \"@tsed/exceptions\";\n\nexport class CustomBadRequest extends BadRequest implements ResponseErrorObject {\n name = \"CUSTOM_BAD_REQUEST\";\n errors: any[];\n headers = {};\n\n constructor(message: string) {\n super(message);\n this.errors = [\"test\"];\n this.headers = {\n \"X-HEADER-ERROR\": \"deny\"\n };\n }\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { InternalServerError } from "@tsed/exceptions";
|
|
2
|
+
export class CustomInternalError extends InternalServerError {
|
|
3
|
+
name = "CUSTOM_INTERNAL_SERVER_ERROR";
|
|
4
|
+
errors;
|
|
5
|
+
headers = {};
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.errors = ["test"];
|
|
9
|
+
this.headers = {
|
|
10
|
+
"X-HEADER-ERROR": "deny"
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=CustomInternalError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomInternalError.js","sourceRoot":"","sources":["../../../src/errors/CustomInternalError.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,mBAAmB,EAAC,MAAM,kBAAkB,CAAC;AAErD,MAAM,OAAO,mBAAoB,SAAQ,mBAAmB;IAC1D,IAAI,GAAG,8BAA8B,CAAC;IACtC,MAAM,CAAQ;IACd,OAAO,GAAG,EAAE,CAAC;IAEb,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,CAAC,MAAM,CAAC,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG;YACb,gBAAgB,EAAE,MAAM;SACzB,CAAC;IACJ,CAAC;CACF","sourcesContent":["import {ResponseErrorObject} from \"@tsed/common\";\nimport {InternalServerError} from \"@tsed/exceptions\";\n\nexport class CustomInternalError extends InternalServerError implements ResponseErrorObject {\n name = \"CUSTOM_INTERNAL_SERVER_ERROR\";\n errors: any[];\n headers = {};\n\n constructor(message: string) {\n super(message);\n this.errors = [\"test\"];\n this.headers = {\n \"X-HEADER-ERROR\": \"deny\"\n };\n }\n}\n"]}
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by barrelsby.
|
|
3
|
+
*/
|
|
4
|
+
export * from "./components/PlatformTestSdk.js";
|
|
5
|
+
export * from "./errors/CustomBadRequest.js";
|
|
6
|
+
export * from "./errors/CustomInternalError.js";
|
|
7
|
+
export * from "./interfaces/PlatformTestingSdkOpts.js";
|
|
8
|
+
export * from "./modules/feature/FeatureModule.js";
|
|
9
|
+
export * from "./modules/feature/controllers/FeatureController.js";
|
|
10
|
+
export * from "./tests/exports.js";
|
|
11
|
+
export * from "./tests/testAcceptMime.js";
|
|
12
|
+
export * from "./tests/testAuth.js";
|
|
13
|
+
export * from "./tests/testBodyParams.js";
|
|
14
|
+
export * from "./tests/testCache.js";
|
|
15
|
+
export * from "./tests/testChildrenControllers.js";
|
|
16
|
+
export * from "./tests/testCookies.js";
|
|
17
|
+
export * from "./tests/testCtrlInheritance.js";
|
|
18
|
+
export * from "./tests/testCustom404.js";
|
|
19
|
+
export * from "./tests/testErrors.js";
|
|
20
|
+
export * from "./tests/testHandlers.js";
|
|
21
|
+
export * from "./tests/testHeaderParams.js";
|
|
22
|
+
export * from "./tests/testHeaders.js";
|
|
23
|
+
export * from "./tests/testInheritanceController.js";
|
|
24
|
+
export * from "./tests/testLocals.js";
|
|
25
|
+
export * from "./tests/testLocation.js";
|
|
26
|
+
export * from "./tests/testMiddlewares.js";
|
|
27
|
+
export * from "./tests/testModule.js";
|
|
28
|
+
export * from "./tests/testMulter.js";
|
|
29
|
+
export * from "./tests/testPathParams.js";
|
|
30
|
+
export * from "./tests/testQueryParams.js";
|
|
31
|
+
export * from "./tests/testRedirect.js";
|
|
32
|
+
export * from "./tests/testResponse.js";
|
|
33
|
+
export * from "./tests/testResponseFilter.js";
|
|
34
|
+
export * from "./tests/testRouting.js";
|
|
35
|
+
export * from "./tests/testScopeRequest.js";
|
|
36
|
+
export * from "./tests/testSession.js";
|
|
37
|
+
export * from "./tests/testStatics.js";
|
|
38
|
+
export * from "./tests/testView.js";
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qCAAqC,CAAC;AACpD,cAAc,iCAAiC,CAAC;AAChD,cAAc,iDAAiD,CAAC;AAChE,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iCAAiC,CAAC;AAChD,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mCAAmC,CAAC;AAClD,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./components/PlatformTestSdk\";\nexport * from \"./errors/CustomBadRequest\";\nexport * from \"./errors/CustomInternalError\";\nexport * from \"./interfaces/PlatformTestingSdkOpts\";\nexport * from \"./modules/feature/FeatureModule\";\nexport * from \"./modules/feature/controllers/FeatureController\";\nexport * from \"./tests/exports\";\nexport * from \"./tests/testAcceptMime\";\nexport * from \"./tests/testAuth\";\nexport * from \"./tests/testBodyParams\";\nexport * from \"./tests/testCache\";\nexport * from \"./tests/testChildrenControllers\";\nexport * from \"./tests/testCookies\";\nexport * from \"./tests/testCtrlInheritance\";\nexport * from \"./tests/testCustom404\";\nexport * from \"./tests/testErrors\";\nexport * from \"./tests/testHandlers\";\nexport * from \"./tests/testHeaderParams\";\nexport * from \"./tests/testHeaders\";\nexport * from \"./tests/testInheritanceController\";\nexport * from \"./tests/testLocals\";\nexport * from \"./tests/testLocation\";\nexport * from \"./tests/testMiddlewares\";\nexport * from \"./tests/testModule\";\nexport * from \"./tests/testMulter\";\nexport * from \"./tests/testPathParams\";\nexport * from \"./tests/testQueryParams\";\nexport * from \"./tests/testRedirect\";\nexport * from \"./tests/testResponse\";\nexport * from \"./tests/testResponseFilter\";\nexport * from \"./tests/testRouting\";\nexport * from \"./tests/testScopeRequest\";\nexport * from \"./tests/testSession\";\nexport * from \"./tests/testStatics\";\nexport * from \"./tests/testView\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlatformTestingSdkOpts.js","sourceRoot":"","sources":["../../../src/interfaces/PlatformTestingSdkOpts.ts"],"names":[],"mappings":"","sourcesContent":["import {PlatformAdapter} from \"@tsed/common\";\nimport {Type} from \"@tsed/core\";\n\nexport interface PlatformTestingSdkOpts {\n rootDir: string;\n platform: Type<PlatformAdapter<any>>;\n server: Type<any>;\n\n [key: string]: any;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,0BAA0B,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./PlatformTestingSdkOpts\";\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { Module } from "@tsed/di";
|
|
3
|
+
import { FeatureController } from "./controllers/FeatureController.js";
|
|
4
|
+
let FeatureModule = class FeatureModule {
|
|
5
|
+
};
|
|
6
|
+
FeatureModule = __decorate([
|
|
7
|
+
Module({
|
|
8
|
+
mount: {
|
|
9
|
+
"/rest": [FeatureController]
|
|
10
|
+
}
|
|
11
|
+
})
|
|
12
|
+
], FeatureModule);
|
|
13
|
+
export { FeatureModule };
|
|
14
|
+
//# sourceMappingURL=FeatureModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FeatureModule.js","sourceRoot":"","sources":["../../../../src/modules/feature/FeatureModule.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAChC,OAAO,EAAC,iBAAiB,EAAC,MAAM,iCAAiC,CAAC;AAOlE,IAAa,aAAa,GAA1B,MAAa,aAAa;CAAG,CAAA;AAAhB,aAAa;IALzB,MAAM,CAAC;QACN,KAAK,EAAE;YACL,OAAO,EAAE,CAAC,iBAAiB,CAAC;SAC7B;KACF,CAAC;GACW,aAAa,CAAG;SAAhB,aAAa","sourcesContent":["import {Module} from \"@tsed/di\";\nimport {FeatureController} from \"./controllers/FeatureController\";\n\n@Module({\n mount: {\n \"/rest\": [FeatureController]\n }\n})\nexport class FeatureModule {}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { Controller, Get } from "@tsed/common";
|
|
3
|
+
import { Hidden } from "@tsed/swagger";
|
|
4
|
+
let FeatureController = class FeatureController {
|
|
5
|
+
get() {
|
|
6
|
+
return "From feature";
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
__decorate([
|
|
10
|
+
Get("/"),
|
|
11
|
+
__metadata("design:type", Function),
|
|
12
|
+
__metadata("design:paramtypes", []),
|
|
13
|
+
__metadata("design:returntype", void 0)
|
|
14
|
+
], FeatureController.prototype, "get", null);
|
|
15
|
+
FeatureController = __decorate([
|
|
16
|
+
Hidden(),
|
|
17
|
+
Controller("/features")
|
|
18
|
+
], FeatureController);
|
|
19
|
+
export { FeatureController };
|
|
20
|
+
//# sourceMappingURL=FeatureController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FeatureController.js","sourceRoot":"","sources":["../../../../../src/modules/feature/controllers/FeatureController.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAE,GAAG,EAAC,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AAIrC,IAAa,iBAAiB,GAA9B,MAAa,iBAAiB;IAE5B,GAAG;QACD,OAAO,cAAc,CAAC;IACxB,CAAC;CACF,CAAA;AAHC;IADC,GAAG,CAAC,GAAG,CAAC;;;;4CAGR;AAJU,iBAAiB;IAF7B,MAAM,EAAE;IACR,UAAU,CAAC,WAAW,CAAC;GACX,iBAAiB,CAK7B;SALY,iBAAiB","sourcesContent":["import {Controller, Get} from \"@tsed/common\";\nimport {Hidden} from \"@tsed/swagger\";\n\n@Hidden()\n@Controller(\"/features\")\nexport class FeatureController {\n @Get(\"/\")\n get() {\n return \"From feature\";\n }\n}\n"]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { testAcceptMime } from "./testAcceptMime.js";
|
|
2
|
+
import { testAuth } from "./testAuth.js";
|
|
3
|
+
import { testBodyParams } from "./testBodyParams.js";
|
|
4
|
+
import { testChildrenControllers } from "./testChildrenControllers.js";
|
|
5
|
+
import { testCookies } from "./testCookies.js";
|
|
6
|
+
import { testCtrlInheritance } from "./testCtrlInheritance.js";
|
|
7
|
+
import { testCustom404 } from "./testCustom404.js";
|
|
8
|
+
import { testErrors } from "./testErrors.js";
|
|
9
|
+
import { testHandlers } from "./testHandlers.js";
|
|
10
|
+
import { testHeaderParams } from "./testHeaderParams.js";
|
|
11
|
+
import { testHeaders } from "./testHeaders.js";
|
|
12
|
+
import { testInheritanceController } from "./testInheritanceController.js";
|
|
13
|
+
import { testLocals } from "./testLocals.js";
|
|
14
|
+
import { testLocation } from "./testLocation.js";
|
|
15
|
+
import { testMiddlewares } from "./testMiddlewares.js";
|
|
16
|
+
import { testModule } from "./testModule.js";
|
|
17
|
+
import { testMulter } from "./testMulter.js";
|
|
18
|
+
import { testPathParams } from "./testPathParams.js";
|
|
19
|
+
import { testQueryParams } from "./testQueryParams.js";
|
|
20
|
+
import { testRedirect } from "./testRedirect.js";
|
|
21
|
+
import { testResponse } from "./testResponse.js";
|
|
22
|
+
import { testResponseFilter } from "./testResponseFilter.js";
|
|
23
|
+
import { testRouting } from "./testRouting.js";
|
|
24
|
+
import { testScopeRequest } from "./testScopeRequest.js";
|
|
25
|
+
import { testSession } from "./testSession.js";
|
|
26
|
+
import { testStatics } from "./testStatics.js";
|
|
27
|
+
import { testView } from "./testView.js";
|
|
28
|
+
import { testCache } from "./testCache.js";
|
|
29
|
+
export const specsContainer = new Map();
|
|
30
|
+
// HANDLERS AND MIDDLEWARES
|
|
31
|
+
specsContainer.set("handlers", testHandlers);
|
|
32
|
+
specsContainer.set("auth", testAuth);
|
|
33
|
+
specsContainer.set("middlewares", testMiddlewares);
|
|
34
|
+
// RESPONSES
|
|
35
|
+
specsContainer.set("headers", testHeaders);
|
|
36
|
+
specsContainer.set("acceptMime", testAcceptMime);
|
|
37
|
+
specsContainer.set("location", testLocation);
|
|
38
|
+
specsContainer.set("redirect", testRedirect);
|
|
39
|
+
specsContainer.set("view", testView);
|
|
40
|
+
specsContainer.set("errors", testErrors);
|
|
41
|
+
specsContainer.set("response", testResponse);
|
|
42
|
+
specsContainer.set("responseFilter", testResponseFilter);
|
|
43
|
+
specsContainer.set("custom404", testCustom404);
|
|
44
|
+
specsContainer.set("statics", testStatics);
|
|
45
|
+
specsContainer.set("cache", testCache);
|
|
46
|
+
// INPUTS
|
|
47
|
+
specsContainer.set("cookies", testCookies);
|
|
48
|
+
specsContainer.set("session", testSession);
|
|
49
|
+
specsContainer.set("headerParams", testHeaderParams);
|
|
50
|
+
specsContainer.set("bodyParams", testBodyParams);
|
|
51
|
+
specsContainer.set("pathParams", testPathParams);
|
|
52
|
+
specsContainer.set("queryParams", testQueryParams);
|
|
53
|
+
specsContainer.set("locals", testLocals);
|
|
54
|
+
specsContainer.set("multer", testMulter);
|
|
55
|
+
// ROUTING
|
|
56
|
+
specsContainer.set("scopeRequest", testScopeRequest);
|
|
57
|
+
specsContainer.set("routing", testRouting);
|
|
58
|
+
specsContainer.set("inheritance", testCtrlInheritance);
|
|
59
|
+
// CODE ORGANIZATION
|
|
60
|
+
specsContainer.set("childrenControllers", testChildrenControllers);
|
|
61
|
+
specsContainer.set("inheritanceController", testInheritanceController);
|
|
62
|
+
specsContainer.set("module", testModule);
|
|
63
|
+
//# sourceMappingURL=exports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exports.js","sourceRoot":"","sources":["../../../src/tests/exports.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpC,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAC,uBAAuB,EAAC,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AACxC,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,yBAAyB,EAAC,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AACxC,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AACxC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":["import {PlatformTestingSdkOpts} from \"../interfaces\";\nimport {testAcceptMime} from \"./testAcceptMime\";\nimport {testAuth} from \"./testAuth\";\nimport {testBodyParams} from \"./testBodyParams\";\nimport {testChildrenControllers} from \"./testChildrenControllers\";\nimport {testCookies} from \"./testCookies\";\nimport {testCtrlInheritance} from \"./testCtrlInheritance\";\nimport {testCustom404} from \"./testCustom404\";\nimport {testErrors} from \"./testErrors\";\nimport {testHandlers} from \"./testHandlers\";\nimport {testHeaderParams} from \"./testHeaderParams\";\nimport {testHeaders} from \"./testHeaders\";\nimport {testInheritanceController} from \"./testInheritanceController\";\nimport {testLocals} from \"./testLocals\";\nimport {testLocation} from \"./testLocation\";\nimport {testMiddlewares} from \"./testMiddlewares\";\nimport {testModule} from \"./testModule\";\nimport {testMulter} from \"./testMulter\";\nimport {testPathParams} from \"./testPathParams\";\nimport {testQueryParams} from \"./testQueryParams\";\nimport {testRedirect} from \"./testRedirect\";\nimport {testResponse} from \"./testResponse\";\nimport {testResponseFilter} from \"./testResponseFilter\";\nimport {testRouting} from \"./testRouting\";\nimport {testScopeRequest} from \"./testScopeRequest\";\nimport {testSession} from \"./testSession\";\nimport {testStatics} from \"./testStatics\";\nimport {testView} from \"./testView\";\nimport {testCache} from \"./testCache\";\n\nexport const specsContainer = new Map<string, (options: PlatformTestingSdkOpts) => void>();\n\n// HANDLERS AND MIDDLEWARES\nspecsContainer.set(\"handlers\", testHandlers);\nspecsContainer.set(\"auth\", testAuth);\nspecsContainer.set(\"middlewares\", testMiddlewares);\n\n// RESPONSES\nspecsContainer.set(\"headers\", testHeaders);\nspecsContainer.set(\"acceptMime\", testAcceptMime);\nspecsContainer.set(\"location\", testLocation);\nspecsContainer.set(\"redirect\", testRedirect);\nspecsContainer.set(\"view\", testView);\nspecsContainer.set(\"errors\", testErrors);\nspecsContainer.set(\"response\", testResponse);\nspecsContainer.set(\"responseFilter\", testResponseFilter);\nspecsContainer.set(\"custom404\", testCustom404);\nspecsContainer.set(\"statics\", testStatics);\nspecsContainer.set(\"cache\", testCache);\n\n// INPUTS\nspecsContainer.set(\"cookies\", testCookies);\nspecsContainer.set(\"session\", testSession);\nspecsContainer.set(\"headerParams\", testHeaderParams);\nspecsContainer.set(\"bodyParams\", testBodyParams);\nspecsContainer.set(\"pathParams\", testPathParams);\nspecsContainer.set(\"queryParams\", testQueryParams);\nspecsContainer.set(\"locals\", testLocals);\nspecsContainer.set(\"multer\", testMulter);\n\n// ROUTING\nspecsContainer.set(\"scopeRequest\", testScopeRequest);\nspecsContainer.set(\"routing\", testRouting);\nspecsContainer.set(\"inheritance\", testCtrlInheritance);\n\n// CODE ORGANIZATION\nspecsContainer.set(\"childrenControllers\", testChildrenControllers);\nspecsContainer.set(\"inheritanceController\", testInheritanceController);\nspecsContainer.set(\"module\", testModule);\n"]}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
+
import { AcceptMime, Controller, Get, HeaderParams, PlatformTest, Post } from "@tsed/common";
|
|
3
|
+
import { ContentType } from "@tsed/schema";
|
|
4
|
+
import SuperTest from "supertest";
|
|
5
|
+
let TestAcceptMimeCtrl = class TestAcceptMimeCtrl {
|
|
6
|
+
scenario1(accept) {
|
|
7
|
+
return {
|
|
8
|
+
accept
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
ping() {
|
|
12
|
+
return "pong";
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
__decorate([
|
|
16
|
+
Post("/scenario-1"),
|
|
17
|
+
AcceptMime("application/json"),
|
|
18
|
+
__param(0, HeaderParams("Accept")),
|
|
19
|
+
__metadata("design:type", Function),
|
|
20
|
+
__metadata("design:paramtypes", [String]),
|
|
21
|
+
__metadata("design:returntype", void 0)
|
|
22
|
+
], TestAcceptMimeCtrl.prototype, "scenario1", null);
|
|
23
|
+
__decorate([
|
|
24
|
+
Get("/scenario-2"),
|
|
25
|
+
ContentType("text"),
|
|
26
|
+
AcceptMime("text"),
|
|
27
|
+
__metadata("design:type", Function),
|
|
28
|
+
__metadata("design:paramtypes", []),
|
|
29
|
+
__metadata("design:returntype", void 0)
|
|
30
|
+
], TestAcceptMimeCtrl.prototype, "ping", null);
|
|
31
|
+
TestAcceptMimeCtrl = __decorate([
|
|
32
|
+
Controller("/accept-mime")
|
|
33
|
+
], TestAcceptMimeCtrl);
|
|
34
|
+
export function testAcceptMime(options) {
|
|
35
|
+
let request;
|
|
36
|
+
beforeAll(PlatformTest.bootstrap(options.server, {
|
|
37
|
+
...options,
|
|
38
|
+
mount: {
|
|
39
|
+
"/rest": [TestAcceptMimeCtrl]
|
|
40
|
+
}
|
|
41
|
+
}));
|
|
42
|
+
beforeAll(() => {
|
|
43
|
+
request = SuperTest(PlatformTest.callback());
|
|
44
|
+
});
|
|
45
|
+
afterAll(PlatformTest.reset);
|
|
46
|
+
describe("Scenario 1: POST /rest/accept-mime/scenario-1", () => {
|
|
47
|
+
it('should return a 200 response when Accept header match with @AcceptMime("application/json")', async () => {
|
|
48
|
+
const response = await request
|
|
49
|
+
.post("/rest/accept-mime/scenario-1")
|
|
50
|
+
.set({
|
|
51
|
+
Accept: "application/json"
|
|
52
|
+
})
|
|
53
|
+
.expect(200);
|
|
54
|
+
expect(response.body).toEqual({
|
|
55
|
+
accept: "application/json"
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
it('should return a 406 response when Accept header doesn\'t match with @AcceptMime("application/json")', async () => {
|
|
59
|
+
const response = await request
|
|
60
|
+
.post("/rest/accept-mime/scenario-1")
|
|
61
|
+
.set({
|
|
62
|
+
Accept: "application/xml"
|
|
63
|
+
})
|
|
64
|
+
.expect(406);
|
|
65
|
+
expect(response.body).toEqual({
|
|
66
|
+
name: "NOT_ACCEPTABLE",
|
|
67
|
+
message: "You must accept content-type application/json",
|
|
68
|
+
status: 406,
|
|
69
|
+
errors: []
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
describe("Scenario 2: GET /rest/accept-mime/scenario-2", () => {
|
|
74
|
+
it('should return a 200 response when Accept header match with @AcceptMime("text")', async () => {
|
|
75
|
+
const response = await request
|
|
76
|
+
.get("/rest/accept-mime/scenario-2")
|
|
77
|
+
.set({
|
|
78
|
+
Accept: "text/*, application/json"
|
|
79
|
+
})
|
|
80
|
+
.expect(200);
|
|
81
|
+
expect(response.text).toEqual("pong");
|
|
82
|
+
});
|
|
83
|
+
it('should return a 406 response when Accept header doesn\'t match with @AcceptMime("text")', async () => {
|
|
84
|
+
const response = await request
|
|
85
|
+
.get("/rest/accept-mime/scenario-2")
|
|
86
|
+
.set({
|
|
87
|
+
Accept: "application/xml"
|
|
88
|
+
})
|
|
89
|
+
.expect(406);
|
|
90
|
+
expect(response.body).toEqual({
|
|
91
|
+
name: "NOT_ACCEPTABLE",
|
|
92
|
+
message: "You must accept content-type text",
|
|
93
|
+
status: 406,
|
|
94
|
+
errors: []
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=testAcceptMime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testAcceptMime.js","sourceRoot":"","sources":["../../../src/tests/testAcceptMime.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,YAAY,EAAE,YAAY,EAAE,IAAI,EAAC,MAAM,cAAc,CAAC;AAC3F,OAAO,EAAC,WAAW,EAAC,MAAM,cAAc,CAAC;AACzC,OAAO,SAAS,MAAM,WAAW,CAAC;AAIlC,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAGtB,SAAS,CAAyB,MAAc;QAC9C,OAAO;YACL,MAAM;SACP,CAAC;IACJ,CAAC;IAKM,IAAI;QACT,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAA;AAZC;IAFC,IAAI,CAAC,aAAa,CAAC;IACnB,UAAU,CAAC,kBAAkB,CAAC;IACpB,WAAA,YAAY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MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC;gBAC5B,IAAI,EAAE,gBAAgB;gBACtB,OAAO,EAAE,+CAA+C;gBACxD,MAAM,EAAE,GAAG;gBACX,MAAM,EAAE,EAAE;aACX,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,QAAQ,CAAC,8CAA8C,EAAE,GAAG,EAAE;QAC5D,EAAE,CAAC,gFAAgF,EAAE,KAAK,IAAI,EAAE;YAC9F,MAAM,QAAQ,GAAG,MAAM,OAAO;iBAC3B,GAAG,CAAC,8BAA8B,CAAC;iBACnC,GAAG,CAAC;gBACH,MAAM,EAAE,0BAA0B;aACnC,CAAC;iBACD,MAAM,CAAC,GAAG,CAAC,CAAC;YAEf,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,yFAAyF,EAAE,KAAK,IAAI,EAAE;YACvG,MAAM,QAAQ,GAAG,MAAM,OAAO;iBAC3B,GAAG,CAAC,8BAA8B,CAAC;iBACnC,GAAG,CAAC;gBACH,MAAM,EAAE,iBAAiB;aAC1B,CAAC;iBACD,MAAM,CAAC,GAAG,CAAC,CAAC;YAEf,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC;gBAC5B,IAAI,EAAE,gBAAgB;gBACtB,OAAO,EAAE,mCAAmC;gBAC5C,MAAM,EAAE,GAAG;gBACX,MAAM,EAAE,EAAE;aACX,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {AcceptMime, Controller, Get, HeaderParams, PlatformTest, Post} from \"@tsed/common\";\nimport {ContentType} from \"@tsed/schema\";\nimport SuperTest from \"supertest\";\nimport {PlatformTestingSdkOpts} from \"../interfaces\";\n\n@Controller(\"/accept-mime\")\nclass TestAcceptMimeCtrl {\n @Post(\"/scenario-1\")\n @AcceptMime(\"application/json\")\n scenario1(@HeaderParams(\"Accept\") accept: string) {\n return {\n accept\n };\n }\n\n @Get(\"/scenario-2\")\n @ContentType(\"text\")\n @AcceptMime(\"text\")\n public ping() {\n return \"pong\";\n }\n}\n\nexport function testAcceptMime(options: PlatformTestingSdkOpts) {\n let request: SuperTest.SuperTest<SuperTest.Test>;\n\n beforeAll(\n PlatformTest.bootstrap(options.server, {\n ...options,\n mount: {\n \"/rest\": [TestAcceptMimeCtrl]\n }\n })\n );\n beforeAll(() => {\n request = SuperTest(PlatformTest.callback());\n });\n afterAll(PlatformTest.reset);\n describe(\"Scenario 1: POST /rest/accept-mime/scenario-1\", () => {\n it('should return a 200 response when Accept header match with @AcceptMime(\"application/json\")', async () => {\n const response = await request\n .post(\"/rest/accept-mime/scenario-1\")\n .set({\n Accept: \"application/json\"\n })\n .expect(200);\n\n expect(response.body).toEqual({\n accept: \"application/json\"\n });\n });\n it('should return a 406 response when Accept header doesn\\'t match with @AcceptMime(\"application/json\")', async () => {\n const response = await request\n .post(\"/rest/accept-mime/scenario-1\")\n .set({\n Accept: \"application/xml\"\n })\n .expect(406);\n\n expect(response.body).toEqual({\n name: \"NOT_ACCEPTABLE\",\n message: \"You must accept content-type application/json\",\n status: 406,\n errors: []\n });\n });\n });\n describe(\"Scenario 2: GET /rest/accept-mime/scenario-2\", () => {\n it('should return a 200 response when Accept header match with @AcceptMime(\"text\")', async () => {\n const response = await request\n .get(\"/rest/accept-mime/scenario-2\")\n .set({\n Accept: \"text/*, application/json\"\n })\n .expect(200);\n\n expect(response.text).toEqual(\"pong\");\n });\n it('should return a 406 response when Accept header doesn\\'t match with @AcceptMime(\"text\")', async () => {\n const response = await request\n .get(\"/rest/accept-mime/scenario-2\")\n .set({\n Accept: \"application/xml\"\n })\n .expect(406);\n\n expect(response.body).toEqual({\n name: \"NOT_ACCEPTABLE\",\n message: \"You must accept content-type text\",\n status: 406,\n errors: []\n });\n });\n });\n}\n"]}
|