express-mock-server 3.4.3 → 3.5.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 (41) hide show
  1. package/README.md +5 -0
  2. package/dist/api/recording/api-recorder.js +12 -1
  3. package/dist/api/recording/api-recorder.js.map +1 -1
  4. package/dist/config.js +24 -22
  5. package/dist/config.js.map +1 -1
  6. package/dist/core/matchers/query-string-matcher.js +1 -1
  7. package/dist/core/matchers/query-string-matcher.js.map +1 -1
  8. package/package.json +4 -2
  9. package/.editorconfig +0 -13
  10. package/.prettierrc +0 -4
  11. package/dist/core/sources-parser.spec.js +0 -32
  12. package/dist/core/sources-parser.spec.js.map +0 -1
  13. package/lib/api/control.js +0 -35
  14. package/lib/api/recording/api-recorder.js +0 -47
  15. package/lib/api/recording/index.js +0 -23
  16. package/lib/api/websocket/index.js +0 -27
  17. package/lib/app.js +0 -76
  18. package/lib/config.js +0 -29
  19. package/lib/constants.js +0 -9
  20. package/lib/core/matchers/MatchItem.js +0 -11
  21. package/lib/core/matchers/MatchingResult.js +0 -80
  22. package/lib/core/matchers/http-get-matcher.js +0 -12
  23. package/lib/core/matchers/http-post-matcher.js +0 -124
  24. package/lib/core/matchers/query-string-matcher.js +0 -113
  25. package/lib/core/request-handler.js +0 -129
  26. package/lib/core/sources-parser.js +0 -200
  27. package/lib/core/sources-parser.spec.js +0 -31
  28. package/lib/core/sources-router.js +0 -97
  29. package/lib/core/utils.js +0 -7
  30. package/lib/index.js +0 -70
  31. package/src/index.js +0 -4
  32. package/test/Digger.js +0 -20
  33. package/test/control-api.spec.js +0 -105
  34. package/test/image.jpg +0 -0
  35. package/test/index.js +0 -183
  36. package/test/mock-api.spec.js +0 -46
  37. package/test/monitoring-api.spec.js +0 -236
  38. package/test/responsekey.js +0 -15
  39. package/test/sources.js +0 -174
  40. package/test/urls.js +0 -14
  41. package/test/websocket-api.spec.js +0 -47
