@webex/internal-plugin-dss 2.60.1-next.9 → 2.60.2

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.
@@ -1,35 +1,28 @@
1
1
  /*!
2
2
  * Copyright (c) 2015-2022 Cisco Systems, Inc. See LICENSE file.
3
3
  */
4
- /* eslint-disable no-underscore-dangle */
5
- import chai from 'chai';
6
- import chaiAsPromised from 'chai-as-promised';
7
- import {assert, expect} from '@webex/test-helper-chai';
4
+
5
+ import {assert} from '@webex/test-helper-chai';
8
6
  import DSS from '@webex/internal-plugin-dss';
9
- import {Batcher} from '@webex/webex-core';
10
7
  import MockWebex from '@webex/test-helper-mock-webex';
11
8
  import sinon from 'sinon';
9
+ import {expect} from 'chai';
12
10
  import {set} from 'lodash';
13
11
  import uuid from 'uuid';
14
- import config from '@webex/internal-plugin-dss/src/config';
15
12
 
16
- chai.use(chaiAsPromised);
17
13
  describe('plugin-dss', () => {
18
14
  describe('DSS', () => {
19
- const originalBatcherRequest = Batcher.prototype.request;
20
15
  let webex;
21
16
  let uuidStub;
22
17
  let mercuryCallbacks;
23
- let clock;
24
18
 
25
19
  beforeEach(() => {
26
- webex = MockWebex({
20
+ webex = new MockWebex({
27
21
  canAuthorize: false,
28
22
  children: {
29
23
  dss: DSS,
30
24
  },
31
25
  });
32
- webex.config.dss = config.dss;
33
26
 
34
27
  uuidStub = sinon.stub(uuid, 'v4').returns('randomid');
35
28
 
@@ -46,14 +39,10 @@ describe('plugin-dss', () => {
46
39
  }),
47
40
  off: sinon.spy(),
48
41
  };
49
-
50
- clock = sinon.useFakeTimers();
51
42
  });
52
43
 
53
44
  afterEach(() => {
54
45
  uuidStub.restore();
55
- clock.restore();
56
- Batcher.prototype.request = originalBatcherRequest;
57
46
  });
58
47
 
59
48
  describe('#register()', () => {
@@ -63,12 +52,10 @@ describe('plugin-dss', () => {
63
52
  assert.callCount(webex.internal.mercury.on, 2);
64
53
 
65
54
  const firstCallArgs = webex.internal.mercury.on.getCall(0).args;
66
-
67
55
  expect(firstCallArgs[0]).to.equal('event:directory.lookup');
68
56
  expect(firstCallArgs[1]).to.be.a('function');
69
57
 
70
58
  const secondCallArgs = webex.internal.mercury.on.getCall(1).args;
71
-
72
59
  expect(secondCallArgs[0]).to.equal('event:directory.search');
73
60
  expect(secondCallArgs[1]).to.be.a('function');
74
61
 
@@ -94,11 +81,9 @@ describe('plugin-dss', () => {
94
81
  assert.callCount(webex.internal.mercury.off, 2);
95
82
 
96
83
  const firstCallArgs = webex.internal.mercury.off.getCall(0).args;
97
-
98
84
  expect(firstCallArgs[0]).to.equal('event:directory.lookup');
99
85
 
100
86
  const secondCallArgs = webex.internal.mercury.off.getCall(1).args;
101
-
102
87
  expect(secondCallArgs[0]).to.equal('event:directory.search');
103
88
 
104
89
  assert.equal(webex.internal.dss.registered, false);
@@ -106,27 +91,24 @@ describe('plugin-dss', () => {
106
91
 
107
92
  it('handles unregister when it is not registered', async () => {
108
93
  const result = await webex.internal.dss.unregister();
109
-
110
94
  await expect(result).equal(undefined);
111
95
  assert.equal(webex.internal.dss.registered, false);
112
96
  });
113
97
  });
114
98
 
115
- const createData = (requestId, sequence, finished, dataPath, results) => {
99
+ const createData = (requestId, sequence, finished, dataPath) => {
116
100
  const data = {
117
101
  requestId,
118
102
  sequence,
119
103
  };
120
-
121
104
  if (finished) {
122
105
  (data as any).finished = finished;
123
106
  }
124
- set(data, dataPath, results);
125
-
107
+ set(data, dataPath, [`data${sequence}`]);
126
108
  return {data};
127
109
  };
128
110
 
129
- const testMakeRequest = async ({method, resource, params, bodyParams}) => {
111
+ const testRequest = async ({method, resource, params, bodyParams, dataPath, event}) => {
130
112
  webex.request = sinon.stub();
131
113
 
132
114
  await webex.internal.dss.register();
@@ -148,58 +130,23 @@ describe('plugin-dss', () => {
148
130
  },
149
131
  ]);
150
132
 
151
- return {requestId, promise};
152
- };
153
-
154
- const testMakeBatchedRequests = async ({requests, calls}) => {
155
- requests.forEach((request, index) => {
156
- uuidStub.onCall(index).returns(request.id);
157
- });
158
- webex.request = sinon.stub();
159
-
160
- await webex.internal.dss.register();
161
-
162
- const promises = calls.map((call) => webex.internal.dss[call.method](call.params));
163
-
164
- await clock.tickAsync(49);
165
- expect(webex.request.notCalled).to.be.true;
166
- await clock.tickAsync(1);
167
- expect(webex.request.called).to.be.true;
133
+ mercuryCallbacks[event](createData(requestId, 1, false, dataPath));
134
+ mercuryCallbacks[event](createData(requestId, 2, true, dataPath));
135
+ mercuryCallbacks[event](createData(requestId, 0, false, dataPath));
168
136
 
169
- requests.forEach((request, index) => {
170
- expect(webex.request.getCall(index).args).to.deep.equal([
171
- {
172
- service: 'directorySearch',
173
- body: {
174
- requestId: request.id,
175
- ...request.bodyParams,
176
- },
177
- contentType: 'application/json',
178
- method: 'POST',
179
- resource: request.resource,
180
- },
181
- ]);
182
- });
183
-
184
- return {promises};
137
+ const result = await promise;
138
+ expect(result).to.deep.equal(['data0', 'data1', 'data2']);
185
139
  };
186
140
 
187
141
  describe('#lookupDetail', () => {
188
142
  it('calls _request correctly', async () => {
189
143
  webex.internal.device.orgId = 'userOrgId';
190
- webex.internal.dss._request = sinon.stub().returns(
191
- Promise.resolve({
192
- resultArray: ['some return value'],
193
- foundArray: ['test id'],
194
- })
195
- );
144
+ webex.internal.dss._request = sinon.stub().returns(Promise.resolve('some return value'));
196
145
 
197
146
  const result = await webex.internal.dss.lookupDetail({id: 'test id'});
198
-
199
147
  expect(webex.internal.dss._request.getCall(0).args).to.deep.equal([
200
148
  {
201
149
  dataPath: 'lookupResult.entities',
202
- foundPath: 'lookupResult.entitiesFound',
203
150
  resource: '/lookup/orgid/userOrgId/identity/test id/detail',
204
151
  },
205
152
  ]);
@@ -207,95 +154,31 @@ describe('plugin-dss', () => {
207
154
  });
208
155
 
209
156
  it('works correctly', async () => {
210
- const {requestId, promise} = await testMakeRequest({
211
- method: 'lookupDetail',
212
- resource: '/lookup/orgid/userOrgId/identity/test id/detail',
213
- params: {id: 'test id'},
214
- bodyParams: {},
215
- });
216
-
217
- mercuryCallbacks['event:directory.lookup'](
218
- createData(requestId, 0, true, 'lookupResult', {
219
- entities: ['data0'],
220
- entitiesFound: ['test id'],
221
- })
222
- );
223
- const result = await promise;
224
-
225
- expect(result).to.deep.equal('data0');
226
- });
227
-
228
- it('fails correctly if lookup fails', async () => {
229
- const {requestId, promise} = await testMakeRequest({
230
- method: 'lookupDetail',
231
- resource: '/lookup/orgid/userOrgId/identity/test id/detail',
232
- params: {id: 'test id'},
233
- bodyParams: {},
234
- });
235
-
236
- mercuryCallbacks['event:directory.lookup'](
237
- createData(requestId, 0, true, 'lookupResult', {entitiesNotFound: ['test id']})
238
- );
239
- const result = await promise;
240
-
241
- expect(result).to.be.null;
242
- });
243
- it('fails with default timeout when mercury does not respond', async () => {
244
- return testMakeRequest({
245
- method: 'lookupDetail',
246
- resource: '/lookup/orgid/userOrgId/identity/test id/detail',
247
- params: {id: 'test id'},
248
- bodyParams: {},
249
- }).then(async ({promise}) => {
250
- promise.catch((err) => {
251
- expect(err.toString()).equal(
252
- 'DssTimeoutError: The DSS did not respond within 6000 ms.' +
253
- '\n Request Id: randomid' +
254
- '\n Resource: /lookup/orgid/userOrgId/identity/test id/detail' +
255
- '\n Params: undefined'
256
- );
257
- });
258
- await clock.tickAsync(6000);
259
- });
260
- });
261
-
262
- it('does not fail with timeout when mercury response in time', async () => {
263
- const {requestId, promise} = await testMakeRequest({
157
+ await testRequest({
264
158
  method: 'lookupDetail',
159
+ dataPath: 'lookupResult.entities',
160
+ event: 'event:directory.lookup',
265
161
  resource: '/lookup/orgid/userOrgId/identity/test id/detail',
266
- params: {id: 'test id'},
162
+ params: {
163
+ id: 'test id',
164
+ },
267
165
  bodyParams: {},
268
166
  });
269
-
270
- await clock.tickAsync(499);
271
-
272
- mercuryCallbacks['event:directory.lookup'](
273
- createData(requestId, 0, true, 'lookupResult', {entitiesNotFound: ['test id']})
274
- );
275
-
276
- return assert.isFulfilled(promise);
277
167
  });
278
168
  });
279
169
 
280
170
  describe('#lookup', () => {
281
171
  it('calls _request correctly', async () => {
282
172
  webex.internal.device.orgId = 'userOrgId';
283
- webex.internal.dss._request = sinon.stub().returns(
284
- Promise.resolve({
285
- resultArray: ['some return value'],
286
- foundArray: ['id1'],
287
- })
288
- );
289
-
290
- const result = await webex.internal.dss.lookup({id: 'id1', shouldBatch: false});
173
+ webex.internal.dss._request = sinon.stub().returns(Promise.resolve('some return value'));
291
174
 
175
+ const result = await webex.internal.dss.lookup({ids: ['id1', 'id2']});
292
176
  expect(webex.internal.dss._request.getCall(0).args).to.deep.equal([
293
177
  {
294
178
  dataPath: 'lookupResult.entities',
295
- foundPath: 'lookupResult.entitiesFound',
296
179
  resource: '/lookup/orgid/userOrgId/identities',
297
180
  params: {
298
- lookupValues: ['id1'],
181
+ lookupValues: ['id1', 'id2'],
299
182
  },
300
183
  },
301
184
  ]);
@@ -304,26 +187,18 @@ describe('plugin-dss', () => {
304
187
 
305
188
  it('calls _request correctly with entityProviderType', async () => {
306
189
  webex.internal.device.orgId = 'userOrgId';
307
- webex.internal.dss._request = sinon.stub().returns(
308
- Promise.resolve({
309
- resultArray: ['some return value'],
310
- foundArray: ['id1'],
311
- })
312
- );
190
+ webex.internal.dss._request = sinon.stub().returns(Promise.resolve('some return value'));
313
191
 
314
192
  const result = await webex.internal.dss.lookup({
315
- id: 'id1',
193
+ ids: ['id1', 'id2'],
316
194
  entityProviderType: 'CI_USER',
317
- shouldBatch: false,
318
195
  });
319
-
320
196
  expect(webex.internal.dss._request.getCall(0).args).to.deep.equal([
321
197
  {
322
198
  dataPath: 'lookupResult.entities',
323
- foundPath: 'lookupResult.entitiesFound',
324
199
  resource: '/lookup/orgid/userOrgId/entityprovidertype/CI_USER',
325
200
  params: {
326
- lookupValues: ['id1'],
201
+ lookupValues: ['id1', 'id2'],
327
202
  },
328
203
  },
329
204
  ]);
@@ -331,350 +206,35 @@ describe('plugin-dss', () => {
331
206
  });
332
207
 
333
208
  it('works correctly', async () => {
334
- const {requestId, promise} = await testMakeRequest({
209
+ await testRequest({
335
210
  method: 'lookup',
211
+ dataPath: 'lookupResult.entities',
212
+ event: 'event:directory.lookup',
336
213
  resource: '/lookup/orgid/userOrgId/identities',
337
- params: {id: 'id1', shouldBatch: false},
338
- bodyParams: {lookupValues: ['id1']},
339
- });
340
-
341
- mercuryCallbacks['event:directory.lookup'](
342
- createData(requestId, 0, true, 'lookupResult', {
343
- entities: ['data0'],
344
- entitiesFound: ['id1'],
345
- })
346
- );
347
- const result = await promise;
348
-
349
- expect(result).to.deep.equal('data0');
350
- });
351
-
352
- it('fails correctly if lookup fails', async () => {
353
- const {requestId, promise} = await testMakeRequest({
354
- method: 'lookup',
355
- resource: '/lookup/orgid/userOrgId/identities',
356
- params: {id: 'id1', shouldBatch: false},
357
- bodyParams: {lookupValues: ['id1']},
358
- });
359
-
360
- mercuryCallbacks['event:directory.lookup'](
361
- createData(requestId, 0, true, 'lookupResult', {entitiesNotFound: ['id1']})
362
- );
363
- const result = await promise;
364
-
365
- expect(result).to.be.null;
366
- });
367
-
368
- it('calls _batchedLookup correctly', async () => {
369
- webex.internal.device.orgId = 'userOrgId';
370
- webex.internal.dss._batchedLookup = sinon
371
- .stub()
372
- .returns(Promise.resolve('some return value'));
373
-
374
- const result = await webex.internal.dss.lookup({id: 'id1'});
375
-
376
- expect(webex.internal.dss._batchedLookup.getCall(0).args).to.deep.equal([
377
- {
378
- resource: '/lookup/orgid/userOrgId/identities',
379
- lookupValue: 'id1',
214
+ params: {
215
+ ids: ['id1', 'id2'],
380
216
  },
381
- ]);
382
- expect(result).to.equal('some return value');
383
- });
384
-
385
- it('calls _batchedLookup correctly with entityProviderType', async () => {
386
- webex.internal.device.orgId = 'userOrgId';
387
- webex.internal.dss._batchedLookup = sinon
388
- .stub()
389
- .returns(Promise.resolve('some return value'));
390
-
391
- const result = await webex.internal.dss.lookup({
392
- id: 'id1',
393
- entityProviderType: 'CI_USER',
394
- });
395
-
396
- expect(webex.internal.dss._batchedLookup.getCall(0).args).to.deep.equal([
397
- {
398
- resource: '/lookup/orgid/userOrgId/entityprovidertype/CI_USER',
399
- lookupValue: 'id1',
217
+ bodyParams: {
218
+ lookupValues: ['id1', 'id2'],
400
219
  },
401
- ]);
402
- expect(result).to.equal('some return value');
403
- });
404
-
405
- it('Single batched lookup is made after 50 ms and works', async () => {
406
- const {promises} = await testMakeBatchedRequests({
407
- requests: [
408
- {
409
- id: 'randomid1',
410
- resource: '/lookup/orgid/userOrgId/identities',
411
- bodyParams: {lookupValues: ['id1']},
412
- },
413
- ],
414
- calls: [
415
- {
416
- method: 'lookup',
417
- params: {id: 'id1', shouldBatch: true},
418
- },
419
- ],
420
- });
421
-
422
- mercuryCallbacks['event:directory.lookup'](
423
- createData('randomid1', 0, true, 'lookupResult', {
424
- entities: ['data0'],
425
- entitiesFound: ['id1'],
426
- })
427
- );
428
- const result = await promises[0];
429
-
430
- expect(result).to.deep.equal('data0');
431
- });
432
-
433
- it('Single batched lookup fails correctly if lookup fails', async () => {
434
- const {promises} = await testMakeBatchedRequests({
435
- requests: [
436
- {
437
- id: 'randomid1',
438
- resource: '/lookup/orgid/userOrgId/identities',
439
- bodyParams: {lookupValues: ['id1']},
440
- },
441
- ],
442
- calls: [
443
- {
444
- method: 'lookup',
445
- params: {id: 'id1', shouldBatch: true},
446
- },
447
- ],
448
- });
449
-
450
- mercuryCallbacks['event:directory.lookup'](
451
- createData('randomid1', 0, true, 'lookupResult', {entitiesNotFound: ['id1']})
452
- );
453
-
454
- const result = await promises[0];
455
-
456
- expect(result).to.be.null;
457
- });
458
-
459
- it('Batch of 2 lookups is made after 50 ms and works', async () => {
460
- const {promises} = await testMakeBatchedRequests({
461
- requests: [
462
- {
463
- id: 'randomid1',
464
- resource: '/lookup/orgid/userOrgId/identities',
465
- bodyParams: {lookupValues: ['id1', 'id2']},
466
- },
467
- ],
468
- calls: [
469
- {
470
- method: 'lookup',
471
- params: {id: 'id1', shouldBatch: true},
472
- },
473
- {
474
- method: 'lookup',
475
- params: {id: 'id2', shouldBatch: true},
476
- },
477
- ],
478
- });
479
-
480
- mercuryCallbacks['event:directory.lookup'](
481
- createData('randomid1', 0, true, 'lookupResult', {
482
- entities: ['data1', 'data2'],
483
- entitiesFound: ['id1', 'id2'],
484
- })
485
- );
486
- const result1 = await promises[0];
487
-
488
- expect(result1).to.equal('data1');
489
- const result2 = await promises[1];
490
-
491
- expect(result2).to.equal('data2');
492
- });
493
-
494
- it('Batch of 2 lookups is made after 50 ms and one fails correctly', async () => {
495
- const {promises} = await testMakeBatchedRequests({
496
- requests: [
497
- {
498
- id: 'randomid1',
499
- resource: '/lookup/orgid/userOrgId/identities',
500
- bodyParams: {lookupValues: ['id1', 'id2']},
501
- },
502
- ],
503
- calls: [
504
- {
505
- method: 'lookup',
506
- params: {id: 'id1', shouldBatch: true},
507
- },
508
- {
509
- method: 'lookup',
510
- params: {id: 'id2', shouldBatch: true},
511
- },
512
- ],
513
- });
514
-
515
- mercuryCallbacks['event:directory.lookup'](
516
- createData('randomid1', 0, true, 'lookupResult', {
517
- entities: ['data2'],
518
- entitiesFound: ['id2'],
519
- entitiesNotFound: ['id1'],
520
- })
521
- );
522
- const result1 = await promises[0];
523
-
524
- expect(result1).to.be.null;
525
-
526
- const result2 = await promises[1];
527
-
528
- expect(result2).to.equal('data2');
529
- });
530
-
531
- it('Two unrelated lookups are made after 50 ms and work', async () => {
532
- const {promises} = await testMakeBatchedRequests({
533
- requests: [
534
- {
535
- id: 'randomid1',
536
- resource: '/lookup/orgid/userOrgId/entityprovidertype/CI_USER',
537
- bodyParams: {lookupValues: ['id1']},
538
- },
539
- {
540
- id: 'randomid2',
541
- resource: '/lookup/orgid/userOrgId/identities',
542
- bodyParams: {lookupValues: ['id2']},
543
- },
544
- ],
545
- calls: [
546
- {
547
- method: 'lookup',
548
- params: {id: 'id1', entityProviderType: 'CI_USER', shouldBatch: true},
549
- },
550
- {
551
- method: 'lookup',
552
- params: {id: 'id2', shouldBatch: true},
553
- },
554
- ],
555
- });
556
-
557
- mercuryCallbacks['event:directory.lookup'](
558
- createData('randomid1', 0, true, 'lookupResult', {
559
- entities: ['data1'],
560
- entitiesFound: ['id1'],
561
- })
562
- );
563
- mercuryCallbacks['event:directory.lookup'](
564
- createData('randomid2', 0, true, 'lookupResult', {
565
- entities: ['data2'],
566
- entitiesFound: ['id2'],
567
- })
568
- );
569
- const result1 = await promises[0];
570
-
571
- expect(result1).to.equal('data1');
572
- const result2 = await promises[1];
573
-
574
- expect(result2).to.equal('data2');
575
- });
576
-
577
- it('Two unrelated lookups are made after 50 ms and one fails correctly', async () => {
578
- const {promises} = await testMakeBatchedRequests({
579
- requests: [
580
- {
581
- id: 'randomid1',
582
- resource: '/lookup/orgid/userOrgId/entityprovidertype/CI_USER',
583
- bodyParams: {lookupValues: ['id1']},
584
- },
585
- {
586
- id: 'randomid2',
587
- resource: '/lookup/orgid/userOrgId/identities',
588
- bodyParams: {lookupValues: ['id2']},
589
- },
590
- ],
591
- calls: [
592
- {
593
- method: 'lookup',
594
- params: {id: 'id1', entityProviderType: 'CI_USER', shouldBatch: true},
595
- },
596
- {
597
- method: 'lookup',
598
- params: {id: 'id2', shouldBatch: true},
599
- },
600
- ],
601
- });
602
-
603
- mercuryCallbacks['event:directory.lookup'](
604
- createData('randomid1', 0, true, 'lookupResult', {entitiesNotFound: ['id1']})
605
- );
606
- mercuryCallbacks['event:directory.lookup'](
607
- createData('randomid2', 0, true, 'lookupResult', {
608
- entities: ['data2'],
609
- entitiesFound: ['id2'],
610
- })
611
- );
612
- const result1 = await promises[0];
613
-
614
- expect(result1).to.be.null;
615
- const result2 = await promises[1];
616
-
617
- expect(result2).to.equal('data2');
618
- });
619
-
620
- it('fails with default timeout when mercury does not respond', async () => {
621
- return testMakeRequest({
622
- method: 'lookup',
623
- resource: '/lookup/orgid/userOrgId/identities',
624
- params: {id: 'id1', shouldBatch: false},
625
- bodyParams: {lookupValues: ['id1']},
626
- }).then(async ({promise}) => {
627
- promise.catch((err) => {
628
- expect(err.toString()).equal(
629
- 'DssTimeoutError: The DSS did not respond within 6000 ms.' +
630
- '\n Request Id: randomid' +
631
- '\n Resource: /lookup/orgid/userOrgId/identities' +
632
- '\n Params: {"lookupValues":["id1"]}'
633
- );
634
- });
635
- await clock.tickAsync(6000);
636
220
  });
637
221
  });
638
-
639
- it('does not fail with timeout when mercury response in time', async () => {
640
- const {promise, requestId} = await testMakeRequest({
641
- method: 'lookup',
642
- resource: '/lookup/orgid/userOrgId/identities',
643
- params: {id: 'id1', shouldBatch: false},
644
- bodyParams: {lookupValues: ['id1']},
645
- });
646
-
647
- await clock.tickAsync(499);
648
-
649
- mercuryCallbacks['event:directory.lookup'](
650
- createData(requestId, 0, true, 'lookupResult', {entitiesNotFound: ['test id']})
651
- );
652
-
653
- return assert.isFulfilled(promise);
654
- });
655
222
  });
656
223
 
657
224
  describe('#lookupByEmail', () => {
658
225
  it('calls _request correctly', async () => {
659
226
  webex.internal.device.orgId = 'userOrgId';
660
- webex.internal.dss._request = sinon.stub().returns(
661
- Promise.resolve({
662
- resultArray: ['some return value'],
663
- foundArray: ['email1'],
664
- })
665
- );
227
+ webex.internal.dss._request = sinon.stub().returns(Promise.resolve('some return value'));
666
228
 
667
229
  const result = await webex.internal.dss.lookupByEmail({
668
- email: 'email1',
230
+ emails: ['email1', 'email2'],
669
231
  });
670
-
671
232
  expect(webex.internal.dss._request.getCall(0).args).to.deep.equal([
672
233
  {
673
234
  dataPath: 'lookupResult.entities',
674
- foundPath: 'lookupResult.entitiesFound',
675
235
  resource: '/lookup/orgid/userOrgId/emails',
676
236
  params: {
677
- lookupValues: ['email1'],
237
+ lookupValues: ['email1', 'email2'],
678
238
  },
679
239
  },
680
240
  ]);
@@ -682,90 +242,31 @@ describe('plugin-dss', () => {
682
242
  });
683
243
 
684
244
  it('works correctly', async () => {
685
- const {requestId, promise} = await testMakeRequest({
245
+ await testRequest({
686
246
  method: 'lookupByEmail',
247
+ dataPath: 'lookupResult.entities',
248
+ event: 'event:directory.lookup',
687
249
  resource: '/lookup/orgid/userOrgId/emails',
688
- params: {email: 'email1'},
689
- bodyParams: {lookupValues: ['email1']},
690
- });
691
-
692
- mercuryCallbacks['event:directory.lookup'](
693
- createData(requestId, 0, true, 'lookupResult', {
694
- entities: ['data0'],
695
- entitiesFound: ['email1'],
696
- })
697
- );
698
- const result = await promise;
699
-
700
- expect(result).to.deep.equal('data0');
701
- });
702
-
703
- it('fails correctly if lookup fails', async () => {
704
- const {requestId, promise} = await testMakeRequest({
705
- method: 'lookupByEmail',
706
- resource: '/lookup/orgid/userOrgId/emails',
707
- params: {email: 'email1'},
708
- bodyParams: {lookupValues: ['email1']},
709
- });
710
-
711
- mercuryCallbacks['event:directory.lookup'](
712
- createData(requestId, 0, true, 'lookupResult', {}) // entitiesNotFound isn't returned for email
713
- );
714
- const result = await promise;
715
-
716
- expect(result).to.be.null;
717
- });
718
-
719
- it('fails with default timeout when mercury does not respond', async () => {
720
- return testMakeRequest({
721
- method: 'lookupByEmail',
722
- resource: '/lookup/orgid/userOrgId/emails',
723
- params: {email: 'email1'},
724
- bodyParams: {lookupValues: ['email1']},
725
- }).then(async ({promise}) => {
726
- promise.catch((err) => {
727
- expect(err.toString()).equal(
728
- 'DssTimeoutError: The DSS did not respond within 6000 ms.' +
729
- '\n Request Id: randomid' +
730
- '\n Resource: /lookup/orgid/userOrgId/emails' +
731
- '\n Params: {"lookupValues":["email1"]}'
732
- );
733
- });
734
- await clock.tickAsync(6000);
735
- });
736
- });
737
-
738
- it('does not fail with timeout when mercury response in time', async () => {
739
- const {requestId, promise} = await testMakeRequest({
740
- method: 'lookupByEmail',
741
- resource: '/lookup/orgid/userOrgId/emails',
742
- params: {email: 'email1'},
743
- bodyParams: {lookupValues: ['email1']},
250
+ params: {
251
+ emails: ['email1', 'email2'],
252
+ },
253
+ bodyParams: {
254
+ lookupValues: ['email1', 'email2'],
255
+ },
744
256
  });
745
-
746
- await clock.tickAsync(5999);
747
-
748
- mercuryCallbacks['event:directory.lookup'](
749
- createData(requestId, 0, true, 'lookupResult', {}) // entitiesNotFound isn't returned for email
750
- );
751
-
752
- return assert.isFulfilled(promise);
753
257
  });
754
258
  });
755
259
 
756
260
  describe('#search', () => {
757
261
  it('calls _request correctly', async () => {
758
262
  webex.internal.device.orgId = 'userOrgId';
759
- webex.internal.dss._request = sinon
760
- .stub()
761
- .returns(Promise.resolve({resultArray: 'some return value'}));
263
+ webex.internal.dss._request = sinon.stub().returns(Promise.resolve('some return value'));
762
264
 
763
265
  const result = await webex.internal.dss.search({
764
266
  requestedTypes: ['PERSON', 'ROBOT'],
765
267
  resultSize: 100,
766
268
  queryString: 'query',
767
269
  });
768
-
769
270
  expect(webex.internal.dss._request.getCall(0).args).to.deep.equal([
770
271
  {
771
272
  dataPath: 'directoryEntities',
@@ -781,96 +282,10 @@ describe('plugin-dss', () => {
781
282
  });
782
283
 
783
284
  it('works correctly', async () => {
784
- const {requestId, promise} = await testMakeRequest({
785
- method: 'search',
786
- resource: '/search/orgid/userOrgId/entities',
787
- params: {
788
- requestedTypes: ['PERSON', 'ROBOT'],
789
- resultSize: 100,
790
- queryString: 'query',
791
- },
792
- bodyParams: {
793
- requestedTypes: ['PERSON', 'ROBOT'],
794
- resultSize: 100,
795
- queryString: 'query',
796
- },
797
- });
798
-
799
- mercuryCallbacks['event:directory.search'](
800
- createData(requestId, 1, false, 'directoryEntities', ['data1'])
801
- );
802
- mercuryCallbacks['event:directory.search'](
803
- createData(requestId, 2, true, 'directoryEntities', ['data2'])
804
- );
805
- mercuryCallbacks['event:directory.search'](
806
- createData(requestId, 0, false, 'directoryEntities', ['data0'])
807
- );
808
- const result = await promise;
809
-
810
- expect(result).to.deep.equal(['data0', 'data1', 'data2']);
811
- });
812
-
813
- it('fails with default timeout when mercury does not respond', async () => {
814
- return testMakeRequest({
815
- method: 'search',
816
- resource: '/search/orgid/userOrgId/entities',
817
- params: {
818
- requestedTypes: ['PERSON', 'ROBOT'],
819
- resultSize: 100,
820
- queryString: 'query',
821
- },
822
- bodyParams: {
823
- requestedTypes: ['PERSON', 'ROBOT'],
824
- resultSize: 100,
825
- queryString: 'query',
826
- },
827
- }).then(async ({promise}) => {
828
- promise.catch((err) => {
829
- expect(err.toString()).equal(
830
- 'DssTimeoutError: The DSS did not respond within 6000 ms.' +
831
- '\n Request Id: randomid' +
832
- '\n Resource: /search/orgid/userOrgId/entities' +
833
- '\n Params: {"queryString":"query","resultSize":100,"requestedTypes":["PERSON","ROBOT"]}'
834
- );
835
- });
836
- await clock.tickAsync(6000);
837
- });
838
- });
839
-
840
- it('does not fail with timeout when mercury response in time', async () => {
841
- const {requestId, promise} = await testMakeRequest({
842
- method: 'search',
843
- resource: '/search/orgid/userOrgId/entities',
844
- params: {
845
- requestedTypes: ['PERSON', 'ROBOT'],
846
- resultSize: 100,
847
- queryString: 'query',
848
- },
849
- bodyParams: {
850
- requestedTypes: ['PERSON', 'ROBOT'],
851
- resultSize: 100,
852
- queryString: 'query',
853
- },
854
- });
855
-
856
- await clock.tickAsync(5999);
857
-
858
- mercuryCallbacks['event:directory.search'](
859
- createData(requestId, 1, false, 'directoryEntities', ['data1'])
860
- );
861
- mercuryCallbacks['event:directory.search'](
862
- createData(requestId, 2, true, 'directoryEntities', ['data2'])
863
- );
864
- mercuryCallbacks['event:directory.search'](
865
- createData(requestId, 0, false, 'directoryEntities', ['data0'])
866
- );
867
-
868
- return assert.isFulfilled(promise);
869
- });
870
-
871
- it('fails with timeout when request only partially resolved', async () => {
872
- return testMakeRequest({
285
+ await testRequest({
873
286
  method: 'search',
287
+ event: 'event:directory.search',
288
+ dataPath: 'directoryEntities',
874
289
  resource: '/search/orgid/userOrgId/entities',
875
290
  params: {
876
291
  requestedTypes: ['PERSON', 'ROBOT'],
@@ -882,23 +297,6 @@ describe('plugin-dss', () => {
882
297
  resultSize: 100,
883
298
  queryString: 'query',
884
299
  },
885
- }).then(async ({requestId, promise}) => {
886
- mercuryCallbacks['event:directory.search'](
887
- createData(requestId, 2, true, 'directoryEntities', ['data2'])
888
- );
889
- mercuryCallbacks['event:directory.search'](
890
- createData(requestId, 0, false, 'directoryEntities', ['data0'])
891
- );
892
-
893
- promise.catch((err) => {
894
- expect(err.toString()).equal(
895
- 'DssTimeoutError: The DSS did not respond within 6000 ms.' +
896
- '\n Request Id: randomid' +
897
- '\n Resource: /search/orgid/userOrgId/entities' +
898
- '\n Params: {"queryString":"query","resultSize":100,"requestedTypes":["PERSON","ROBOT"]}'
899
- );
900
- });
901
- await clock.tickAsync(6000);
902
300
  });
903
301
  });
904
302
  });
@@ -906,7 +304,7 @@ describe('plugin-dss', () => {
906
304
  describe('#_request', () => {
907
305
  it('handles a request correctly', async () => {
908
306
  webex.request = sinon.stub();
909
- uuid.v4();
307
+ uuid.v4.returns('randomid');
910
308
  const promise = webex.internal.dss._request({
911
309
  resource: '/search/orgid/userOrgId/entities',
912
310
  params: {some: 'param'},
@@ -928,324 +326,36 @@ describe('plugin-dss', () => {
928
326
 
929
327
  webex.internal.dss.trigger(webex.internal.dss._getResultEventName('randomid'), {
930
328
  sequence: 1,
931
- a: {b: {c: ['data1']}},
932
- });
933
- webex.internal.dss.trigger(webex.internal.dss._getResultEventName('randomid'), {
934
- sequence: 2,
935
- finished: true,
936
- a: {b: {c: ['data2']}},
937
- });
938
- webex.internal.dss.trigger(webex.internal.dss._getResultEventName('randomid'), {
939
- sequence: 0,
940
- a: {b: {c: ['data0']}},
941
- });
942
-
943
- const result = await promise;
944
-
945
- expect(result).to.deep.equal({
946
- resultArray: ['data0', 'data1', 'data2'],
947
- });
948
- });
949
-
950
- it('handles a request with foundPath correctly', async () => {
951
- webex.request = sinon.stub();
952
- uuid.v4.returns('randomid');
953
- const promise = webex.internal.dss._request({
954
- resource: '/search/orgid/userOrgId/entities',
955
- params: {some: 'param'},
956
- dataPath: 'a.b.c',
957
- foundPath: 'someFoundPath',
958
- });
959
-
960
- expect(webex.request.getCall(0).args).to.deep.equal([
961
- {
962
- service: 'directorySearch',
963
- body: {
964
- requestId: 'randomid',
965
- some: 'param',
329
+ a: {
330
+ b: {
331
+ c: ['data1'],
966
332
  },
967
- contentType: 'application/json',
968
- method: 'POST',
969
- resource: '/search/orgid/userOrgId/entities',
970
333
  },
971
- ]);
972
-
973
- webex.internal.dss.trigger(webex.internal.dss._getResultEventName('randomid'), {
974
- sequence: 1,
975
- a: {b: {c: ['data1']}},
976
- someFoundPath: ['id1'],
977
334
  });
335
+
978
336
  webex.internal.dss.trigger(webex.internal.dss._getResultEventName('randomid'), {
979
337
  sequence: 2,
980
338
  finished: true,
981
- a: {b: {c: ['data2']}},
982
- someFoundPath: ['id2'],
983
- });
984
- webex.internal.dss.trigger(webex.internal.dss._getResultEventName('randomid'), {
985
- sequence: 0,
986
- a: {b: {c: ['data0']}},
987
- someFoundPath: ['id0'],
988
- });
989
-
990
- const result = await promise;
991
-
992
- expect(result).to.deep.equal({
993
- resultArray: ['data0', 'data1', 'data2'],
994
- foundArray: ['id0', 'id1', 'id2'],
995
- });
996
- });
997
-
998
- it('handles a request with foundPath and notFoundPath correctly', async () => {
999
- webex.request = sinon.stub();
1000
- uuid.v4.returns('randomid');
1001
- const promise = webex.internal.dss._request({
1002
- resource: '/search/orgid/userOrgId/entities',
1003
- params: {some: 'param'},
1004
- dataPath: 'a.b.c',
1005
- foundPath: 'someFoundPath',
1006
- notFoundPath: 'someNotFoundPath',
1007
- });
1008
-
1009
- expect(webex.request.getCall(0).args).to.deep.equal([
1010
- {
1011
- service: 'directorySearch',
1012
- body: {
1013
- requestId: 'randomid',
1014
- some: 'param',
339
+ a: {
340
+ b: {
341
+ c: ['data2'],
1015
342
  },
1016
- contentType: 'application/json',
1017
- method: 'POST',
1018
- resource: '/search/orgid/userOrgId/entities',
1019
343
  },
1020
- ]);
1021
-
1022
- webex.internal.dss.trigger(webex.internal.dss._getResultEventName('randomid'), {
1023
- sequence: 1,
1024
- a: {b: {c: ['data1']}},
1025
- someFoundPath: ['id1'],
1026
- });
1027
- webex.internal.dss.trigger(webex.internal.dss._getResultEventName('randomid'), {
1028
- sequence: 2,
1029
- finished: true,
1030
- a: {b: {c: ['data2']}},
1031
- someFoundPath: ['id2'],
1032
- someNotFoundPath: ['id3'],
1033
344
  });
345
+
1034
346
  webex.internal.dss.trigger(webex.internal.dss._getResultEventName('randomid'), {
1035
347
  sequence: 0,
1036
- a: {b: {c: ['data0']}},
1037
- someFoundPath: ['id0'],
1038
- });
1039
-
1040
- const result = await promise;
1041
-
1042
- expect(result).to.deep.equal({
1043
- resultArray: ['data0', 'data1', 'data2'],
1044
- foundArray: ['id0', 'id1', 'id2'],
1045
- notFoundArray: ['id3'],
1046
- });
1047
- });
1048
- });
1049
-
1050
- describe('#_batchedLookup', () => {
1051
- const checkStandardProperties = (batcher) => {
1052
- expect(batcher.dataPath).to.equal('lookupResult.entities');
1053
- expect(batcher.entitiesFoundPath).to.equal('lookupResult.entitiesFound');
1054
- expect(batcher.entitiesNotFoundPath).to.equal('lookupResult.entitiesNotFound');
1055
- expect(batcher.requestKey).to.equal('lookupValues');
1056
- expect(batcher.config).to.deep.equal({
1057
- batcherWait: 50,
1058
- batcherMaxCalls: 50,
1059
- batcherMaxWait: 150,
1060
- requestTimeout: 6000,
1061
- });
1062
- };
1063
-
1064
- it('calls batcher.request on new batcher for first lookup', async () => {
1065
- const resource = '/lookup/orgid/userOrgId/identities';
1066
- const response = 'response1';
1067
-
1068
- Batcher.prototype.request = sinon.stub().returns(Promise.resolve(response));
1069
-
1070
- expect(webex.internal.dss.batchers).to.deep.equal({});
1071
-
1072
- const result = await webex.internal.dss._batchedLookup({
1073
- resource,
1074
- lookupValue: 'id1',
1075
- });
1076
-
1077
- const batcher = webex.internal.dss.batchers[resource];
1078
-
1079
- expect(batcher).to.exist;
1080
- expect(batcher.resource).to.equal(resource);
1081
- checkStandardProperties(batcher);
1082
-
1083
- expect(Batcher.prototype.request.getCall(0).args).to.deep.equal(['id1']);
1084
- expect(result).to.equal(response);
1085
- });
1086
-
1087
- it('calls batcher.request on new batcher for lookup with new resource', async () => {
1088
- const resource1 = '/lookup/orgid/userOrgId/identities';
1089
- const resource2 = '/lookup/orgid/userOrgId/entityprovidertype/CI_USER';
1090
- const response1 = 'response1';
1091
- const response2 = 'response2';
1092
-
1093
- Batcher.prototype.request = sinon
1094
- .stub()
1095
- .onFirstCall()
1096
- .returns(Promise.resolve(response1))
1097
- .onSecondCall()
1098
- .returns(Promise.resolve(response2));
1099
-
1100
- expect(webex.internal.dss.batchers).to.deep.equal({});
1101
-
1102
- await webex.internal.dss._batchedLookup({
1103
- resource: resource1,
1104
- lookupValue: 'id1',
1105
- });
1106
-
1107
- const result = await webex.internal.dss._batchedLookup({
1108
- resource: resource2,
1109
- lookupValue: 'id2',
1110
- });
1111
-
1112
- expect(webex.internal.dss.batchers[resource1]).to.exist;
1113
- const batcher = webex.internal.dss.batchers[resource2];
1114
-
1115
- expect(batcher).to.exist;
1116
- expect(batcher.resource).to.equal(resource2);
1117
- checkStandardProperties(batcher);
1118
-
1119
- expect(Batcher.prototype.request.getCall(1).args).to.deep.equal(['id2']);
1120
- expect(result).to.equal(response2);
1121
- });
1122
-
1123
- it('calls batcher.request on existing batcher for lookup with existing reource', async () => {
1124
- const resource1 = '/lookup/orgid/userOrgId/identities';
1125
- const response1 = 'response1';
1126
- const response2 = 'response2';
1127
-
1128
- Batcher.prototype.request = sinon
1129
- .stub()
1130
- .onFirstCall()
1131
- .returns(Promise.resolve(response1))
1132
- .onSecondCall()
1133
- .returns(Promise.resolve(response2));
1134
-
1135
- expect(webex.internal.dss.batchers).to.deep.equal({});
1136
-
1137
- await webex.internal.dss._batchedLookup({
1138
- resource: resource1,
1139
- lookupValue: 'id1',
1140
- });
1141
- expect(webex.internal.dss.batchers[resource1]).to.exist;
1142
- const initialBatcher = webex.internal.dss.batchers[resource1];
1143
-
1144
- const result = await webex.internal.dss._batchedLookup({
1145
- resource: resource1,
1146
- lookupValue: 'id2',
1147
- });
1148
-
1149
- const batcher = webex.internal.dss.batchers[resource1];
1150
-
1151
- expect(batcher).to.equal(initialBatcher);
1152
- expect(batcher.resource).to.equal(resource1);
1153
- checkStandardProperties(batcher);
1154
-
1155
- expect(Batcher.prototype.request.getCall(1).args).to.deep.equal(['id2']);
1156
- expect(result).to.equal(response2);
1157
- });
1158
- // TODO
1159
- it.skip('fails fails when mercury does not respond, later batches can still pass ok', async () => {
1160
- // Batch 1
1161
- const {
1162
- promises: [p1, p2, p3],
1163
- } = await testMakeBatchedRequests({
1164
- requests: [
1165
- {
1166
- id: 'req-id-1',
1167
- resource: '/lookup/orgid/userOrgId/identities',
1168
- bodyParams: {lookupValues: ['id1', 'id2', 'id3']},
1169
- },
1170
- ],
1171
- calls: [
1172
- {
1173
- method: 'lookup',
1174
- params: {id: 'id1', shouldBatch: true},
1175
- },
1176
- {
1177
- method: 'lookup',
1178
- params: {id: 'id2', shouldBatch: true},
1179
- },
1180
- {
1181
- method: 'lookup',
1182
- params: {id: 'id3', shouldBatch: true},
1183
- },
1184
- ],
1185
- });
1186
-
1187
- // Batch 2
1188
- const {
1189
- promises: [p4],
1190
- } = await testMakeBatchedRequests({
1191
- requests: [
1192
- {
1193
- id: 'randomid',
1194
- resource: '/lookup/orgid/userOrgId/identities',
1195
- bodyParams: {lookupValues: ['id4']},
348
+ a: {
349
+ b: {
350
+ c: ['data0'],
1196
351
  },
1197
- ],
1198
- calls: [
1199
- {
1200
- method: 'lookup',
1201
- params: {id: 'id4', shouldBatch: true},
1202
- },
1203
- ],
352
+ },
1204
353
  });
1205
354
 
1206
- // Batch 1 - only 1 mercury response out of 2 received
1207
- mercuryCallbacks['event:directory.lookup'](
1208
- createData('req-id-1', 0, false, 'lookupResult', {
1209
- entitiesFound: ['id1', 'id3'],
1210
- entities: ['data1', 'data3'],
1211
- })
1212
- );
1213
-
1214
- // Batch 2 - response
1215
- mercuryCallbacks['event:directory.lookup'](
1216
- createData('randomid', 0, true, 'lookupResult', {entitiesNotFound: ['id4']})
1217
- );
1218
-
1219
- // Timeout
1220
- await clock.tickAsync(6000);
1221
-
1222
- return Promise.all([
1223
- assert.isRejected(
1224
- p1,
1225
- 'The DSS did not respond within 6000 ms.' +
1226
- '\n Request Id: req-id-1' +
1227
- '\n Resource: /lookup/orgid/userOrgId/identities' +
1228
- '\n Params: {"lookupValues":["id1","id2","id3"]}'
1229
- ),
1230
- assert.isRejected(
1231
- p2,
1232
- 'The DSS did not respond within 6000 ms.' +
1233
- '\n Request Id: req-id-1' +
1234
- '\n Resource: /lookup/orgid/userOrgId/identities' +
1235
- '\n Params: {"lookupValues":["id1","id2","id3"]}'
1236
- ),
1237
- assert.isRejected(
1238
- p3,
1239
- 'The DSS did not respond within 6000 ms.' +
1240
- '\n Request Id: req-id-1' +
1241
- '\n Resource: /lookup/orgid/userOrgId/identities' +
1242
- '\n Params: {"lookupValues":["id1","id2","id3"]}'
1243
- ),
1244
- assert.isFulfilled(p4),
1245
- ]);
355
+ const result = await promise;
356
+ expect(result).to.deep.equal(['data0', 'data1', 'data2']);
1246
357
  });
1247
358
  });
1248
-
1249
359
  describe('#searchPlaces', () => {
1250
360
  it('calls _request correctly', async () => {
1251
361
  webex.internal.device.orgId = 'userOrgId';
@@ -1271,8 +381,10 @@ describe('plugin-dss', () => {
1271
381
  });
1272
382
 
1273
383
  it('works correctly', async () => {
1274
- await testMakeRequest({
384
+ await testRequest({
1275
385
  method: 'searchPlaces',
386
+ event: 'event:directory.search',
387
+ dataPath: 'directoryEntities',
1276
388
  resource: '/search/orgid/userOrgId/places',
1277
389
  params: {
1278
390
  isOnlySchedulableRooms: true,
@@ -1286,6 +398,6 @@ describe('plugin-dss', () => {
1286
398
  },
1287
399
  });
1288
400
  });
1289
- });
401
+ });
1290
402
  });
1291
403
  });