mock-config-server 3.3.1 → 3.3.3
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/storages/File/FileStorage.js +0 -5
- package/dist/src/core/database/createDatabaseRoutes/storages/File/FileWriter.js +4 -8
- package/dist/src/core/database/createDatabaseRoutes/storages/Memory/MemoryStorage.js +0 -4
- package/package.json +2 -2
- package/dist/src/core/database/createDatabaseRoutes/createDatabaseRoutes.test.ts +0 -112
- package/dist/src/core/database/createDatabaseRoutes/helpers/array/createNewId/createNewId.test.ts +0 -13
- package/dist/src/core/database/createDatabaseRoutes/helpers/array/findIndexById/findIndexById.test.ts +0 -17
- package/dist/src/core/database/createDatabaseRoutes/helpers/array/isIndex/isIndex.test.ts +0 -30
- package/dist/src/core/database/createDatabaseRoutes/helpers/createNestedDatabaseRoutes/createNestedDatabaseRoutes.test.ts +0 -399
- package/dist/src/core/database/createDatabaseRoutes/helpers/createShallowDatabaseRoutes/createShallowDatabaseRoutes.test.ts +0 -118
- package/dist/src/core/database/createDatabaseRoutes/helpers/operators/operators.d.ts +0 -3
- package/dist/src/core/database/createDatabaseRoutes/helpers/operators/operators.js +0 -30
- package/dist/src/core/database/createDatabaseRoutes/helpers/search/search.d.ts +0 -3
- package/dist/src/core/database/createDatabaseRoutes/helpers/search/search.js +0 -31
- package/dist/src/core/database/createDatabaseRoutes/helpers/splitDatabaseByNesting/splitDatabaseByNesting.test.ts +0 -25
- package/dist/src/core/database/createDatabaseRoutes/storages/File/FileStorage.test.ts +0 -156
- package/dist/src/core/database/createDatabaseRoutes/storages/File/FileWriter.test.ts +0 -48
- package/dist/src/core/database/createDatabaseRoutes/storages/Memory/MemoryStorage.test.ts +0 -96
- package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.test.ts +0 -851
- package/dist/src/core/graphql/createGraphQLRoutes/helpers/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.test.ts +0 -116
- package/dist/src/core/middlewares/cookieParseMiddleware/cookieParseMiddleware.test.ts +0 -22
- package/dist/src/core/middlewares/cookieParseMiddleware/helpers/parseCookie/parseCookie.test.ts +0 -45
- package/dist/src/core/middlewares/corsMiddleware/corsMiddleware.test.ts +0 -152
- package/dist/src/core/middlewares/corsMiddleware/helpers/getAllowedOrigins/getAllowedOrigins.test.ts +0 -15
- package/dist/src/core/middlewares/errorMiddleware/errorMiddleware.test.ts +0 -29
- package/dist/src/core/middlewares/noCorsMiddleware/noCorsMiddleware.test.ts +0 -49
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getGraphqlUrlSuggestions/getGraphqlUrlSuggestions.test.ts +0 -27
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getLevenshteinDistance/getLevenshteinDistance.test.ts +0 -12
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/getRestUrlSuggestions.test.ts +0 -54
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/getActualRestUrlMeaningfulString/getActualRestUrlMeaningfulString.test.ts +0 -12
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/getPatternRestUrlMeaningfulString/getPatternRestUrlMeaningfulString.test.ts +0 -10
- package/dist/src/core/middlewares/notFoundMiddleware/notFoundMiddleware.test.ts +0 -285
- package/dist/src/core/rest/createRestRoutes/createRestRoutes.test.ts +0 -648
- package/dist/src/core/rest/createRestRoutes/helpers/prepareRestRequestConfigs/prepareRestRequestConfigs.test.ts +0 -154
- package/dist/src/utils/helpers/config/resolveEntityValues/resolveEntityValues.test.ts +0 -1452
- package/dist/src/utils/helpers/entities/convertToEntityDescriptor/convertToEntityDescriptor.test.ts +0 -27
- package/dist/src/utils/helpers/entities/isEntityDescriptor/isEntityDescriptor.test.ts +0 -15
- package/dist/src/utils/helpers/graphql/getGraphQLInput/getGraphQLInput.test.ts +0 -140
- package/dist/src/utils/helpers/graphql/parseQuery/parseQuery.test.ts +0 -32
- package/dist/src/utils/helpers/interceptors/callRequestInterceptor/callRequestInterceptors.test.ts +0 -53
- package/dist/src/utils/helpers/interceptors/callResponseInterceptors/callResponseInterceptors.test.ts +0 -262
- package/dist/src/utils/helpers/isPlainObject/isPlainObject.test.ts +0 -20
- package/dist/src/utils/helpers/isPrimitive/isPrimitive.test.ts +0 -26
- package/dist/src/utils/helpers/isRegExp/isRegExp.test.ts +0 -20
- package/dist/src/utils/helpers/url/convertWin32PathToUnix/convertWin32PathToUnix.test.ts +0 -21
- package/dist/src/utils/helpers/url/getUrlParts/getUrlParts.test.ts +0 -8
- package/dist/src/utils/helpers/url/removeLeadingAndTrailingSlashes/removeLeadingAndTrailingSlashes.test.ts +0 -10
- package/dist/src/utils/helpers/url/urlJoin/urlJoin.test.ts +0 -9
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import type { GraphQLRequestConfig } from '@/utils/types';
|
|
2
|
-
|
|
3
|
-
import { prepareGraphQLRequestConfigs } from './prepareGraphQLRequestConfigs';
|
|
4
|
-
|
|
5
|
-
describe('prepareGraphQLRequestConfigs', () => {
|
|
6
|
-
test('Should not sort routes if they does not contain entities', () => {
|
|
7
|
-
const GraphQLRequestConfigs: GraphQLRequestConfig[] = [
|
|
8
|
-
{
|
|
9
|
-
operationName: 'GetUser',
|
|
10
|
-
operationType: 'query',
|
|
11
|
-
routes: [
|
|
12
|
-
{
|
|
13
|
-
data: { name: 'John', surname: 'Doe' }
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
data: { name: 'John', surname: 'Smith' }
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
data: { name: 'John', surname: 'John' }
|
|
20
|
-
}
|
|
21
|
-
]
|
|
22
|
-
}
|
|
23
|
-
];
|
|
24
|
-
expect(prepareGraphQLRequestConfigs(GraphQLRequestConfigs)).toStrictEqual(
|
|
25
|
-
GraphQLRequestConfigs
|
|
26
|
-
);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('Should sort routes by their specificity of entities', () => {
|
|
30
|
-
const GraphQLRequestConfigs: GraphQLRequestConfig[] = [
|
|
31
|
-
{
|
|
32
|
-
operationName: 'GetUser',
|
|
33
|
-
operationType: 'query',
|
|
34
|
-
routes: [
|
|
35
|
-
{
|
|
36
|
-
entities: {
|
|
37
|
-
headers: {
|
|
38
|
-
header1: 'value'
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
data: { name: 'John', surname: 'Doe' }
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
entities: {
|
|
45
|
-
headers: {
|
|
46
|
-
header1: 'value',
|
|
47
|
-
header2: 'value'
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
data: { name: 'John', surname: 'Doe' }
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
entities: {
|
|
54
|
-
headers: {
|
|
55
|
-
header1: 'value'
|
|
56
|
-
},
|
|
57
|
-
query: {
|
|
58
|
-
query1: 'value',
|
|
59
|
-
query2: 'value'
|
|
60
|
-
},
|
|
61
|
-
variables: {
|
|
62
|
-
variable1: 'value1',
|
|
63
|
-
variable2: 'value2'
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
data: { name: 'John', surname: 'Doe' }
|
|
67
|
-
}
|
|
68
|
-
]
|
|
69
|
-
}
|
|
70
|
-
];
|
|
71
|
-
const expectedGraphQLRequestConfigs: GraphQLRequestConfig[] = [
|
|
72
|
-
{
|
|
73
|
-
operationName: 'GetUser',
|
|
74
|
-
operationType: 'query',
|
|
75
|
-
routes: [
|
|
76
|
-
{
|
|
77
|
-
entities: {
|
|
78
|
-
headers: {
|
|
79
|
-
header1: 'value'
|
|
80
|
-
},
|
|
81
|
-
query: {
|
|
82
|
-
query1: 'value',
|
|
83
|
-
query2: 'value'
|
|
84
|
-
},
|
|
85
|
-
variables: {
|
|
86
|
-
variable1: 'value1',
|
|
87
|
-
variable2: 'value2'
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
data: { name: 'John', surname: 'Doe' }
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
entities: {
|
|
94
|
-
headers: {
|
|
95
|
-
header1: 'value',
|
|
96
|
-
header2: 'value'
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
data: { name: 'John', surname: 'Doe' }
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
entities: {
|
|
103
|
-
headers: {
|
|
104
|
-
header1: 'value'
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
data: { name: 'John', surname: 'Doe' }
|
|
108
|
-
}
|
|
109
|
-
]
|
|
110
|
-
}
|
|
111
|
-
];
|
|
112
|
-
expect(prepareGraphQLRequestConfigs(GraphQLRequestConfigs)).toStrictEqual(
|
|
113
|
-
expectedGraphQLRequestConfigs
|
|
114
|
-
);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import express from 'express';
|
|
2
|
-
import request from 'supertest';
|
|
3
|
-
|
|
4
|
-
import { cookieParseMiddleware } from './cookieParseMiddleware';
|
|
5
|
-
|
|
6
|
-
describe('cookieParseMiddleware', () => {
|
|
7
|
-
test('Should correctly parse cookies', async () => {
|
|
8
|
-
const server = express();
|
|
9
|
-
cookieParseMiddleware(server);
|
|
10
|
-
|
|
11
|
-
let parsedCookies = {};
|
|
12
|
-
|
|
13
|
-
server.use((request, _response, next) => {
|
|
14
|
-
parsedCookies = request.cookies;
|
|
15
|
-
next();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
await request(server).get('/').set({ cookie: 'key=value' });
|
|
19
|
-
|
|
20
|
-
expect(parsedCookies).toEqual({ key: 'value' });
|
|
21
|
-
});
|
|
22
|
-
});
|
package/dist/src/core/middlewares/cookieParseMiddleware/helpers/parseCookie/parseCookie.test.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { parseCookie } from './parseCookie';
|
|
2
|
-
|
|
3
|
-
describe('parseCookie', () => {
|
|
4
|
-
test('Should return an empty object for empty string', () => {
|
|
5
|
-
const cookieString = '';
|
|
6
|
-
const cookies = parseCookie(cookieString);
|
|
7
|
-
|
|
8
|
-
expect(cookies).toEqual({});
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
test('Should return an object with a single key-value pair', () => {
|
|
12
|
-
const cookieString = 'name=value';
|
|
13
|
-
const cookies = parseCookie(cookieString);
|
|
14
|
-
|
|
15
|
-
expect(cookies).toEqual({ name: 'value' });
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test('Should return an object with multiple key-value pairs for a cookie string with multiple key-value pairs', () => {
|
|
19
|
-
const cookieString = 'name1=value1; name2=value2; name3=value3';
|
|
20
|
-
const cookies = parseCookie(cookieString);
|
|
21
|
-
|
|
22
|
-
expect(cookies).toEqual({ name1: 'value1', name2: 'value2', name3: 'value3' });
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test('Should handle cookies with no value by setting the value to an empty string', () => {
|
|
26
|
-
const cookieString = 'name1';
|
|
27
|
-
const cookies = parseCookie(cookieString);
|
|
28
|
-
|
|
29
|
-
expect(cookies).toEqual({ name1: '' });
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test('Should trim whitespace from keys and values', () => {
|
|
33
|
-
const cookieString = ' name1 = value1 ; name2=value2; name3 = value3 ';
|
|
34
|
-
const cookies = parseCookie(cookieString);
|
|
35
|
-
|
|
36
|
-
expect(cookies).toEqual({ name1: 'value1', name2: 'value2', name3: 'value3' });
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test('Should ignore cookies with no name', () => {
|
|
40
|
-
const cookieString = '=value';
|
|
41
|
-
const cookies = parseCookie(cookieString);
|
|
42
|
-
|
|
43
|
-
expect(cookies).toEqual({});
|
|
44
|
-
});
|
|
45
|
-
});
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import express from 'express';
|
|
2
|
-
import request from 'supertest';
|
|
3
|
-
|
|
4
|
-
import type { Cors } from '@/utils/types';
|
|
5
|
-
|
|
6
|
-
import { corsMiddleware } from './corsMiddleware';
|
|
7
|
-
|
|
8
|
-
describe('corsMiddleware', () => {
|
|
9
|
-
const testOrigin = 'https://test.com';
|
|
10
|
-
|
|
11
|
-
test('Should set default cors for OPTIONS preflight request if does not set custom cors settings', async () => {
|
|
12
|
-
const server = express();
|
|
13
|
-
const cors: Cors = {
|
|
14
|
-
origin: testOrigin
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
corsMiddleware(server, cors);
|
|
18
|
-
|
|
19
|
-
const response = await request(server).options('/').set({ origin: testOrigin });
|
|
20
|
-
|
|
21
|
-
expect(response.headers).toMatchObject({
|
|
22
|
-
'access-control-allow-headers': '*',
|
|
23
|
-
'access-control-expose-headers': '*',
|
|
24
|
-
'access-control-allow-methods': 'GET,OPTIONS,PUT,PATCH,POST,DELETE',
|
|
25
|
-
'access-control-allow-origin': 'https://test.com',
|
|
26
|
-
'access-control-max-age': '3600',
|
|
27
|
-
'access-control-allow-credentials': 'true'
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('Should set default cors for request if does not set custom cors settings', async () => {
|
|
32
|
-
const server = express();
|
|
33
|
-
const cors: Cors = {
|
|
34
|
-
origin: testOrigin
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
corsMiddleware(server, cors);
|
|
38
|
-
|
|
39
|
-
const response = await request(server).get('/').set({ origin: testOrigin });
|
|
40
|
-
|
|
41
|
-
expect(response.headers).toMatchObject({
|
|
42
|
-
'access-control-allow-origin': 'https://test.com',
|
|
43
|
-
'access-control-allow-credentials': 'true',
|
|
44
|
-
'access-control-expose-headers': '*'
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
expect(response.headers).not.toMatchObject({
|
|
48
|
-
'access-control-allow-headers': expect.any(String),
|
|
49
|
-
'access-control-allow-methods': expect.any(String),
|
|
50
|
-
'access-control-max-age': expect.any(String)
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
const unsuitableOrigins = [
|
|
55
|
-
'https://uncorrectDomain.com',
|
|
56
|
-
[],
|
|
57
|
-
/https:\/\/uncorrectDomain.com/g,
|
|
58
|
-
() => 'https://uncorrectDomain.com',
|
|
59
|
-
() => Promise.resolve('https://uncorrectDomain.com')
|
|
60
|
-
];
|
|
61
|
-
|
|
62
|
-
unsuitableOrigins.forEach((unsuitableOrigin) => {
|
|
63
|
-
test('Should not set default cors for OPTIONS preflight request if origin does not match', async () => {
|
|
64
|
-
const server = express();
|
|
65
|
-
const cors: Cors = {
|
|
66
|
-
origin: unsuitableOrigin
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
corsMiddleware(server, cors);
|
|
70
|
-
|
|
71
|
-
const response = await request(server).options('/').set({ origin: testOrigin });
|
|
72
|
-
|
|
73
|
-
expect(response.headers).not.toMatchObject({
|
|
74
|
-
'access-control-allow-headers': expect.any(String),
|
|
75
|
-
'access-control-expose-headers': expect.any(String),
|
|
76
|
-
'access-control-allow-methods': expect.any(String),
|
|
77
|
-
'access-control-allow-origin': expect.any(String),
|
|
78
|
-
'access-control-max-age': expect.any(String),
|
|
79
|
-
'access-control-allow-credentials': expect.any(String)
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
test('Should not set cors for request if origin does not match', async () => {
|
|
84
|
-
const server = express();
|
|
85
|
-
const cors: Cors = {
|
|
86
|
-
origin: unsuitableOrigin
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
corsMiddleware(server, cors);
|
|
90
|
-
|
|
91
|
-
const response = await request(server).get('/').set({ origin: testOrigin });
|
|
92
|
-
|
|
93
|
-
expect(response.headers).not.toMatchObject({
|
|
94
|
-
'access-control-allow-origin': expect.any(String),
|
|
95
|
-
'access-control-allow-credentials': expect.any(String),
|
|
96
|
-
'access-control-expose-headers': expect.any(String)
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
const corsParamsAndHeaders: { params: Omit<Cors, 'origin'>; headers: Record<string, string> }[] =
|
|
102
|
-
[
|
|
103
|
-
{
|
|
104
|
-
params: { allowedHeaders: ['header1', 'header2'] },
|
|
105
|
-
headers: {
|
|
106
|
-
'access-control-allow-headers': 'header1, header2'
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
params: { exposedHeaders: ['header1', 'header2'] },
|
|
111
|
-
headers: {
|
|
112
|
-
'access-control-expose-headers': 'header1, header2'
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
params: { maxAge: 10000 },
|
|
117
|
-
headers: {
|
|
118
|
-
'access-control-max-age': '10000'
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
params: { methods: ['GET', 'POST'] },
|
|
123
|
-
headers: {
|
|
124
|
-
'access-control-allow-methods': 'GET, POST'
|
|
125
|
-
}
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
params: { credentials: false },
|
|
129
|
-
headers: {
|
|
130
|
-
'access-control-allow-credentials': 'false'
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
];
|
|
134
|
-
|
|
135
|
-
corsParamsAndHeaders.forEach(({ params, headers }) =>
|
|
136
|
-
test(`Should set allow param(s) ${Object.keys(params).join(', ')} to header(s) ${Object.keys(
|
|
137
|
-
headers
|
|
138
|
-
).join(', ')}`, async () => {
|
|
139
|
-
const server = express();
|
|
140
|
-
const cors: Cors = {
|
|
141
|
-
origin: testOrigin,
|
|
142
|
-
...params
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
corsMiddleware(server, cors);
|
|
146
|
-
|
|
147
|
-
const response = await request(server).options('/').set({ origin: testOrigin });
|
|
148
|
-
|
|
149
|
-
expect(response.headers).toMatchObject(headers);
|
|
150
|
-
})
|
|
151
|
-
);
|
|
152
|
-
});
|
package/dist/src/core/middlewares/corsMiddleware/helpers/getAllowedOrigins/getAllowedOrigins.test.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { getAllowedOrigins } from './getAllowedOrigins';
|
|
2
|
-
|
|
3
|
-
describe('getAllowedOrigins', () => {
|
|
4
|
-
test('Function should return array if get string or RegExp parameter', () => {
|
|
5
|
-
expect(getAllowedOrigins(/origin/g)).toEqual([/origin/g]);
|
|
6
|
-
expect(getAllowedOrigins('https://origin.com')).toEqual(['https://origin.com']);
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
test('Function should return array if get array parameter', () => {
|
|
10
|
-
expect(getAllowedOrigins([/origin/g, 'https://origin.com'])).toEqual([
|
|
11
|
-
/origin/g,
|
|
12
|
-
'https://origin.com'
|
|
13
|
-
]);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import express from 'express';
|
|
2
|
-
import request from 'supertest';
|
|
3
|
-
|
|
4
|
-
import { errorMiddleware } from './errorMiddleware';
|
|
5
|
-
|
|
6
|
-
describe('errorMiddleware', () => {
|
|
7
|
-
test('Should handle error from server handler', async () => {
|
|
8
|
-
const server = express();
|
|
9
|
-
|
|
10
|
-
server.get('/error', () => {
|
|
11
|
-
throw new Error('error');
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
server.get('/success', (_request, response) => {
|
|
15
|
-
response.send('success');
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
errorMiddleware(server);
|
|
19
|
-
|
|
20
|
-
const errorResponse = await request(server).get('/error');
|
|
21
|
-
const successResponse = await request(server).get('/success');
|
|
22
|
-
|
|
23
|
-
expect(errorResponse.status).toEqual(500);
|
|
24
|
-
expect(errorResponse.text).toContain('error');
|
|
25
|
-
|
|
26
|
-
expect(successResponse.status).toEqual(200);
|
|
27
|
-
expect(successResponse.text).toEqual('success');
|
|
28
|
-
});
|
|
29
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import express from 'express';
|
|
2
|
-
import request from 'supertest';
|
|
3
|
-
|
|
4
|
-
import { noCorsMiddleware } from './noCorsMiddleware';
|
|
5
|
-
|
|
6
|
-
describe('noCorsMiddleware', () => {
|
|
7
|
-
test('Should set no cors settings for OPTIONS preflight request', async () => {
|
|
8
|
-
const server = express();
|
|
9
|
-
|
|
10
|
-
noCorsMiddleware(server);
|
|
11
|
-
|
|
12
|
-
const preflightHeaders = {
|
|
13
|
-
'access-control-request-method': 'GET,OPTIONS,PUT,PATCH,POST,DELETE',
|
|
14
|
-
'access-control-request-headers': '*',
|
|
15
|
-
origin: '/'
|
|
16
|
-
};
|
|
17
|
-
const response = await request(server).options('/').set(preflightHeaders);
|
|
18
|
-
|
|
19
|
-
expect(response.headers).toMatchObject({
|
|
20
|
-
'access-control-allow-origin': '*',
|
|
21
|
-
'access-control-allow-credentials': 'true',
|
|
22
|
-
'access-control-expose-headers': '*',
|
|
23
|
-
'access-control-allow-headers': '*',
|
|
24
|
-
'access-control-allow-methods': 'GET,OPTIONS,PUT,PATCH,POST,DELETE',
|
|
25
|
-
'access-control-max-age': '3600'
|
|
26
|
-
});
|
|
27
|
-
expect(response.statusCode).toBe(204);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('Should set no cors settings for request', async () => {
|
|
31
|
-
const server = express();
|
|
32
|
-
|
|
33
|
-
noCorsMiddleware(server);
|
|
34
|
-
|
|
35
|
-
const response = await request(server).get('/');
|
|
36
|
-
|
|
37
|
-
expect(response.headers).toMatchObject({
|
|
38
|
-
'access-control-allow-origin': '*',
|
|
39
|
-
'access-control-allow-credentials': 'true',
|
|
40
|
-
'access-control-expose-headers': '*'
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
expect(response.headers).not.toMatchObject({
|
|
44
|
-
'access-control-allow-headers': expect.any(String),
|
|
45
|
-
'access-control-allow-methods': expect.any(String),
|
|
46
|
-
'access-control-max-age': expect.any(String)
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { GraphqlRequestSuggestionConfigs } from './getGraphqlUrlSuggestions';
|
|
2
|
-
import { getGraphqlUrlSuggestions } from './getGraphqlUrlSuggestions';
|
|
3
|
-
|
|
4
|
-
describe('getGraphqlUrlSuggestions', () => {
|
|
5
|
-
test('Should correctly return suggestions', () => {
|
|
6
|
-
const requestConfigs: GraphqlRequestSuggestionConfigs = [
|
|
7
|
-
{ operationType: 'query', operationName: '/GetDevelopers' },
|
|
8
|
-
{ operationType: 'mutation', operationName: '/CreateDeveloper' }
|
|
9
|
-
];
|
|
10
|
-
expect(
|
|
11
|
-
getGraphqlUrlSuggestions({
|
|
12
|
-
url: new URL('http://localhost:31299/?query=query Getdevoper { developers }}'),
|
|
13
|
-
requestConfigs
|
|
14
|
-
})
|
|
15
|
-
).toEqual([
|
|
16
|
-
{ operationType: 'query', operationName: '/GetDevelopers' },
|
|
17
|
-
{ operationType: 'mutation', operationName: '/CreateDeveloper' }
|
|
18
|
-
]);
|
|
19
|
-
|
|
20
|
-
expect(
|
|
21
|
-
getGraphqlUrlSuggestions({
|
|
22
|
-
url: new URL('http://localhost:31299/?query=query devel { developers }}'),
|
|
23
|
-
requestConfigs
|
|
24
|
-
})
|
|
25
|
-
).toEqual([]);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { getLevenshteinDistance } from './getLevenshteinDistance';
|
|
2
|
-
|
|
3
|
-
describe('getLevenshteinDistance', () => {
|
|
4
|
-
test('Should correct return Levenshtein distance', () => {
|
|
5
|
-
expect(getLevenshteinDistance('users', 'users')).toEqual(0);
|
|
6
|
-
expect(getLevenshteinDistance('psts', 'posts')).toEqual(1);
|
|
7
|
-
expect(getLevenshteinDistance('postss', 'posts')).toEqual(1);
|
|
8
|
-
expect(getLevenshteinDistance('users', 'Users')).toEqual(1);
|
|
9
|
-
expect(getLevenshteinDistance('1234', '1234567')).toEqual(3);
|
|
10
|
-
expect(getLevenshteinDistance('', '1234')).toEqual(4);
|
|
11
|
-
});
|
|
12
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { RestRequestSuggestionConfigs } from './getRestUrlSuggestions';
|
|
2
|
-
import { getRestUrlSuggestions } from './getRestUrlSuggestions';
|
|
3
|
-
|
|
4
|
-
describe('getRestUrlSuggestions', () => {
|
|
5
|
-
test('Should correctly return suggestions', () => {
|
|
6
|
-
const requestConfigs: RestRequestSuggestionConfigs = [
|
|
7
|
-
{ method: 'get', path: '/posts/:postId' },
|
|
8
|
-
{ method: 'post', path: '/posts/:postId/comments/:commentId' }
|
|
9
|
-
];
|
|
10
|
-
expect(
|
|
11
|
-
getRestUrlSuggestions({
|
|
12
|
-
url: new URL('http://localhost:31299/posts/5/comments/2'),
|
|
13
|
-
requestConfigs
|
|
14
|
-
})
|
|
15
|
-
).toEqual([{ method: 'post', path: '/posts/5/comments/2' }]);
|
|
16
|
-
expect(
|
|
17
|
-
getRestUrlSuggestions({
|
|
18
|
-
url: new URL('http://localhost:31299/psts/5/commennts/2'),
|
|
19
|
-
requestConfigs
|
|
20
|
-
})
|
|
21
|
-
).toEqual([{ method: 'post', path: '/posts/5/comments/2' }]);
|
|
22
|
-
expect(
|
|
23
|
-
getRestUrlSuggestions({
|
|
24
|
-
url: new URL('http://localhost:31299/post/5/omments/2'),
|
|
25
|
-
requestConfigs
|
|
26
|
-
})
|
|
27
|
-
).toEqual([{ method: 'post', path: '/posts/5/comments/2' }]);
|
|
28
|
-
expect(
|
|
29
|
-
getRestUrlSuggestions({
|
|
30
|
-
url: new URL('http://localhost:31299/ps/5/cots/2'),
|
|
31
|
-
requestConfigs
|
|
32
|
-
})
|
|
33
|
-
).toEqual([]);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('Should return requests with same query params as provided', () => {
|
|
37
|
-
const requestConfigs: RestRequestSuggestionConfigs = [
|
|
38
|
-
{ method: 'get', path: '/users' },
|
|
39
|
-
{ method: 'get', path: '/users/:userId' },
|
|
40
|
-
{ method: 'post', path: '/user' },
|
|
41
|
-
{ method: 'post', path: '/login' },
|
|
42
|
-
{ method: 'delete', path: '/logout' }
|
|
43
|
-
];
|
|
44
|
-
expect(
|
|
45
|
-
getRestUrlSuggestions({
|
|
46
|
-
url: new URL('http://localhost:31299/login?remember=true?action=success'),
|
|
47
|
-
requestConfigs
|
|
48
|
-
})
|
|
49
|
-
).toEqual([
|
|
50
|
-
{ method: 'post', path: '/login?remember=true?action=success' },
|
|
51
|
-
{ method: 'delete', path: '/logout?remember=true?action=success' }
|
|
52
|
-
]);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { getActualRestUrlMeaningfulString } from './getActualRestUrlMeaningfulString';
|
|
2
|
-
|
|
3
|
-
describe('getActualRestUrlMeaningfulString', () => {
|
|
4
|
-
test('Should correctly return actual rest meaningful string', () => {
|
|
5
|
-
expect(
|
|
6
|
-
getActualRestUrlMeaningfulString(
|
|
7
|
-
['base', 'rest', 'posts', '2', 'comments', '5'],
|
|
8
|
-
['base', 'rest', 'posts', ':postId', 'comments', ':commentId']
|
|
9
|
-
)
|
|
10
|
-
).toEqual('baserestpostscomments');
|
|
11
|
-
});
|
|
12
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { getPatternRestUrlMeaningfulString } from './getPatternRestUrlMeaningfulString';
|
|
2
|
-
|
|
3
|
-
describe('getPatternRestUrlMeaningfulString', () => {
|
|
4
|
-
test('Should correct return rest url pattern meaningful string', () => {
|
|
5
|
-
expect(
|
|
6
|
-
getPatternRestUrlMeaningfulString(['rest', 'posts', ':postId', 'comments', ':commentId'])
|
|
7
|
-
).toEqual('restpostscomments');
|
|
8
|
-
expect(getPatternRestUrlMeaningfulString(['users'])).toEqual('users');
|
|
9
|
-
});
|
|
10
|
-
});
|