@tsed/platform-test-sdk 7.73.3 → 7.73.5

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 (121) hide show
  1. package/lib/cjs/components/PlatformTestSdk.js.map +1 -0
  2. package/lib/cjs/errors/CustomBadRequest.js.map +1 -0
  3. package/lib/cjs/errors/CustomInternalError.js.map +1 -0
  4. package/lib/cjs/index.js.map +1 -0
  5. package/lib/cjs/interfaces/PlatformTestingSdkOpts.js.map +1 -0
  6. package/lib/cjs/interfaces/index.js.map +1 -0
  7. package/lib/cjs/modules/feature/FeatureModule.js.map +1 -0
  8. package/lib/cjs/modules/feature/controllers/FeatureController.js.map +1 -0
  9. package/lib/cjs/tests/exports.js.map +1 -0
  10. package/lib/cjs/tests/testAcceptMime.js.map +1 -0
  11. package/lib/cjs/tests/testAuth.js.map +1 -0
  12. package/lib/cjs/tests/testBodyParams.js.map +1 -0
  13. package/lib/cjs/tests/testCache.js.map +1 -0
  14. package/lib/cjs/tests/testChildrenControllers.js.map +1 -0
  15. package/lib/cjs/tests/testCookies.js.map +1 -0
  16. package/lib/cjs/tests/testCustom404.js.map +1 -0
  17. package/lib/cjs/tests/testDeepQueryParams.js.map +1 -0
  18. package/lib/cjs/tests/testErrors.js.map +1 -0
  19. package/lib/cjs/tests/testHandlers.js.map +1 -0
  20. package/lib/cjs/tests/testHeaderParams.js.map +1 -0
  21. package/lib/cjs/tests/testHeaders.js.map +1 -0
  22. package/lib/cjs/tests/testInheritanceController.js.map +1 -0
  23. package/lib/cjs/tests/testLocals.js.map +1 -0
  24. package/lib/cjs/tests/testLocation.js.map +1 -0
  25. package/lib/cjs/tests/testMiddlewares.js.map +1 -0
  26. package/lib/cjs/tests/testModule.js.map +1 -0
  27. package/lib/cjs/tests/testMulter.js.map +1 -0
  28. package/lib/cjs/tests/testPathParams.js.map +1 -0
  29. package/lib/cjs/tests/testQueryParams.js.map +1 -0
  30. package/lib/cjs/tests/testRedirect.js.map +1 -0
  31. package/lib/cjs/tests/testResponse.js.map +1 -0
  32. package/lib/cjs/tests/testResponseFilter.js.map +1 -0
  33. package/lib/cjs/tests/testRouting.js.map +1 -0
  34. package/lib/cjs/tests/testScopeRequest.js.map +1 -0
  35. package/lib/cjs/tests/testSession.js.map +1 -0
  36. package/lib/cjs/tests/testStatics.js.map +1 -0
  37. package/lib/cjs/tests/testStream.js.map +1 -0
  38. package/lib/cjs/tests/testView.js.map +1 -0
  39. package/lib/esm/components/PlatformTestSdk.js.map +1 -0
  40. package/lib/esm/errors/CustomBadRequest.js.map +1 -0
  41. package/lib/esm/errors/CustomInternalError.js.map +1 -0
  42. package/lib/esm/index.js.map +1 -0
  43. package/lib/esm/interfaces/PlatformTestingSdkOpts.js.map +1 -0
  44. package/lib/esm/interfaces/index.js.map +1 -0
  45. package/lib/esm/modules/feature/FeatureModule.js.map +1 -0
  46. package/lib/esm/modules/feature/controllers/FeatureController.js.map +1 -0
  47. package/lib/esm/tests/exports.js.map +1 -0
  48. package/lib/esm/tests/testAcceptMime.js.map +1 -0
  49. package/lib/esm/tests/testAuth.js.map +1 -0
  50. package/lib/esm/tests/testBodyParams.js.map +1 -0
  51. package/lib/esm/tests/testCache.js.map +1 -0
  52. package/lib/esm/tests/testChildrenControllers.js.map +1 -0
  53. package/lib/esm/tests/testCookies.js.map +1 -0
  54. package/lib/esm/tests/testCustom404.js.map +1 -0
  55. package/lib/esm/tests/testDeepQueryParams.js.map +1 -0
  56. package/lib/esm/tests/testErrors.js.map +1 -0
  57. package/lib/esm/tests/testHandlers.js.map +1 -0
  58. package/lib/esm/tests/testHeaderParams.js.map +1 -0
  59. package/lib/esm/tests/testHeaders.js.map +1 -0
  60. package/lib/esm/tests/testInheritanceController.js.map +1 -0
  61. package/lib/esm/tests/testLocals.js.map +1 -0
  62. package/lib/esm/tests/testLocation.js.map +1 -0
  63. package/lib/esm/tests/testMiddlewares.js.map +1 -0
  64. package/lib/esm/tests/testModule.js.map +1 -0
  65. package/lib/esm/tests/testMulter.js.map +1 -0
  66. package/lib/esm/tests/testPathParams.js.map +1 -0
  67. package/lib/esm/tests/testQueryParams.js.map +1 -0
  68. package/lib/esm/tests/testRedirect.js.map +1 -0
  69. package/lib/esm/tests/testResponse.js.map +1 -0
  70. package/lib/esm/tests/testResponseFilter.js.map +1 -0
  71. package/lib/esm/tests/testRouting.js.map +1 -0
  72. package/lib/esm/tests/testScopeRequest.js.map +1 -0
  73. package/lib/esm/tests/testSession.js.map +1 -0
  74. package/lib/esm/tests/testStatics.js.map +1 -0
  75. package/lib/esm/tests/testStream.js.map +1 -0
  76. package/lib/esm/tests/testView.js.map +1 -0
  77. package/lib/tsconfig.esm.tsbuildinfo +1 -0
  78. package/lib/tsconfig.tsbuildinfo +1 -0
  79. package/package.json +14 -14
  80. package/src/components/PlatformTestSdk.ts +29 -0
  81. package/src/data/file.txt +1 -0
  82. package/src/data/response.data.json +3 -0
  83. package/src/data/swagger.json +32 -0
  84. package/src/errors/CustomBadRequest.ts +16 -0
  85. package/src/errors/CustomInternalError.ts +16 -0
  86. package/src/index.ts +40 -0
  87. package/src/interfaces/PlatformTestingSdkOpts.ts +10 -0
  88. package/src/interfaces/index.ts +4 -0
  89. package/src/modules/feature/FeatureModule.ts +9 -0
  90. package/src/modules/feature/controllers/FeatureController.ts +11 -0
  91. package/src/tests/exports.ts +71 -0
  92. package/src/tests/testAcceptMime.ts +95 -0
  93. package/src/tests/testAuth.ts +339 -0
  94. package/src/tests/testBodyParams.ts +483 -0
  95. package/src/tests/testCache.ts +279 -0
  96. package/src/tests/testChildrenControllers.ts +55 -0
  97. package/src/tests/testCookies.ts +36 -0
  98. package/src/tests/testCustom404.ts +33 -0
  99. package/src/tests/testDeepQueryParams.ts +120 -0
  100. package/src/tests/testErrors.ts +226 -0
  101. package/src/tests/testHandlers.ts +90 -0
  102. package/src/tests/testHeaderParams.ts +152 -0
  103. package/src/tests/testHeaders.ts +91 -0
  104. package/src/tests/testInheritanceController.ts +200 -0
  105. package/src/tests/testLocals.ts +46 -0
  106. package/src/tests/testLocation.ts +37 -0
  107. package/src/tests/testMiddlewares.ts +159 -0
  108. package/src/tests/testModule.ts +46 -0
  109. package/src/tests/testMulter.ts +151 -0
  110. package/src/tests/testPathParams.ts +123 -0
  111. package/src/tests/testQueryParams.ts +233 -0
  112. package/src/tests/testRedirect.ts +124 -0
  113. package/src/tests/testResponse.ts +528 -0
  114. package/src/tests/testResponseFilter.ts +101 -0
  115. package/src/tests/testRouting.ts +65 -0
  116. package/src/tests/testScopeRequest.ts +111 -0
  117. package/src/tests/testSession.ts +103 -0
  118. package/src/tests/testStatics.ts +61 -0
  119. package/src/tests/testStream.ts +59 -0
  120. package/src/tests/testView.ts +68 -0
  121. package/tsconfig.json +63 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/platform-test-sdk",
