@webex/internal-plugin-device 3.0.0-beta.2 → 3.0.0-beta.200
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/README.md +10 -6
- package/dist/config.js +0 -8
- package/dist/config.js.map +1 -1
- package/dist/constants.js +2 -3
- package/dist/constants.js.map +1 -1
- package/dist/device.js +94 -171
- package/dist/device.js.map +1 -1
- package/dist/features/feature-collection.js +1 -8
- package/dist/features/feature-collection.js.map +1 -1
- package/dist/features/feature-model.js +15 -42
- package/dist/features/feature-model.js.map +1 -1
- package/dist/features/features-model.js +9 -21
- package/dist/features/features-model.js.map +1 -1
- package/dist/features/index.js +0 -8
- package/dist/features/index.js.map +1 -1
- package/dist/index.js +2 -24
- package/dist/index.js.map +1 -1
- package/dist/interceptors/device-url.js +12 -33
- package/dist/interceptors/device-url.js.map +1 -1
- package/dist/metrics.js +0 -2
- package/dist/metrics.js.map +1 -1
- package/package.json +10 -10
- package/src/config.js +8 -9
- package/src/constants.js +3 -5
- package/src/device.js +142 -146
- package/src/features/feature-collection.js +1 -1
- package/src/features/feature-model.js +5 -11
- package/src/features/features-model.js +3 -9
- package/src/features/index.js +1 -5
- package/src/index.js +3 -11
- package/src/interceptors/device-url.js +5 -7
- package/src/metrics.js +1 -2
- package/test/integration/spec/device.js +210 -239
- package/test/integration/spec/webex.js +9 -9
- package/test/unit/spec/device.js +44 -53
- package/test/unit/spec/features/feature-collection.js +2 -2
- package/test/unit/spec/features/feature-model.js +23 -39
- package/test/unit/spec/features/features-model.js +4 -12
- package/test/unit/spec/interceptors/device-url.js +69 -109
- package/test/unit/spec/wdm-dto.json +5 -13
|
@@ -17,21 +17,21 @@ describe('plugin-device', () => {
|
|
|
17
17
|
let user;
|
|
18
18
|
let webex;
|
|
19
19
|
|
|
20
|
-
beforeEach('create test users and webex instance',
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
user = createdUser;
|
|
20
|
+
beforeEach('create test users and webex instance', () =>
|
|
21
|
+
testUsers.create({count: 1}).then(([createdUser]) => {
|
|
22
|
+
user = createdUser;
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
webex = new WebexCore({
|
|
25
|
+
credentials: user.token,
|
|
26
|
+
});
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
device = webex.internal.device;
|
|
29
|
+
})
|
|
30
|
+
);
|
|
31
31
|
|
|
32
|
-
afterEach('unregister the device and remove test users',
|
|
33
|
-
() =>
|
|
34
|
-
|
|
32
|
+
afterEach('unregister the device and remove test users', () =>
|
|
33
|
+
device.unregister().then(() => testUsers.remove([user]))
|
|
34
|
+
);
|
|
35
35
|
|
|
36
36
|
describe('events', () => {
|
|
37
37
|
describe('when a meeting is started', () => {
|
|
@@ -40,11 +40,11 @@ describe('plugin-device', () => {
|
|
|
40
40
|
webex.trigger('meeting started');
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
it(
|
|
43
|
+
it("should set 'isInMeeting' to 'true'", () => {
|
|
44
44
|
assert.isTrue(device.isInMeeting);
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
it(
|
|
47
|
+
it("should call 'resetLogoutTimer()'", () => {
|
|
48
48
|
assert.called(device.resetLogoutTimer);
|
|
49
49
|
});
|
|
50
50
|
});
|
|
@@ -56,11 +56,11 @@ describe('plugin-device', () => {
|
|
|
56
56
|
webex.trigger('meeting ended');
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
-
it(
|
|
59
|
+
it("should set 'isInMeeting' to 'false'", () => {
|
|
60
60
|
assert.isFalse(device.isInMeeting);
|
|
61
61
|
});
|
|
62
62
|
|
|
63
|
-
it(
|
|
63
|
+
it("should call 'resetLogoutTimer()'", () => {
|
|
64
64
|
assert.called(device.resetLogoutTimer);
|
|
65
65
|
});
|
|
66
66
|
});
|
|
@@ -90,13 +90,13 @@ describe('plugin-device', () => {
|
|
|
90
90
|
services.updateServices();
|
|
91
91
|
});
|
|
92
92
|
|
|
93
|
-
describe(
|
|
93
|
+
describe("when the 'wdm' service does exist after wait", () => {
|
|
94
94
|
it('should return a resolved promise', () => {
|
|
95
95
|
assert.isFulfilled(device.canRegister());
|
|
96
96
|
});
|
|
97
97
|
});
|
|
98
98
|
|
|
99
|
-
describe(
|
|
99
|
+
describe("when the 'wdm' service does not exist after wait", () => {
|
|
100
100
|
beforeEach('remove wdm service', () => {
|
|
101
101
|
services.get = sinon.stub().returns(undefined);
|
|
102
102
|
services.waitForCatalog = sinon.stub().resolves();
|
|
@@ -129,14 +129,16 @@ describe('plugin-device', () => {
|
|
|
129
129
|
describe('#clear()', () => {
|
|
130
130
|
beforeEach('append a feature', () => {
|
|
131
131
|
device.features.set({
|
|
132
|
-
developer: [
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
132
|
+
developer: [
|
|
133
|
+
{
|
|
134
|
+
key: 'console',
|
|
135
|
+
type: 'boolean',
|
|
136
|
+
val: 'true',
|
|
137
|
+
value: true,
|
|
138
|
+
mutable: true,
|
|
139
|
+
lastModified: '2015-06-29T20:02:48.033Z',
|
|
140
|
+
},
|
|
141
|
+
],
|
|
140
142
|
});
|
|
141
143
|
});
|
|
142
144
|
|
|
@@ -172,14 +174,13 @@ describe('plugin-device', () => {
|
|
|
172
174
|
device.isReachabilityChecked = false;
|
|
173
175
|
});
|
|
174
176
|
|
|
175
|
-
it('should set the in-network property to false',
|
|
176
|
-
() =>
|
|
177
|
-
.
|
|
178
|
-
|
|
179
|
-
}));
|
|
177
|
+
it('should set the in-network property to false', () =>
|
|
178
|
+
device.checkNetworkReachability().then(() => {
|
|
179
|
+
assert.isFalse(device.isInNetwork);
|
|
180
|
+
}));
|
|
180
181
|
|
|
181
|
-
it('should return a resolved promise',
|
|
182
|
-
|
|
182
|
+
it('should return a resolved promise', () =>
|
|
183
|
+
assert.isFulfilled(device.checkNetworkReachability()));
|
|
183
184
|
|
|
184
185
|
describe('when the device has inactivity enforcement', () => {
|
|
185
186
|
let logoutTimer;
|
|
@@ -190,8 +191,9 @@ describe('plugin-device', () => {
|
|
|
190
191
|
device.intranetInactivityCheckUrl = undefined;
|
|
191
192
|
});
|
|
192
193
|
|
|
193
|
-
it('should not reset the logout timer',
|
|
194
|
-
|
|
194
|
+
it('should not reset the logout timer', () =>
|
|
195
|
+
device
|
|
196
|
+
.checkNetworkReachability()
|
|
195
197
|
.then(() => assert.equal(device.logoutTimer, logoutTimer)));
|
|
196
198
|
});
|
|
197
199
|
});
|
|
@@ -213,17 +215,19 @@ describe('plugin-device', () => {
|
|
|
213
215
|
device.request = sinon.stub().resolves({});
|
|
214
216
|
});
|
|
215
217
|
|
|
216
|
-
it(
|
|
218
|
+
it("should call 'resetLogoutTimer()'", () => {
|
|
217
219
|
device.isReachabilityChecked = false;
|
|
218
220
|
|
|
219
|
-
return device
|
|
221
|
+
return device
|
|
222
|
+
.checkNetworkReachability()
|
|
220
223
|
.then(() => assert.called(device.resetLogoutTimer));
|
|
221
224
|
});
|
|
222
225
|
|
|
223
226
|
it('should set the reachability check to true', () => {
|
|
224
227
|
device.isReachabilityChecked = false;
|
|
225
228
|
|
|
226
|
-
return device
|
|
229
|
+
return device
|
|
230
|
+
.checkNetworkReachability()
|
|
227
231
|
.then(() => assert.isTrue(device.isReachabilityChecked));
|
|
228
232
|
});
|
|
229
233
|
|
|
@@ -232,12 +236,11 @@ describe('plugin-device', () => {
|
|
|
232
236
|
|
|
233
237
|
assert.isFalse(device.isInNetwork);
|
|
234
238
|
|
|
235
|
-
return device.checkNetworkReachability()
|
|
236
|
-
.then(() => assert.isTrue(device.isInNetwork));
|
|
239
|
+
return device.checkNetworkReachability().then(() => assert.isTrue(device.isInNetwork));
|
|
237
240
|
});
|
|
238
241
|
|
|
239
|
-
it('should return a resolved promise',
|
|
240
|
-
|
|
242
|
+
it('should return a resolved promise', () =>
|
|
243
|
+
assert.isFulfilled(device.checkNetworkReachability()));
|
|
241
244
|
});
|
|
242
245
|
|
|
243
246
|
describe('when the network is not reachable', () => {
|
|
@@ -249,16 +252,16 @@ describe('plugin-device', () => {
|
|
|
249
252
|
it('should set the reachability check to true', () => {
|
|
250
253
|
device.isReachabilityChecked = false;
|
|
251
254
|
|
|
252
|
-
return device
|
|
255
|
+
return device
|
|
256
|
+
.checkNetworkReachability()
|
|
253
257
|
.then(() => assert.isTrue(device.isReachabilityChecked));
|
|
254
258
|
});
|
|
255
259
|
|
|
256
|
-
it('should set the in-network property to false',
|
|
257
|
-
() => device.
|
|
258
|
-
.then(() => assert.isFalse(device.isInNetwork)));
|
|
260
|
+
it('should set the in-network property to false', () =>
|
|
261
|
+
device.checkNetworkReachability().then(() => assert.isFalse(device.isInNetwork)));
|
|
259
262
|
|
|
260
|
-
it('should return a resolved promise',
|
|
261
|
-
|
|
263
|
+
it('should return a resolved promise', () =>
|
|
264
|
+
assert.isFulfilled(device.checkNetworkReachability()));
|
|
262
265
|
});
|
|
263
266
|
});
|
|
264
267
|
});
|
|
@@ -280,33 +283,25 @@ describe('plugin-device', () => {
|
|
|
280
283
|
describe('when the device is registered', () => {
|
|
281
284
|
beforeEach('register the device', () => device.register());
|
|
282
285
|
|
|
283
|
-
it('should resolve the promise with the websocket url',
|
|
284
|
-
|
|
285
|
-
.
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}));
|
|
286
|
+
it('should resolve the promise with the websocket url', () =>
|
|
287
|
+
device.getWebSocketUrl(wait).then((url) => {
|
|
288
|
+
assert.isDefined(url);
|
|
289
|
+
assert.isTrue(services.isServiceUrl(url));
|
|
290
|
+
assert.include(url, 'mercury');
|
|
291
|
+
}));
|
|
290
292
|
});
|
|
291
293
|
|
|
292
294
|
describe('when the device is not registered', () => {
|
|
293
295
|
describe('when the device successfully registers', () => {
|
|
294
|
-
it('should resolve the promise with the websocket url',
|
|
295
|
-
()
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
.then(([url]) => {
|
|
300
|
-
assert.isTrue(services.isServiceUrl(url));
|
|
301
|
-
assert.include(
|
|
302
|
-
services.getServiceFromUrl(url).name,
|
|
303
|
-
'mercury'
|
|
304
|
-
);
|
|
305
|
-
}));
|
|
296
|
+
it('should resolve the promise with the websocket url', () =>
|
|
297
|
+
Promise.all([device.getWebSocketUrl(wait), device.register()]).then(([url]) => {
|
|
298
|
+
assert.isTrue(services.isServiceUrl(url));
|
|
299
|
+
assert.include(services.getServiceFromUrl(url).name, 'mercury');
|
|
300
|
+
}));
|
|
306
301
|
});
|
|
307
302
|
|
|
308
|
-
it('should return a rejected promise if the device never registers',
|
|
309
|
-
|
|
303
|
+
it('should return a rejected promise if the device never registers', () =>
|
|
304
|
+
assert.isRejected(device.getWebSocketUrl(wait)));
|
|
310
305
|
});
|
|
311
306
|
});
|
|
312
307
|
|
|
@@ -321,13 +316,12 @@ describe('plugin-device', () => {
|
|
|
321
316
|
beforeEach('register the device', () => device.register());
|
|
322
317
|
|
|
323
318
|
describe('when the priority host can be mapped', () => {
|
|
324
|
-
it('should resolve the promise with the websocket url',
|
|
325
|
-
|
|
326
|
-
.
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}));
|
|
319
|
+
it('should resolve the promise with the websocket url', () =>
|
|
320
|
+
device.getWebSocketUrl(wait).then((url) => {
|
|
321
|
+
assert.isDefined(url);
|
|
322
|
+
assert.isTrue(services.isServiceUrl(url));
|
|
323
|
+
assert.include(url, 'mercury');
|
|
324
|
+
}));
|
|
331
325
|
});
|
|
332
326
|
|
|
333
327
|
describe('when the priority host cannot be mapped', () => {
|
|
@@ -336,14 +330,14 @@ describe('plugin-device', () => {
|
|
|
336
330
|
services.convertUrlToPriorityHostUrl.returns(undefined);
|
|
337
331
|
});
|
|
338
332
|
|
|
339
|
-
it('should return a rejected promise',
|
|
340
|
-
|
|
333
|
+
it('should return a rejected promise', () =>
|
|
334
|
+
assert.isRejected(device.getWebSocketUrl(wait)));
|
|
341
335
|
});
|
|
342
336
|
});
|
|
343
337
|
|
|
344
338
|
describe('when the device is not registered', () => {
|
|
345
|
-
it('should return a rejected promise',
|
|
346
|
-
|
|
339
|
+
it('should return a rejected promise', () =>
|
|
340
|
+
assert.isRejected(device.getWebSocketUrl(wait)));
|
|
347
341
|
});
|
|
348
342
|
});
|
|
349
343
|
});
|
|
@@ -355,7 +349,7 @@ describe('plugin-device', () => {
|
|
|
355
349
|
spy = sinon.spy();
|
|
356
350
|
});
|
|
357
351
|
|
|
358
|
-
it(
|
|
352
|
+
it("should trigger a 'meeting started' event", () => {
|
|
359
353
|
webex.on('meeting started', spy);
|
|
360
354
|
device.meetingStarted();
|
|
361
355
|
assert.called(spy);
|
|
@@ -389,7 +383,7 @@ describe('plugin-device', () => {
|
|
|
389
383
|
spy = sinon.spy();
|
|
390
384
|
});
|
|
391
385
|
|
|
392
|
-
it(
|
|
386
|
+
it("should trigger a 'meeting ended' event", () => {
|
|
393
387
|
webex.on('meeting ended', spy);
|
|
394
388
|
device.meetingEnded();
|
|
395
389
|
assert.called(spy);
|
|
@@ -405,8 +399,8 @@ describe('plugin-device', () => {
|
|
|
405
399
|
body: {
|
|
406
400
|
exampleKey: 'exampleValue',
|
|
407
401
|
services: [],
|
|
408
|
-
serviceHostMap: []
|
|
409
|
-
}
|
|
402
|
+
serviceHostMap: [],
|
|
403
|
+
},
|
|
410
404
|
};
|
|
411
405
|
|
|
412
406
|
spy = sinon.spy();
|
|
@@ -417,12 +411,12 @@ describe('plugin-device', () => {
|
|
|
417
411
|
assert.equal(device.exampleKey, customResponse.body.exampleKey);
|
|
418
412
|
});
|
|
419
413
|
|
|
420
|
-
it(
|
|
414
|
+
it("should not set a 'services' property", () => {
|
|
421
415
|
device.processRegistrationSuccess(customResponse);
|
|
422
416
|
assert.isUndefined(device.services);
|
|
423
417
|
});
|
|
424
418
|
|
|
425
|
-
it(
|
|
419
|
+
it("should not set a 'serviceHostMap' property", () => {
|
|
426
420
|
device.processRegistrationSuccess(customResponse);
|
|
427
421
|
assert.isUndefined(device.serviceHostMap);
|
|
428
422
|
});
|
|
@@ -455,8 +449,8 @@ describe('plugin-device', () => {
|
|
|
455
449
|
device.register = sinon.spy();
|
|
456
450
|
});
|
|
457
451
|
|
|
458
|
-
it('should attempt to register', () =>
|
|
459
|
-
.then(() => assert.called(device.register)));
|
|
452
|
+
it('should attempt to register', () =>
|
|
453
|
+
device.refresh().then(() => assert.called(device.register)));
|
|
460
454
|
});
|
|
461
455
|
|
|
462
456
|
describe('when the device is registered', () => {
|
|
@@ -465,16 +459,13 @@ describe('plugin-device', () => {
|
|
|
465
459
|
beforeEach('register the device', () => {
|
|
466
460
|
exampleResponse = {
|
|
467
461
|
body: {
|
|
468
|
-
exampleKey: 'example response value'
|
|
469
|
-
}
|
|
462
|
+
exampleKey: 'example response value',
|
|
463
|
+
},
|
|
470
464
|
};
|
|
471
465
|
|
|
472
|
-
return device.register()
|
|
473
|
-
.
|
|
474
|
-
|
|
475
|
-
{...exampleResponse}
|
|
476
|
-
));
|
|
477
|
-
});
|
|
466
|
+
return device.register().then(() => {
|
|
467
|
+
device.request = sinon.stub().returns(Promise.resolve({...exampleResponse}));
|
|
468
|
+
});
|
|
478
469
|
});
|
|
479
470
|
|
|
480
471
|
describe('when the device is ephemeral', () => {
|
|
@@ -482,12 +473,15 @@ describe('plugin-device', () => {
|
|
|
482
473
|
device.config.ephemeral = true;
|
|
483
474
|
});
|
|
484
475
|
|
|
485
|
-
it('should set the ttl property to the config values',
|
|
486
|
-
|
|
476
|
+
it('should set the ttl property to the config values', () =>
|
|
477
|
+
device
|
|
478
|
+
.refresh()
|
|
487
479
|
.then(() =>
|
|
488
|
-
assert.calledWith(
|
|
489
|
-
|
|
490
|
-
|
|
480
|
+
assert.calledWith(
|
|
481
|
+
device.request,
|
|
482
|
+
sinon.match.hasNested('body.ttl', device.config.ephemeralDeviceTTL)
|
|
483
|
+
)
|
|
484
|
+
));
|
|
491
485
|
});
|
|
492
486
|
|
|
493
487
|
describe('when the refresh request is sent', () => {
|
|
@@ -496,52 +490,54 @@ describe('plugin-device', () => {
|
|
|
496
490
|
|
|
497
491
|
beforeEach('configure device plugin', () => {
|
|
498
492
|
customHeaders = {
|
|
499
|
-
testHeader: 'example header value'
|
|
493
|
+
testHeader: 'example header value',
|
|
500
494
|
};
|
|
501
495
|
|
|
502
496
|
customBody = {
|
|
503
|
-
testBody: 'example body value'
|
|
497
|
+
testBody: 'example body value',
|
|
504
498
|
};
|
|
505
499
|
});
|
|
506
500
|
|
|
507
501
|
it('should allow for custom header key:values', () => {
|
|
508
502
|
device.config.headers = {...customHeaders};
|
|
509
503
|
|
|
510
|
-
return device
|
|
504
|
+
return device
|
|
505
|
+
.refresh()
|
|
511
506
|
.then(() =>
|
|
512
|
-
assert.calledWith(
|
|
513
|
-
|
|
514
|
-
|
|
507
|
+
assert.calledWith(
|
|
508
|
+
device.request,
|
|
509
|
+
sinon.match.hasNested('headers.testHeader', customHeaders.testHeader)
|
|
510
|
+
)
|
|
511
|
+
);
|
|
515
512
|
});
|
|
516
513
|
|
|
517
514
|
it('should allow for custom body key:values', () => {
|
|
518
515
|
device.config.body = {...customBody};
|
|
519
516
|
|
|
520
|
-
return device
|
|
517
|
+
return device
|
|
518
|
+
.refresh()
|
|
521
519
|
.then(() =>
|
|
522
|
-
assert.calledWith(
|
|
523
|
-
|
|
524
|
-
|
|
520
|
+
assert.calledWith(
|
|
521
|
+
device.request,
|
|
522
|
+
sinon.match.hasNested('body.testBody', customBody.testBody)
|
|
523
|
+
)
|
|
524
|
+
);
|
|
525
525
|
});
|
|
526
526
|
|
|
527
|
-
it(
|
|
527
|
+
it("should use the device's url property", () => {
|
|
528
528
|
device.config.body = {...customBody};
|
|
529
529
|
|
|
530
|
-
return device
|
|
531
|
-
.
|
|
532
|
-
|
|
533
|
-
'uri', device.url
|
|
534
|
-
)));
|
|
530
|
+
return device
|
|
531
|
+
.refresh()
|
|
532
|
+
.then(() => assert.calledWith(device.request, sinon.match.has('uri', device.url)));
|
|
535
533
|
});
|
|
536
534
|
|
|
537
535
|
it('should send a PUT request', () => {
|
|
538
536
|
device.config.body = {...customBody};
|
|
539
537
|
|
|
540
|
-
return device
|
|
541
|
-
.
|
|
542
|
-
|
|
543
|
-
'method', 'PUT'
|
|
544
|
-
)));
|
|
538
|
+
return device
|
|
539
|
+
.refresh()
|
|
540
|
+
.then(() => assert.calledWith(device.request, sinon.match.has('method', 'PUT')));
|
|
545
541
|
});
|
|
546
542
|
});
|
|
547
543
|
|
|
@@ -550,12 +546,10 @@ describe('plugin-device', () => {
|
|
|
550
546
|
device.processRegistrationSuccess = sinon.stub();
|
|
551
547
|
});
|
|
552
548
|
|
|
553
|
-
it('should return a resolved promise',
|
|
554
|
-
() => assert.isFulfilled(device.refresh()));
|
|
549
|
+
it('should return a resolved promise', () => assert.isFulfilled(device.refresh()));
|
|
555
550
|
|
|
556
|
-
it(
|
|
557
|
-
() => device.
|
|
558
|
-
.then(() => assert.called(device.processRegistrationSuccess)));
|
|
551
|
+
it("should call 'processRegistrationSuccess()'", () =>
|
|
552
|
+
device.refresh().then(() => assert.called(device.processRegistrationSuccess)));
|
|
559
553
|
});
|
|
560
554
|
|
|
561
555
|
describe('when the device fails to refresh', () => {
|
|
@@ -573,9 +567,9 @@ describe('plugin-device', () => {
|
|
|
573
567
|
options: {
|
|
574
568
|
url: device.url,
|
|
575
569
|
headers: {
|
|
576
|
-
trackingId: 'tid'
|
|
577
|
-
}
|
|
578
|
-
}
|
|
570
|
+
trackingId: 'tid',
|
|
571
|
+
},
|
|
572
|
+
},
|
|
579
573
|
})
|
|
580
574
|
);
|
|
581
575
|
});
|
|
@@ -584,12 +578,11 @@ describe('plugin-device', () => {
|
|
|
584
578
|
device.request = request;
|
|
585
579
|
});
|
|
586
580
|
|
|
587
|
-
it('should clear the current device', () =>
|
|
588
|
-
.then(() => assert.isUndefined(device.url)));
|
|
581
|
+
it('should clear the current device', () =>
|
|
582
|
+
device.refresh().then(() => assert.isUndefined(device.url)));
|
|
589
583
|
|
|
590
584
|
it('should attempt to register a new device', () =>
|
|
591
|
-
device.refresh()
|
|
592
|
-
.then(() => assert.called(device.register)));
|
|
585
|
+
device.refresh().then(() => assert.called(device.register)));
|
|
593
586
|
});
|
|
594
587
|
|
|
595
588
|
describe('when the device was found', () => {
|
|
@@ -604,9 +597,9 @@ describe('plugin-device', () => {
|
|
|
604
597
|
options: {
|
|
605
598
|
url: device.url,
|
|
606
599
|
headers: {
|
|
607
|
-
trackingId: 'tid'
|
|
608
|
-
}
|
|
609
|
-
}
|
|
600
|
+
trackingId: 'tid',
|
|
601
|
+
},
|
|
602
|
+
},
|
|
610
603
|
})
|
|
611
604
|
);
|
|
612
605
|
});
|
|
@@ -615,36 +608,32 @@ describe('plugin-device', () => {
|
|
|
615
608
|
device.request = request;
|
|
616
609
|
});
|
|
617
610
|
|
|
618
|
-
it('should return a rejected promise',
|
|
619
|
-
() => assert.isRejected(device.refresh()));
|
|
611
|
+
it('should return a rejected promise', () => assert.isRejected(device.refresh()));
|
|
620
612
|
});
|
|
621
613
|
});
|
|
622
614
|
});
|
|
623
615
|
});
|
|
624
616
|
|
|
625
617
|
describe('when the device cannot register', () => {
|
|
626
|
-
beforeEach(
|
|
627
|
-
device.canRegister = sinon.stub().rejects(
|
|
628
|
-
new Error()
|
|
629
|
-
);
|
|
618
|
+
beforeEach("setup 'canRegister()' stub", () => {
|
|
619
|
+
device.canRegister = sinon.stub().rejects(new Error());
|
|
630
620
|
});
|
|
631
621
|
|
|
632
|
-
it('should return a rejected promise',
|
|
633
|
-
() => assert.isRejected(device.refresh()));
|
|
622
|
+
it('should return a rejected promise', () => assert.isRejected(device.refresh()));
|
|
634
623
|
});
|
|
635
624
|
});
|
|
636
625
|
|
|
637
626
|
describe('#register()', () => {
|
|
638
627
|
describe('when the device can register', () => {
|
|
639
628
|
describe('when the device is already registered', () => {
|
|
640
|
-
beforeEach(
|
|
629
|
+
beforeEach("setup 'register()' spy and register", () => {
|
|
641
630
|
device.refresh = sinon.spy();
|
|
642
631
|
|
|
643
632
|
return device.register();
|
|
644
633
|
});
|
|
645
634
|
|
|
646
|
-
it('should attempt to refresh', () =>
|
|
647
|
-
.then(() => assert.called(device.refresh)));
|
|
635
|
+
it('should attempt to refresh', () =>
|
|
636
|
+
device.register().then(() => assert.called(device.refresh)));
|
|
648
637
|
});
|
|
649
638
|
|
|
650
639
|
describe('when the device is not already registered', () => {
|
|
@@ -653,13 +642,11 @@ describe('plugin-device', () => {
|
|
|
653
642
|
beforeEach('setup stubs and scoped variables', () => {
|
|
654
643
|
exampleResponse = {
|
|
655
644
|
body: {
|
|
656
|
-
exampleKey: 'example response value'
|
|
657
|
-
}
|
|
645
|
+
exampleKey: 'example response value',
|
|
646
|
+
},
|
|
658
647
|
};
|
|
659
648
|
|
|
660
|
-
device.request = sinon.stub().returns(Promise.resolve(
|
|
661
|
-
{...exampleResponse}
|
|
662
|
-
));
|
|
649
|
+
device.request = sinon.stub().returns(Promise.resolve({...exampleResponse}));
|
|
663
650
|
});
|
|
664
651
|
|
|
665
652
|
describe('when the registration request is sent', () => {
|
|
@@ -668,73 +655,75 @@ describe('plugin-device', () => {
|
|
|
668
655
|
|
|
669
656
|
beforeEach('configure device plugin', () => {
|
|
670
657
|
customHeaders = {
|
|
671
|
-
testHeader: 'example header value'
|
|
658
|
+
testHeader: 'example header value',
|
|
672
659
|
};
|
|
673
660
|
|
|
674
661
|
customBody = {
|
|
675
|
-
testBody: 'example body value'
|
|
662
|
+
testBody: 'example body value',
|
|
676
663
|
};
|
|
677
664
|
});
|
|
678
665
|
|
|
679
666
|
it('should allow for custom header key:values', () => {
|
|
680
667
|
device.config.headers = {...customHeaders};
|
|
681
668
|
|
|
682
|
-
return device
|
|
669
|
+
return device
|
|
670
|
+
.register()
|
|
683
671
|
.then(() =>
|
|
684
|
-
assert.calledWith(
|
|
685
|
-
|
|
686
|
-
|
|
672
|
+
assert.calledWith(
|
|
673
|
+
device.request,
|
|
674
|
+
sinon.match.hasNested('headers.testHeader', customHeaders.testHeader)
|
|
675
|
+
)
|
|
676
|
+
);
|
|
687
677
|
});
|
|
688
678
|
|
|
689
679
|
it('should allow for custom body key:values', () => {
|
|
690
680
|
device.config.body = {...customBody};
|
|
691
681
|
|
|
692
|
-
return device
|
|
682
|
+
return device
|
|
683
|
+
.register()
|
|
693
684
|
.then(() =>
|
|
694
|
-
assert.calledWith(
|
|
695
|
-
|
|
696
|
-
|
|
685
|
+
assert.calledWith(
|
|
686
|
+
device.request,
|
|
687
|
+
sinon.match.hasNested('body.testBody', customBody.testBody)
|
|
688
|
+
)
|
|
689
|
+
);
|
|
697
690
|
});
|
|
698
691
|
|
|
699
|
-
it(
|
|
692
|
+
it("should use the 'wdm' service", () => {
|
|
700
693
|
device.config.body = {...customBody};
|
|
701
694
|
|
|
702
|
-
return device
|
|
703
|
-
.
|
|
704
|
-
|
|
705
|
-
'service', 'wdm'
|
|
706
|
-
)));
|
|
695
|
+
return device
|
|
696
|
+
.register()
|
|
697
|
+
.then(() => assert.calledWith(device.request, sinon.match.has('service', 'wdm')));
|
|
707
698
|
});
|
|
708
699
|
|
|
709
|
-
it(
|
|
700
|
+
it("should use the 'devices' resource", () => {
|
|
710
701
|
device.config.body = {...customBody};
|
|
711
702
|
|
|
712
|
-
return device
|
|
703
|
+
return device
|
|
704
|
+
.register()
|
|
713
705
|
.then(() =>
|
|
714
|
-
assert.calledWith(device.request, sinon.match.has(
|
|
715
|
-
|
|
716
|
-
)));
|
|
706
|
+
assert.calledWith(device.request, sinon.match.has('resource', 'devices'))
|
|
707
|
+
);
|
|
717
708
|
});
|
|
718
709
|
|
|
719
710
|
it('should send a POST request', () => {
|
|
720
711
|
device.config.body = {...customBody};
|
|
721
712
|
|
|
722
|
-
return device
|
|
723
|
-
.
|
|
724
|
-
|
|
725
|
-
'method', 'POST'
|
|
726
|
-
)));
|
|
713
|
+
return device
|
|
714
|
+
.register()
|
|
715
|
+
.then(() => assert.calledWith(device.request, sinon.match.has('method', 'POST')));
|
|
727
716
|
});
|
|
728
717
|
|
|
729
718
|
it('should set TTL if configured as ephemeral', () => {
|
|
730
719
|
device.config.ephemeral = true;
|
|
731
720
|
device.config.ephemeralDeviceTTL = 3600;
|
|
732
721
|
|
|
733
|
-
return device
|
|
722
|
+
return device
|
|
723
|
+
.register()
|
|
734
724
|
.then(() =>
|
|
735
|
-
assert.calledWith(device.request, sinon.match.hasNested(
|
|
736
|
-
|
|
737
|
-
)));
|
|
725
|
+
assert.calledWith(device.request, sinon.match.hasNested('body.ttl', 3600))
|
|
726
|
+
);
|
|
738
727
|
});
|
|
739
728
|
});
|
|
740
729
|
|
|
@@ -743,12 +732,10 @@ describe('plugin-device', () => {
|
|
|
743
732
|
device.processRegistrationSuccess = sinon.stub();
|
|
744
733
|
});
|
|
745
734
|
|
|
746
|
-
it('should return a resolved promise',
|
|
747
|
-
() => assert.isFulfilled(device.register()));
|
|
735
|
+
it('should return a resolved promise', () => assert.isFulfilled(device.register()));
|
|
748
736
|
|
|
749
|
-
it(
|
|
750
|
-
() => device.
|
|
751
|
-
.then(() => assert.called(device.processRegistrationSuccess)));
|
|
737
|
+
it("should call 'processRegistrationSuccess()'", () =>
|
|
738
|
+
device.register().then(() => assert.called(device.processRegistrationSuccess)));
|
|
752
739
|
});
|
|
753
740
|
|
|
754
741
|
describe('when the device fails to register', () => {
|
|
@@ -759,28 +746,24 @@ describe('plugin-device', () => {
|
|
|
759
746
|
options: {
|
|
760
747
|
url: 'http://not-a-url.com/resource',
|
|
761
748
|
headers: {
|
|
762
|
-
trackingId: 'tid'
|
|
763
|
-
}
|
|
764
|
-
}
|
|
749
|
+
trackingId: 'tid',
|
|
750
|
+
},
|
|
751
|
+
},
|
|
765
752
|
})
|
|
766
753
|
);
|
|
767
754
|
});
|
|
768
755
|
|
|
769
|
-
it('should return a rejected promise',
|
|
770
|
-
() => assert.isRejected(device.register()));
|
|
756
|
+
it('should return a rejected promise', () => assert.isRejected(device.register()));
|
|
771
757
|
});
|
|
772
758
|
});
|
|
773
759
|
});
|
|
774
760
|
|
|
775
761
|
describe('when the device cannot register', () => {
|
|
776
|
-
beforeEach(
|
|
777
|
-
device.canRegister = sinon.stub().rejects(
|
|
778
|
-
new Error()
|
|
779
|
-
);
|
|
762
|
+
beforeEach("setup 'canRegister()' stub", () => {
|
|
763
|
+
device.canRegister = sinon.stub().rejects(new Error());
|
|
780
764
|
});
|
|
781
765
|
|
|
782
|
-
it('should return a rejected promise',
|
|
783
|
-
() => assert.isRejected(device.register()));
|
|
766
|
+
it('should return a rejected promise', () => assert.isRejected(device.register()));
|
|
784
767
|
});
|
|
785
768
|
});
|
|
786
769
|
|
|
@@ -804,7 +787,7 @@ describe('plugin-device', () => {
|
|
|
804
787
|
});
|
|
805
788
|
|
|
806
789
|
describe('when the user is not in a meeting', () => {
|
|
807
|
-
beforeEach(
|
|
790
|
+
beforeEach("setup the 'setLogoutTimer()' spy", () => {
|
|
808
791
|
device.setLogoutTimer = sinon.stub();
|
|
809
792
|
});
|
|
810
793
|
|
|
@@ -816,10 +799,7 @@ describe('plugin-device', () => {
|
|
|
816
799
|
it('should set the logout timer to the in-network duration', () => {
|
|
817
800
|
device.resetLogoutTimer();
|
|
818
801
|
|
|
819
|
-
assert.calledWith(
|
|
820
|
-
device.setLogoutTimer,
|
|
821
|
-
device.intranetInactivityCheckUrl
|
|
822
|
-
);
|
|
802
|
+
assert.calledWith(device.setLogoutTimer, device.intranetInactivityCheckUrl);
|
|
823
803
|
});
|
|
824
804
|
});
|
|
825
805
|
|
|
@@ -831,10 +811,7 @@ describe('plugin-device', () => {
|
|
|
831
811
|
it('should set the logout timer to the intranet duration', () => {
|
|
832
812
|
device.resetLogoutTimer();
|
|
833
813
|
|
|
834
|
-
assert.calledWith(
|
|
835
|
-
device.setLogoutTimer,
|
|
836
|
-
device.intranetInactivityDuration
|
|
837
|
-
);
|
|
814
|
+
assert.calledWith(device.setLogoutTimer, device.intranetInactivityDuration);
|
|
838
815
|
});
|
|
839
816
|
});
|
|
840
817
|
});
|
|
@@ -848,33 +825,31 @@ describe('plugin-device', () => {
|
|
|
848
825
|
describe('when the unregistration request is sent', () => {
|
|
849
826
|
let url;
|
|
850
827
|
|
|
851
|
-
beforeEach(
|
|
828
|
+
beforeEach("setup the 'request()' stub", () => {
|
|
852
829
|
device.request = sinon.stub().resolves();
|
|
853
830
|
url = device.url;
|
|
854
831
|
});
|
|
855
832
|
|
|
856
|
-
it(
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
))));
|
|
833
|
+
it("should use the device's url property", () =>
|
|
834
|
+
device
|
|
835
|
+
.unregister()
|
|
836
|
+
.then(() => assert.calledWith(device.request, sinon.match.has('uri', url))));
|
|
861
837
|
|
|
862
|
-
it('should send a DELETE request', () =>
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
))));
|
|
838
|
+
it('should send a DELETE request', () =>
|
|
839
|
+
device
|
|
840
|
+
.unregister()
|
|
841
|
+
.then(() => assert.calledWith(device.request, sinon.match.has('method', 'DELETE'))));
|
|
867
842
|
});
|
|
868
843
|
|
|
869
844
|
describe('when the device unregistration request is successful', () => {
|
|
870
|
-
it('should clear the device url', () =>
|
|
871
|
-
.then(() => assert.isUndefined(device.url)));
|
|
845
|
+
it('should clear the device url', () =>
|
|
846
|
+
device.unregister().then(() => assert.isUndefined(device.url)));
|
|
872
847
|
});
|
|
873
848
|
|
|
874
849
|
describe('when the device unregistration request fails', () => {
|
|
875
850
|
let request;
|
|
876
851
|
|
|
877
|
-
beforeEach(
|
|
852
|
+
beforeEach("setup the 'request' stub", () => {
|
|
878
853
|
request = device.request;
|
|
879
854
|
|
|
880
855
|
device.request = sinon.stub().rejects(
|
|
@@ -883,9 +858,9 @@ describe('plugin-device', () => {
|
|
|
883
858
|
options: {
|
|
884
859
|
url: device.url,
|
|
885
860
|
headers: {
|
|
886
|
-
trackingId: 'tid'
|
|
887
|
-
}
|
|
888
|
-
}
|
|
861
|
+
trackingId: 'tid',
|
|
862
|
+
},
|
|
863
|
+
},
|
|
889
864
|
})
|
|
890
865
|
);
|
|
891
866
|
});
|
|
@@ -894,14 +869,12 @@ describe('plugin-device', () => {
|
|
|
894
869
|
device.request = request;
|
|
895
870
|
});
|
|
896
871
|
|
|
897
|
-
it('returns a rejected promise',
|
|
898
|
-
() => assert.isRejected(device.unregister()));
|
|
872
|
+
it('returns a rejected promise', () => assert.isRejected(device.unregister()));
|
|
899
873
|
});
|
|
900
874
|
});
|
|
901
875
|
|
|
902
876
|
describe('when the device is not registered', () => {
|
|
903
|
-
it('should return a resolved promise',
|
|
904
|
-
() => assert.isFulfilled(device.unregister()));
|
|
877
|
+
it('should return a resolved promise', () => assert.isFulfilled(device.unregister()));
|
|
905
878
|
});
|
|
906
879
|
});
|
|
907
880
|
|
|
@@ -909,23 +882,21 @@ describe('plugin-device', () => {
|
|
|
909
882
|
describe('when the device is registered', () => {
|
|
910
883
|
beforeEach('register the device', () => device.register());
|
|
911
884
|
|
|
912
|
-
it('should return a resolved promise',
|
|
913
|
-
|
|
885
|
+
it('should return a resolved promise', () =>
|
|
886
|
+
assert.isFulfilled(device.waitForRegistration()));
|
|
914
887
|
});
|
|
915
888
|
|
|
916
889
|
describe('when the device is not registered', () => {
|
|
917
890
|
describe('when the device registers', () => {
|
|
918
|
-
it('should return a resolved promise once registered',
|
|
919
|
-
()
|
|
920
|
-
device.
|
|
921
|
-
|
|
922
|
-
])
|
|
923
|
-
.then(() => assert.isTrue(device.registered)));
|
|
891
|
+
it('should return a resolved promise once registered', () =>
|
|
892
|
+
Promise.all([device.waitForRegistration(), device.register()]).then(() =>
|
|
893
|
+
assert.isTrue(device.registered)
|
|
894
|
+
));
|
|
924
895
|
});
|
|
925
896
|
|
|
926
897
|
describe('when the device does not register', () => {
|
|
927
|
-
it('should return a rejected promise',
|
|
928
|
-
|
|
898
|
+
it('should return a rejected promise', () =>
|
|
899
|
+
assert.isRejected(device.waitForRegistration()));
|
|
929
900
|
});
|
|
930
901
|
});
|
|
931
902
|
});
|