mock-config-server 1.0.3 → 2.0.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 (130) hide show
  1. package/README.md +277 -213
  2. package/dist/bin/mock-config-server.d.ts +2 -2
  3. package/dist/bin/mock-config-server.js +67 -65
  4. package/dist/bin/resolveExportsFromSourceCode.d.ts +1 -1
  5. package/dist/bin/resolveExportsFromSourceCode.js +11 -11
  6. package/dist/bin/validateMockServerConfig/validateBaseUrl/validateBaseUrl.d.ts +1 -0
  7. package/dist/bin/validateMockServerConfig/validateBaseUrl/validateBaseUrl.js +12 -0
  8. package/dist/bin/validateMockServerConfig/validateCors/validateCors.d.ts +1 -0
  9. package/dist/bin/validateMockServerConfig/validateCors/validateCors.js +82 -0
  10. package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateGraphqlConfig.d.ts +1 -0
  11. package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateGraphqlConfig.js +48 -0
  12. package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateRoutes/validateRoutes.d.ts +2 -0
  13. package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateRoutes/validateRoutes.js +71 -0
  14. package/dist/bin/validateMockServerConfig/validateInterceptors/validateInterceptors.d.ts +1 -0
  15. package/dist/bin/validateMockServerConfig/validateInterceptors/validateInterceptors.js +21 -0
  16. package/dist/bin/validateMockServerConfig/validateMockServerConfig.d.ts +1 -0
  17. package/dist/bin/validateMockServerConfig/validateMockServerConfig.js +34 -0
  18. package/dist/bin/validateMockServerConfig/validatePort/validatePort.d.ts +1 -0
  19. package/dist/bin/validateMockServerConfig/validatePort/validatePort.js +9 -0
  20. package/dist/bin/validateMockServerConfig/validateRestConfig/validateRestConfig.d.ts +1 -0
  21. package/dist/bin/validateMockServerConfig/validateRestConfig/validateRestConfig.js +52 -0
  22. package/dist/bin/validateMockServerConfig/validateRestConfig/validateRoutes/validateRoutes.d.ts +2 -0
  23. package/dist/bin/validateMockServerConfig/validateRestConfig/validateRoutes/validateRoutes.js +104 -0
  24. package/dist/bin/validateMockServerConfig/validateStaticPath/validateStaticPath.d.ts +1 -0
  25. package/dist/bin/validateMockServerConfig/validateStaticPath/validateStaticPath.js +44 -0
  26. package/dist/index.d.ts +1 -1
  27. package/dist/index.js +17 -17
  28. package/dist/src/configs/isEntitiesEqual/isEntityValuesEqual.d.ts +1 -2
  29. package/dist/src/configs/isEntitiesEqual/isEntityValuesEqual.js +29 -29
  30. package/dist/src/cors/corsMiddleware/corsMiddleware.d.ts +3 -3
  31. package/dist/src/cors/corsMiddleware/corsMiddleware.js +44 -32
  32. package/dist/src/cors/getOrigins/getAllowedOrigins.d.ts +2 -2
  33. package/dist/src/cors/getOrigins/getAllowedOrigins.js +13 -16
  34. package/dist/src/cors/noCorsMiddleware/noCorsMiddleware.d.ts +2 -2
  35. package/dist/src/cors/noCorsMiddleware/noCorsMiddleware.js +20 -15
  36. package/dist/src/graphql/createGraphQLRoutes/createGraphQLRoutes.d.ts +3 -0
  37. package/dist/src/graphql/createGraphQLRoutes/createGraphQLRoutes.js +73 -0
  38. package/dist/src/graphql/getGraphQLInput/getGraphQLInput.d.ts +3 -0
  39. package/dist/src/graphql/getGraphQLInput/getGraphQLInput.js +21 -0
  40. package/dist/src/graphql/parseGraphQLRequest/parseGraphQLRequest.d.ts +3 -0
  41. package/dist/src/graphql/parseGraphQLRequest/parseGraphQLRequest.js +12 -0
  42. package/dist/src/graphql/parseQuery/parseQuery.d.ts +7 -0
  43. package/dist/src/graphql/parseQuery/parseQuery.js +21 -0
  44. package/dist/src/graphql/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.d.ts +2 -0
  45. package/dist/src/graphql/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.js +28 -0
  46. package/dist/src/index.d.ts +3 -3
  47. package/dist/src/index.js +19 -19
  48. package/dist/src/notFound/notFoundMiddleware.d.ts +8 -0
  49. package/dist/src/notFound/notFoundMiddleware.js +47 -0
  50. package/dist/src/notFound/urlSuggestions/getGraphqlUrlSuggestions/getGraphqlUrlSuggestions.d.ts +6 -0
  51. package/dist/src/notFound/urlSuggestions/getGraphqlUrlSuggestions/getGraphqlUrlSuggestions.js +18 -0
  52. package/dist/src/notFound/urlSuggestions/getGraphqlUrlSuggestions/index.d.ts +1 -0
  53. package/dist/src/notFound/urlSuggestions/getGraphqlUrlSuggestions/index.js +17 -0
  54. package/dist/src/notFound/urlSuggestions/getLevenshteinDistance/getLevenshteinDistance.d.ts +1 -0
  55. package/dist/src/notFound/urlSuggestions/getLevenshteinDistance/getLevenshteinDistance.js +80 -0
  56. package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/getRestUrlSuggestions.d.ts +6 -0
  57. package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/getRestUrlSuggestions.js +34 -0
  58. package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/helpers/getActualRestUrlMeaningfulString/getActualRestUrlMeaningfulString.d.ts +1 -0
  59. package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/helpers/getActualRestUrlMeaningfulString/getActualRestUrlMeaningfulString.js +7 -0
  60. package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/helpers/getPatternRestUrlMeaningfulString/getPatternRestUrlMeaningfulString.d.ts +1 -0
  61. package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/helpers/getPatternRestUrlMeaningfulString/getPatternRestUrlMeaningfulString.js +5 -0
  62. package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/helpers/index.d.ts +2 -0
  63. package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/helpers/index.js +18 -0
  64. package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/index.d.ts +1 -0
  65. package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/index.js +17 -0
  66. package/dist/src/notFound/urlSuggestions/index.d.ts +2 -0
  67. package/dist/src/notFound/urlSuggestions/index.js +18 -0
  68. package/dist/src/rest/createRestRoutes/createRestRoutes.d.ts +3 -0
  69. package/dist/src/{routes/createRoutes/createRoutes.js → rest/createRestRoutes/createRestRoutes.js} +41 -43
  70. package/dist/src/rest/prepareRestRequestConfigs/prepareRestRequestConfigs.d.ts +2 -0
  71. package/dist/src/{configs/prepareRequestConfigs/prepareRequestConfigs.js → rest/prepareRestRequestConfigs/prepareRestRequestConfigs.js} +30 -30
  72. package/dist/src/routes/callRequestInterceptors/callRequestInterceptors.d.ts +12 -12
  73. package/dist/src/routes/callRequestInterceptors/callRequestInterceptors.js +13 -13
  74. package/dist/src/routes/callResponseInterceptors/callResponseInterceptors.d.ts +14 -14
  75. package/dist/src/routes/callResponseInterceptors/callResponseInterceptors.js +31 -31
  76. package/dist/src/server/createMockServer/createMockServer.d.ts +3 -3
  77. package/dist/src/server/createMockServer/createMockServer.js +48 -35
  78. package/dist/src/server/startMockServer/startMockServer.d.ts +2 -2
  79. package/dist/src/server/startMockServer/startMockServer.js +17 -13
  80. package/dist/src/static/staticMiddleware/staticMiddleware.d.ts +3 -3
  81. package/dist/src/static/staticMiddleware/staticMiddleware.js +30 -29
  82. package/dist/src/utils/constants/appPath.d.ts +1 -1
  83. package/dist/src/utils/constants/appPath.js +4 -4
  84. package/dist/src/utils/constants/default.d.ts +11 -10
  85. package/dist/src/utils/constants/default.js +14 -13
  86. package/dist/src/utils/constants/index.d.ts +2 -2
  87. package/dist/src/utils/constants/index.js +18 -18
  88. package/dist/src/utils/helpers/index.d.ts +3 -2
  89. package/dist/src/utils/helpers/index.js +19 -18
  90. package/dist/src/utils/helpers/isPlainObject.d.ts +1 -1
  91. package/dist/src/utils/helpers/isPlainObject.js +5 -5
  92. package/dist/src/utils/helpers/sleep.d.ts +1 -1
  93. package/dist/src/utils/helpers/sleep.js +7 -7
  94. package/dist/src/utils/helpers/url/getUrlParts/getUrlParts.d.ts +1 -0
  95. package/dist/src/utils/helpers/url/getUrlParts/getUrlParts.js +6 -0
  96. package/dist/src/utils/helpers/url/index.d.ts +2 -0
  97. package/dist/src/utils/helpers/url/index.js +18 -0
  98. package/dist/src/utils/helpers/url/removeLeadingAndTrailingSlashes/removeLeadingAndTrailingSlashes.d.ts +1 -0
  99. package/dist/src/utils/helpers/url/removeLeadingAndTrailingSlashes/removeLeadingAndTrailingSlashes.js +5 -0
  100. package/dist/src/utils/types/configs.d.ts +63 -34
  101. package/dist/src/utils/types/configs.js +2 -2
  102. package/dist/src/utils/types/graphql.d.ts +5 -0
  103. package/dist/src/utils/types/graphql.js +2 -0
  104. package/dist/src/utils/types/index.d.ts +4 -3
  105. package/dist/src/utils/types/index.js +20 -19
  106. package/dist/src/utils/types/interceptors.d.ts +15 -15
  107. package/dist/src/utils/types/interceptors.js +2 -2
  108. package/dist/src/utils/types/server.d.ts +32 -24
  109. package/dist/src/utils/types/server.js +2 -2
  110. package/package.json +102 -99
  111. package/dist/jest.config.d.ts +0 -3
  112. package/dist/jest.config.js +0 -7
  113. package/dist/src/configs/isEntitiesEqual/isEntityValuesEqual.test.d.ts +0 -1
  114. package/dist/src/configs/isEntitiesEqual/isEntityValuesEqual.test.js +0 -25
  115. package/dist/src/configs/prepareRequestConfigs/prepareRequestConfigs.d.ts +0 -2
  116. package/dist/src/configs/prepareRequestConfigs/prepareRequestConfigs.test.d.ts +0 -1
  117. package/dist/src/configs/prepareRequestConfigs/prepareRequestConfigs.test.js +0 -151
  118. package/dist/src/cors/corsMiddleware/corsMiddleware.test.d.ts +0 -1
  119. package/dist/src/cors/corsMiddleware/corsMiddleware.test.js +0 -86
  120. package/dist/src/cors/getOrigins/getAllowedOrigins.test.d.ts +0 -1
  121. package/dist/src/cors/getOrigins/getAllowedOrigins.test.js +0 -24
  122. package/dist/src/cors/noCorsMiddleware/noCorsMiddleware.test.d.ts +0 -1
  123. package/dist/src/cors/noCorsMiddleware/noCorsMiddleware.test.js +0 -22
  124. package/dist/src/routes/callRequestInterceptors/callRequestInterceptors.test.d.ts +0 -1
  125. package/dist/src/routes/callRequestInterceptors/callRequestInterceptors.test.js +0 -28
  126. package/dist/src/routes/callResponseInterceptors/callResponseInterceptors.test.d.ts +0 -1
  127. package/dist/src/routes/callResponseInterceptors/callResponseInterceptors.test.js +0 -36
  128. package/dist/src/routes/createRoutes/createRoutes.d.ts +0 -3
  129. package/dist/src/routes/createRoutes/createRoutes.test.d.ts +0 -1
  130. package/dist/src/routes/createRoutes/createRoutes.test.js +0 -276