3
- "version": "7.73.3",
3
+ "version": "7.73.5",
4
4
  "description": "Package to test platform adapter integration with Ts.ED",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./lib/cjs/index.js",
@@ -25,25 +25,25 @@
25
25
  "Adapter"
26
26
  ],
27
27
  "dependencies": {
28
- "@tsed/ajv": "7.73.3",
29
- "@tsed/common": "7.73.3",
30
- "@tsed/core": "7.73.3",
31
- "@tsed/di": "7.73.3",
32
- "@tsed/json-mapper": "7.73.3",
28
+ "@tsed/ajv": "7.73.5",
29
+ "@tsed/common": "7.73.5",
30
+ "@tsed/core": "7.73.5",
31
+ "@tsed/di": "7.73.5",
32
+ "@tsed/json-mapper": "7.73.5",
33
33
  "@tsed/logger": "6.6.3",
34
- "@tsed/platform-cache": "7.73.3",
35
- "@tsed/platform-params": "7.73.3",
36
- "@tsed/platform-router": "7.73.3",
37
- "@tsed/platform-views": "7.73.3",
38
- "@tsed/schema": "7.73.3",
39
- "@tsed/swagger": "7.73.3",
34
+ "@tsed/platform-cache": "7.73.5",
35
+ "@tsed/platform-params": "7.73.5",
36
+ "@tsed/platform-router": "7.73.5",
37
+ "@tsed/platform-views": "7.73.5",
38
+ "@tsed/schema": "7.73.5",
39
+ "@tsed/swagger": "7.73.5",
40
40
  "ajv": "^8.12.0",
41
41
  "axios": "1.6.8",
42
42
  "read-pkg-up": "7.0.1"
43
43
  },