package/test/sources.js DELETED
@@ -1,174 +0,0 @@
1
- import urls from './urls';
2
- import responseKey, { responseKeyParam } from './responsekey';
3
- import path from 'path';
4
-
5
- const q1q2q3FilledQs = [
6
- { name: 'q1', values: ['.*'] },
7
- { name: 'q2', values: ['.*'] },
8
- { name: 'q3', values: ['.*'] },
9
- ];
10
-
11
- const q1filledQs = [{ name: 'q1', values: ['1'] }];
12
-
13
- const dynamicResponseQs = [{ name: 'q1', values: ['.*'] }];
14
-
15
- const sources = [
16
- [
17
- // codes
18
- createSource({ method: 'GET', path: urls.base, statusCode: 200 }),
19
- createSource({ method: 'GET', path: urls.error, statusCode: 500 }),
20
- createSource({ method: 'POST', path: urls.error, statusCode: 500 }),
21
- createSource({ method: 'GET', path: urls.notFound, statusCode: 404 }),
22
- // query strings
23
- createSource({
24
- method: 'GET',
25
- path: urls.items,
26
- statusCode: 200,
27
- key: responseKey.qsOptionalEmpty,
28
- }),
29
- createSource({
30
- method: 'GET',
31
- path: urls.items,
32
- statusCode: 200,
33
- key: responseKey.qsOptionalQ1Q2Q3Filed,
34
- queryStringParameters: q1q2q3FilledQs,
35
- }),
36
- createSource({
37
- method: 'GET',
38
- path: urls.items,
39
- statusCode: 200,
40
- key: responseKey.qsOptionalQ1filled,
41
- queryStringParameters: q1filledQs,
42
- }),
43
- // item
44
- createSource({
45
- method: 'GET',
46
- path: urls.item,
47
- statusCode: 200,
48
- key: responseKey.urlParamBase,
49
- }),
50
- createSource({
51
- method: 'GET',
52
- path: urls.itemHardId,
53
- statusCode: 200,
54
- key: responseKey.urlParamHardId,
55
- }),
56
- createSource({
57
- method: 'GET',
58
- path: urls.items,
59
- statusCode: 200,
60
- key: responseKey.qsMultiQ1,
61
- queryStringParameters: [{ name: 'q1', values: ['1', '2', '3'] }],
62
- }),
63
-
64
- // dynamic response
65
-
66
- createDynamicSource({
67
- method: 'POST',
68
- path: urls.dynamicResponse,
69
- statusCode: 200,
70
- key: responseKey.dynamicResponse,
71
- queryStringParameters: dynamicResponseQs,
72
- }),
73
-
74
- // response with file
75
- {
76
- request: {
77
- method: 'GET',
78
- path: urls.itemsLogo,
79
- },
80
- response: {
81
- statusCode: 200,
82
- file: {
83
- type: 'image/jpg',
84
- path: path.join(__dirname, 'image.jpg'),
85
- },
86
- },
87
- },
88
-
89
- {
90
- request: {
91
- method: 'POST',
92
- path: '/docs/upload',
93
- useFullRequestInResponse: true,
94
- },
95
- response: () => {
96
- return {
97
- statusCode: 200,
98
- };
99
- },
100
- },
101
- ],
102
- ];
103
-
104
- export default sources;
105
-
106
- /**
107
- *
108
- */
109
- function createDynamicSource({
110
- method,
111
- path,
112
- statusCode,
113
- key,
114
- queryStringParameters = null,
115
- }) {
116
- let body = {};
117
- body[responseKeyParam] = key;
118
-
119
- return {
120
- request: {
121
- method,
122
- path,
123
- queryStringParameters,
124
- body: {
125
- type: 'JSON',
126
- value: JSON.stringify({
127
- bodyParam1: 'bodyValue1',
128
- }),
129
- matchType: 'ONLY_MATCHING_FIELDS',
130
- },
131
- },
132
- response: function (urlParams, qsParams, bodyParams) {
133
- body['requestParams'] = {
134
- qsParams,
135
- bodyParams,
136
- urlParams,
137
- };
138
- return {
139
- statusCode,
140
- body: JSON.stringify(body),
141
- };
142
- },
143
- };
144
- }
145
-
146
- /**
147
- *
148
- */
149
- export function createSource({
150
- method,
151
- path,
152
- statusCode,
153
- delay,
154
- key,
155
- formDataKey = null,
156
- queryStringParameters = null,
157
- }) {
158
- let body = {};
159
- body[responseKeyParam] = key;
160
-
161
- return {
162
- request: {
163
- method,
164
- path,
165
- formDataKey,
166
- queryStringParameters,
167
- },
168
- response: {
169
- delay,
170
- statusCode,
171
- body: JSON.stringify(body),
172
- },
173
- };
174
- }
package/test/urls.js DELETED
@@ -1,14 +0,0 @@
1
- const urls = {
2
- base: '/',
3
- error: '/error',
4
- notFound: '/not-found',
5
- items: '/items',
6
- itemsLogo: '/items/logo',
7
- item: '/item/:id',
8
- itemHardId: '/item/hardId',
9
- dynamicResponseBase: '/dynamic/response/',
10
- dynamicResponseKey: 'urlParam',
11
- dynamicResponse: '/dynamic/response/:urlParam'
12
- };
13
-
14
- export default urls;
@@ -1,47 +0,0 @@
1
- import chai from 'chai';
2
- import chaiHttp from 'chai-http';
3
- import { serverStart, serverStop } from '../lib';
4
- import sources from './sources';
5
-
6
- chai.use(chaiHttp);
7
-
8
- const should = chai.should();
9
-
10
- describe('websocket API', () => {
11
- let server;
12
-
13
- before(() => {
14
- server = serverStart(sources, { port: 1337, webSocketEnabled: true });
15
- });
16
-
17
- after(() => {
18
- serverStop();
19
- });
20
-
21
- it('should send message to clients', done => {
22
- chai
23
- .request(server)
24
- .post('/api/v1/websocket/clients/message')
25
- .end((err, res) => {
26
- should.not.exist(err);
27
-
28
- res.status.should.equal(200);
29
- res.body.status.should.be.true;
30
- done();
31
- });
32
- });
33
-
34
- it('should disconnect all clients', done => {
35
- chai
36
- .request(server)
37
- .post('/api/v1/websocket/clients/disconnect')
38
- .end((err, res) => {
39
- should.not.exist(err);
40
-
41
- res.status.should.equal(200);
42
- res.body.status.should.be.true;
43
- done();
44
- });
45
- });
46
-
47
- });