mock-config-server 3.3.0 → 3.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/core/database/createDatabaseRoutes/createDatabaseRoutes.test.ts +112 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/array/createNewId/createNewId.test.ts +13 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/array/findIndexById/findIndexById.test.ts +17 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/array/isIndex/isIndex.test.ts +30 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/createNestedDatabaseRoutes/createNestedDatabaseRoutes.test.ts +399 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/createShallowDatabaseRoutes/createShallowDatabaseRoutes.test.ts +118 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/operators/operators.d.ts +3 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/operators/operators.js +30 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/search/search.d.ts +3 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/search/search.js +31 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/splitDatabaseByNesting/splitDatabaseByNesting.test.ts +25 -0
- package/dist/src/core/database/createDatabaseRoutes/storages/File/FileStorage.test.ts +156 -0
- package/dist/src/core/database/createDatabaseRoutes/storages/File/FileWriter.test.ts +48 -0
- package/dist/src/core/database/createDatabaseRoutes/storages/Memory/MemoryStorage.test.ts +96 -0
- package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.test.ts +851 -0
- package/dist/src/core/graphql/createGraphQLRoutes/helpers/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.test.ts +116 -0
- package/dist/src/core/middlewares/cookieParseMiddleware/cookieParseMiddleware.test.ts +22 -0
- package/dist/src/core/middlewares/cookieParseMiddleware/helpers/parseCookie/parseCookie.test.ts +45 -0
- package/dist/src/core/middlewares/corsMiddleware/corsMiddleware.test.ts +152 -0
- package/dist/src/core/middlewares/corsMiddleware/helpers/getAllowedOrigins/getAllowedOrigins.test.ts +15 -0
- package/dist/src/core/middlewares/errorMiddleware/errorMiddleware.test.ts +29 -0
- package/dist/src/core/middlewares/noCorsMiddleware/noCorsMiddleware.test.ts +49 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getGraphqlUrlSuggestions/getGraphqlUrlSuggestions.test.ts +27 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getLevenshteinDistance/getLevenshteinDistance.test.ts +12 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/getRestUrlSuggestions.test.ts +54 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/getActualRestUrlMeaningfulString/getActualRestUrlMeaningfulString.test.ts +12 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/getPatternRestUrlMeaningfulString/getPatternRestUrlMeaningfulString.test.ts +10 -0
- package/dist/src/core/middlewares/notFoundMiddleware/notFoundMiddleware.test.ts +285 -0
- package/dist/src/core/rest/createRestRoutes/createRestRoutes.test.ts +648 -0
- package/dist/src/core/rest/createRestRoutes/helpers/prepareRestRequestConfigs/prepareRestRequestConfigs.test.ts +154 -0
- package/dist/src/static/views/components/header/index.js +1 -1
- package/dist/src/static/views/features/tab/index.js +12 -12
- package/dist/src/utils/helpers/config/resolveEntityValues/resolveEntityValues.test.ts +1452 -0
- package/dist/src/utils/helpers/entities/convertToEntityDescriptor/convertToEntityDescriptor.test.ts +27 -0
- package/dist/src/utils/helpers/entities/isEntityDescriptor/isEntityDescriptor.test.ts +15 -0
- package/dist/src/utils/helpers/graphql/getGraphQLInput/getGraphQLInput.test.ts +140 -0
- package/dist/src/utils/helpers/graphql/parseQuery/parseQuery.test.ts +32 -0
- package/dist/src/utils/helpers/interceptors/callRequestInterceptor/callRequestInterceptors.test.ts +53 -0
- package/dist/src/utils/helpers/interceptors/callResponseInterceptors/callResponseInterceptors.test.ts +262 -0
- package/dist/src/utils/helpers/isPlainObject/isPlainObject.test.ts +20 -0
- package/dist/src/utils/helpers/isPrimitive/isPrimitive.test.ts +26 -0
- package/dist/src/utils/helpers/isRegExp/isRegExp.test.ts +20 -0
- package/dist/src/utils/helpers/url/convertWin32PathToUnix/convertWin32PathToUnix.test.ts +21 -0
- package/dist/src/utils/helpers/url/getUrlParts/getUrlParts.test.ts +8 -0
- package/dist/src/utils/helpers/url/removeLeadingAndTrailingSlashes/removeLeadingAndTrailingSlashes.test.ts +10 -0
- package/dist/src/utils/helpers/url/urlJoin/urlJoin.test.ts +9 -0
- package/package.json +2 -3
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import request from 'supertest';
|
|
3
|
+
|
|
4
|
+
import { createGraphQLRoutes } from '@/core/graphql';
|
|
5
|
+
import { createRestRoutes } from '@/core/rest';
|
|
6
|
+
import { urlJoin } from '@/utils/helpers';
|
|
7
|
+
import type { BaseUrl, MockServerConfig } from '@/utils/types';
|
|
8
|
+
|
|
9
|
+
import type { GraphqlRequestSuggestionConfigs } from './helpers/getGraphqlUrlSuggestions/getGraphqlUrlSuggestions';
|
|
10
|
+
import type { RestRequestSuggestionConfigs } from './helpers/getRestUrlSuggestions/getRestUrlSuggestions';
|
|
11
|
+
import { notFoundMiddleware } from './notFoundMiddleware';
|
|
12
|
+
|
|
13
|
+
const createServer = (
|
|
14
|
+
mockServerConfig: Pick<MockServerConfig, 'rest' | 'graphql' | 'interceptors' | 'baseUrl'>
|
|
15
|
+
) => {
|
|
16
|
+
const { baseUrl, rest, interceptors, graphql } = mockServerConfig;
|
|
17
|
+
|
|
18
|
+
const server = express();
|
|
19
|
+
|
|
20
|
+
const serverBaseUrl = baseUrl ?? '/';
|
|
21
|
+
|
|
22
|
+
const restBaseUrl = urlJoin(serverBaseUrl, rest?.baseUrl ?? '/');
|
|
23
|
+
const routerWithRestRoutes = createRestRoutes({
|
|
24
|
+
router: express.Router(),
|
|
25
|
+
restConfig: { configs: rest?.configs ?? [] },
|
|
26
|
+
serverResponseInterceptor: interceptors?.response
|
|
27
|
+
});
|
|
28
|
+
server.use(restBaseUrl, routerWithRestRoutes);
|
|
29
|
+
|
|
30
|
+
const graphqlBaseUrl = urlJoin(serverBaseUrl, graphql?.baseUrl ?? '/');
|
|
31
|
+
const routerWithGraphqlRoutes = createGraphQLRoutes({
|
|
32
|
+
router: express.Router(),
|
|
33
|
+
graphqlConfig: { configs: graphql?.configs ?? [] },
|
|
34
|
+
serverResponseInterceptor: interceptors?.response
|
|
35
|
+
});
|
|
36
|
+
server.use(graphqlBaseUrl, routerWithGraphqlRoutes);
|
|
37
|
+
|
|
38
|
+
server.set('view engine', 'ejs');
|
|
39
|
+
server.set('views', urlJoin(__dirname, '../../../static/views'));
|
|
40
|
+
server.use(express.static(urlJoin(__dirname, '../../../static/views')));
|
|
41
|
+
server.use(express.json());
|
|
42
|
+
|
|
43
|
+
notFoundMiddleware(server, mockServerConfig);
|
|
44
|
+
|
|
45
|
+
return server;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
describe('notFoundMiddleware: HTML response', () => {
|
|
49
|
+
const server = createServer({
|
|
50
|
+
rest: {
|
|
51
|
+
configs: [
|
|
52
|
+
{
|
|
53
|
+
path: '/posts',
|
|
54
|
+
method: 'get',
|
|
55
|
+
routes: [{ data: {} }]
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
graphql: {
|
|
60
|
+
configs: [
|
|
61
|
+
{
|
|
62
|
+
operationName: 'GetPosts',
|
|
63
|
+
operationType: 'query',
|
|
64
|
+
routes: [{ data: {} }]
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('Should send correct HTML REST response', async () => {
|
|
71
|
+
const response = await request(server).get('/pstss').set('accept', 'text/html');
|
|
72
|
+
|
|
73
|
+
expect(response.statusCode).toBe(404);
|
|
74
|
+
expect(response.get('Content-Type')).toContain('text/html');
|
|
75
|
+
expect(response.text).toContain('GET /posts');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('Should send correct HTML GraphQL response', async () => {
|
|
79
|
+
const response = await request(server)
|
|
80
|
+
.get('/?query=query getPost { posts }')
|
|
81
|
+
.set('accept', 'text/html');
|
|
82
|
+
|
|
83
|
+
expect(response.statusCode).toBe(404);
|
|
84
|
+
expect(response.get('Content-Type')).toContain('text/html');
|
|
85
|
+
expect(response.text).toContain('query GetPosts');
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
interface ResponseBody {
|
|
90
|
+
restRequestSuggestions?: RestRequestSuggestionConfigs;
|
|
91
|
+
graphqlRequestSuggestions?: GraphqlRequestSuggestionConfigs;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const responseBody = ({
|
|
95
|
+
restRequestSuggestions = [],
|
|
96
|
+
graphqlRequestSuggestions = []
|
|
97
|
+
}: ResponseBody) => ({
|
|
98
|
+
message: 'Request or page not found. Similar requests in data',
|
|
99
|
+
data: {
|
|
100
|
+
restRequestSuggestions,
|
|
101
|
+
graphqlRequestSuggestions
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe('notFoundMiddleware: REST', () => {
|
|
106
|
+
const serverBaseUrl: BaseUrl = '/base';
|
|
107
|
+
const restBaseUrl: BaseUrl = '/rest';
|
|
108
|
+
const rest: MockServerConfig['rest'] = {
|
|
109
|
+
configs: [
|
|
110
|
+
{
|
|
111
|
+
path: '/posts',
|
|
112
|
+
method: 'get',
|
|
113
|
+
routes: [{ data: {} }]
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
path: '/posts/:postId',
|
|
117
|
+
method: 'get',
|
|
118
|
+
routes: [{ data: {}, entities: { params: { postId: '1' } } }]
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
{
|
|
122
|
+
path: '/developers',
|
|
123
|
+
method: 'post',
|
|
124
|
+
routes: [{ data: {} }]
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
path: '/developers/:developerId',
|
|
128
|
+
method: 'post',
|
|
129
|
+
routes: [{ data: {}, entities: { params: { developerId: '1' } } }]
|
|
130
|
+
}
|
|
131
|
+
]
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
test('Should send correct REST suggestions', async () => {
|
|
135
|
+
const server = createServer({
|
|
136
|
+
rest
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const response = await request(server).get('/pstss');
|
|
140
|
+
|
|
141
|
+
expect(response.statusCode).toBe(404);
|
|
142
|
+
expect(response.body).toStrictEqual(
|
|
143
|
+
responseBody({ restRequestSuggestions: [{ path: '/posts', method: 'get' }] })
|
|
144
|
+
);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('Should send correct REST suggestions with serverBaseUrl', async () => {
|
|
148
|
+
const server = createServer({
|
|
149
|
+
baseUrl: serverBaseUrl,
|
|
150
|
+
rest
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const response = await request(server).get('/bas/dveloprs');
|
|
154
|
+
|
|
155
|
+
expect(response.statusCode).toBe(404);
|
|
156
|
+
expect(response.body).toStrictEqual(
|
|
157
|
+
responseBody({ restRequestSuggestions: [{ path: '/base/developers', method: 'post' }] })
|
|
158
|
+
);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test('Should send correct REST suggestions with restBaseUrl', async () => {
|
|
162
|
+
const server = createServer({
|
|
163
|
+
rest: {
|
|
164
|
+
...rest,
|
|
165
|
+
baseUrl: restBaseUrl
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const response = await request(server).get('/res/pstss');
|
|
170
|
+
|
|
171
|
+
expect(response.statusCode).toBe(404);
|
|
172
|
+
expect(response.body).toStrictEqual(
|
|
173
|
+
responseBody({ restRequestSuggestions: [{ path: '/rest/posts', method: 'get' }] })
|
|
174
|
+
);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test('Should send correct REST suggestions with serverBaseUrl and restBaseUrl', async () => {
|
|
178
|
+
const server = createServer({
|
|
179
|
+
baseUrl: serverBaseUrl,
|
|
180
|
+
rest: {
|
|
181
|
+
...rest,
|
|
182
|
+
baseUrl: restBaseUrl
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const response = await request(server).get('/bas/res/post');
|
|
187
|
+
|
|
188
|
+
expect(response.statusCode).toBe(404);
|
|
189
|
+
expect(response.body).toStrictEqual(
|
|
190
|
+
responseBody({ restRequestSuggestions: [{ path: '/base/rest/posts', method: 'get' }] })
|
|
191
|
+
);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
describe('notFoundMiddleware: GraphQL', () => {
|
|
196
|
+
const serverBaseUrl: MockServerConfig['baseUrl'] = '/base';
|
|
197
|
+
const graphqlBaseUrl: BaseUrl = '/graphql';
|
|
198
|
+
|
|
199
|
+
const graphql: MockServerConfig['graphql'] = {
|
|
200
|
+
configs: [
|
|
201
|
+
{
|
|
202
|
+
operationName: 'GetPosts',
|
|
203
|
+
operationType: 'query',
|
|
204
|
+
routes: [{ data: {} }]
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
operationName: 'GetDevelopers',
|
|
208
|
+
operationType: 'mutation',
|
|
209
|
+
routes: [{ data: {} }]
|
|
210
|
+
}
|
|
211
|
+
]
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
test('Should send correct GraphQL suggestions', async () => {
|
|
215
|
+
const server = createServer({
|
|
216
|
+
graphql
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
const response = await request(server).get('/?query=query getPost { posts }');
|
|
220
|
+
|
|
221
|
+
expect(response.statusCode).toBe(404);
|
|
222
|
+
expect(response.body).toStrictEqual(
|
|
223
|
+
responseBody({
|
|
224
|
+
graphqlRequestSuggestions: [{ operationName: ' GetPosts', operationType: 'query' }]
|
|
225
|
+
})
|
|
226
|
+
);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
test('Should send correct GraphQL suggestions with serverBaseUrl', async () => {
|
|
230
|
+
const server = createServer({
|
|
231
|
+
baseUrl: serverBaseUrl,
|
|
232
|
+
graphql
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
const response = await request(server).get('/bse?query=query developers { posts }');
|
|
236
|
+
|
|
237
|
+
expect(response.statusCode).toBe(404);
|
|
238
|
+
expect(response.body).toStrictEqual(
|
|
239
|
+
responseBody({
|
|
240
|
+
graphqlRequestSuggestions: [
|
|
241
|
+
{ operationName: '/base GetDevelopers', operationType: 'mutation' }
|
|
242
|
+
]
|
|
243
|
+
})
|
|
244
|
+
);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test('Should send correct GraphQL suggestions with graphqlBaseUrl', async () => {
|
|
248
|
+
const server = createServer({
|
|
249
|
+
graphql: {
|
|
250
|
+
...graphql,
|
|
251
|
+
baseUrl: graphqlBaseUrl
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
const response = await request(server).get('/graph?query=query posts { posts }');
|
|
256
|
+
|
|
257
|
+
expect(response.statusCode).toBe(404);
|
|
258
|
+
expect(response.body).toStrictEqual(
|
|
259
|
+
responseBody({
|
|
260
|
+
graphqlRequestSuggestions: [{ operationName: '/graphql GetPosts', operationType: 'query' }]
|
|
261
|
+
})
|
|
262
|
+
);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test('Should send correct GraphQL suggestions with serverBaseUrl and graphqlBaseUrl', async () => {
|
|
266
|
+
const server = createServer({
|
|
267
|
+
baseUrl: serverBaseUrl,
|
|
268
|
+
graphql: {
|
|
269
|
+
...graphql,
|
|
270
|
+
baseUrl: graphqlBaseUrl
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
const response = await request(server).get('/bas/graphq?query=query posts { posts }');
|
|
275
|
+
|
|
276
|
+
expect(response.statusCode).toBe(404);
|
|
277
|
+
expect(response.body).toStrictEqual(
|
|
278
|
+
responseBody({
|
|
279
|
+
graphqlRequestSuggestions: [
|
|
280
|
+
{ operationName: '/base/graphql GetPosts', operationType: 'query' }
|
|
281
|
+
]
|
|
282
|
+
})
|
|
283
|
+
);
|
|
284
|
+
});
|
|
285
|
+
});
|