44
44
  "devDependencies": {
45
- "@tsed/barrels": "7.73.3",
46
- "@tsed/typescript": "7.73.3",
45
+ "@tsed/barrels": "7.73.5",
46
+ "@tsed/typescript": "7.73.5",
47
47
  "eslint": "^8.57.0",
48
48
  "jest": "^29.7.0",
49
49
  "typescript": "4.9.5"
@@ -0,0 +1,29 @@
1
+ import {PlatformTest} from "@tsed/common";
2
+ import {PlatformTestingSdkOpts} from "../interfaces/index.js";
3
+ import {specsContainer} from "../tests/exports.js";
4
+
5
+ export class PlatformTestSdk {
6
+ protected constructor(private options: PlatformTestingSdkOpts) {}
7
+
8
+ static create(options: PlatformTestingSdkOpts) {
9
+ return new PlatformTestSdk(options);
10
+ }
11
+
12
+ test(name: string, options: any = {}) {
13
+ specsContainer.get(name)!({
14
+ ...this.options,
15
+ ...options
16
+ });
17
+ }
18
+
19
+ bootstrap(options: any = {}) {
20
+ return PlatformTest.bootstrap(this.options.server, {
21
+ ...this.options,
22
+ ...options
23
+ });
24
+ }
25
+
26
+ reset() {
27
+ return PlatformTest.reset;
28
+ }
29
+ }
@@ -0,0 +1 @@
1
+ test content
@@ -0,0 +1,3 @@
1
+ {
2
+ "id": "1"
3
+ }
@@ -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,16 @@
1
+ import {ResponseErrorObject} from "@tsed/common";
2
+ import {BadRequest} from "@tsed/exceptions";
3
+
4
+ export class CustomBadRequest extends BadRequest implements ResponseErrorObject {
5
+ name = "CUSTOM_BAD_REQUEST";
6
+ errors: any[];
7
+ headers = {};
8
+
9
+ constructor(message: string) {
10
+ super(message);
11
+ this.errors = ["test"];
12
+ this.headers = {
13
+ "X-HEADER-ERROR": "deny"
14
+ };
15
+ }
16
+ }
@@ -0,0 +1,16 @@
1
+ import {ResponseErrorObject} from "@tsed/common";
2
+ import {InternalServerError} from "@tsed/exceptions";
3
+
4
+ export class CustomInternalError extends InternalServerError implements ResponseErrorObject {
5
+ name = "CUSTOM_INTERNAL_SERVER_ERROR";
6
+ errors: any[];
7
+ headers = {};
8
+
9
+ constructor(message: string) {
10
+ super(message);
11
+ this.errors = ["test"];
12
+ this.headers = {
13
+ "X-HEADER-ERROR": "deny"
14
+ };
15
+ }
16
+ }
package/src/index.ts ADDED
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @file Automatically generated by @tsed/barrels.
3
+ */
4
+ export * from "./components/PlatformTestSdk.js";
5
+ export * from "./errors/CustomBadRequest.js";
6
+ export * from "./errors/CustomInternalError.js";
7
+ export * from "./interfaces/index.js";
8
+ export * from "./interfaces/PlatformTestingSdkOpts.js";
9
+ export * from "./modules/feature/controllers/FeatureController.js";
10
+ export * from "./modules/feature/FeatureModule.js";
11
+ export * from "./tests/exports.js";
12
+ export * from "./tests/testAcceptMime.js";
13
+ export * from "./tests/testAuth.js";
14
+ export * from "./tests/testBodyParams.js";
15
+ export * from "./tests/testCache.js";
16
+ export * from "./tests/testChildrenControllers.js";
17
+ export * from "./tests/testCookies.js";
18
+ export * from "./tests/testCustom404.js";
19
+ export * from "./tests/testDeepQueryParams.js";
20
+ export * from "./tests/testErrors.js";
21
+ export * from "./tests/testHandlers.js";
22
+ export * from "./tests/testHeaderParams.js";
23
+ export * from "./tests/testHeaders.js";
24
+ export * from "./tests/testInheritanceController.js";
25
+ export * from "./tests/testLocals.js";
26
+ export * from "./tests/testLocation.js";
27
+ export * from "./tests/testMiddlewares.js";
28
+ export * from "./tests/testModule.js";
29
+ export * from "./tests/testMulter.js";
30
+ export * from "./tests/testPathParams.js";
31
+ export * from "./tests/testQueryParams.js";
32
+ export * from "./tests/testRedirect.js";
33
+ export * from "./tests/testResponse.js";
34
+ export * from "./tests/testResponseFilter.js";
35
+ export * from "./tests/testRouting.js";
36
+ export * from "./tests/testScopeRequest.js";
37
+ export * from "./tests/testSession.js";
38
+ export * from "./tests/testStatics.js";
39
+ export * from "./tests/testStream.js";
40
+ export * from "./tests/testView.js";
@@ -0,0 +1,10 @@
1
+ import {PlatformAdapter} from "@tsed/common";
2
+ import {Type} from "@tsed/core";
3
+
4
+ export interface PlatformTestingSdkOpts {
5
+ rootDir: string;
6
+ platform: Type<PlatformAdapter<any>>;
7
+ server: Type<any>;
8
+
9
+ [key: string]: any;
10
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @file Automatically generated by @tsed/barrels.
3
+ */
4
+ export * from "./PlatformTestingSdkOpts.js";
@@ -0,0 +1,9 @@
1
+ import {Module} from "@tsed/di";
2
+ import {FeatureController} from "./controllers/FeatureController.js";
3
+
4
+ @Module({
5
+ mount: {
6
+ "/rest": [FeatureController]
7
+ }
8
+ })
9
+ export class FeatureModule {}
@@ -0,0 +1,11 @@
1
+ import {Controller, Get} from "@tsed/common";
2
+ import {Hidden} from "@tsed/swagger";
3
+
4
+ @Hidden()
5
+ @Controller("/features")
6
+ export class FeatureController {
7
+ @Get("/")
8
+ get() {
9
+ return "From feature";
10
+ }
11
+ }
@@ -0,0 +1,71 @@
1
+ import {PlatformTestingSdkOpts} from "../interfaces/index.js";
2
+ import {testAcceptMime} from "./testAcceptMime.js";
3
+ import {testAuth} from "./testAuth.js";
4
+ import {testBodyParams} from "./testBodyParams.js";
5
+ import {testChildrenControllers} from "./testChildrenControllers.js";
6
+ import {testCookies} from "./testCookies.js";
7
+ import {testCustom404} from "./testCustom404.js";
8
+ import {testDeepQueryParams} from "./testDeepQueryParams.js";
9
+ import {testErrors} from "./testErrors.js";
10
+ import {testHandlers} from "./testHandlers.js";
11
+ import {testHeaderParams} from "./testHeaderParams.js";
12
+ import {testHeaders} from "./testHeaders.js";
13
+ import {testInheritanceController} from "./testInheritanceController.js";
14
+ import {testLocals} from "./testLocals.js";
15
+ import {testLocation} from "./testLocation.js";
16
+ import {testMiddlewares} from "./testMiddlewares.js";
17
+ import {testModule} from "./testModule.js";
18
+ import {testMulter} from "./testMulter.js";
19
+ import {testPathParams} from "./testPathParams.js";
20
+ import {testQueryParams} from "./testQueryParams.js";
21
+ import {testRedirect} from "./testRedirect.js";
22
+ import {testResponse} from "./testResponse.js";
23
+ import {testResponseFilter} from "./testResponseFilter.js";
24
+ import {testRouting} from "./testRouting.js";
25
+ import {testScopeRequest} from "./testScopeRequest.js";
26
+ import {testSession} from "./testSession.js";
27
+ import {testStatics} from "./testStatics.js";
28
+ import {testStream} from "./testStream.js";
29
+ import {testView} from "./testView.js";
30
+ import {testCache} from "./testCache.js";
31
+
32
+ export const specsContainer = new Map<string, (options: PlatformTestingSdkOpts) => void>();
33
+
34
+ // HANDLERS AND MIDDLEWARES
35
+ specsContainer.set("handlers", testHandlers);
36
+ specsContainer.set("auth", testAuth);
37
+ specsContainer.set("middlewares", testMiddlewares);
38
+
39
+ // RESPONSES
40
+ specsContainer.set("headers", testHeaders);
41
+ specsContainer.set("acceptMime", testAcceptMime);
42
+ specsContainer.set("location", testLocation);
43
+ specsContainer.set("redirect", testRedirect);
44
+ specsContainer.set("view", testView);
45
+ specsContainer.set("errors", testErrors);
46
+ specsContainer.set("response", testResponse);
47
+ specsContainer.set("stream", testStream);
48
+ specsContainer.set("responseFilter", testResponseFilter);
49
+ specsContainer.set("custom404", testCustom404);
50
+ specsContainer.set("statics", testStatics);
51
+ specsContainer.set("cache", testCache);
52
+
53
+ // INPUTS
54
+ specsContainer.set("cookies", testCookies);
55
+ specsContainer.set("session", testSession);
56
+ specsContainer.set("headerParams", testHeaderParams);
57
+ specsContainer.set("bodyParams", testBodyParams);
58
+ specsContainer.set("pathParams", testPathParams);
59
+ specsContainer.set("queryParams", testQueryParams);
60
+ specsContainer.set("deepQueryParams", testDeepQueryParams);
61
+ specsContainer.set("locals", testLocals);
62
+ specsContainer.set("multer", testMulter);
63
+
64
+ // ROUTING
65
+ specsContainer.set("scopeRequest", testScopeRequest);
66
+ specsContainer.set("routing", testRouting);
67
+
68
+ // CODE ORGANIZATION
69
+ specsContainer.set("childrenControllers", testChildrenControllers);
70
+ specsContainer.set("inheritanceController", testInheritanceController);
71
+ specsContainer.set("module", testModule);
@@ -0,0 +1,95 @@
1
+ import {AcceptMime, Controller, Get, HeaderParams, PlatformTest, Post} from "@tsed/common";
2
+ import {ContentType} from "@tsed/schema";
3
+ import SuperTest from "supertest";
4
+ import {PlatformTestingSdkOpts} from "../interfaces/index.js";
5
+
6
+ @Controller("/accept-mime")
7
+ class TestAcceptMimeCtrl {
8
+ @Post("/scenario-1")
9
+ @AcceptMime("application/json")
10
+ scenario1(@HeaderParams("Accept") accept: string) {
11
+ return {
12
+ accept
13
+ };
14
+ }
15
+
16
+ @Get("/scenario-2")
17
+ @ContentType("text")
18
+ @AcceptMime("text")
19
+ public ping() {
20
+ return "pong";
21
+ }
22
+ }
23
+
24
+ export function testAcceptMime(options: PlatformTestingSdkOpts) {
25
+ let request: SuperTest.Agent;
26
+
27
+ beforeAll(
28
+ PlatformTest.bootstrap(options.server, {
29
+ ...options,
30
+ mount: {
31
+ "/rest": [TestAcceptMimeCtrl]
32
+ }
33
+ })
34
+ );
35
+ beforeAll(() => {
36
+ request = SuperTest(PlatformTest.callback());
37
+ });
38
+ afterAll(PlatformTest.reset);
39
+ describe("Scenario 1: POST /rest/accept-mime/scenario-1", () => {
40
+ it('should return a 200 response when Accept header match with @AcceptMime("application/json")', async () => {
41
+ const response = await request
42
+ .post("/rest/accept-mime/scenario-1")
43
+ .set({
44
+ Accept: "application/json"
45
+ })
46
+ .expect(200);
47
+
48
+ expect(response.body).toEqual({
49
+ accept: "application/json"
50
+ });
51
+ });
52
+ it('should return a 406 response when Accept header doesn\'t match with @AcceptMime("application/json")', async () => {
53
+ const response = await request
54
+ .post("/rest/accept-mime/scenario-1")
55
+ .set({
56
+ Accept: "application/xml"
57
+ })
58
+ .expect(406);
59
+
60
+ expect(response.body).toEqual({
61
+ name: "NOT_ACCEPTABLE",
62
+ message: "You must accept content-type application/json",
63
+ status: 406,
64
+ errors: []
65
+ });
66
+ });
67
+ });
68
+ describe("Scenario 2: GET /rest/accept-mime/scenario-2", () => {
69
+ it('should return a 200 response when Accept header match with @AcceptMime("text")', async () => {
70
+ const response = await request
71
+ .get("/rest/accept-mime/scenario-2")
72
+ .set({
73
+ Accept: "text/*, application/json"
74
+ })
75
+ .expect(200);
76
+
77
+ expect(response.text).toEqual("pong");
78
+ });
79
+ it('should return a 406 response when Accept header doesn\'t match with @AcceptMime("text")', async () => {
80
+ const response = await request
81
+ .get("/rest/accept-mime/scenario-2")
82
+ .set({
83
+ Accept: "application/xml"
84
+ })
85
+ .expect(406);
86
+
87
+ expect(response.body).toEqual({
88
+ name: "NOT_ACCEPTABLE",
89
+ message: "You must accept content-type text",
90
+ status: 406,
91
+ errors: []
92
+ });
93
+ });
94
+ });
95
+ }