express-mock-server 3.0.0 → 3.4.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 (53) hide show
  1. package/dist/api/control.js +2 -2
  2. package/dist/api/control.js.map +1 -1
  3. package/dist/api/recording/api-recorder.js +3 -5
  4. package/dist/api/recording/api-recorder.js.map +1 -1
  5. package/dist/api/recording/index.js.map +1 -1
  6. package/dist/api/websocket/index.js +35 -0
  7. package/dist/api/websocket/index.js.map +1 -0
  8. package/dist/app.js +11 -0
  9. package/dist/app.js.map +1 -1
  10. package/dist/config.js.map +1 -1
  11. package/dist/constants.js +1 -1
  12. package/dist/constants.js.map +1 -1
  13. package/dist/core/matchers/MatchItem.js.map +1 -1
  14. package/dist/core/matchers/MatchingResult.js +1 -1
  15. package/dist/core/matchers/MatchingResult.js.map +1 -1
  16. package/dist/core/matchers/http-post-matcher.js.map +1 -1
  17. package/dist/core/matchers/query-string-matcher.js +21 -4
  18. package/dist/core/matchers/query-string-matcher.js.map +1 -1
  19. package/dist/core/request-handler.js +41 -5
  20. package/dist/core/request-handler.js.map +1 -1
  21. package/dist/core/sources-parser.js.map +1 -1
  22. package/dist/core/sources-parser.spec.js.map +1 -1
  23. package/dist/core/sources-router.js +11 -11
  24. package/dist/core/sources-router.js.map +1 -1
  25. package/dist/core/utils.js.map +1 -1
  26. package/dist/index.js +35 -1
  27. package/dist/index.js.map +1 -1
  28. package/lib/api/control.js +5 -5
  29. package/lib/api/recording/api-recorder.js +6 -6
  30. package/lib/api/recording/index.js +1 -1
  31. package/lib/api/websocket/index.js +27 -0
  32. package/lib/app.js +10 -0
  33. package/lib/config.js +1 -1
  34. package/lib/constants.js +1 -1
  35. package/lib/core/matchers/MatchingResult.js +1 -1
  36. package/lib/core/matchers/http-post-matcher.js +1 -1
  37. package/lib/core/matchers/query-string-matcher.js +20 -4
  38. package/lib/core/request-handler.js +50 -7
  39. package/lib/core/sources-parser.js +8 -8
  40. package/lib/core/sources-parser.spec.js +6 -6
  41. package/lib/core/sources-router.js +12 -12
  42. package/lib/core/utils.js +1 -1
  43. package/lib/index.js +33 -1
  44. package/package.json +17 -15
  45. package/src/index.js +1 -1
  46. package/test/image.jpg +0 -0
  47. package/test/index.js +40 -3
  48. package/test/mock-api.spec.js +14 -0
  49. package/test/monitoring-api.spec.js +94 -1
  50. package/test/responsekey.js +1 -0
  51. package/test/sources.js +44 -21
  52. package/test/urls.js +1 -0
  53. package/test/websocket-api.spec.js +47 -0
