@webex/internal-plugin-mercury 3.0.0-beta.9 → 3.0.0-beta.91

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.
@@ -13,22 +13,23 @@ import {
13
13
  // NotFound,
14
14
  config,
15
15
  ConnectionError,
16
- Socket
16
+ Socket,
17
17
  } from '@webex/internal-plugin-mercury';
18
18
  import uuid from 'uuid';
19
19
  import FakeTimers from '@sinonjs/fake-timers';
20
20
 
21
21
  describe('plugin-mercury', () => {
22
22
  describe('Socket', () => {
23
- let clock,
24
- mockWebSocket,
25
- socket;
23
+ let clock, mockWebSocket, socket;
26
24
 
27
- const mockoptions = Object.assign({
28
- logger: console,
29
- token: 'mocktoken',
30
- trackingId: 'mocktrackingid'
31
- }, config.mercury);
25
+ const mockoptions = Object.assign(
26
+ {
27
+ logger: console,
28
+ token: 'mocktoken',
29
+ trackingId: 'mocktrackingid',
30
+ },
31
+ config.mercury
32
+ );
32
33
 
33
34
  beforeEach(() => {
34
35
  clock = FakeTimers.install({now: Date.now()});
@@ -39,11 +40,14 @@ describe('plugin-mercury', () => {
39
40
  });
40
41
 
41
42
  beforeEach('mock WebSocket and open a Socket', () => {
42
- sinon.stub(Socket, 'getWebSocketConstructor').callsFake(() => function (...args) {
43
- mockWebSocket = new MockWebSocket(...args);
43
+ sinon.stub(Socket, 'getWebSocketConstructor').callsFake(
44
+ () =>
45
+ function (...args) {
46
+ mockWebSocket = new MockWebSocket(...args);
44
47
 
45
- return mockWebSocket;
46
- });
48
+ return mockWebSocket;
49
+ }
50
+ );
47
51
 
48
52
  sinon.spy(Socket.prototype, '_ping');
49
53
 
@@ -61,11 +65,10 @@ describe('plugin-mercury', () => {
61
65
  Socket.prototype._ping.restore();
62
66
  }
63
67
 
64
- return Promise.resolve(socket && socket.close())
65
- .then(() => {
66
- mockWebSocket = undefined;
67
- socket = undefined;
68
- });
68
+ return Promise.resolve(socket && socket.close()).then(() => {
69
+ mockWebSocket = undefined;
70
+ socket = undefined;
71
+ });
69
72
  });
70
73
 
71
74
  describe('#open()', () => {
@@ -75,42 +78,65 @@ describe('plugin-mercury', () => {
75
78
  socket = new Socket();
76
79
  });
77
80
 
78
- afterEach(() => socket.close()
79
- .catch(() => console.log()));
81
+ afterEach(() => socket.close().catch(() => console.log()));
80
82
 
81
83
  it('requires a url', () => assert.isRejected(socket.open(), /`url` is required/));
82
84
 
83
- it('requires a forceCloseDelay option', () => assert.isRejected(socket.open('ws://example.com'), /missing required property forceCloseDelay/));
84
-
85
- it('requires a pingInterval option', () => assert.isRejected(socket.open('ws://example.com', {
86
- forceCloseDelay: mockoptions.forceCloseDelay
87
- }), /missing required property pingInterval/));
88
-
89
- it('requires a pongTimeout option', () => assert.isRejected(socket.open('ws://example.com', {
90
- forceCloseDelay: mockoptions.forceCloseDelay,
91
- pingInterval: mockoptions.pingInterval
92
- }), /missing required property pongTimeout/));
93
-
94
- it('requires a token option', () => assert.isRejected(socket.open('ws://example.com', {
95
- forceCloseDelay: mockoptions.forceCloseDelay,
96
- pingInterval: mockoptions.pingInterval,
97
- pongTimeout: mockoptions.pongTimeout
98
- }), /missing required property token/));
99
-
100
- it('requires a trackingId option', () => assert.isRejected(socket.open('ws://example.com', {
101
- forceCloseDelay: mockoptions.forceCloseDelay,
102
- pingInterval: mockoptions.pingInterval,
103
- pongTimeout: mockoptions.pongTimeout,
104
- token: 'mocktoken'
105
- }), /missing required property trackingId/));
106
-
107
- it('requires a logger option', () => assert.isRejected(socket.open('ws://example.com', {
108
- forceCloseDelay: mockoptions.forceCloseDelay,
109
- pingInterval: mockoptions.pingInterval,
110
- pongTimeout: mockoptions.pongTimeout,
111
- token: 'mocktoken',
112
- trackingId: 'mocktrackingid'
113
- }), /missing required property logger/));
85
+ it('requires a forceCloseDelay option', () =>
86
+ assert.isRejected(
87
+ socket.open('ws://example.com'),
88
+ /missing required property forceCloseDelay/
89
+ ));
90
+
91
+ it('requires a pingInterval option', () =>
92
+ assert.isRejected(
93
+ socket.open('ws://example.com', {
94
+ forceCloseDelay: mockoptions.forceCloseDelay,
95
+ }),
96
+ /missing required property pingInterval/
97
+ ));
98
+
99
+ it('requires a pongTimeout option', () =>
100
+ assert.isRejected(
101
+ socket.open('ws://example.com', {
102
+ forceCloseDelay: mockoptions.forceCloseDelay,
103
+ pingInterval: mockoptions.pingInterval,
104
+ }),
105
+ /missing required property pongTimeout/
106
+ ));
107
+
108
+ it('requires a token option', () =>
109
+ assert.isRejected(
110
+ socket.open('ws://example.com', {
111
+ forceCloseDelay: mockoptions.forceCloseDelay,
112
+ pingInterval: mockoptions.pingInterval,
113
+ pongTimeout: mockoptions.pongTimeout,
114
+ }),
115
+ /missing required property token/
116
+ ));
117
+
118
+ it('requires a trackingId option', () =>
119
+ assert.isRejected(
120
+ socket.open('ws://example.com', {
121
+ forceCloseDelay: mockoptions.forceCloseDelay,
122
+ pingInterval: mockoptions.pingInterval,
123
+ pongTimeout: mockoptions.pongTimeout,
124
+ token: 'mocktoken',
125
+ }),
126
+ /missing required property trackingId/
127
+ ));
128
+
129
+ it('requires a logger option', () =>
130
+ assert.isRejected(
131
+ socket.open('ws://example.com', {
132
+ forceCloseDelay: mockoptions.forceCloseDelay,
133
+ pingInterval: mockoptions.pingInterval,
134
+ pongTimeout: mockoptions.pongTimeout,
135
+ token: 'mocktoken',
136
+ trackingId: 'mocktrackingid',
137
+ }),
138
+ /missing required property logger/
139
+ ));
114
140
 
115
141
  it('accepts a logLevelToken option', () => {
116
142
  const promise = socket.open('ws://example.com', {
@@ -120,7 +146,7 @@ describe('plugin-mercury', () => {
120
146
  logger: console,
121
147
  token: 'mocktoken',
122
148
  trackingId: 'mocktrackingid',
123
- logLevelToken: 'mocklogleveltoken'
149
+ logLevelToken: 'mocklogleveltoken',
124
150
  });
125
151
 
126
152
  mockWebSocket.readyState = 1;
@@ -130,9 +156,9 @@ describe('plugin-mercury', () => {
130
156
  data: JSON.stringify({
131
157
  id: uuid.v4(),
132
158
  data: {
133
- eventType: 'mercury.buffer_state'
134
- }
135
- })
159
+ eventType: 'mercury.buffer_state',
160
+ },
161
+ }),
136
162
  });
137
163
 
138
164
  return promise.then(() => {
@@ -196,9 +222,14 @@ describe('plugin-mercury', () => {
196
222
  return assert.isRejected(s.open(), /`url` is required/);
197
223
  });
198
224
 
199
- it('cannot be called more than once', () => assert.isRejected(socket.open('ws://example.com'), /Socket#open\(\) can only be called once/));
225
+ it('cannot be called more than once', () =>
226
+ assert.isRejected(
227
+ socket.open('ws://example.com'),
228
+ /Socket#open\(\) can only be called once/
229
+ ));
200
230
 
201
- it('sets the underlying socket\'s binary type', () => assert.equal(socket.binaryType, 'arraybuffer'));
231
+ it("sets the underlying socket's binary type", () =>
232
+ assert.equal(socket.binaryType, 'arraybuffer'));
202
233
 
203
234
  describe('when connection fails because this is a service account', () => {
204
235
  it('rejects with a BadRequest', () => {
@@ -214,18 +245,17 @@ describe('plugin-mercury', () => {
214
245
 
215
246
  mockWebSocket.emit('close', {
216
247
  code: 4400,
217
- reason: 'Service accounts can\'t use this endpoint'
248
+ reason: "Service accounts can't use this endpoint",
218
249
  });
219
250
 
220
- return assert.isRejected(promise)
221
- .then((reason) => {
222
- assert.instanceOf(reason, BadRequest);
223
- assert.match(reason.code, 4400);
224
- assert.match(reason.reason, /Service accounts can't use this endpoint/);
225
- assert.match(reason.message, /Service accounts can't use this endpoint/);
251
+ return assert.isRejected(promise).then((reason) => {
252
+ assert.instanceOf(reason, BadRequest);
253
+ assert.match(reason.code, 4400);
254
+ assert.match(reason.reason, /Service accounts can't use this endpoint/);
255
+ assert.match(reason.message, /Service accounts can't use this endpoint/);
226
256
 
227
- return s.close();
228
- });
257
+ return s.close();
258
+ });
229
259
  });
230
260
  });
231
261
 
@@ -243,18 +273,17 @@ describe('plugin-mercury', () => {
243
273
 
244
274
  mockWebSocket.emit('close', {
245
275
  code: 4401,
246
- reason: 'Authorization Failed'
276
+ reason: 'Authorization Failed',
247
277
  });
248
278
 
249
- return assert.isRejected(promise)
250
- .then((reason) => {
251
- assert.instanceOf(reason, NotAuthorized);
252
- assert.match(reason.code, 4401);
253
- assert.match(reason.reason, /Authorization Failed/);
254
- assert.match(reason.message, /Authorization Failed/);
279
+ return assert.isRejected(promise).then((reason) => {
280
+ assert.instanceOf(reason, NotAuthorized);
281
+ assert.match(reason.code, 4401);
282
+ assert.match(reason.reason, /Authorization Failed/);
283
+ assert.match(reason.message, /Authorization Failed/);
255
284
 
256
- return s.close();
257
- });
285
+ return s.close();
286
+ });
258
287
  });
259
288
  });
260
289
 
@@ -272,18 +301,17 @@ describe('plugin-mercury', () => {
272
301
 
273
302
  mockWebSocket.emit('close', {
274
303
  code: 4403,
275
- reason: 'Not entitled'
304
+ reason: 'Not entitled',
276
305
  });
277
306
 
278
- return assert.isRejected(promise)
279
- .then((reason) => {
280
- assert.instanceOf(reason, Forbidden);
281
- assert.match(reason.code, 4403);
282
- assert.match(reason.reason, /Not entitled/);
283
- assert.match(reason.message, /Not entitled/);
307
+ return assert.isRejected(promise).then((reason) => {
308
+ assert.instanceOf(reason, Forbidden);
309
+ assert.match(reason.code, 4403);
310
+ assert.match(reason.reason, /Not entitled/);
311
+ assert.match(reason.message, /Not entitled/);
284
312
 
285
- return s.close();
286
- });
313
+ return s.close();
314
+ });
287
315
  });
288
316
  });
289
317
 
@@ -314,24 +342,23 @@ describe('plugin-mercury', () => {
314
342
  // });
315
343
 
316
344
  describe('when connection fails for non-authorization reasons', () => {
317
- it('rejects with the close event\'s reason', () => {
345
+ it("rejects with the close event's reason", () => {
318
346
  const s = new Socket();
319
347
  const promise = s.open('ws://example.com', mockoptions);
320
348
 
321
349
  mockWebSocket.emit('close', {
322
350
  code: 4001,
323
- reason: 'No'
351
+ reason: 'No',
324
352
  });
325
353
 
326
- return assert.isRejected(promise)
327
- .then((reason) => {
328
- assert.instanceOf(reason, ConnectionError);
329
- assert.match(reason.code, 4001);
330
- assert.match(reason.reason, /No/);
331
- assert.match(reason.message, /No/);
354
+ return assert.isRejected(promise).then((reason) => {
355
+ assert.instanceOf(reason, ConnectionError);
356
+ assert.match(reason.code, 4001);
357
+ assert.match(reason.reason, /No/);
358
+ assert.match(reason.message, /No/);
332
359
 
333
- return s.close();
334
- });
360
+ return s.close();
361
+ });
335
362
  });
336
363
  });
337
364
 
@@ -359,7 +386,7 @@ describe('plugin-mercury', () => {
359
386
  logger: console,
360
387
  token: 'mocktoken',
361
388
  trackingId: 'mocktrackingid',
362
- logLevelToken: 'mocklogleveltoken'
389
+ logLevelToken: 'mocklogleveltoken',
363
390
  }).catch((reason) => console.error(reason));
364
391
  mockWebSocket.readyState = 1;
365
392
  mockWebSocket.emit('open');
@@ -390,13 +417,12 @@ describe('plugin-mercury', () => {
390
417
  data: JSON.stringify({
391
418
  id: uuid.v4(),
392
419
  data: {
393
- eventType: 'mercury.buffer_state'
394
- }
395
- })
420
+ eventType: 'mercury.buffer_state',
421
+ },
422
+ }),
396
423
  });
397
424
 
398
- return promise
399
- .then(() => s.close());
425
+ return promise.then(() => s.close());
400
426
  });
401
427
 
402
428
  it('resolves upon receiving registration status', () => {
@@ -409,31 +435,35 @@ describe('plugin-mercury', () => {
409
435
  data: JSON.stringify({
410
436
  id: uuid.v4(),
411
437
  data: {
412
- eventType: 'mercury.registration_status'
413
- }
414
- })
438
+ eventType: 'mercury.registration_status',
439
+ },
440
+ }),
415
441
  });
416
442
 
417
- return promise
418
- .then(() => s.close());
443
+ return promise.then(() => s.close());
419
444
  });
420
445
  });
421
446
  });
422
447
 
423
448
  describe('#close()', () => {
424
- it('closes the socket', () => socket.close()
425
- .then(() => assert.called(mockWebSocket.close)));
426
-
427
- it('only accepts valid close codes', () => Promise.all([
428
- assert.isRejected(socket.close({code: 1001}), /`options.code` must be 1000 or between 3000 and 4999 \(inclusive\)/),
429
- socket.close({code: 1000})
430
- ]));
431
-
432
- it('accepts a reason', () => socket.close({
433
- code: 3001,
434
- reason: 'Custom Normal'
435
- })
436
- .then(() => assert.calledWith(mockWebSocket.close, 3001, 'Custom Normal')));
449
+ it('closes the socket', () => socket.close().then(() => assert.called(mockWebSocket.close)));
450
+
451
+ it('only accepts valid close codes', () =>
452
+ Promise.all([
453
+ assert.isRejected(
454
+ socket.close({code: 1001}),
455
+ /`options.code` must be 1000 or between 3000 and 4999 \(inclusive\)/
456
+ ),
457
+ socket.close({code: 1000}),
458
+ ]));
459
+
460
+ it('accepts a reason', () =>
461
+ socket
462
+ .close({
463
+ code: 3001,
464
+ reason: 'Custom Normal',
465
+ })
466
+ .then(() => assert.calledWith(mockWebSocket.close, 3001, 'Custom Normal')));
437
467
 
438
468
  it('can safely be called called multiple times', () => {
439
469
  const p1 = socket.close();
@@ -454,32 +484,33 @@ describe('plugin-mercury', () => {
454
484
  data: JSON.stringify({
455
485
  id: uuid.v4(),
456
486
  data: {
457
- eventType: 'mercury.buffer_state'
458
- }
459
- })
487
+ eventType: 'mercury.buffer_state',
488
+ },
489
+ }),
460
490
  });
461
491
 
462
- return promise
463
- .then(() => {
464
- const spy = sinon.spy();
492
+ return promise.then(() => {
493
+ const spy = sinon.spy();
465
494
 
466
- socket.on('close', spy);
467
- mockWebSocket.close = () => new Promise(() => { /* eslint no-inline-comments: [0] */ });
468
- mockWebSocket.removeAllListeners('close');
495
+ socket.on('close', spy);
496
+ mockWebSocket.close = () =>
497
+ new Promise(() => {
498
+ /* eslint no-inline-comments: [0] */
499
+ });
500
+ mockWebSocket.removeAllListeners('close');
469
501
 
470
- const promise = socket.close();
502
+ const promise = socket.close();
471
503
 
472
- clock.tick(mockoptions.forceCloseDelay);
504
+ clock.tick(mockoptions.forceCloseDelay);
473
505
 
474
- return promise
475
- .then(() => {
476
- assert.called(spy);
477
- assert.calledWith(spy, {
478
- code: 1000,
479
- reason: 'Done (forced)'
480
- });
481
- });
506
+ return promise.then(() => {
507
+ assert.called(spy);
508
+ assert.calledWith(spy, {
509
+ code: 1000,
510
+ reason: 'Done (forced)',
511
+ });
482
512
  });
513
+ });
483
514
  });
484
515
 
485
516
  it('cancels any outstanding ping/pong timers', () => {
@@ -493,7 +524,7 @@ describe('plugin-mercury', () => {
493
524
  clock.tick(2 * mockoptions.pingInterval);
494
525
  assert.neverCalledWith(spy, {
495
526
  code: 1000,
496
- reason: 'Pong not received'
527
+ reason: 'Pong not received',
497
528
  });
498
529
  assert.calledOnce(socket._ping);
499
530
  });
@@ -504,7 +535,8 @@ describe('plugin-mercury', () => {
504
535
  it('fails', () => {
505
536
  mockWebSocket.readyState = 0;
506
537
 
507
- return assert.isRejected(socket.send('test0'), /INVALID_STATE_ERROR/)
538
+ return assert
539
+ .isRejected(socket.send('test0'), /INVALID_STATE_ERROR/)
508
540
  .then(() => {
509
541
  mockWebSocket.readyState = 2;
510
542
 
@@ -530,7 +562,7 @@ describe('plugin-mercury', () => {
530
562
 
531
563
  it('sends JSON.stringifyable object', () => {
532
564
  socket.send({
533
- json: true
565
+ json: true,
534
566
  });
535
567
  assert.calledWith(mockWebSocket.send, '{"json":true}');
536
568
  });
@@ -549,39 +581,42 @@ describe('plugin-mercury', () => {
549
581
  assert.calledOnce(socket._ping);
550
582
  mockWebSocket.emit('close', {
551
583
  code: 1000,
552
- reason: 'Done'
584
+ reason: 'Done',
553
585
  });
554
586
  assert.calledOnce(socket._ping);
555
587
  clock.tick(5 * mockoptions.pingInterval);
556
588
  assert.neverCalledWith(spy, {
557
589
  code: 1000,
558
- reason: 'Pong not received'
590
+ reason: 'Pong not received',
559
591
  });
560
592
  assert.calledOnce(socket._ping);
561
593
  });
562
594
 
563
595
  describe('when it receives close code 1005', () => {
564
- forEach({
565
- Replaced: 4000,
566
- 'Authentication Failed': 1008,
567
- 'Authentication did not happen within the timeout window of 30000 seconds.': 1008
568
- }, (code, reason) => {
569
- it(`emits code ${code} for reason ${reason}`, () => {
570
- const spy = sinon.spy();
571
-
572
- socket.on('close', spy);
573
-
574
- mockWebSocket.emit('close', {
575
- code: 1005,
576
- reason
577
- });
578
- assert.called(spy);
579
- assert.calledWith(spy, {
580
- code,
581
- reason
596
+ forEach(
597
+ {
598
+ Replaced: 4000,
599
+ 'Authentication Failed': 1008,
600
+ 'Authentication did not happen within the timeout window of 30000 seconds.': 1008,
601
+ },
602
+ (code, reason) => {
603
+ it(`emits code ${code} for reason ${reason}`, () => {
604
+ const spy = sinon.spy();
605
+
606
+ socket.on('close', spy);
607
+
608
+ mockWebSocket.emit('close', {
609
+ code: 1005,
610
+ reason,
611
+ });
612
+ assert.called(spy);
613
+ assert.calledWith(spy, {
614
+ code,
615
+ reason,
616
+ });
582
617
  });
583
- });
584
- });
618
+ }
619
+ );
585
620
  });
586
621
  });
587
622
 
@@ -597,8 +632,8 @@ describe('plugin-mercury', () => {
597
632
  mockWebSocket.emit('message', {
598
633
  data: JSON.stringify({
599
634
  sequenceNumber: 3,
600
- id: 'mockid'
601
- })
635
+ id: 'mockid',
636
+ }),
602
637
  });
603
638
 
604
639
  assert.called(spy);
@@ -608,15 +643,15 @@ describe('plugin-mercury', () => {
608
643
  mockWebSocket.emit('message', {
609
644
  data: JSON.stringify({
610
645
  sequenceNumber: 3,
611
- id: 'mockid'
612
- })
646
+ id: 'mockid',
647
+ }),
613
648
  });
614
649
 
615
650
  assert.calledWith(spy, {
616
651
  data: {
617
652
  sequenceNumber: 3,
618
- id: 'mockid'
619
- }
653
+ id: 'mockid',
654
+ },
620
655
  });
621
656
  });
622
657
 
@@ -628,16 +663,16 @@ describe('plugin-mercury', () => {
628
663
  mockWebSocket.emit('message', {
629
664
  data: JSON.stringify({
630
665
  sequenceNumber: 2,
631
- id: 'mockid'
632
- })
666
+ id: 'mockid',
667
+ }),
633
668
  });
634
669
  assert.notCalled(spy2);
635
670
 
636
671
  mockWebSocket.emit('message', {
637
672
  data: JSON.stringify({
638
673
  sequenceNumber: 4,
639
- id: 'mockid'
640
- })
674
+ id: 'mockid',
675
+ }),
641
676
  });
642
677
  assert.calledOnce(spy2);
643
678
  assert.calledWith(spy2, 4, 3);
@@ -648,15 +683,15 @@ describe('plugin-mercury', () => {
648
683
  mockWebSocket.emit('message', {
649
684
  data: JSON.stringify({
650
685
  sequenceNumber: 5,
651
- id: 'mockid'
652
- })
686
+ id: 'mockid',
687
+ }),
653
688
  });
654
689
  assert.called(socket._acknowledge);
655
690
  assert.calledWith(socket._acknowledge, {
656
691
  data: {
657
692
  sequenceNumber: 5,
658
- id: 'mockid'
659
- }
693
+ id: 'mockid',
694
+ },
660
695
  });
661
696
  });
662
697
 
@@ -669,8 +704,8 @@ describe('plugin-mercury', () => {
669
704
  data: JSON.stringify({
670
705
  sequenceNumber: 5,
671
706
  id: 'mockid1',
672
- type: 'pong'
673
- })
707
+ type: 'pong',
708
+ }),
674
709
  });
675
710
 
676
711
  assert.calledOnce(pongSpy);
@@ -679,8 +714,8 @@ describe('plugin-mercury', () => {
679
714
  mockWebSocket.emit('message', {
680
715
  data: JSON.stringify({
681
716
  sequenceNumber: 6,
682
- id: 'mockid2'
683
- })
717
+ id: 'mockid2',
718
+ }),
684
719
  });
685
720
 
686
721
  assert.calledOnce(pongSpy);
@@ -689,24 +724,30 @@ describe('plugin-mercury', () => {
689
724
  });
690
725
 
691
726
  describe('#_acknowledge', () => {
692
- it('requires an event', () => assert.isRejected(socket._acknowledge(), /`event` is required/));
727
+ it('requires an event', () =>
728
+ assert.isRejected(socket._acknowledge(), /`event` is required/));
693
729
 
694
- it('requires a message id', () => assert.isRejected(socket._acknowledge({}), /`event.data.id` is required/));
730
+ it('requires a message id', () =>
731
+ assert.isRejected(socket._acknowledge({}), /`event.data.id` is required/));
695
732
 
696
733
  it('acknowledges the specified message', () => {
697
734
  const id = 'mockuuid';
698
735
 
699
- return socket._acknowledge({
700
- data: {
701
- type: 'not an ack',
702
- id
703
- }
704
- })
736
+ return socket
737
+ ._acknowledge({
738
+ data: {
739
+ type: 'not an ack',
740
+ id,
741
+ },
742
+ })
705
743
  .then(() => {
706
- assert.calledWith(mockWebSocket.send, JSON.stringify({
707
- messageId: id,
708
- type: 'ack'
709
- }));
744
+ assert.calledWith(
745
+ mockWebSocket.send,
746
+ JSON.stringify({
747
+ messageId: id,
748
+ type: 'ack',
749
+ })
750
+ );
710
751
  });
711
752
  });
712
753
  });
@@ -718,12 +759,15 @@ describe('plugin-mercury', () => {
718
759
  id = uuid.v4();
719
760
  });
720
761
 
721
- it('sends a ping up the socket', () => socket._ping(id)
722
- .then(() => {
723
- assert.calledWith(mockWebSocket.send, JSON.stringify({
724
- id,
725
- type: 'ping'
726
- }));
762
+ it('sends a ping up the socket', () =>
763
+ socket._ping(id).then(() => {
764
+ assert.calledWith(
765
+ mockWebSocket.send,
766
+ JSON.stringify({
767
+ id,
768
+ type: 'ping',
769
+ })
770
+ );
727
771
  }));
728
772
 
729
773
  it('considers the socket closed if no pong is received in an acceptable time period', () => {
@@ -737,7 +781,7 @@ describe('plugin-mercury', () => {
737
781
  assert.called(spy);
738
782
  assert.calledWith(spy, {
739
783
  code: 1000,
740
- reason: 'Pong not received'
784
+ reason: 'Pong not received',
741
785
  });
742
786
  });
743
787
 
@@ -756,13 +800,13 @@ describe('plugin-mercury', () => {
756
800
  mockWebSocket.emit('message', {
757
801
  data: JSON.stringify({
758
802
  type: 'pong',
759
- id: 1
760
- })
803
+ id: 1,
804
+ }),
761
805
  });
762
806
 
763
807
  assert.calledWith(spy, {
764
808
  code: 1000,
765
- reason: 'Pong mismatch'
809
+ reason: 'Pong mismatch',
766
810
  });
767
811
  });
768
812
  });