package/package.json CHANGED
@@ -1,99 +1,102 @@
1
- {
2
- "name": "mock-config-server",
3
- "version": "1.0.3",
4
- "description": "Tool that easily and quickly imitates server operation, create full fake api in few steps",
5
- "author": {
6
- "name": "SIBERIA CAN CODE 🧊",
7
- "url": "https://github.com/siberiacancode"
8
- },
9
- "contributors": [
10
- {
11
- "name": "Dmitry Babin",
12
- "url": "https://github.com/debabin"
13
- },
14
- {
15
- "name": "Nursultan Zianurov",
16
- "url": "https://github.com/MiaInturi"
17
- },
18
- {
19
- "name": "Sergey Kryavkin",
20
- "url": "https://github.com/RiceWithMeat"
21
- }
22
- ],
23
- "license": "ISC",
24
- "main": "./dist/index.js",
25
- "types": "./dist/index.d.ts",
26
- "bin": {
27
- "mock-config-server": "dist/bin/mock-config-server.js"
28
- },
29
- "files": [
30
- "dist/**/*"
31
- ],
32
- "engines": {
33
- "node": ">=14"
34
- },
35
- "scripts": {
36
- "build": "rimraf dist && tsc -p ./tsconfig.json",
37
- "prepare": "yarn build",
38
- "test": "jest",
39
- "lint": "eslint . --ext ts --no-error-on-unmatched-pattern",
40
- "format": "prettier --write '**/*.ts'"
41
- },
42
- "lint-staged": {
43
- "*.js": "yarn format",
44
- "*.ts": [
45
- "yarn format",
46
- "yarn lint --fix",
47
- "git add *"
48
- ]
49
- },
50
- "dependencies": {
51
- "@types/body-parser": "^1.19.2",
52
- "@types/express": "^4.17.15",
53
- "@types/flat": "^5.0.2",
54
- "body-parser": "^1.20.0",
55
- "esbuild": "^0.16.6",
56
- "express": "^4.18.1",
57
- "flat": "^5.0.2"
58
- },
59
- "devDependencies": {
60
- "@types/jest": "^29.2.4",
61
- "@types/supertest": "^2.0.12",
62
- "@typescript-eslint/eslint-plugin": "^5.31.0",
63
- "@typescript-eslint/parser": "^5.31.0",
64
- "eslint": "^8.15.0",
65
- "eslint-config-airbnb": "^19.0.4",
66
- "eslint-config-airbnb-typescript": "^17.0.0",
67
- "eslint-config-prettier": "^8.5.0",
68
- "eslint-import-resolver-typescript": "^3.4.1",
69
- "eslint-plugin-import": "^2.26.0",
70
- "eslint-plugin-prettier": "^4.2.1",
71
- "eslint-plugin-simple-import-sort": "^7.0.0",
72
- "husky": "^8.0.1",
73
- "jest": "^29.3.1",
74
- "lint-staged": "^13.0.3",
75
- "nodemon": "^2.0.19",
76
- "prettier": "^2.7.1",
77
- "rimraf": "^3.0.2",
78
- "supertest": "^6.3.3",
79
- "ts-jest": "^29.0.3",
80
- "typescript": "^4.7.4"
81
- },
82
- "homepage": "https://github.com/siberiacancode/mock-config-server",
83
- "repository": {
84
- "type": "git",
85
- "url": "https://github.com/siberiacancode/mock-config-server.git"
86
- },
87
- "keywords": [
88
- "server",
89
- "fake",
90
- "REST",
91
- "rest",
92
- "API",
93
- "api",
94
- "mock",
95
- "mocking",
96
- "config",
97
- "data"
98
- ]
99
- }
1
+ {
2
+ "name": "mock-config-server",
3
+ "version": "2.0.0",
4
+ "description": "Tool that easily and quickly imitates server operation, create full fake api in few steps",
5
+ "author": {
6
+ "name": "SIBERIA CAN CODE 🧊",
7
+ "url": "https://github.com/siberiacancode"
8
+ },
9
+ "contributors": [
10
+ {
11
+ "name": "Dmitry Babin",
12
+ "url": "https://github.com/debabin"
13
+ },
14
+ {
15
+ "name": "Nursultan Zianurov",
16
+ "url": "https://github.com/MiaInturi"
17
+ },
18
+ {
19
+ "name": "Sergey Kryavkin",
20
+ "url": "https://github.com/RiceWithMeat"
21
+ }
22
+ ],
23
+ "license": "ISC",
24
+ "main": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "bin": {
27
+ "mock-config-server": "dist/bin/mock-config-server.js"
28
+ },
29
+ "files": [
30
+ "dist/**/*"
31
+ ],
32
+ "engines": {
33
+ "node": ">=14"
34
+ },
35
+ "scripts": {
36
+ "build": "rimraf dist && tsc -p tsconfig.production.json",
37
+ "prepare": "yarn build",
38
+ "test": "jest",
39
+ "lint": "eslint . --ext ts --no-error-on-unmatched-pattern",
40
+ "format": "prettier --write '**/*.ts'"
41
+ },
42
+ "lint-staged": {
43
+ "*.js": "yarn format",
44
+ "*.ts": [
45
+ "yarn format",
46
+ "yarn lint --fix",
47
+ "git add *"
48
+ ]
49
+ },
50
+ "dependencies": {
51
+ "@types/body-parser": "^1.19.2",
52
+ "@types/express": "^4.17.17",
53
+ "@types/flat": "^5.0.2",
54
+ "ansi-colors": "^4.1.3",
55
+ "body-parser": "^1.20.0",
56
+ "ejs": "^3.1.8",
57
+ "esbuild": "^0.17.8",
58
+ "express": "^4.18.1",
59
+ "flat": "^5.0.2",
60
+ "graphql": "^16.6.0"
61
+ },
62
+ "devDependencies": {
63
+ "@types/jest": "^29.4.0",
64
+ "@types/supertest": "^2.0.12",
65
+ "@typescript-eslint/eslint-plugin": "^5.51.0",
66
+ "@typescript-eslint/parser": "^5.51.0",
67
+ "eslint": "^8.34.0",
68
+ "eslint-config-airbnb": "^19.0.4",
69
+ "eslint-config-airbnb-typescript": "^17.0.0",
70
+ "eslint-config-prettier": "^8.5.0",
71
+ "eslint-import-resolver-typescript": "^3.4.1",
72
+ "eslint-plugin-import": "^2.27.5",
73
+ "eslint-plugin-prettier": "^4.2.1",
74
+ "eslint-plugin-simple-import-sort": "^10.0.0",
75
+ "husky": "^8.0.1",
76
+ "jest": "^29.4.2",
77
+ "lint-staged": "^13.1.1",
78
+ "nodemon": "^2.0.19",
79
+ "prettier": "^2.8.3",
80
+ "rimraf": "4.1.2",
81
+ "supertest": "^6.3.3",
82
+ "ts-jest": "^29.0.3",
83
+ "typescript": "^4.9.5"
84
+ },
85
+ "homepage": "https://github.com/siberiacancode/mock-config-server",
86
+ "repository": {
87
+ "type": "git",
88
+ "url": "https://github.com/siberiacancode/mock-config-server.git"
89
+ },
90
+ "keywords": [
91
+ "server",
92
+ "fake",
93
+ "REST",
94
+ "rest",
95
+ "API",
96
+ "api",
97
+ "mock",
98
+ "mocking",
99
+ "config",
100
+ "data"
101
+ ]
102
+ }
@@ -1,3 +0,0 @@
1
- export = jestConfig;
2
- /** @type {import('ts-jest').JestConfigWithTsJest} */
3
- declare const jestConfig: import('ts-jest').JestConfigWithTsJest;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- /** @type {import('ts-jest').JestConfigWithTsJest} */
3
- const jestConfig = {
4
- preset: 'ts-jest',
5
- testEnvironment: 'node'
6
- };
7
- module.exports = jestConfig;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const isEntityValuesEqual_1 = require("./isEntityValuesEqual");
4
- describe('isEntityValuesEqual', () => {
5
- test('Primitive values should compare independent of their types', () => {
6
- expect((0, isEntityValuesEqual_1.isEntityValuesEqual)(13, '13')).toBe(true);
7
- expect((0, isEntityValuesEqual_1.isEntityValuesEqual)(true, 'true')).toBe(true);
8
- });
9
- test('Arrays should be full equal with nested objects (independent of primitive values types)', () => {
10
- expect((0, isEntityValuesEqual_1.isEntityValuesEqual)([1, 2, 3], ['1', '2', '3'])).toBe(true);
11
- expect((0, isEntityValuesEqual_1.isEntityValuesEqual)([{ key1: 'value1', key2: 'value2' }], [{ key2: 'value2', key1: 'value1' }])).toBe(true);
12
- expect((0, isEntityValuesEqual_1.isEntityValuesEqual)([{ key1: 'value1', key2: 'value2' }], [{ key1: 'value1', key2: 'value2', key3: 'value3' }])).toBe(false);
13
- expect((0, isEntityValuesEqual_1.isEntityValuesEqual)([{ key1: 'value1', key2: { nestedKey1: 'nestedValue1' } }], [{ key1: 'value1', key2: { nestedKey1: 'nestedValue1' } }])).toBe(true);
14
- expect((0, isEntityValuesEqual_1.isEntityValuesEqual)([{ key1: 'value1', key2: { nestedKey1: 'nestedValue1' } }], [{ key1: 'value1', key2: { nestedKey1: 'nestedValue1', nestedKey2: 'nestedValue2' } }])).toBe(false);
15
- });
16
- test('Plain objects should compare by "second includes first" with nested objects', () => {
17
- expect((0, isEntityValuesEqual_1.isEntityValuesEqual)({ key1: 'value1', key2: 'value2' }, { key1: 'value1', key2: 'value2', key3: 'value3' })).toBe(true);
18
- expect((0, isEntityValuesEqual_1.isEntityValuesEqual)({ key1: 'value1', key2: 'value2', key3: 'value3' }, { key1: 'value1', key2: 'value2' })).toBe(false);
19
- expect((0, isEntityValuesEqual_1.isEntityValuesEqual)({ key1: 'value1', key2: { nestedKey1: 'nestedValue1' } }, {
20
- key1: 'value1',
21
- key2: { nestedKey1: 'nestedValue1', nestedKey2: 'nestedValue2' },
22
- key3: 'value3'
23
- })).toBe(true);
24
- });
25
- });
@@ -1,2 +0,0 @@
1
- import type { RequestConfig } from '../../utils/types';
2
- export declare const prepareRequestConfigs: (requestConfigs: RequestConfig[]) => RequestConfig[];
@@ -1,151 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const prepareRequestConfigs_1 = require("./prepareRequestConfigs");
4
- describe('prepareRequestConfigs', () => {
5
- test('Should not sort routes if they does not contain entities', () => {
6
- const requestConfigs = [
7
- {
8
- path: '/user',
9
- method: 'get',
10
- routes: [
11
- {
12
- data: { name: 'John', surname: 'Doe' }
13
- },
14
- {
15
- data: { name: 'John', surname: 'Smith' }
16
- },
17
- {
18
- data: { name: 'John', surname: 'John' }
19
- }
20
- ]
21
- }
22
- ];
23
- expect((0, prepareRequestConfigs_1.prepareRequestConfigs)(requestConfigs)).toStrictEqual(requestConfigs);
24
- });
25
- test('Should sort routes by their specificity of entities', () => {
26
- const requestConfigs = [
27
- {
28
- path: '/user',
29
- method: 'get',
30
- routes: [
31
- {
32
- entities: {
33
- headers: {
34
- header1: 'value'
35
- }
36
- },
37
- data: { name: 'John', surname: 'Doe' }
38
- },
39
- {
40
- entities: {
41
- headers: {
42
- header1: 'value',
43
- header2: 'value'
44
- }
45
- },
46
- data: { name: 'John', surname: 'Doe' }
47
- },
48
- {
49
- entities: {
50
- headers: {
51
- header1: 'value'
52
- },
53
- query: {
54
- query1: 'value',
55
- query2: 'value'
56
- }
57
- },
58
- data: { name: 'John', surname: 'Doe' }
59
- }
60
- ]
61
- }
62
- ];
63
- const expectedRequestConfigs = [
64
- {
65
- path: '/user',
66
- method: 'get',
67
- routes: [
68
- {
69
- entities: {
70
- headers: {
71
- header1: 'value'
72
- },
73
- query: {
74
- query1: 'value',
75
- query2: 'value'
76
- }
77
- },
78
- data: { name: 'John', surname: 'Doe' }
79
- },
80
- {
81
- entities: {
82
- headers: {
83
- header1: 'value',
84
- header2: 'value'
85
- }
86
- },
87
- data: { name: 'John', surname: 'Doe' }
88
- },
89
- {
90
- entities: {
91
- headers: {
92
- header1: 'value'
93
- }
94
- },
95
- data: { name: 'John', surname: 'Doe' }
96
- }
97
- ]
98
- }
99
- ];
100
- expect((0, prepareRequestConfigs_1.prepareRequestConfigs)(requestConfigs)).toStrictEqual(expectedRequestConfigs);
101
- });
102
- test('Should set not object body weight equals to one', () => {
103
- const requestConfigs = [
104
- {
105
- path: '/user',
106
- method: 'post',
107
- routes: [
108
- {
109
- entities: {
110
- body: ['value', 'value', 'value']
111
- },
112
- data: { name: 'John', surname: 'Doe' }
113
- },
114
- {
115
- entities: {
116
- headers: {
117
- header1: 'value',
118
- header2: 'value'
119
- }
120
- },
121
- data: { name: 'John', surname: 'Doe' }
122
- }
123
- ]
124
- }
125
- ];
126
- const expectedRequestConfigs = [
127
- {
128
- path: '/user',
129
- method: 'post',
130
- routes: [
131
- {
132
- entities: {
133
- headers: {
134
- header1: 'value',
135
- header2: 'value'
136
- }
137
- },
138
- data: { name: 'John', surname: 'Doe' }
139
- },
140
- {
141
- entities: {
142
- body: ['value', 'value', 'value']
143
- },
144
- data: { name: 'John', surname: 'Doe' }
145
- }
146
- ]
147
- }
148
- ];
149
- expect((0, prepareRequestConfigs_1.prepareRequestConfigs)(requestConfigs)).toStrictEqual(expectedRequestConfigs);
150
- });
151
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,86 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const express_1 = __importDefault(require("express"));
7
- const supertest_1 = __importDefault(require("supertest"));
8
- const corsMiddleware_1 = require("./corsMiddleware");
9
- describe('corsMiddleware', () => {
10
- test('Should set default cors for request if does not set custom cors settings', async () => {
11
- const server = (0, express_1.default)();
12
- const cors = {
13
- origin: ['https://test.com', 'https://uncorrectDomain.com']
14
- };
15
- (0, corsMiddleware_1.corsMiddleware)(server, cors);
16
- const response = await (0, supertest_1.default)(server).get('/').set({ origin: 'https://test.com' });
17
- expect(response.headers).toMatchObject({
18
- 'access-control-allow-headers': '*',
19
- 'access-control-allow-methods': '*',
20
- 'access-control-allow-origin': 'https://test.com',
21
- 'access-control-max-age': '3600',
22
- 'access-control-allow-credentials': 'true'
23
- });
24
- });
25
- test('Should not set cors for request if origin does not match', async () => {
26
- const server = (0, express_1.default)();
27
- const cors = {
28
- origin: 'https://uncorrectDomain.com'
29
- };
30
- (0, corsMiddleware_1.corsMiddleware)(server, cors);
31
- const response = await (0, supertest_1.default)(server).get('/').set({ origin: 'https://test.com' });
32
- expect(response.headers).not.toHaveProperty('access-control-allow-headers');
33
- expect(response.headers).not.toHaveProperty('access-control-allow-methods');
34
- expect(response.headers).not.toHaveProperty('access-control-allow-origin');
35
- expect(response.headers).not.toHaveProperty('access-control-max-age');
36
- expect(response.headers).not.toHaveProperty('access-control-allow-credentials');
37
- });
38
- test('Should set allow headers to access-control-allow-headers', async () => {
39
- const server = (0, express_1.default)();
40
- const cors = {
41
- origin: 'https://test.com',
42
- headers: ['header1', 'header2']
43
- };
44
- (0, corsMiddleware_1.corsMiddleware)(server, cors);
45
- const response = await (0, supertest_1.default)(server).get('/').set({ origin: 'https://test.com' });
46
- expect(response.headers).toMatchObject({
47
- 'access-control-allow-headers': 'header1, header2'
48
- });
49
- });
50
- test('Should set methods to access-control-allow-methods', async () => {
51
- const server = (0, express_1.default)();
52
- const cors = {
53
- origin: 'https://test.com',
54
- methods: ['GET', 'POST']
55
- };
56
- (0, corsMiddleware_1.corsMiddleware)(server, cors);
57
- const response = await (0, supertest_1.default)(server).get('/').set({ origin: 'https://test.com' });
58
- expect(response.headers).toMatchObject({
59
- 'access-control-allow-methods': 'GET, POST'
60
- });
61
- });
62
- test('Should set methods to access-control-allow-credentials', async () => {
63
- const server = (0, express_1.default)();
64
- const cors = {
65
- origin: 'https://test.com',
66
- credentials: false
67
- };
68
- (0, corsMiddleware_1.corsMiddleware)(server, cors);
69
- const response = await (0, supertest_1.default)(server).get('/').set({ origin: 'https://test.com' });
70
- expect(response.headers).toMatchObject({
71
- 'access-control-allow-credentials': 'false'
72
- });
73
- });
74
- test('Should set max-age to access-control-max-age', async () => {
75
- const server = (0, express_1.default)();
76
- const cors = {
77
- origin: 'https://test.com',
78
- maxAge: 10000
79
- };
80
- (0, corsMiddleware_1.corsMiddleware)(server, cors);
81
- const response = await (0, supertest_1.default)(server).get('/').set({ origin: 'https://test.com' });
82
- expect(response.headers).toMatchObject({
83
- 'access-control-max-age': '10000'
84
- });
85
- });
86
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const getAllowedOrigins_1 = require("./getAllowedOrigins");
4
- describe('getAllowedOrigins', () => {
5
- test('Function should return array if get string or RegExp parameter', async () => {
6
- expect((0, getAllowedOrigins_1.getAllowedOrigins)(/origin/g)).resolves.toEqual([/origin/g]);
7
- expect((0, getAllowedOrigins_1.getAllowedOrigins)('https://origin.com')).resolves.toEqual(['https://origin.com']);
8
- });
9
- test('Function should return array if get array parameter', () => {
10
- expect((0, getAllowedOrigins_1.getAllowedOrigins)([/origin/g, 'https://origin.com'])).resolves.toEqual([
11
- /origin/g,
12
- 'https://origin.com'
13
- ]);
14
- });
15
- test('Function should return array if get function parameter', () => {
16
- expect((0, getAllowedOrigins_1.getAllowedOrigins)(() => [/origin/g, 'https://origin.com'])).resolves.toEqual([
17
- /origin/g,
18
- 'https://origin.com'
19
- ]);
20
- });
21
- test('Function should return array if get promise parameter', () => {
22
- expect((0, getAllowedOrigins_1.getAllowedOrigins)(() => Promise.resolve([/origin/g, 'https://origin.com']))).resolves.toEqual([/origin/g, 'https://origin.com']);
23
- });
24
- });
@@ -1,22 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const express_1 = __importDefault(require("express"));
7
- const supertest_1 = __importDefault(require("supertest"));
8
- const noCorsMiddleware_1 = require("./noCorsMiddleware");
9
- describe('noCorsMiddleware', () => {
10
- test('Should set no cors settings for request', async () => {
11
- const server = (0, express_1.default)();
12
- (0, noCorsMiddleware_1.noCorsMiddleware)(server);
13
- const response = await (0, supertest_1.default)(server).get('/');
14
- expect(response.headers).toMatchObject({
15
- 'access-control-allow-headers': '*',
16
- 'access-control-allow-methods': '*',
17
- 'access-control-allow-origin': '*',
18
- 'access-control-max-age': '3600',
19
- 'access-control-allow-credentials': 'true'
20
- });
21
- });
22
- });
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const callRequestInterceptors_1 = require("./callRequestInterceptors");
4
- describe('callRequestInterceptors', () => {
5
- test('Should call all passed request interceptors in order: route -> request -> server', () => {
6
- const request = {};
7
- const routeInterceptor = jest.fn();
8
- const requestInterceptor = jest.fn();
9
- const serverInterceptor = jest.fn();
10
- (0, callRequestInterceptors_1.callRequestInterceptors)({ request });
11
- expect(routeInterceptor.mock.calls.length).toBe(0);
12
- expect(requestInterceptor.mock.calls.length).toBe(0);
13
- expect(serverInterceptor.mock.calls.length).toBe(0);
14
- (0, callRequestInterceptors_1.callRequestInterceptors)({
15
- request,
16
- interceptors: {
17
- routeInterceptor,
18
- requestInterceptor,
19
- serverInterceptor
20
- }
21
- });
22
- expect(routeInterceptor.mock.calls.length).toBe(1);
23
- expect(requestInterceptor.mock.calls.length).toBe(1);
24
- expect(serverInterceptor.mock.calls.length).toBe(1);
25
- expect(routeInterceptor.mock.invocationCallOrder[0]).toBeLessThan(requestInterceptor.mock.invocationCallOrder[0]);
26
- expect(requestInterceptor.mock.invocationCallOrder[0]).toBeLessThan(serverInterceptor.mock.invocationCallOrder[0]);
27
- });
28
- });
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const callResponseInterceptors_1 = require("./callResponseInterceptors");
4
- describe('callResponseInterceptors', () => {
5
- test('Should call all passed response interceptors in order: route -> request -> server', () => {
6
- const initialData = '';
7
- const request = {};
8
- const response = {};
9
- const routeInterceptor = jest.fn((data) => `${data}routeInterceptor;`);
10
- const requestInterceptor = jest.fn((data) => `${data}requestInterceptor;`);
11
- const serverInterceptor = jest.fn((data) => `${data}serverInterceptor`);
12
- expect((0, callResponseInterceptors_1.callResponseInterceptors)({
13
- data: initialData,
14
- request,
15
- response
16
- })).toBe('');
17
- expect(routeInterceptor.mock.calls.length).toBe(0);
18
- expect(requestInterceptor.mock.calls.length).toBe(0);
19
- expect(serverInterceptor.mock.calls.length).toBe(0);
20
- expect((0, callResponseInterceptors_1.callResponseInterceptors)({
21
- data: initialData,
22
- request,
23
- response,
24
- interceptors: {
25
- routeInterceptor,
26
- requestInterceptor,
27
- serverInterceptor
28
- }
29
- })).toBe('routeInterceptor;requestInterceptor;serverInterceptor');
30
- expect(routeInterceptor.mock.calls.length).toBe(1);
31
- expect(requestInterceptor.mock.calls.length).toBe(1);
32
- expect(serverInterceptor.mock.calls.length).toBe(1);
33
- expect(routeInterceptor.mock.invocationCallOrder[0]).toBeLessThan(requestInterceptor.mock.invocationCallOrder[0]);
34
- expect(requestInterceptor.mock.invocationCallOrder[0]).toBeLessThan(serverInterceptor.mock.invocationCallOrder[0]);
35
- });
36
- });
@@ -1,3 +0,0 @@
1
- import type { IRouter } from 'express';
2
- import type { MockServerConfig } from '../../utils/types';
3
- export declare const createRoutes: (router: IRouter, mockServerConfig: Pick<MockServerConfig, 'configs' | 'interceptors'>) => IRouter;
@@ -1 +0,0 @@
1
- export {};