@@ -11,7 +11,7 @@ export class SourcesRouter {
11
11
 
12
12
  registerSources(app, isLogEnabled) {
13
13
  const map = this.parser.getMap();
14
- Object.keys(map).forEach(path => {
14
+ Object.keys(map).forEach((path) => {
15
15
  this.registerGET(app, path, isLogEnabled);
16
16
  this.registerPOST(app, path, isLogEnabled);
17
17
  this.registerPUT(app, path, isLogEnabled);
@@ -26,8 +26,8 @@ export class SourcesRouter {
26
26
 
27
27
  if (gets) {
28
28
  gets.forEach(() => {
29
- app.get(path, (req, res) => {
30
- requestHandler(this.parser, req, res);
29
+ app.get(path, (req, res, next) => {
30
+ requestHandler(this.parser, req, res, next);
31
31
  });
32
32
  this.logRegisteredPath(isLogEnabled, methods.GET, path);
33
33
  });
@@ -39,8 +39,8 @@ export class SourcesRouter {
39
39
  const posts = pathItem[methods.POST];
40
40
  if (posts) {
41
41
  posts.forEach(() => {
42
- app.post(path, (req, res) => {
43
- requestHandler(this.parser, req, res);
42
+ app.post(path, (req, res, next) => {
43
+ requestHandler(this.parser, req, res, next);
44
44
  });
45
45
  this.logRegisteredPath(isLogEnabled, methods.POST, path);
46
46
  });
@@ -52,8 +52,8 @@ export class SourcesRouter {
52
52
  const puts = pathItem[methods.PUT];
53
53
  if (puts) {
54
54
  puts.forEach(() => {
55
- app.put(path, (req, res) => {
56
- requestHandler(this.parser, req, res);
55
+ app.put(path, (req, res, next) => {
56
+ requestHandler(this.parser, req, res, next);
57
57
  });
58
58
  this.logRegisteredPath(isLogEnabled, methods.PUT, path);
59
59
  });
@@ -65,8 +65,8 @@ export class SourcesRouter {
65
65
  const deletes = pathItem[methods.DELETE];
66
66
  if (deletes) {
67
67
  deletes.forEach(() => {
68
- app.delete(path, (req, res) => {
69
- requestHandler(this.parser, req, res);
68
+ app.delete(path, (req, res, next) => {
69
+ requestHandler(this.parser, req, res, next);
70
70
  });
71
71
  this.logRegisteredPath(isLogEnabled, methods.DELETE, path);
72
72
  });
@@ -78,8 +78,8 @@ export class SourcesRouter {
78
78
  const patches = pathItem[methods.PATCH];
79
79
  if (patches) {
80
80
  patches.forEach(() => {
81
- app.patch(path, (req, res) => {
82
- requestHandler(this.parser, req, res);
81
+ app.patch(path, (req, res, next) => {
82
+ requestHandler(this.parser, req, res, next);
83
83
  });
84
84
  this.logRegisteredPath(isLogEnabled, methods.PATCH, path);
85
85
  });
@@ -87,7 +87,7 @@ export class SourcesRouter {
87
87
  }
88
88
 
89
89
  /**
90
- * Method to log registred path
90
+ * Method to log registered path
91
91
  */
92
92
  logRegisteredPath(isLogEnabled, method, path) {
93
93
  if (isLogEnabled) {
package/lib/core/utils.js CHANGED
@@ -1,4 +1,4 @@
1
- export const isFunction = functionToCheck => {
1
+ export const isFunction = (functionToCheck) => {
2
2
  const getType = {};
3
3
  return (
4
4
  functionToCheck &&
package/lib/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  import 'colors';
2
2
  import config from './config';
3
3
  import { App } from './app';
4
+ import ws from 'ws';
4
5
 
5
6
  const { port } = config;
6
- let server = null;
7
+ let server,
8
+ wsServer = null;
7
9
 
8
10
  /**
9
11
  * Method to start server.
@@ -12,6 +14,7 @@ let server = null;
12
14
  * @param {Object} serverConfig
13
15
  * @param serverConfig.controlApiUrl ['/api/v1']
14
16
  * @param serverConfig.port [8080]
17
+ * @param serverConfig.webSocketEnabled false
15
18
  */
16
19
  export function serverStart(sources, serverConfig = {}) {
17
20
  const app = new App(sources, serverConfig);
@@ -21,6 +24,12 @@ export function serverStart(sources, serverConfig = {}) {
21
24
  console.log(`*************************`.yellow);
22
25
  console.log('Server START'.bgGreen.white);
23
26
  });
27
+
28
+ if (serverConfig.webSocketEnabled) {
29
+ wsServer = startWebSocket(server);
30
+ app.initWebSocketApi(wsServer);
31
+ }
32
+
24
33
  return server;
25
34
  }
26
35
 
@@ -31,6 +40,29 @@ export function serverStop() {
31
40
  if (server) {
32
41
  server.close();
33
42
  }
43
+ if (wsServer) {
44
+ wsServer.close();
45
+ }
46
+ }
47
+
48
+ function startWebSocket(server) {
49
+ const wsServer = new ws.Server({ noServer: true });
50
+ wsServer.on('connection', (socket) => {
51
+ console.log('WebSocket client connected');
52
+ socket.on('message', (message) => {
53
+ console.log('WebSocket client message received');
54
+ console.log(message);
55
+ });
56
+ socket.on('close', () => console.log('WebSocket client disconnected'));
57
+ });
58
+
59
+ server.on('upgrade', (request, socket, head) => {
60
+ wsServer.handleUpgrade(request, socket, head, (socket) => {
61
+ wsServer.emit('connection', socket, request);
62
+ });
63
+ });
64
+
65
+ return wsServer;
34
66
  }
35
67
 
36
68
  function getServerPort(serverConfig) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-mock-server",
3
- "version": "3.0.0",
3
+ "version": "3.4.0",
4
4
  "description": "Mock server powered by Express.js",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -31,24 +31,26 @@
31
31
  "body-parser": "1.19.0",
32
32
  "colors": "1.4.0",
33
33
  "express": "4.17.1",
34
- "http-status-codes": "1.4.0",
35
- "morgan": "1.9.1",
36
- "nconf": "0.10.0",
37
- "rimraf": "3.0.0",
38
- "uuid": "3.3.3"
34
+ "http-status-codes": "2.1.4",
35
+ "morgan": "1.10.0",
36
+ "nconf": "0.11.3",
37
+ "rimraf": "3.0.2",
38
+ "uuid": "8.3.2",
39
+ "ws": "7.4.6"
39
40
  },
40
41
  "devDependencies": {
41
- "@babel/cli": "7.7.5",
42
- "@babel/core": "7.7.5",
43
- "@babel/preset-env": "7.7.6",
44
- "@babel/register": "7.7.4",
45
- "chai": "4.2.0",
42
+ "@babel/cli": "7.16.0",
43
+ "@babel/core": "7.16.0",
44
+ "@babel/preset-env": "7.16.4",
45
+ "@babel/register": "7.16.0",
46
+ "chai": "4.3.4",
46
47
  "chai-http": "4.3.0",
47
48
  "mocha": "6.2.2",
48
- "nodemon": "2.0.2",
49
- "prettier": "1.19.1",
50
- "request": "2.88.0",
51
- "run-sequence": "2.2.1"
49
+ "nodemon": "2.0.15",
50
+ "prettier": "2.5.1",
51
+ "request": "2.88.2",
52
+ "run-sequence": "2.2.1",
53
+ "websocket": "^1.0.34"
52
54
  },
53
55
  "babel": {
54
56
  "presets": [
package/src/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import { serverStart } from '../lib';
2
2
  import sources from '../test/sources';
3
3
 
4
- serverStart(sources, { port: 2121 });
4
+ serverStart(sources, { port: 2121, webSocketEnabled: true });
package/test/image.jpg ADDED
Binary file
package/test/index.js CHANGED
@@ -6,12 +6,15 @@ import sources from './sources';
6
6
  import urls from './urls';
7
7
  import responseKey, { responseKeyParam } from './responsekey';
8
8
  import Digger from './Digger';
9
+ import { client as WebSocketClient } from 'websocket';
9
10
 
10
11
  const PORT = 1337;
11
12
  const SERVER_NAME = '127.0.0.1';
12
13
  const SERVER_URL_WITHOUT_PORT = 'http://' + SERVER_NAME;
13
14
  const SERVER_URL = SERVER_URL_WITHOUT_PORT + ':' + PORT;
14
15
 
16
+ const WS_SERVER_URL = 'ws://' + SERVER_NAME + ':' + PORT;
17
+
15
18
  function createItemsExpectation(qs, key, done) {
16
19
  http.get(SERVER_URL + urls.items + qs, res => {
17
20
  new Digger(res, data => {
@@ -38,10 +41,8 @@ function createCodeExpectation(url, code, done) {
38
41
  }
39
42
 
40
43
  describe('server', () => {
41
-
42
-
43
44
  before(() => {
44
- serverStart(sources, { port: PORT });
45
+ serverStart(sources, { port: PORT, webSocketEnabled: true });
45
46
  });
46
47
 
47
48
  after(() => {
@@ -86,6 +87,31 @@ describe('server', () => {
86
87
  createItemsExpectation(qs, responseKey.qsOptionalEmpty, done);
87
88
  });
88
89
 
90
+ it('multi q1 filled = matched for the same values', done => {
91
+ const qs = '?q1=1&q1=2&q1=3';
92
+ createItemsExpectation(qs, responseKey.qsMultiQ1, done);
93
+ });
94
+
95
+ it('multi q1 filled = matched also for different order of values', done => {
96
+ const qs = '?q1=1&q1=3&q1=2';
97
+ createItemsExpectation(qs, responseKey.qsMultiQ1, done);
98
+ });
99
+
100
+ it('multi q1 filled = no matched because more values', done => {
101
+ const qs = '?q1=1&q1=2&q1=3&q1=4';
102
+ createItemsExpectation(qs, responseKey.qsOptionalEmpty, done);
103
+ });
104
+
105
+ it('multi q1 filled = no matched because one value is different', done => {
106
+ const qs = '?q1=1&q1=2&q1=4';
107
+ createItemsExpectation(qs, responseKey.qsOptionalEmpty, done);
108
+ });
109
+
110
+ it('multi q1 filled = no matched because less values', done => {
111
+ const qs = '?q1=1&q1=2';
112
+ createItemsExpectation(qs, responseKey.qsOptionalEmpty, done);
113
+ });
114
+
89
115
  it('q1, q2, q3 filled = expected q1, q2, q3', done => {
90
116
  const qs = '?q1=1&q2=2&q3=3';
91
117
  createItemsExpectation(qs, responseKey.qsOptionalQ1Q2Q3Filed, done);
@@ -113,6 +139,17 @@ describe('server', () => {
113
139
  });
114
140
  });
115
141
 
142
+ describe('websocket', () => {
143
+ it('try to connect', done => {
144
+ const client = new WebSocketClient();
145
+ client.on('connect', function(connection) {
146
+ assert.equal('open', connection.state);
147
+ done();
148
+ });
149
+ client.connect(WS_SERVER_URL, 'echo-protocol');
150
+ });
151
+ });
152
+
116
153
  function createDynamicResponseExpectation(key, done) {
117
154
  const urlParamValue = 'urlParamValue';
118
155
 
@@ -29,4 +29,18 @@ describe('API mocks', () => {
29
29
  done();
30
30
  });
31
31
  });
32
+
33
+ it('should call mocked API with file response', done => {
34
+ chai
35
+ .request(server)
36
+ .get('/items/logo')
37
+ .end((err, res) => {
38
+ console.log(res.body);
39
+ should.not.exist(err);
40
+ res.status.should.equal(200);
41
+ res.type.should.equal('image/jpg');
42
+ chai.expect(res.body).to.have.lengthOf(2317786);
43
+ done();
44
+ });
45
+ });
32
46
  });
@@ -96,7 +96,7 @@ describe('recording API', () => {
96
96
  });
97
97
  });
98
98
 
99
- it('should monitor POST API call', done => {
99
+ it('should monitor POST API call with empty body', done => {
100
100
  chai
101
101
  .request(server)
102
102
  .post('/api/v1/recording/start')
@@ -140,4 +140,97 @@ describe('recording API', () => {
140
140
  });
141
141
  });
142
142
  });
143
+
144
+ it('should monitor POST API call with application/json', done => {
145
+ chai
146
+ .request(server)
147
+ .post('/api/v1/recording/start')
148
+ .end((err, res) => {
149
+ should.not.exist(err);
150
+ res.status.should.equal(200);
151
+ res.body.id.should.be.a('string');
152
+
153
+ const monitoringId = res.body.id;
154
+
155
+ chai
156
+ .request(server)
157
+ .post(`/dynamic/response/555?queryParam=queryValue`)
158
+ .send({ test: 'pokus' })
159
+ .end((err, res) => {
160
+ should.not.exist(err);
161
+ res.status.should.equal(200);
162
+
163
+ chai
164
+ .request(server)
165
+ .post(`/api/v1/recording/${monitoringId}/stop`)
166
+ .end((err, res) => {
167
+ should.not.exist(err);
168
+ res.status.should.equal(200);
169
+ res.body.should.be.an('array').and.to.have.lengthOf(1);
170
+ res.body[0].method.should.equal('POST');
171
+ res.body[0].path.should.equal('/dynamic/response/555');
172
+ res.body[0].query.should.deep.equal({
173
+ queryParam: 'queryValue'
174
+ });
175
+
176
+ res.body[0].responseBody.should.deep.equal({
177
+ responseKey: 'dynamicResponse',
178
+ requestParams: {
179
+ qsParams: { queryParam: 'queryValue' },
180
+ bodyParams: { test: 'pokus' },
181
+ urlParams: { urlParam: '555' }
182
+ }
183
+ });
184
+ done();
185
+ });
186
+ });
187
+ });
188
+ });
189
+
190
+ it('should monitor POST API call with text/plain', done => {
191
+ chai
192
+ .request(server)
193
+ .post('/api/v1/recording/start')
194
+ .end((err, res) => {
195
+ should.not.exist(err);
196
+ res.status.should.equal(200);
197
+ res.body.id.should.be.a('string');
198
+
199
+ const monitoringId = res.body.id;
200
+
201
+ chai
202
+ .request(server)
203
+ .post(`/dynamic/response/555?queryParam=queryValue`)
204
+ .set('content-type', 'text/plain')
205
+ .send('test text body')
206
+ .end((err, res) => {
207
+ should.not.exist(err);
208
+ res.status.should.equal(200);
209
+
210
+ chai
211
+ .request(server)
212
+ .post(`/api/v1/recording/${monitoringId}/stop`)
213
+ .end((err, res) => {
214
+ should.not.exist(err);
215
+ res.status.should.equal(200);
216
+ res.body.should.be.an('array').and.to.have.lengthOf(1);
217
+ res.body[0].method.should.equal('POST');
218
+ res.body[0].path.should.equal('/dynamic/response/555');
219
+ res.body[0].query.should.deep.equal({
220
+ queryParam: 'queryValue'
221
+ });
222
+
223
+ res.body[0].responseBody.should.deep.equal({
224
+ responseKey: 'dynamicResponse',
225
+ requestParams: {
226
+ qsParams: { queryParam: 'queryValue' },
227
+ bodyParams: 'test text body',
228
+ urlParams: { urlParam: '555' }
229
+ }
230
+ });
231
+ done();
232
+ });
233
+ });
234
+ });
235
+ });
143
236
  });
@@ -2,6 +2,7 @@ export const responseKeyParam = 'responseKey';
2
2
 
3
3
  const responseKey = {
4
4
  qsOptionalEmpty: 'qsOptionalEmpty',
5
+ qsMultiQ1: 'qsMultiQ1',
5
6
  qsOptionalQ1Q2Q3Filed: 'qsOptionalQ1Q2Q3Filed',
6
7
  qsOptionalQ1filled: 'qsOptionalQ1filled',
7
8
 
package/test/sources.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import urls from './urls';
2
2
  import responseKey, { responseKeyParam } from './responsekey';
3
+ import path from 'path';
3
4
 
4
5
  const q1q2q3FilledQs = [
5
6
  { name: 'q1', values: ['.*'] },
6
7
  { name: 'q2', values: ['.*'] },
7
- { name: 'q3', values: ['.*'] }
8
+ { name: 'q3', values: ['.*'] },
8
9
  ];
9
10
 
10
11
  const q1filledQs = [{ name: 'q1', values: ['1'] }];
@@ -23,34 +24,41 @@ const sources = [
23
24
  method: 'GET',
24
25
  path: urls.items,
25
26
  statusCode: 200,
26
- key: responseKey.qsOptionalEmpty
27
+ key: responseKey.qsOptionalEmpty,
27
28
  }),
28
29
  createSource({
29
30
  method: 'GET',
30
31
  path: urls.items,
31
32
  statusCode: 200,
32
33
  key: responseKey.qsOptionalQ1Q2Q3Filed,
33
- queryStringParameters: q1q2q3FilledQs
34
+ queryStringParameters: q1q2q3FilledQs,
34
35
  }),
35
36
  createSource({
36
37
  method: 'GET',
37
38
  path: urls.items,
38
39
  statusCode: 200,
39
40
  key: responseKey.qsOptionalQ1filled,
40
- queryStringParameters: q1filledQs
41
+ queryStringParameters: q1filledQs,
41
42
  }),
42
43
  // item
43
44
  createSource({
44
45
  method: 'GET',
45
46
  path: urls.item,
46
47
  statusCode: 200,
47
- key: responseKey.urlParamBase
48
+ key: responseKey.urlParamBase,
48
49
  }),
49
50
  createSource({
50
51
  method: 'GET',
51
52
  path: urls.itemHardId,
52
53
  statusCode: 200,
53
- key: responseKey.urlParamHardId
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'] }],
54
62
  }),
55
63
 
56
64
  // dynamic response
@@ -60,9 +68,24 @@ const sources = [
60
68
  path: urls.dynamicResponse,
61
69
  statusCode: 200,
62
70
  key: responseKey.dynamicResponse,
63
- queryStringParameters: dynamicResponseQs
64
- })
65
- ]
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
+ ],
66
89
  ];
67
90
 
68
91
  export default sources;
@@ -75,7 +98,7 @@ function createDynamicSource({
75
98
  path,
76
99
  statusCode,
77
100
  key,
78
- queryStringParameters = null
101
+ queryStringParameters = null,
79
102
  }) {
80
103
  let body = {};
81
104
  body[responseKeyParam] = key;
@@ -88,22 +111,22 @@ function createDynamicSource({
88
111
  body: {
89
112
  type: 'JSON',
90
113
  value: JSON.stringify({
91
- bodyParam1: 'bodyValue1'
114
+ bodyParam1: 'bodyValue1',
92
115
  }),
93
- matchType: 'ONLY_MATCHING_FIELDS'
94
- }
116
+ matchType: 'ONLY_MATCHING_FIELDS',
117
+ },
95
118
  },
96
- response: function(urlParams, qsParams, bodyParams) {
119
+ response: function (urlParams, qsParams, bodyParams) {
97
120
  body['requestParams'] = {
98
121
  qsParams,
99
122
  bodyParams,
100
- urlParams
123
+ urlParams,
101
124
  };
102
125
  return {
103
126
  statusCode,
104
- body: JSON.stringify(body)
127
+ body: JSON.stringify(body),
105
128
  };
106
- }
129
+ },
107
130
  };
108
131
  }
109
132
 
@@ -116,7 +139,7 @@ export function createSource({
116
139
  statusCode,
117
140
  delay,
118
141
  key,
119
- queryStringParameters = null
142
+ queryStringParameters = null,
120
143
  }) {
121
144
  let body = {};
122
145
  body[responseKeyParam] = key;
@@ -125,12 +148,12 @@ export function createSource({
125
148
  request: {
126
149
  method,
127
150
  path,
128
- queryStringParameters
151
+ queryStringParameters,
129
152
  },
130
153
  response: {
131
154
  delay,
132
155
  statusCode,
133
- body: JSON.stringify(body)
134
- }
156
+ body: JSON.stringify(body),
157
+ },
135
158
  };
136
159
  }
package/test/urls.js CHANGED
@@ -3,6 +3,7 @@ const urls = {
3
3
  error: '/error',
4
4
  notFound: '/not-found',
5
5
  items: '/items',
6
+ itemsLogo: '/items/logo',
6
7
  item: '/item/:id',
7
8
  itemHardId: '/item/hardId',
8
9
  dynamicResponseBase: '/dynamic/response/',
@@ -0,0 +1,47 @@
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
+ });