@webex/internal-plugin-ediscovery 2.59.2 → 2.59.3-next.1

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,1084 +1,1084 @@
1
- import EDiscovery from '@webex/internal-plugin-ediscovery';
2
- import MockWebex from '@webex/test-helper-mock-webex';
3
- import sinon from 'sinon';
4
- import {assert, expect} from '@webex/test-helper-chai';
5
- import config from '@webex/internal-plugin-ediscovery/src/config';
6
-
7
- /* eslint-disable max-len */
8
- describe('EDiscovery Content API Tests', () => {
9
- let webex;
10
- const uuid = 'cc06f622-46ab-45b9-b3a6-5d70bad1d70a';
11
- const url =
12
- 'https://ediscovery-intb.wbx2.com/ediscovery/api/v1/reports/cc06f622-46ab-45b9-b3a6-5d70bad1d70a';
13
- const invalidUrl = 'https://ediscovery-intb.wbx2.com/ediscovery/api/v1/reports/';
14
- const defaultTimeout = 30000;
15
-
16
- beforeEach(() => {
17
- webex = new MockWebex({
18
- children: {
19
- ediscovery: EDiscovery,
20
- },
21
- });
22
- webex.config.ediscovery = config.ediscovery;
23
- });
24
-
25
- describe('GetContent Tests', () => {
26
- it('GetContent succeeds', async () => {
27
- const result = webex.internal.ediscovery
28
- .getContent(uuid, {offset: 0, size: 1})
29
- .then((res) => {
30
- expect(res.statusCode).equal(200);
31
- });
32
-
33
- return result;
34
- });
35
-
36
- it('GetContent fails with no params', async () => {
37
- const result = expect(webex.internal.ediscovery.getContent()).to.be.rejectedWith(
38
- Error,
39
- 'Undefined parameter'
40
- );
41
-
42
- return result;
43
- });
44
-
45
- it('GetContent timeout defaults to 30s', async () => {
46
- const result = webex.internal.ediscovery.getContent(uuid).then(() => {
47
- sinon.assert.calledWith(webex.request, sinon.match.has('timeout', defaultTimeout));
48
- });
49
-
50
- return result;
51
- });
52
-
53
- it('GetContent timeout defaults to 30s when other options are specified', async () => {
54
- const result = webex.internal.ediscovery.getContent(uuid, {offset: 0, size: 1}).then(() => {
55
- sinon.assert.calledWith(webex.request, sinon.match.has('timeout', defaultTimeout));
56
- });
57
-
58
- return result;
59
- });
60
-
61
- it('GetContent timeout can be overwritten to 5s with timeout as the only option', async () => {
62
- const result = webex.internal.ediscovery.getContent(uuid, {timeoutMs: 5000}).then(() => {
63
- sinon.assert.calledWith(webex.request, sinon.match.has('timeout', 5000));
64
- });
65
-
66
- return result;
67
- });
68
-
69
- it('GetContent timeout can be overwritten to 5s when other options are specified', async () => {
70
- const result = webex.internal.ediscovery
71
- .getContent(uuid, {offset: 0, size: 1, timeoutMs: 5000})
72
- .then(() => {
73
- sinon.assert.calledWith(webex.request, sinon.match.has('timeout', 5000));
74
- sinon.assert.calledWith(webex.request, sinon.match.has('qs', {offset: 0, size: 1}));
75
- });
76
-
77
- return result;
78
- });
79
-
80
- it('GetContent makes one request when called multiple times with identical params', async () => {
81
- webex.internal.ediscovery.getContent(uuid, {offset: 0, size: 1, timeoutMs: 5000});
82
- webex.internal.ediscovery.getContent(uuid, {offset: 0, size: 1, timeoutMs: 5000});
83
- const result = webex.internal.ediscovery
84
- .getContent(uuid, {offset: 0, size: 1, timeoutMs: 5000})
85
- .then(() => {
86
- sinon.assert.calledOnce(webex.request);
87
- });
88
-
89
- return result;
90
- });
91
-
92
- it('GetContent makes multiple requests when called multiple times with different params', async () => {
93
- webex.internal.ediscovery.getContent(uuid, {offset: 0, size: 1, timeoutMs: 5000});
94
- webex.internal.ediscovery.getContent(uuid, {offset: 1, size: 1, timeoutMs: 5000});
95
- const result = webex.internal.ediscovery
96
- .getContent(uuid, {offset: 0, size: 2, timeoutMs: 5000})
97
- .then(() => {
98
- sinon.assert.calledThrice(webex.request);
99
- });
100
-
101
- return result;
102
- });
103
- });
104
-
105
- describe('GetContent by url Tests', () => {
106
- it('GetContent by url succeeds', async () => {
107
- const result = webex.internal.ediscovery.getContent(url, {offset: 0, size: 1}).then((res) => {
108
- expect(res.statusCode).equal(200);
109
- });
110
-
111
- return result;
112
- });
113
-
114
- it('GetContent by url fails with no params', async () => {
115
- const result = expect(webex.internal.ediscovery.getContent()).to.be.rejectedWith(
116
- Error,
117
- 'Undefined parameter'
118
- );
119
-
120
- return result;
121
- });
122
-
123
- it('GetContent by url fails with a url that does not contain a report id', async () => {
124
- const result = expect(webex.internal.ediscovery.getContent(invalidUrl)).to.be.rejectedWith(
125
- Error,
126
- 'Report url does not contain a report id'
127
- );
128
-
129
- return result;
130
- });
131
-
132
- it('GetContent by url timeout defaults to 30s', async () => {
133
- const result = webex.internal.ediscovery.getContent(url).then(() => {
134
- sinon.assert.calledWith(webex.request, sinon.match.has('timeout', defaultTimeout));
135
- });
136
-
137
- return result;
138
- });
139
-
140
- it('GetContent by url timeout defaults to 30s when other options are specified', async () => {
141
- const result = webex.internal.ediscovery.getContent(url, {offset: 0, size: 1}).then(() => {
142
- sinon.assert.calledWith(webex.request, sinon.match.has('timeout', defaultTimeout));
143
- });
144
-
145
- return result;
146
- });
147
-
148
- it('GetContent by url timeout can be overwritten to 5s with timeout as the only option', async () => {
149
- const result = webex.internal.ediscovery.getContent(url, {timeoutMs: 5000}).then(() => {
150
- sinon.assert.calledWith(webex.request, sinon.match.has('timeout', 5000));
151
- });
152
-
153
- return result;
154
- });
155
-
156
- it('GetContent by url timeout can be overwritten to 5s when other options are specified', async () => {
157
- const result = webex.internal.ediscovery
158
- .getContent(url, {offset: 0, size: 1, timeoutMs: 5000})
159
- .then(() => {
160
- sinon.assert.calledWith(webex.request, sinon.match.has('timeout', 5000));
161
- sinon.assert.calledWith(webex.request, sinon.match.has('qs', {offset: 0, size: 1}));
162
- });
163
-
164
- return result;
165
- });
166
-
167
- it('GetContent by url makes one request when called multiple times with identical params', async () => {
168
- webex.internal.ediscovery.getContent(url, {offset: 0, size: 1, timeoutMs: 5000});
169
- webex.internal.ediscovery.getContent(url, {offset: 0, size: 1, timeoutMs: 5000});
170
- const result = webex.internal.ediscovery
171
- .getContent(url, {offset: 0, size: 1, timeoutMs: 5000})
172
- .then(() => {
173
- sinon.assert.calledOnce(webex.request);
174
- });
175
-
176
- return result;
177
- });
178
-
179
- it('GetContent by url makes multiple requests when called multiple times with different params', async () => {
180
- webex.internal.ediscovery.getContent(url, {offset: 0, size: 1, timeoutMs: 5000});
181
- webex.internal.ediscovery.getContent(url, {offset: 1, size: 1, timeoutMs: 5000});
182
- const result = webex.internal.ediscovery
183
- .getContent(url, {offset: 0, size: 2, timeoutMs: 5000})
184
- .then(() => {
185
- sinon.assert.calledThrice(webex.request);
186
- });
187
-
188
- return result;
189
- });
190
- });
191
-
192
- describe('GetContentContainer Tests', () => {
193
- it('GetContentContainer succeeds', async () => {
194
- const result = webex.internal.ediscovery
195
- .getContentContainer(uuid, {offset: 0, size: 1})
196
- .then((res) => {
197
- expect(res.statusCode).equal(200);
198
- });
199
-
200
- return result;
201
- });
202
-
203
- it('GetContentContainer fails with no params', async () => {
204
- const result = expect(webex.internal.ediscovery.getContentContainer()).to.be.rejectedWith(
205
- Error,
206
- 'Undefined parameter'
207
- );
208
-
209
- return result;
210
- });
211
-
212
- it('GetContentContainer timeout defaults to 30s', async () => {
213
- const result = webex.internal.ediscovery.getContentContainer(uuid).then(() => {
214
- sinon.assert.calledWith(webex.request, sinon.match.has('timeout', defaultTimeout));
215
- });
216
-
217
- return result;
218
- });
219
-
220
- it('GetContentContainer timeout defaults to 30s when other options are specified', async () => {
221
- const result = webex.internal.ediscovery
222
- .getContentContainer(uuid, {offset: 0, size: 1})
223
- .then(() => {
224
- sinon.assert.calledWith(webex.request, sinon.match.has('timeout', defaultTimeout));
225
- });
226
-
227
- return result;
228
- });
229
-
230
- it('GetContentContainer timeout can be overwritten to 5s with timeout as the only option', async () => {
231
- const result = webex.internal.ediscovery
232
- .getContentContainer(uuid, {timeoutMs: 5000})
233
- .then(() => {
234
- sinon.assert.calledWith(webex.request, sinon.match.has('timeout', 5000));
235
- });
236
-
237
- return result;
238
- });
239
-
240
- it('GetContentContainer timeout can be overwritten to 5s when other options are specified', async () => {
241
- const result = webex.internal.ediscovery
242
- .getContentContainer(uuid, {
243
- offset: 0,
244
- size: 1,
245
- timeoutMs: 5000,
246
- types: [],
247
- })
248
- .then(() => {
249
- sinon.assert.calledWith(webex.request, sinon.match.has('timeout', 5000));
250
- sinon.assert.calledWith(webex.request, sinon.match.has('types', []));
251
- sinon.assert.calledWith(webex.request, sinon.match.has('qs', {offset: 0, size: 1}));
252
- });
253
-
254
- return result;
255
- });
256
-
257
- it('GetContentContainer makes one request when called multiple times with identical params', async () => {
258
- webex.internal.ediscovery.getContentContainer(uuid, {
259
- offset: 0,
260
- size: 1,
261
- timeoutMs: 5000,
262
- types: [],
263
- });
264
- webex.internal.ediscovery.getContentContainer(uuid, {
265
- offset: 0,
266
- size: 1,
267
- timeoutMs: 5000,
268
- types: [],
269
- });
270
- const result = webex.internal.ediscovery
271
- .getContentContainer(uuid, {
272
- offset: 0,
273
- size: 1,
274
- timeoutMs: 5000,
275
- types: [],
276
- })
277
- .then(() => {
278
- sinon.assert.calledOnce(webex.request);
279
- });
280
-
281
- return result;
282
- });
283
-
284
- it('GetContentContainer makes multiple requests when called multiple times with different params', async () => {
285
- webex.internal.ediscovery.getContentContainer(uuid, {
286
- offset: 0,
287
- size: 1,
288
- timeoutMs: 5000,
289
- types: ['MEETING'],
290
- });
291
- webex.internal.ediscovery.getContentContainer(uuid, {
292
- offset: 0,
293
- size: 1,
294
- timeoutMs: 5000,
295
- types: ['SPACE'],
296
- });
297
- const result = webex.internal.ediscovery
298
- .getContentContainer(uuid, {
299
- offset: 0,
300
- size: 1,
301
- timeoutMs: 5000,
302
- types: undefined,
303
- })
304
- .then(() => {
305
- sinon.assert.calledThrice(webex.request);
306
- });
307
-
308
- return result;
309
- });
310
-
311
- it('GetContentContainer sets report in contentContainerCache if it does not exist', async () => {
312
- const mockResponse = {body: [{containerId: uuid}]};
313
-
314
- webex.internal.ediscovery.request = sinon.stub().resolves(mockResponse);
315
-
316
- webex.internal.ediscovery.contentContainerCache = {
317
- set: sinon.stub(),
318
- has: sinon.stub().returns(false),
319
- clear: sinon.stub(),
320
- };
321
- const result = webex.internal.ediscovery
322
- .getContentContainer(uuid, {offset: 0, size: 1})
323
- .then(() => {
324
- assert.calledWith(webex.internal.ediscovery.contentContainerCache.has, uuid);
325
- assert.calledWith(webex.internal.ediscovery.contentContainerCache.set, uuid, new Map());
326
- });
327
-
328
- return result;
329
- });
330
-
331
- it('GetContentContainer does not retrieve container from contentContainerCache if available', async () => {
332
- const mockCachedContainer = {containerId: uuid};
333
- const containerIdMap = {
334
- get: sinon.stub().withArgs(uuid).returns(mockCachedContainer),
335
- set: sinon.stub(),
336
- has: sinon.stub().returns(true),
337
- };
338
-
339
- webex.internal.ediscovery.contentContainerCache = {
340
- get: sinon.stub().withArgs(uuid).returns(containerIdMap),
341
- set: sinon.stub(),
342
- has: sinon.stub().returns(true),
343
- clear: sinon.stub(),
344
- };
345
- const result = webex.internal.ediscovery
346
- .getContentContainer(uuid, {offset: 0, size: 1})
347
- .then((res) => {
348
- expect(res).to.not.equal(mockCachedContainer);
349
- assert.callCount(webex.internal.ediscovery.contentContainerCache.has, 0);
350
- assert.callCount(containerIdMap.has, 0);
351
- assert.callCount(containerIdMap.get, 0);
352
- });
353
-
354
- return result;
355
- });
356
-
357
- it('GetContentContainer populates contentContainerCache with container when retrieved', async () => {
358
- const mockResponse = {body: [{containerId: uuid}]};
359
-
360
- webex.internal.ediscovery.request = sinon.stub().resolves(mockResponse);
361
-
362
- const containerIdMap = {
363
- set: sinon.stub(),
364
- has: sinon.stub().returns(false),
365
- };
366
-
367
- webex.internal.ediscovery.contentContainerCache = {
368
- get: sinon.stub().withArgs(uuid).returns(containerIdMap),
369
- has: sinon.stub().returns(true),
370
- clear: sinon.stub(),
371
- };
372
- const result = webex.internal.ediscovery
373
- .getContentContainer(uuid, {offset: 0, size: 1})
374
- .then((res) => {
375
- expect(res).to.equal(mockResponse);
376
- assert.callCount(webex.internal.ediscovery.contentContainerCache.has, 1);
377
- assert.calledWith(
378
- containerIdMap.set,
379
- mockResponse.body[0].containerId,
380
- mockResponse.body[0]
381
- );
382
- });
383
-
384
- return result;
385
- });
386
- });
387
-
388
- describe('GetContentContainer by url Tests', () => {
389
- it('GetContentContainer succeeds', async () => {
390
- const result = webex.internal.ediscovery
391
- .getContentContainer(url, {offset: 0, size: 1})
392
- .then((res) => {
393
- expect(res.statusCode).equal(200);
394
- });
395
-
396
- return result;
397
- });
398
-
399
- it('GetContentContainer by url fails with no params', async () => {
400
- const result = expect(webex.internal.ediscovery.getContentContainer()).to.be.rejectedWith(
401
- Error,
402
- 'Undefined parameter'
403
- );
404
-
405
- return result;
406
- });
407
-
408
- it('GetContentContainer by url fails with a url that does not contain a report id', async () => {
409
- const result = expect(
410
- webex.internal.ediscovery.getContentContainer(invalidUrl)
411
- ).to.be.rejectedWith(Error, 'Report url does not contain a report id');
412
-
413
- return result;
414
- });
415
-
416
- it('GetContentContainer by url timeout defaults to 30s', async () => {
417
- const result = webex.internal.ediscovery.getContentContainer(url).then(() => {
418
- sinon.assert.calledWith(webex.request, sinon.match.has('timeout', defaultTimeout));
419
- });
420
-
421
- return result;
422
- });
423
-
424
- it('GetContentContainer by url timeout defaults to 30s when other options are specified', async () => {
425
- const result = webex.internal.ediscovery
426
- .getContentContainer(url, {offset: 0, size: 1})
427
- .then(() => {
428
- sinon.assert.calledWith(webex.request, sinon.match.has('timeout', defaultTimeout));
429
- });
430
-
431
- return result;
432
- });
433
-
434
- it('GetContentContainer by url timeout can be overwritten to 5s with timeout as the only option', async () => {
435
- const result = webex.internal.ediscovery
436
- .getContentContainer(url, {timeoutMs: 5000})
437
- .then(() => {
438
- sinon.assert.calledWith(webex.request, sinon.match.has('timeout', 5000));
439
- });
440
-
441
- return result;
442
- });
443
-
444
- it('GetContentContainer by url timeout can be overwritten to 5s when other options are specified', async () => {
445
- const result = webex.internal.ediscovery
446
- .getContentContainer(url, {offset: 0, size: 1, timeoutMs: 5000})
447
- .then(() => {
448
- sinon.assert.calledWith(webex.request, sinon.match.has('timeout', 5000));
449
- sinon.assert.calledWith(webex.request, sinon.match.has('qs', {offset: 0, size: 1}));
450
- });
451
-
452
- return result;
453
- });
454
-
455
- it('GetContentContainer by url makes one request when called multiple times with identical params', async () => {
456
- webex.internal.ediscovery.getContentContainer(url, {
457
- offset: 0,
458
- size: 1,
459
- timeoutMs: 5000,
460
- types: [],
461
- });
462
- webex.internal.ediscovery.getContentContainer(url, {
463
- offset: 0,
464
- size: 1,
465
- timeoutMs: 5000,
466
- types: [],
467
- });
468
- const result = webex.internal.ediscovery
469
- .getContentContainer(url, {
470
- offset: 0,
471
- size: 1,
472
- timeoutMs: 5000,
473
- types: [],
474
- })
475
- .then(() => {
476
- sinon.assert.calledOnce(webex.request);
477
- });
478
-
479
- return result;
480
- });
481
-
482
- it('GetContentContainer by url makes multiple requests when called multiple times with different types', async () => {
483
- webex.internal.ediscovery.getContentContainer(url, {
484
- offset: 0,
485
- size: 1,
486
- timeoutMs: 5000,
487
- types: ['MEETING'],
488
- });
489
- webex.internal.ediscovery.getContentContainer(url, {
490
- offset: 0,
491
- size: 1,
492
- timeoutMs: 5000,
493
- types: ['SPACE'],
494
- });
495
- const result = webex.internal.ediscovery
496
- .getContentContainer(url, {
497
- offset: 0,
498
- size: 1,
499
- timeoutMs: 5000,
500
- types: undefined,
501
- })
502
- .then(() => {
503
- sinon.assert.calledThrice(webex.request);
504
- });
505
-
506
- return result;
507
- });
508
-
509
- it('GetContentContainer by url sets report in contentContainerCache if it does not exist', async () => {
510
- const mockResponse = {body: [{containerId: uuid}]};
511
-
512
- webex.internal.ediscovery.request = sinon.stub().resolves(mockResponse);
513
-
514
- webex.internal.ediscovery.contentContainerCache = {
515
- set: sinon.stub(),
516
- has: sinon.stub().returns(false),
517
- clear: sinon.stub(),
518
- };
519
- const result = webex.internal.ediscovery
520
- .getContentContainer(url, {offset: 0, size: 1})
521
- .then(() => {
522
- assert.calledWith(webex.internal.ediscovery.contentContainerCache.has, uuid);
523
- assert.calledWith(webex.internal.ediscovery.contentContainerCache.set, uuid, new Map());
524
- });
525
-
526
- return result;
527
- });
528
-
529
- it('GetContentContainer by url does not retrieve container from contentContainerCache if available', async () => {
530
- const mockCachedContainer = {containerId: uuid};
531
- const containerIdMap = {
532
- get: sinon.stub().withArgs(uuid).returns(mockCachedContainer),
533
- set: sinon.stub(),
534
- has: sinon.stub().returns(true),
535
- };
536
-
537
- webex.internal.ediscovery.contentContainerCache = {
538
- get: sinon.stub().withArgs(uuid).returns(containerIdMap),
539
- set: sinon.stub(),
540
- has: sinon.stub().returns(true),
541
- clear: sinon.stub(),
542
- };
543
- const result = webex.internal.ediscovery
544
- .getContentContainer(url, {offset: 0, size: 1})
545
- .then((res) => {
546
- expect(res).to.not.equal(mockCachedContainer);
547
- assert.callCount(webex.internal.ediscovery.contentContainerCache.has, 0);
548
- assert.callCount(containerIdMap.has, 0);
549
- assert.callCount(containerIdMap.get, 0);
550
- });
551
-
552
- return result;
553
- });
554
-
555
- it('GetContentContainer by url populates contentContainerCache with container when retrieved', async () => {
556
- const mockResponse = {body: [{containerId: uuid}]};
557
-
558
- webex.internal.ediscovery.request = sinon.stub().resolves(mockResponse);
559
-
560
- const containerIdMap = {
561
- set: sinon.stub(),
562
- has: sinon.stub().returns(false),
563
- };
564
-
565
- webex.internal.ediscovery.contentContainerCache = {
566
- get: sinon.stub().withArgs(uuid).returns(containerIdMap),
567
- has: sinon.stub().returns(true),
568
- clear: sinon.stub(),
569
- };
570
- const result = webex.internal.ediscovery
571
- .getContentContainer(url, {offset: 0, size: 1})
572
- .then((res) => {
573
- expect(res).to.equal(mockResponse);
574
- assert.callCount(webex.internal.ediscovery.contentContainerCache.has, 1);
575
- assert.calledWith(
576
- containerIdMap.set,
577
- mockResponse.body[0].containerId,
578
- mockResponse.body[0]
579
- );
580
- });
581
-
582
- return result;
583
- });
584
- });
585
-
586
- describe('GetContentContainerByContainerId Tests', () => {
587
- it('GetContentContainerByContainerId succeeds', async () => {
588
- const result = webex.internal.ediscovery
589
- .getContentContainerByContainerId(uuid, uuid)
590
- .then((res) => {
591
- expect(res).to.not.equal(undefined);
592
- });
593
-
594
- return result;
595
- });
596
-
597
- it('GetContentContainerByContainerId fails with no params', async () => {
598
- const result = expect(
599
- webex.internal.ediscovery.getContentContainerByContainerId()
600
- ).to.be.rejectedWith(Error, 'Undefined parameter');
601
-
602
- return result;
603
- });
604
-
605
- it('GetContentContainerByContainerId timeout defaults to 30s', async () => {
606
- const result = webex.internal.ediscovery
607
- .getContentContainerByContainerId(uuid, uuid)
608
- .then(() => {
609
- sinon.assert.calledWith(webex.request, sinon.match.has('timeout', defaultTimeout));
610
- });
611
-
612
- return result;
613
- });
614
-
615
- it('GetContentContainerByContainerId timeout can be overwritten to 5s with timeout as the only option', async () => {
616
- const result = webex.internal.ediscovery
617
- .getContentContainerByContainerId(uuid, uuid, {timeoutMs: 5000})
618
- .then(() => {
619
- sinon.assert.calledWith(webex.request, sinon.match.has('timeout', 5000));
620
- });
621
-
622
- return result;
623
- });
624
-
625
- it('GetContentContainerByContainerId makes one request when called multiple times with identical params', async () => {
626
- webex.internal.ediscovery.getContentContainerByContainerId(uuid, uuid, {timeoutMs: 5000});
627
- webex.internal.ediscovery.getContentContainerByContainerId(uuid, uuid, {timeoutMs: 5000});
628
- const result = webex.internal.ediscovery
629
- .getContentContainerByContainerId(uuid, uuid, {timeoutMs: 5000})
630
- .then(() => {
631
- sinon.assert.calledOnce(webex.request);
632
- });
633
-
634
- return result;
635
- });
636
-
637
- it('GetContentContainerByContainerId makes multiple requests when called multiple times with different params', async () => {
638
- webex.internal.ediscovery.getContentContainerByContainerId(
639
- uuid,
640
- '0d4084ce-8cef-43fd-9313-fb64579996ba',
641
- {timeoutMs: 5000}
642
- );
643
- webex.internal.ediscovery.getContentContainerByContainerId(
644
- uuid,
645
- '089fcf55-3f38-4763-a441-b1c3540404cf',
646
- {timeoutMs: 5000}
647
- );
648
- const result = webex.internal.ediscovery
649
- .getContentContainerByContainerId(uuid, uuid, {timeoutMs: 5000})
650
- .then(() => {
651
- sinon.assert.calledThrice(webex.request);
652
- });
653
-
654
- return result;
655
- });
656
-
657
- it('GetContentContainerByContainerId sets report in contentContainerCache if it does not exist', async () => {
658
- const mockResponse = {body: {containerId: uuid}};
659
-
660
- webex.internal.ediscovery.request = sinon.stub().resolves(mockResponse);
661
-
662
- webex.internal.ediscovery.contentContainerCache = {
663
- set: sinon.stub(),
664
- has: sinon.stub().returns(false),
665
- clear: sinon.stub(),
666
- };
667
- const result = webex.internal.ediscovery
668
- .getContentContainerByContainerId(uuid, uuid)
669
- .then(() => {
670
- assert.calledWith(webex.internal.ediscovery.contentContainerCache.has, uuid);
671
- assert.calledWith(webex.internal.ediscovery.contentContainerCache.set, uuid, new Map());
672
- });
673
-
674
- return result;
675
- });
676
-
677
- it('GetContentContainerByContainerId retrieves container from contentContainerCache if available', async () => {
678
- const mockCachedContainer = {containerId: uuid};
679
-
680
- const containerIdMap = {
681
- get: sinon.stub().withArgs(uuid).returns(mockCachedContainer),
682
- set: sinon.stub(),
683
- has: sinon.stub().returns(true),
684
- };
685
-
686
- webex.internal.ediscovery.contentContainerCache = {
687
- get: sinon.stub().withArgs(uuid).returns(containerIdMap),
688
- set: sinon.stub(),
689
- has: sinon.stub().returns(true),
690
- clear: sinon.stub(),
691
- };
692
- const result = webex.internal.ediscovery
693
- .getContentContainerByContainerId(uuid, uuid)
694
- .then((res) => {
695
- expect(res.body).to.equal(mockCachedContainer);
696
- assert.callCount(webex.internal.ediscovery.contentContainerCache.has, 1);
697
- assert.callCount(containerIdMap.has, 1);
698
- assert.callCount(containerIdMap.get, 1);
699
- });
700
-
701
- return result;
702
- });
703
-
704
- it('GetContentContainerByContainerId populates contentContainerCache with container when retrieved', async () => {
705
- const mockResponse = {body: {containerId: uuid}};
706
-
707
- webex.internal.ediscovery.request = sinon.stub().resolves(mockResponse);
708
-
709
- const containerIdMap = {
710
- set: sinon.stub(),
711
- has: sinon.stub().returns(false),
712
- };
713
-
714
- webex.internal.ediscovery.contentContainerCache = {
715
- get: sinon.stub().withArgs(uuid).returns(containerIdMap),
716
- set: sinon.stub(),
717
- has: sinon.stub().returns(true),
718
- clear: sinon.stub(),
719
- };
720
- const result = webex.internal.ediscovery
721
- .getContentContainerByContainerId(uuid, uuid)
722
- .then((res) => {
723
- expect(res).to.equal(mockResponse);
724
- assert.callCount(webex.internal.ediscovery.contentContainerCache.has, 2);
725
- assert.callCount(containerIdMap.has, 1);
726
- assert.calledWith(containerIdMap.set, mockResponse.body.containerId, mockResponse.body);
727
- });
728
-
729
- return result;
730
- });
731
-
732
- it('GetContentContainerByContainerId cannot write container to contentContainerCache without containerId', async () => {
733
- const mockResponse = {body: {}};
734
-
735
- webex.internal.ediscovery.request = sinon.stub().resolves(mockResponse);
736
-
737
- const containerIdMap = {
738
- set: sinon.stub(),
739
- has: sinon.stub().returns(false),
740
- };
741
-
742
- webex.internal.ediscovery.contentContainerCache = {
743
- get: sinon.stub().withArgs(uuid).returns(containerIdMap),
744
- set: sinon.stub(),
745
- has: sinon.stub().returns(true),
746
- clear: sinon.stub(),
747
- };
748
- const result = webex.internal.ediscovery
749
- .getContentContainerByContainerId(uuid, uuid)
750
- .then((res) => {
751
- expect(res).to.equal(mockResponse);
752
- assert.callCount(webex.internal.ediscovery.contentContainerCache.has, 2);
753
- assert.callCount(containerIdMap.has, 1);
754
- assert.notCalled(containerIdMap.set);
755
- });
756
-
757
- return result;
758
- });
759
- });
760
-
761
- describe('GetContentContainerByContainerId by url Tests', () => {
762
- it('GetContentContainerByContainerId by url succeeds', async () => {
763
- const result = webex.internal.ediscovery
764
- .getContentContainerByContainerId(url, uuid)
765
- .then((res) => {
766
- expect(res).to.not.equal(undefined);
767
- });
768
-
769
- return result;
770
- });
771
-
772
- it('GetContentContainerByContainerId by url fails with no params', async () => {
773
- const result = expect(
774
- webex.internal.ediscovery.getContentContainerByContainerId()
775
- ).to.be.rejectedWith(Error, 'Undefined parameter');
776
-
777
- return result;
778
- });
779
-
780
- it('GetContentContainerByContainerId by url fails with a url that does not contain a report id', async () => {
781
- const result = expect(
782
- webex.internal.ediscovery.getContentContainerByContainerId(invalidUrl, uuid)
783
- ).to.be.rejectedWith(Error, 'Report url does not contain a report id');
784
-
785
- return result;
786
- });
787
-
788
- it('GetContentContainerByContainerId by url timeout defaults to 30s', async () => {
789
- const result = webex.internal.ediscovery
790
- .getContentContainerByContainerId(url, uuid)
791
- .then(() => {
792
- sinon.assert.calledWith(webex.request, sinon.match.has('timeout', defaultTimeout));
793
- });
794
-
795
- return result;
796
- });
797
-
798
- it('GetContentContainerByContainerId by url timeout can be overwritten to 5s with timeout as the only option', async () => {
799
- const result = webex.internal.ediscovery
800
- .getContentContainerByContainerId(url, uuid, {timeoutMs: 5000})
801
- .then(() => {
802
- sinon.assert.calledWith(webex.request, sinon.match.has('timeout', 5000));
803
- });
804
-
805
- return result;
806
- });
807
-
808
- it('GetContentContainerByContainerId by url makes one request when called multiple times with identical params', async () => {
809
- webex.internal.ediscovery.getContentContainerByContainerId(url, uuid, {timeoutMs: 5000});
810
- webex.internal.ediscovery.getContentContainerByContainerId(url, uuid, {timeoutMs: 5000});
811
- const result = webex.internal.ediscovery
812
- .getContentContainerByContainerId(url, uuid, {timeoutMs: 5000})
813
- .then(() => {
814
- sinon.assert.calledOnce(webex.request);
815
- });
816
-
817
- return result;
818
- });
819
-
820
- it('GetContentContainerByContainerId by url makes multiple requests when called multiple times with different params', async () => {
821
- webex.internal.ediscovery.getContentContainerByContainerId(
822
- url,
823
- '0d4084ce-8cef-43fd-9313-fb64579996ba',
824
- {timeoutMs: 5000}
825
- );
826
- webex.internal.ediscovery.getContentContainerByContainerId(
827
- url,
828
- '089fcf55-3f38-4763-a441-b1c3540404cf',
829
- {timeoutMs: 5000}
830
- );
831
- const result = webex.internal.ediscovery
832
- .getContentContainerByContainerId(url, uuid, {timeoutMs: 5000})
833
- .then(() => {
834
- sinon.assert.calledThrice(webex.request);
835
- });
836
-
837
- return result;
838
- });
839
-
840
- it('GetContentContainerByContainerId by url sets report in contentContainerCache if it does not exist', async () => {
841
- const mockResponse = {body: {containerId: uuid}};
842
-
843
- webex.internal.ediscovery.request = sinon.stub().resolves(mockResponse);
844
-
845
- webex.internal.ediscovery.contentContainerCache = {
846
- set: sinon.stub(),
847
- has: sinon.stub().returns(false),
848
- };
849
-
850
- const result = await webex.internal.ediscovery.getContentContainerByContainerId(url, uuid);
851
-
852
- assert.calledWith(webex.internal.ediscovery.contentContainerCache.has, uuid);
853
- assert.calledWith(webex.internal.ediscovery.contentContainerCache.set, uuid, new Map());
854
-
855
- return result;
856
- });
857
-
858
- it('GetContentContainerByContainerId by url retrieves container from contentContainerCache if available', async () => {
859
- const mockCachedContainer = {containerId: uuid};
860
-
861
- const containerIdMap = {
862
- get: sinon.stub().withArgs(uuid).returns(mockCachedContainer),
863
- set: sinon.stub(),
864
- has: sinon.stub().returns(true),
865
- };
866
-
867
- webex.internal.ediscovery.contentContainerCache = {
868
- get: sinon.stub().withArgs(uuid).returns(containerIdMap),
869
- set: sinon.stub(),
870
- has: sinon.stub().returns(true),
871
- clear: sinon.stub(),
872
- };
873
- const result = webex.internal.ediscovery
874
- .getContentContainerByContainerId(url, uuid)
875
- .then((res) => {
876
- expect(res.body).to.equal(mockCachedContainer);
877
- assert.callCount(webex.internal.ediscovery.contentContainerCache.has, 1);
878
- assert.callCount(containerIdMap.has, 1);
879
- assert.callCount(containerIdMap.get, 1);
880
- });
881
-
882
- return result;
883
- });
884
-
885
- it('GetContentContainerByContainerId by url populates contentContainerCache with container when retrieved', async () => {
886
- const mockResponse = {body: {containerId: uuid}};
887
-
888
- webex.internal.ediscovery.request = sinon.stub().resolves(mockResponse);
889
-
890
- const containerIdMap = {
891
- set: sinon.stub(),
892
- has: sinon.stub().returns(false),
893
- };
894
-
895
- webex.internal.ediscovery.contentContainerCache = {
896
- get: sinon.stub().withArgs(uuid).returns(containerIdMap),
897
- set: sinon.stub(),
898
- has: sinon.stub().returns(true),
899
- clear: sinon.stub(),
900
- };
901
- const result = webex.internal.ediscovery
902
- .getContentContainerByContainerId(url, uuid)
903
- .then((res) => {
904
- expect(res).to.equal(mockResponse);
905
- assert.callCount(webex.internal.ediscovery.contentContainerCache.has, 2);
906
- assert.callCount(containerIdMap.has, 1);
907
- assert.calledWith(containerIdMap.set, mockResponse.body.containerId, mockResponse.body);
908
- });
909
-
910
- return result;
911
- });
912
-
913
- it('GetContentContainerByContainerId by url cannot write container to contentContainerCache without containerId', async () => {
914
- const mockResponse = {body: {}};
915
-
916
- webex.internal.ediscovery.request = sinon.stub().resolves(mockResponse);
917
-
918
- const containerIdMap = {
919
- set: sinon.stub(),
920
- has: sinon.stub().returns(false),
921
- };
922
-
923
- webex.internal.ediscovery.contentContainerCache = {
924
- get: sinon.stub().withArgs(uuid).returns(containerIdMap),
925
- set: sinon.stub(),
926
- has: sinon.stub().returns(true),
927
- clear: sinon.stub(),
928
- };
929
- const result = webex.internal.ediscovery
930
- .getContentContainerByContainerId(url, uuid)
931
- .then((res) => {
932
- expect(res).to.equal(mockResponse);
933
- assert.callCount(webex.internal.ediscovery.contentContainerCache.has, 2);
934
- assert.callCount(containerIdMap.has, 1);
935
- assert.notCalled(containerIdMap.set);
936
- });
937
-
938
- return result;
939
- });
940
- });
941
-
942
- describe('ClearCache Tests', () => {
943
- it('Clear caches of spaces and content containers', async () => {
944
- const spaceIdMap = {
945
- set: sinon.stub(),
946
- has: sinon.stub().returns(false),
947
- };
948
-
949
- webex.internal.ediscovery.contentContainerCache = {
950
- get: sinon.stub().withArgs(uuid).returns(spaceIdMap),
951
- set: sinon.stub(),
952
- has: sinon.stub().returns(true),
953
- clear: sinon.stub(),
954
- };
955
-
956
- const containerIdMap = {
957
- set: sinon.stub(),
958
- has: sinon.stub().returns(false),
959
- };
960
-
961
- webex.internal.ediscovery.contentContainerCache = {
962
- get: sinon.stub().withArgs(uuid).returns(containerIdMap),
963
- set: sinon.stub(),
964
- has: sinon.stub().returns(false),
965
- clear: sinon.stub(),
966
- };
967
-
968
- webex.internal.ediscovery.clearCache();
969
-
970
- assert.callCount(webex.internal.ediscovery.contentContainerCache.clear, 1);
971
- });
972
- });
973
-
974
- describe('PostAuditLog Tests', () => {
975
- it('PostAuditLog with valid reportId succeeds', () => {
976
- webex.internal.ediscovery.postAuditLog(uuid, {timeoutMs: 1000}).then((res) => {
977
- expect(res.statusCode).equal(200);
978
- sinon.assert.calledWith(webex.request, sinon.match.has('timeout', 1000));
979
- });
980
- });
981
-
982
- it('PostAuditLog with no reportId is rejected', () => {
983
- const noUuid = '';
984
-
985
- expect(webex.internal.ediscovery.postAuditLog(noUuid, {timeoutMs: 1000})).to.be.rejectedWith(
986
- Error,
987
- 'No report ID specified'
988
- );
989
- });
990
-
991
- it('PostAuditLog propagates http error on failure', () => {
992
- webex.request = sinon.stub().returns(
993
- Promise.resolve({
994
- body: {},
995
- statusCode: 400,
996
- })
997
- );
998
-
999
- webex.internal.ediscovery.postAuditLog(uuid, {timeoutMs: 1000}).then((res) => {
1000
- expect(res.statusCode).equal(400);
1001
- });
1002
- });
1003
- });
1004
-
1005
- describe('_getReportIdFromUrl Tests', () => {
1006
- it('_getReportIdFromUrl of report url', async () => {
1007
- const url =
1008
- 'https://ediscovery-intb.ciscospark.com/ediscovery/api/v1/reports/16bf0d01-b1f7-483b-89a2-915144158fb9';
1009
-
1010
- const uuid = webex.internal.ediscovery._getReportIdFromUrl(url);
1011
-
1012
- expect(uuid).equal('16bf0d01-b1f7-483b-89a2-915144158fb9');
1013
- });
1014
-
1015
- it('_createRequestOptions of report url with multiple uuids', async () => {
1016
- const url =
1017
- 'https://ediscovery-intb.ciscospark.com/ediscovery/api/v1/reports/16bf0d01-b1f7-483b-89a2-915144158fb9/contents/0498830f-1d63-4faa-b53b-35e1b12ccf9f';
1018
-
1019
- const uuid = webex.internal.ediscovery._getReportIdFromUrl(url);
1020
-
1021
- expect(uuid).equal('16bf0d01-b1f7-483b-89a2-915144158fb9');
1022
- });
1023
- });
1024
-
1025
- describe('_isUrl Tests', () => {
1026
- it('_isUrl with a url', async () => {
1027
- const url =
1028
- 'https://ediscovery-intb.ciscospark.com/ediscovery/api/v1/reports/16bf0d01-b1f7-483b-89a2-915144158fb9';
1029
-
1030
- assert(webex.internal.ediscovery._isUrl(url));
1031
- });
1032
-
1033
- it('_isUrl with a uuid', async () => {
1034
- assert(!webex.internal.ediscovery._isUrl('16bf0d01-b1f7-483b-89a2-915144158fb9'));
1035
- });
1036
-
1037
- it('_isUrl with a string', async () => {
1038
- assert(!webex.internal.ediscovery._isUrl('abcdefghij'));
1039
- });
1040
- });
1041
-
1042
- describe('_createRequestOptions Tests', () => {
1043
- it('_createRequestOptions with uuid', async () => {
1044
- const uuid = '16bf0d01-b1f7-483b-89a2-915144158fb9';
1045
- const resource = '/my/extra/resource/path';
1046
- const [options, returnedUUID] = webex.internal.ediscovery._createRequestOptions(
1047
- uuid,
1048
- resource
1049
- );
1050
-
1051
- expect(uuid).equal(returnedUUID);
1052
- expect(options.service).equal('ediscovery');
1053
- expect(options.resource).equal(`reports/${uuid}/${resource}`);
1054
- });
1055
-
1056
- it('_createRequestOptions with url', async () => {
1057
- const url =
1058
- 'https://ediscovery-intb.ciscospark.com/ediscovery/api/v1/reports/16bf0d01-b1f7-483b-89a2-915144158fb9';
1059
- const resource = '/my/extra/resource/path';
1060
- const [options, returnedUUID] = webex.internal.ediscovery._createRequestOptions(
1061
- url,
1062
- resource
1063
- );
1064
-
1065
- expect(returnedUUID).equal('16bf0d01-b1f7-483b-89a2-915144158fb9');
1066
- expect(options.url).equal(url + resource);
1067
- });
1068
-
1069
- it('_createRequestOptions with url with details after the uuid', async () => {
1070
- const url =
1071
- 'https://ediscovery-intb.ciscospark.com/ediscovery/api/v1/reports/16bf0d01-b1f7-483b-89a2-915144158fb9';
1072
- const urlPlus =
1073
- 'https://ediscovery-intb.ciscospark.com/ediscovery/api/v1/reports/16bf0d01-b1f7-483b-89a2-915144158fb9/contents/and/more';
1074
- const resource = '/my/extra/resource/path';
1075
- const [options, returnedUUID] = webex.internal.ediscovery._createRequestOptions(
1076
- urlPlus,
1077
- resource
1078
- );
1079
-
1080
- expect(returnedUUID).equal('16bf0d01-b1f7-483b-89a2-915144158fb9');
1081
- expect(options.url).equal(url + resource);
1082
- });
1083
- });
1084
- });
1
+ import EDiscovery from '@webex/internal-plugin-ediscovery';
2
+ import MockWebex from '@webex/test-helper-mock-webex';
3
+ import sinon from 'sinon';
4
+ import {assert, expect} from '@webex/test-helper-chai';
5
+ import config from '@webex/internal-plugin-ediscovery/src/config';
6
+
7
+ /* eslint-disable max-len */
8
+ describe('EDiscovery Content API Tests', () => {
9
+ let webex;
10
+ const uuid = 'cc06f622-46ab-45b9-b3a6-5d70bad1d70a';
11
+ const url =
12
+ 'https://ediscovery-intb.wbx2.com/ediscovery/api/v1/reports/cc06f622-46ab-45b9-b3a6-5d70bad1d70a';
13
+ const invalidUrl = 'https://ediscovery-intb.wbx2.com/ediscovery/api/v1/reports/';
14
+ const defaultTimeout = 30000;
15
+
16
+ beforeEach(() => {
17
+ webex = new MockWebex({
18
+ children: {
19
+ ediscovery: EDiscovery,
20
+ },
21
+ });
22
+ webex.config.ediscovery = config.ediscovery;
23
+ });
24
+
25
+ describe('GetContent Tests', () => {
26
+ it('GetContent succeeds', async () => {
27
+ const result = webex.internal.ediscovery
28
+ .getContent(uuid, {offset: 0, size: 1})
29
+ .then((res) => {
30
+ expect(res.statusCode).equal(200);
31
+ });
32
+
33
+ return result;
34
+ });
35
+
36
+ it('GetContent fails with no params', async () => {
37
+ const result = expect(webex.internal.ediscovery.getContent()).to.be.rejectedWith(
38
+ Error,
39
+ 'Undefined parameter'
40
+ );
41
+
42
+ return result;
43
+ });
44
+
45
+ it('GetContent timeout defaults to 30s', async () => {
46
+ const result = webex.internal.ediscovery.getContent(uuid).then(() => {
47
+ sinon.assert.calledWith(webex.request, sinon.match.has('timeout', defaultTimeout));
48
+ });
49
+
50
+ return result;
51
+ });
52
+
53
+ it('GetContent timeout defaults to 30s when other options are specified', async () => {
54
+ const result = webex.internal.ediscovery.getContent(uuid, {offset: 0, size: 1}).then(() => {
55
+ sinon.assert.calledWith(webex.request, sinon.match.has('timeout', defaultTimeout));
56
+ });
57
+
58
+ return result;
59
+ });
60
+
61
+ it('GetContent timeout can be overwritten to 5s with timeout as the only option', async () => {
62
+ const result = webex.internal.ediscovery.getContent(uuid, {timeoutMs: 5000}).then(() => {
63
+ sinon.assert.calledWith(webex.request, sinon.match.has('timeout', 5000));
64
+ });
65
+
66
+ return result;
67
+ });
68
+
69
+ it('GetContent timeout can be overwritten to 5s when other options are specified', async () => {
70
+ const result = webex.internal.ediscovery
71
+ .getContent(uuid, {offset: 0, size: 1, timeoutMs: 5000})
72
+ .then(() => {
73
+ sinon.assert.calledWith(webex.request, sinon.match.has('timeout', 5000));
74
+ sinon.assert.calledWith(webex.request, sinon.match.has('qs', {offset: 0, size: 1}));
75
+ });
76
+
77
+ return result;
78
+ });
79
+
80
+ it('GetContent makes one request when called multiple times with identical params', async () => {
81
+ webex.internal.ediscovery.getContent(uuid, {offset: 0, size: 1, timeoutMs: 5000});
82
+ webex.internal.ediscovery.getContent(uuid, {offset: 0, size: 1, timeoutMs: 5000});
83
+ const result = webex.internal.ediscovery
84
+ .getContent(uuid, {offset: 0, size: 1, timeoutMs: 5000})
85
+ .then(() => {
86
+ sinon.assert.calledOnce(webex.request);
87
+ });
88
+
89
+ return result;
90
+ });
91
+
92
+ it('GetContent makes multiple requests when called multiple times with different params', async () => {
93
+ webex.internal.ediscovery.getContent(uuid, {offset: 0, size: 1, timeoutMs: 5000});
94
+ webex.internal.ediscovery.getContent(uuid, {offset: 1, size: 1, timeoutMs: 5000});
95
+ const result = webex.internal.ediscovery
96
+ .getContent(uuid, {offset: 0, size: 2, timeoutMs: 5000})
97
+ .then(() => {
98
+ sinon.assert.calledThrice(webex.request);
99
+ });
100
+
101
+ return result;
102
+ });
103
+ });
104
+
105
+ describe('GetContent by url Tests', () => {
106
+ it('GetContent by url succeeds', async () => {
107
+ const result = webex.internal.ediscovery.getContent(url, {offset: 0, size: 1}).then((res) => {
108
+ expect(res.statusCode).equal(200);
109
+ });
110
+
111
+ return result;
112
+ });
113
+
114
+ it('GetContent by url fails with no params', async () => {
115
+ const result = expect(webex.internal.ediscovery.getContent()).to.be.rejectedWith(
116
+ Error,
117
+ 'Undefined parameter'
118
+ );
119
+
120
+ return result;
121
+ });
122
+
123
+ it('GetContent by url fails with a url that does not contain a report id', async () => {
124
+ const result = expect(webex.internal.ediscovery.getContent(invalidUrl)).to.be.rejectedWith(
125
+ Error,
126
+ 'Report url does not contain a report id'
127
+ );
128
+
129
+ return result;
130
+ });
131
+
132
+ it('GetContent by url timeout defaults to 30s', async () => {
133
+ const result = webex.internal.ediscovery.getContent(url).then(() => {
134
+ sinon.assert.calledWith(webex.request, sinon.match.has('timeout', defaultTimeout));
135
+ });
136
+
137
+ return result;
138
+ });
139
+
140
+ it('GetContent by url timeout defaults to 30s when other options are specified', async () => {
141
+ const result = webex.internal.ediscovery.getContent(url, {offset: 0, size: 1}).then(() => {
142
+ sinon.assert.calledWith(webex.request, sinon.match.has('timeout', defaultTimeout));
143
+ });
144
+
145
+ return result;
146
+ });
147
+
148
+ it('GetContent by url timeout can be overwritten to 5s with timeout as the only option', async () => {
149
+ const result = webex.internal.ediscovery.getContent(url, {timeoutMs: 5000}).then(() => {
150
+ sinon.assert.calledWith(webex.request, sinon.match.has('timeout', 5000));
151
+ });
152
+
153
+ return result;
154
+ });
155
+
156
+ it('GetContent by url timeout can be overwritten to 5s when other options are specified', async () => {
157
+ const result = webex.internal.ediscovery
158
+ .getContent(url, {offset: 0, size: 1, timeoutMs: 5000})
159
+ .then(() => {
160
+ sinon.assert.calledWith(webex.request, sinon.match.has('timeout', 5000));
161
+ sinon.assert.calledWith(webex.request, sinon.match.has('qs', {offset: 0, size: 1}));
162
+ });
163
+
164
+ return result;
165
+ });
166
+
167
+ it('GetContent by url makes one request when called multiple times with identical params', async () => {
168
+ webex.internal.ediscovery.getContent(url, {offset: 0, size: 1, timeoutMs: 5000});
169
+ webex.internal.ediscovery.getContent(url, {offset: 0, size: 1, timeoutMs: 5000});
170
+ const result = webex.internal.ediscovery
171
+ .getContent(url, {offset: 0, size: 1, timeoutMs: 5000})
172
+ .then(() => {
173
+ sinon.assert.calledOnce(webex.request);
174
+ });
175
+
176
+ return result;
177
+ });
178
+
179
+ it('GetContent by url makes multiple requests when called multiple times with different params', async () => {
180
+ webex.internal.ediscovery.getContent(url, {offset: 0, size: 1, timeoutMs: 5000});
181
+ webex.internal.ediscovery.getContent(url, {offset: 1, size: 1, timeoutMs: 5000});
182
+ const result = webex.internal.ediscovery
183
+ .getContent(url, {offset: 0, size: 2, timeoutMs: 5000})
184
+ .then(() => {
185
+ sinon.assert.calledThrice(webex.request);
186
+ });
187
+
188
+ return result;
189
+ });
190
+ });
191
+
192
+ describe('GetContentContainer Tests', () => {
193
+ it('GetContentContainer succeeds', async () => {
194
+ const result = webex.internal.ediscovery
195
+ .getContentContainer(uuid, {offset: 0, size: 1})
196
+ .then((res) => {
197
+ expect(res.statusCode).equal(200);
198
+ });
199
+
200
+ return result;
201
+ });
202
+
203
+ it('GetContentContainer fails with no params', async () => {
204
+ const result = expect(webex.internal.ediscovery.getContentContainer()).to.be.rejectedWith(
205
+ Error,
206
+ 'Undefined parameter'
207
+ );
208
+
209
+ return result;
210
+ });
211
+
212
+ it('GetContentContainer timeout defaults to 30s', async () => {
213
+ const result = webex.internal.ediscovery.getContentContainer(uuid).then(() => {
214
+ sinon.assert.calledWith(webex.request, sinon.match.has('timeout', defaultTimeout));
215
+ });
216
+
217
+ return result;
218
+ });
219
+
220
+ it('GetContentContainer timeout defaults to 30s when other options are specified', async () => {
221
+ const result = webex.internal.ediscovery
222
+ .getContentContainer(uuid, {offset: 0, size: 1})
223
+ .then(() => {
224
+ sinon.assert.calledWith(webex.request, sinon.match.has('timeout', defaultTimeout));
225
+ });
226
+
227
+ return result;
228
+ });
229
+
230
+ it('GetContentContainer timeout can be overwritten to 5s with timeout as the only option', async () => {
231
+ const result = webex.internal.ediscovery
232
+ .getContentContainer(uuid, {timeoutMs: 5000})
233
+ .then(() => {
234
+ sinon.assert.calledWith(webex.request, sinon.match.has('timeout', 5000));
235
+ });
236
+
237
+ return result;
238
+ });
239
+
240
+ it('GetContentContainer timeout can be overwritten to 5s when other options are specified', async () => {
241
+ const result = webex.internal.ediscovery
242
+ .getContentContainer(uuid, {
243
+ offset: 0,
244
+ size: 1,
245
+ timeoutMs: 5000,
246
+ types: [],
247
+ })
248
+ .then(() => {
249
+ sinon.assert.calledWith(webex.request, sinon.match.has('timeout', 5000));
250
+ sinon.assert.calledWith(webex.request, sinon.match.has('types', []));
251
+ sinon.assert.calledWith(webex.request, sinon.match.has('qs', {offset: 0, size: 1}));
252
+ });
253
+
254
+ return result;
255
+ });
256
+
257
+ it('GetContentContainer makes one request when called multiple times with identical params', async () => {
258
+ webex.internal.ediscovery.getContentContainer(uuid, {
259
+ offset: 0,
260
+ size: 1,
261
+ timeoutMs: 5000,
262
+ types: [],
263
+ });
264
+ webex.internal.ediscovery.getContentContainer(uuid, {
265
+ offset: 0,
266
+ size: 1,
267
+ timeoutMs: 5000,
268
+ types: [],
269
+ });
270
+ const result = webex.internal.ediscovery
271
+ .getContentContainer(uuid, {
272
+ offset: 0,
273
+ size: 1,
274
+ timeoutMs: 5000,
275
+ types: [],
276
+ })
277
+ .then(() => {
278
+ sinon.assert.calledOnce(webex.request);
279
+ });
280
+
281
+ return result;
282
+ });
283
+
284
+ it('GetContentContainer makes multiple requests when called multiple times with different params', async () => {
285
+ webex.internal.ediscovery.getContentContainer(uuid, {
286
+ offset: 0,
287
+ size: 1,
288
+ timeoutMs: 5000,
289
+ types: ['MEETING'],
290
+ });
291
+ webex.internal.ediscovery.getContentContainer(uuid, {
292
+ offset: 0,
293
+ size: 1,
294
+ timeoutMs: 5000,
295
+ types: ['SPACE'],
296
+ });
297
+ const result = webex.internal.ediscovery
298
+ .getContentContainer(uuid, {
299
+ offset: 0,
300
+ size: 1,
301
+ timeoutMs: 5000,
302
+ types: undefined,
303
+ })
304
+ .then(() => {
305
+ sinon.assert.calledThrice(webex.request);
306
+ });
307
+
308
+ return result;
309
+ });
310
+
311
+ it('GetContentContainer sets report in contentContainerCache if it does not exist', async () => {
312
+ const mockResponse = {body: [{containerId: uuid}]};
313
+
314
+ webex.internal.ediscovery.request = sinon.stub().resolves(mockResponse);
315
+
316
+ webex.internal.ediscovery.contentContainerCache = {
317
+ set: sinon.stub(),
318
+ has: sinon.stub().returns(false),
319
+ clear: sinon.stub(),
320
+ };
321
+ const result = webex.internal.ediscovery
322
+ .getContentContainer(uuid, {offset: 0, size: 1})
323
+ .then(() => {
324
+ assert.calledWith(webex.internal.ediscovery.contentContainerCache.has, uuid);
325
+ assert.calledWith(webex.internal.ediscovery.contentContainerCache.set, uuid, new Map());
326
+ });
327
+
328
+ return result;
329
+ });
330
+
331
+ it('GetContentContainer does not retrieve container from contentContainerCache if available', async () => {
332
+ const mockCachedContainer = {containerId: uuid};
333
+ const containerIdMap = {
334
+ get: sinon.stub().withArgs(uuid).returns(mockCachedContainer),
335
+ set: sinon.stub(),
336
+ has: sinon.stub().returns(true),
337
+ };
338
+
339
+ webex.internal.ediscovery.contentContainerCache = {
340
+ get: sinon.stub().withArgs(uuid).returns(containerIdMap),
341
+ set: sinon.stub(),
342
+ has: sinon.stub().returns(true),
343
+ clear: sinon.stub(),
344
+ };
345
+ const result = webex.internal.ediscovery
346
+ .getContentContainer(uuid, {offset: 0, size: 1})
347
+ .then((res) => {
348
+ expect(res).to.not.equal(mockCachedContainer);
349
+ assert.callCount(webex.internal.ediscovery.contentContainerCache.has, 0);
350
+ assert.callCount(containerIdMap.has, 0);
351
+ assert.callCount(containerIdMap.get, 0);
352
+ });
353
+
354
+ return result;
355
+ });
356
+
357
+ it('GetContentContainer populates contentContainerCache with container when retrieved', async () => {
358
+ const mockResponse = {body: [{containerId: uuid}]};
359
+
360
+ webex.internal.ediscovery.request = sinon.stub().resolves(mockResponse);
361
+
362
+ const containerIdMap = {
363
+ set: sinon.stub(),
364
+ has: sinon.stub().returns(false),
365
+ };
366
+
367
+ webex.internal.ediscovery.contentContainerCache = {
368
+ get: sinon.stub().withArgs(uuid).returns(containerIdMap),
369
+ has: sinon.stub().returns(true),
370
+ clear: sinon.stub(),
371
+ };
372
+ const result = webex.internal.ediscovery
373
+ .getContentContainer(uuid, {offset: 0, size: 1})
374
+ .then((res) => {
375
+ expect(res).to.equal(mockResponse);
376
+ assert.callCount(webex.internal.ediscovery.contentContainerCache.has, 1);
377
+ assert.calledWith(
378
+ containerIdMap.set,
379
+ mockResponse.body[0].containerId,
380
+ mockResponse.body[0]
381
+ );
382
+ });
383
+
384
+ return result;
385
+ });
386
+ });
387
+
388
+ describe('GetContentContainer by url Tests', () => {
389
+ it('GetContentContainer succeeds', async () => {
390
+ const result = webex.internal.ediscovery
391
+ .getContentContainer(url, {offset: 0, size: 1})
392
+ .then((res) => {
393
+ expect(res.statusCode).equal(200);
394
+ });
395
+
396
+ return result;
397
+ });
398
+
399
+ it('GetContentContainer by url fails with no params', async () => {
400
+ const result = expect(webex.internal.ediscovery.getContentContainer()).to.be.rejectedWith(
401
+ Error,
402
+ 'Undefined parameter'
403
+ );
404
+
405
+ return result;
406
+ });
407
+
408
+ it('GetContentContainer by url fails with a url that does not contain a report id', async () => {
409
+ const result = expect(
410
+ webex.internal.ediscovery.getContentContainer(invalidUrl)
411
+ ).to.be.rejectedWith(Error, 'Report url does not contain a report id');
412
+
413
+ return result;
414
+ });
415
+
416
+ it('GetContentContainer by url timeout defaults to 30s', async () => {
417
+ const result = webex.internal.ediscovery.getContentContainer(url).then(() => {
418
+ sinon.assert.calledWith(webex.request, sinon.match.has('timeout', defaultTimeout));
419
+ });
420
+
421
+ return result;
422
+ });
423
+
424
+ it('GetContentContainer by url timeout defaults to 30s when other options are specified', async () => {
425
+ const result = webex.internal.ediscovery
426
+ .getContentContainer(url, {offset: 0, size: 1})
427
+ .then(() => {
428
+ sinon.assert.calledWith(webex.request, sinon.match.has('timeout', defaultTimeout));
429
+ });
430
+
431
+ return result;
432
+ });
433
+
434
+ it('GetContentContainer by url timeout can be overwritten to 5s with timeout as the only option', async () => {
435
+ const result = webex.internal.ediscovery
436
+ .getContentContainer(url, {timeoutMs: 5000})
437
+ .then(() => {
438
+ sinon.assert.calledWith(webex.request, sinon.match.has('timeout', 5000));
439
+ });
440
+
441
+ return result;
442
+ });
443
+
444
+ it('GetContentContainer by url timeout can be overwritten to 5s when other options are specified', async () => {
445
+ const result = webex.internal.ediscovery
446
+ .getContentContainer(url, {offset: 0, size: 1, timeoutMs: 5000})
447
+ .then(() => {
448
+ sinon.assert.calledWith(webex.request, sinon.match.has('timeout', 5000));
449
+ sinon.assert.calledWith(webex.request, sinon.match.has('qs', {offset: 0, size: 1}));
450
+ });
451
+
452
+ return result;
453
+ });
454
+
455
+ it('GetContentContainer by url makes one request when called multiple times with identical params', async () => {
456
+ webex.internal.ediscovery.getContentContainer(url, {
457
+ offset: 0,
458
+ size: 1,
459
+ timeoutMs: 5000,
460
+ types: [],
461
+ });
462
+ webex.internal.ediscovery.getContentContainer(url, {
463
+ offset: 0,
464
+ size: 1,
465
+ timeoutMs: 5000,
466
+ types: [],
467
+ });
468
+ const result = webex.internal.ediscovery
469
+ .getContentContainer(url, {
470
+ offset: 0,
471
+ size: 1,
472
+ timeoutMs: 5000,
473
+ types: [],
474
+ })
475
+ .then(() => {
476
+ sinon.assert.calledOnce(webex.request);
477
+ });
478
+
479
+ return result;
480
+ });
481
+
482
+ it('GetContentContainer by url makes multiple requests when called multiple times with different types', async () => {
483
+ webex.internal.ediscovery.getContentContainer(url, {
484
+ offset: 0,
485
+ size: 1,
486
+ timeoutMs: 5000,
487
+ types: ['MEETING'],
488
+ });
489
+ webex.internal.ediscovery.getContentContainer(url, {
490
+ offset: 0,
491
+ size: 1,
492
+ timeoutMs: 5000,
493
+ types: ['SPACE'],
494
+ });
495
+ const result = webex.internal.ediscovery
496
+ .getContentContainer(url, {
497
+ offset: 0,
498
+ size: 1,
499
+ timeoutMs: 5000,
500
+ types: undefined,
501
+ })
502
+ .then(() => {
503
+ sinon.assert.calledThrice(webex.request);
504
+ });
505
+
506
+ return result;
507
+ });
508
+
509
+ it('GetContentContainer by url sets report in contentContainerCache if it does not exist', async () => {
510
+ const mockResponse = {body: [{containerId: uuid}]};
511
+
512
+ webex.internal.ediscovery.request = sinon.stub().resolves(mockResponse);
513
+
514
+ webex.internal.ediscovery.contentContainerCache = {
515
+ set: sinon.stub(),
516
+ has: sinon.stub().returns(false),
517
+ clear: sinon.stub(),
518
+ };
519
+ const result = webex.internal.ediscovery
520
+ .getContentContainer(url, {offset: 0, size: 1})
521
+ .then(() => {
522
+ assert.calledWith(webex.internal.ediscovery.contentContainerCache.has, uuid);
523
+ assert.calledWith(webex.internal.ediscovery.contentContainerCache.set, uuid, new Map());
524
+ });
525
+
526
+ return result;
527
+ });
528
+
529
+ it('GetContentContainer by url does not retrieve container from contentContainerCache if available', async () => {
530
+ const mockCachedContainer = {containerId: uuid};
531
+ const containerIdMap = {
532
+ get: sinon.stub().withArgs(uuid).returns(mockCachedContainer),
533
+ set: sinon.stub(),
534
+ has: sinon.stub().returns(true),
535
+ };
536
+
537
+ webex.internal.ediscovery.contentContainerCache = {
538
+ get: sinon.stub().withArgs(uuid).returns(containerIdMap),
539
+ set: sinon.stub(),
540
+ has: sinon.stub().returns(true),
541
+ clear: sinon.stub(),
542
+ };
543
+ const result = webex.internal.ediscovery
544
+ .getContentContainer(url, {offset: 0, size: 1})
545
+ .then((res) => {
546
+ expect(res).to.not.equal(mockCachedContainer);
547
+ assert.callCount(webex.internal.ediscovery.contentContainerCache.has, 0);
548
+ assert.callCount(containerIdMap.has, 0);
549
+ assert.callCount(containerIdMap.get, 0);
550
+ });
551
+
552
+ return result;
553
+ });
554
+
555
+ it('GetContentContainer by url populates contentContainerCache with container when retrieved', async () => {
556
+ const mockResponse = {body: [{containerId: uuid}]};
557
+
558
+ webex.internal.ediscovery.request = sinon.stub().resolves(mockResponse);
559
+
560
+ const containerIdMap = {
561
+ set: sinon.stub(),
562
+ has: sinon.stub().returns(false),
563
+ };
564
+
565
+ webex.internal.ediscovery.contentContainerCache = {
566
+ get: sinon.stub().withArgs(uuid).returns(containerIdMap),
567
+ has: sinon.stub().returns(true),
568
+ clear: sinon.stub(),
569
+ };
570
+ const result = webex.internal.ediscovery
571
+ .getContentContainer(url, {offset: 0, size: 1})
572
+ .then((res) => {
573
+ expect(res).to.equal(mockResponse);
574
+ assert.callCount(webex.internal.ediscovery.contentContainerCache.has, 1);
575
+ assert.calledWith(
576
+ containerIdMap.set,
577
+ mockResponse.body[0].containerId,
578
+ mockResponse.body[0]
579
+ );
580
+ });
581
+
582
+ return result;
583
+ });
584
+ });
585
+
586
+ describe('GetContentContainerByContainerId Tests', () => {
587
+ it('GetContentContainerByContainerId succeeds', async () => {
588
+ const result = webex.internal.ediscovery
589
+ .getContentContainerByContainerId(uuid, uuid)
590
+ .then((res) => {
591
+ expect(res).to.not.equal(undefined);
592
+ });
593
+
594
+ return result;
595
+ });
596
+
597
+ it('GetContentContainerByContainerId fails with no params', async () => {
598
+ const result = expect(
599
+ webex.internal.ediscovery.getContentContainerByContainerId()
600
+ ).to.be.rejectedWith(Error, 'Undefined parameter');
601
+
602
+ return result;
603
+ });
604
+
605
+ it('GetContentContainerByContainerId timeout defaults to 30s', async () => {
606
+ const result = webex.internal.ediscovery
607
+ .getContentContainerByContainerId(uuid, uuid)
608
+ .then(() => {
609
+ sinon.assert.calledWith(webex.request, sinon.match.has('timeout', defaultTimeout));
610
+ });
611
+
612
+ return result;
613
+ });
614
+
615
+ it('GetContentContainerByContainerId timeout can be overwritten to 5s with timeout as the only option', async () => {
616
+ const result = webex.internal.ediscovery
617
+ .getContentContainerByContainerId(uuid, uuid, {timeoutMs: 5000})
618
+ .then(() => {
619
+ sinon.assert.calledWith(webex.request, sinon.match.has('timeout', 5000));
620
+ });
621
+
622
+ return result;
623
+ });
624
+
625
+ it('GetContentContainerByContainerId makes one request when called multiple times with identical params', async () => {
626
+ webex.internal.ediscovery.getContentContainerByContainerId(uuid, uuid, {timeoutMs: 5000});
627
+ webex.internal.ediscovery.getContentContainerByContainerId(uuid, uuid, {timeoutMs: 5000});
628
+ const result = webex.internal.ediscovery
629
+ .getContentContainerByContainerId(uuid, uuid, {timeoutMs: 5000})
630
+ .then(() => {
631
+ sinon.assert.calledOnce(webex.request);
632
+ });
633
+
634
+ return result;
635
+ });
636
+
637
+ it('GetContentContainerByContainerId makes multiple requests when called multiple times with different params', async () => {
638
+ webex.internal.ediscovery.getContentContainerByContainerId(
639
+ uuid,
640
+ '0d4084ce-8cef-43fd-9313-fb64579996ba',
641
+ {timeoutMs: 5000}
642
+ );
643
+ webex.internal.ediscovery.getContentContainerByContainerId(
644
+ uuid,
645
+ '089fcf55-3f38-4763-a441-b1c3540404cf',
646
+ {timeoutMs: 5000}
647
+ );
648
+ const result = webex.internal.ediscovery
649
+ .getContentContainerByContainerId(uuid, uuid, {timeoutMs: 5000})
650
+ .then(() => {
651
+ sinon.assert.calledThrice(webex.request);
652
+ });
653
+
654
+ return result;
655
+ });
656
+
657
+ it('GetContentContainerByContainerId sets report in contentContainerCache if it does not exist', async () => {
658
+ const mockResponse = {body: {containerId: uuid}};
659
+
660
+ webex.internal.ediscovery.request = sinon.stub().resolves(mockResponse);
661
+
662
+ webex.internal.ediscovery.contentContainerCache = {
663
+ set: sinon.stub(),
664
+ has: sinon.stub().returns(false),
665
+ clear: sinon.stub(),
666
+ };
667
+ const result = webex.internal.ediscovery
668
+ .getContentContainerByContainerId(uuid, uuid)
669
+ .then(() => {
670
+ assert.calledWith(webex.internal.ediscovery.contentContainerCache.has, uuid);
671
+ assert.calledWith(webex.internal.ediscovery.contentContainerCache.set, uuid, new Map());
672
+ });
673
+
674
+ return result;
675
+ });
676
+
677
+ it('GetContentContainerByContainerId retrieves container from contentContainerCache if available', async () => {
678
+ const mockCachedContainer = {containerId: uuid};
679
+
680
+ const containerIdMap = {
681
+ get: sinon.stub().withArgs(uuid).returns(mockCachedContainer),
682
+ set: sinon.stub(),
683
+ has: sinon.stub().returns(true),
684
+ };
685
+
686
+ webex.internal.ediscovery.contentContainerCache = {
687
+ get: sinon.stub().withArgs(uuid).returns(containerIdMap),
688
+ set: sinon.stub(),
689
+ has: sinon.stub().returns(true),
690
+ clear: sinon.stub(),
691
+ };
692
+ const result = webex.internal.ediscovery
693
+ .getContentContainerByContainerId(uuid, uuid)
694
+ .then((res) => {
695
+ expect(res.body).to.equal(mockCachedContainer);
696
+ assert.callCount(webex.internal.ediscovery.contentContainerCache.has, 1);
697
+ assert.callCount(containerIdMap.has, 1);
698
+ assert.callCount(containerIdMap.get, 1);
699
+ });
700
+
701
+ return result;
702
+ });
703
+
704
+ it('GetContentContainerByContainerId populates contentContainerCache with container when retrieved', async () => {
705
+ const mockResponse = {body: {containerId: uuid}};
706
+
707
+ webex.internal.ediscovery.request = sinon.stub().resolves(mockResponse);
708
+
709
+ const containerIdMap = {
710
+ set: sinon.stub(),
711
+ has: sinon.stub().returns(false),
712
+ };
713
+
714
+ webex.internal.ediscovery.contentContainerCache = {
715
+ get: sinon.stub().withArgs(uuid).returns(containerIdMap),
716
+ set: sinon.stub(),
717
+ has: sinon.stub().returns(true),
718
+ clear: sinon.stub(),
719
+ };
720
+ const result = webex.internal.ediscovery
721
+ .getContentContainerByContainerId(uuid, uuid)
722
+ .then((res) => {
723
+ expect(res).to.equal(mockResponse);
724
+ assert.callCount(webex.internal.ediscovery.contentContainerCache.has, 2);
725
+ assert.callCount(containerIdMap.has, 1);
726
+ assert.calledWith(containerIdMap.set, mockResponse.body.containerId, mockResponse.body);
727
+ });
728
+
729
+ return result;
730
+ });
731
+
732
+ it('GetContentContainerByContainerId cannot write container to contentContainerCache without containerId', async () => {
733
+ const mockResponse = {body: {}};
734
+
735
+ webex.internal.ediscovery.request = sinon.stub().resolves(mockResponse);
736
+
737
+ const containerIdMap = {
738
+ set: sinon.stub(),
739
+ has: sinon.stub().returns(false),
740
+ };
741
+
742
+ webex.internal.ediscovery.contentContainerCache = {
743
+ get: sinon.stub().withArgs(uuid).returns(containerIdMap),
744
+ set: sinon.stub(),
745
+ has: sinon.stub().returns(true),
746
+ clear: sinon.stub(),
747
+ };
748
+ const result = webex.internal.ediscovery
749
+ .getContentContainerByContainerId(uuid, uuid)
750
+ .then((res) => {
751
+ expect(res).to.equal(mockResponse);
752
+ assert.callCount(webex.internal.ediscovery.contentContainerCache.has, 2);
753
+ assert.callCount(containerIdMap.has, 1);
754
+ assert.notCalled(containerIdMap.set);
755
+ });
756
+
757
+ return result;
758
+ });
759
+ });
760
+
761
+ describe('GetContentContainerByContainerId by url Tests', () => {
762
+ it('GetContentContainerByContainerId by url succeeds', async () => {
763
+ const result = webex.internal.ediscovery
764
+ .getContentContainerByContainerId(url, uuid)
765
+ .then((res) => {
766
+ expect(res).to.not.equal(undefined);
767
+ });
768
+
769
+ return result;
770
+ });
771
+
772
+ it('GetContentContainerByContainerId by url fails with no params', async () => {
773
+ const result = expect(
774
+ webex.internal.ediscovery.getContentContainerByContainerId()
775
+ ).to.be.rejectedWith(Error, 'Undefined parameter');
776
+
777
+ return result;
778
+ });
779
+
780
+ it('GetContentContainerByContainerId by url fails with a url that does not contain a report id', async () => {
781
+ const result = expect(
782
+ webex.internal.ediscovery.getContentContainerByContainerId(invalidUrl, uuid)
783
+ ).to.be.rejectedWith(Error, 'Report url does not contain a report id');
784
+
785
+ return result;
786
+ });
787
+
788
+ it('GetContentContainerByContainerId by url timeout defaults to 30s', async () => {
789
+ const result = webex.internal.ediscovery
790
+ .getContentContainerByContainerId(url, uuid)
791
+ .then(() => {
792
+ sinon.assert.calledWith(webex.request, sinon.match.has('timeout', defaultTimeout));
793
+ });
794
+
795
+ return result;
796
+ });
797
+
798
+ it('GetContentContainerByContainerId by url timeout can be overwritten to 5s with timeout as the only option', async () => {
799
+ const result = webex.internal.ediscovery
800
+ .getContentContainerByContainerId(url, uuid, {timeoutMs: 5000})
801
+ .then(() => {
802
+ sinon.assert.calledWith(webex.request, sinon.match.has('timeout', 5000));
803
+ });
804
+
805
+ return result;
806
+ });
807
+
808
+ it('GetContentContainerByContainerId by url makes one request when called multiple times with identical params', async () => {
809
+ webex.internal.ediscovery.getContentContainerByContainerId(url, uuid, {timeoutMs: 5000});
810
+ webex.internal.ediscovery.getContentContainerByContainerId(url, uuid, {timeoutMs: 5000});
811
+ const result = webex.internal.ediscovery
812
+ .getContentContainerByContainerId(url, uuid, {timeoutMs: 5000})
813
+ .then(() => {
814
+ sinon.assert.calledOnce(webex.request);
815
+ });
816
+
817
+ return result;
818
+ });
819
+
820
+ it('GetContentContainerByContainerId by url makes multiple requests when called multiple times with different params', async () => {
821
+ webex.internal.ediscovery.getContentContainerByContainerId(
822
+ url,
823
+ '0d4084ce-8cef-43fd-9313-fb64579996ba',
824
+ {timeoutMs: 5000}
825
+ );
826
+ webex.internal.ediscovery.getContentContainerByContainerId(
827
+ url,
828
+ '089fcf55-3f38-4763-a441-b1c3540404cf',
829
+ {timeoutMs: 5000}
830
+ );
831
+ const result = webex.internal.ediscovery
832
+ .getContentContainerByContainerId(url, uuid, {timeoutMs: 5000})
833
+ .then(() => {
834
+ sinon.assert.calledThrice(webex.request);
835
+ });
836
+
837
+ return result;
838
+ });
839
+
840
+ it('GetContentContainerByContainerId by url sets report in contentContainerCache if it does not exist', async () => {
841
+ const mockResponse = {body: {containerId: uuid}};
842
+
843
+ webex.internal.ediscovery.request = sinon.stub().resolves(mockResponse);
844
+
845
+ webex.internal.ediscovery.contentContainerCache = {
846
+ set: sinon.stub(),
847
+ has: sinon.stub().returns(false),
848
+ };
849
+
850
+ const result = await webex.internal.ediscovery.getContentContainerByContainerId(url, uuid);
851
+
852
+ assert.calledWith(webex.internal.ediscovery.contentContainerCache.has, uuid);
853
+ assert.calledWith(webex.internal.ediscovery.contentContainerCache.set, uuid, new Map());
854
+
855
+ return result;
856
+ });
857
+
858
+ it('GetContentContainerByContainerId by url retrieves container from contentContainerCache if available', async () => {
859
+ const mockCachedContainer = {containerId: uuid};
860
+
861
+ const containerIdMap = {
862
+ get: sinon.stub().withArgs(uuid).returns(mockCachedContainer),
863
+ set: sinon.stub(),
864
+ has: sinon.stub().returns(true),
865
+ };
866
+
867
+ webex.internal.ediscovery.contentContainerCache = {
868
+ get: sinon.stub().withArgs(uuid).returns(containerIdMap),
869
+ set: sinon.stub(),
870
+ has: sinon.stub().returns(true),
871
+ clear: sinon.stub(),
872
+ };
873
+ const result = webex.internal.ediscovery
874
+ .getContentContainerByContainerId(url, uuid)
875
+ .then((res) => {
876
+ expect(res.body).to.equal(mockCachedContainer);
877
+ assert.callCount(webex.internal.ediscovery.contentContainerCache.has, 1);
878
+ assert.callCount(containerIdMap.has, 1);
879
+ assert.callCount(containerIdMap.get, 1);
880
+ });
881
+
882
+ return result;
883
+ });
884
+
885
+ it('GetContentContainerByContainerId by url populates contentContainerCache with container when retrieved', async () => {
886
+ const mockResponse = {body: {containerId: uuid}};
887
+
888
+ webex.internal.ediscovery.request = sinon.stub().resolves(mockResponse);
889
+
890
+ const containerIdMap = {
891
+ set: sinon.stub(),
892
+ has: sinon.stub().returns(false),
893
+ };
894
+
895
+ webex.internal.ediscovery.contentContainerCache = {
896
+ get: sinon.stub().withArgs(uuid).returns(containerIdMap),
897
+ set: sinon.stub(),
898
+ has: sinon.stub().returns(true),
899
+ clear: sinon.stub(),
900
+ };
901
+ const result = webex.internal.ediscovery
902
+ .getContentContainerByContainerId(url, uuid)
903
+ .then((res) => {
904
+ expect(res).to.equal(mockResponse);
905
+ assert.callCount(webex.internal.ediscovery.contentContainerCache.has, 2);
906
+ assert.callCount(containerIdMap.has, 1);
907
+ assert.calledWith(containerIdMap.set, mockResponse.body.containerId, mockResponse.body);
908
+ });
909
+
910
+ return result;
911
+ });
912
+
913
+ it('GetContentContainerByContainerId by url cannot write container to contentContainerCache without containerId', async () => {
914
+ const mockResponse = {body: {}};
915
+
916
+ webex.internal.ediscovery.request = sinon.stub().resolves(mockResponse);
917
+
918
+ const containerIdMap = {
919
+ set: sinon.stub(),
920
+ has: sinon.stub().returns(false),
921
+ };
922
+
923
+ webex.internal.ediscovery.contentContainerCache = {
924
+ get: sinon.stub().withArgs(uuid).returns(containerIdMap),
925
+ set: sinon.stub(),
926
+ has: sinon.stub().returns(true),
927
+ clear: sinon.stub(),
928
+ };
929
+ const result = webex.internal.ediscovery
930
+ .getContentContainerByContainerId(url, uuid)
931
+ .then((res) => {
932
+ expect(res).to.equal(mockResponse);
933
+ assert.callCount(webex.internal.ediscovery.contentContainerCache.has, 2);
934
+ assert.callCount(containerIdMap.has, 1);
935
+ assert.notCalled(containerIdMap.set);
936
+ });
937
+
938
+ return result;
939
+ });
940
+ });
941
+
942
+ describe('ClearCache Tests', () => {
943
+ it('Clear caches of spaces and content containers', async () => {
944
+ const spaceIdMap = {
945
+ set: sinon.stub(),
946
+ has: sinon.stub().returns(false),
947
+ };
948
+
949
+ webex.internal.ediscovery.contentContainerCache = {
950
+ get: sinon.stub().withArgs(uuid).returns(spaceIdMap),
951
+ set: sinon.stub(),
952
+ has: sinon.stub().returns(true),
953
+ clear: sinon.stub(),
954
+ };
955
+
956
+ const containerIdMap = {
957
+ set: sinon.stub(),
958
+ has: sinon.stub().returns(false),
959
+ };
960
+
961
+ webex.internal.ediscovery.contentContainerCache = {
962
+ get: sinon.stub().withArgs(uuid).returns(containerIdMap),
963
+ set: sinon.stub(),
964
+ has: sinon.stub().returns(false),
965
+ clear: sinon.stub(),
966
+ };
967
+
968
+ webex.internal.ediscovery.clearCache();
969
+
970
+ assert.callCount(webex.internal.ediscovery.contentContainerCache.clear, 1);
971
+ });
972
+ });
973
+
974
+ describe('PostAuditLog Tests', () => {
975
+ it('PostAuditLog with valid reportId succeeds', () => {
976
+ webex.internal.ediscovery.postAuditLog(uuid, {timeoutMs: 1000}).then((res) => {
977
+ expect(res.statusCode).equal(200);
978
+ sinon.assert.calledWith(webex.request, sinon.match.has('timeout', 1000));
979
+ });
980
+ });
981
+
982
+ it('PostAuditLog with no reportId is rejected', () => {
983
+ const noUuid = '';
984
+
985
+ expect(webex.internal.ediscovery.postAuditLog(noUuid, {timeoutMs: 1000})).to.be.rejectedWith(
986
+ Error,
987
+ 'No report ID specified'
988
+ );
989
+ });
990
+
991
+ it('PostAuditLog propagates http error on failure', () => {
992
+ webex.request = sinon.stub().returns(
993
+ Promise.resolve({
994
+ body: {},
995
+ statusCode: 400,
996
+ })
997
+ );
998
+
999
+ webex.internal.ediscovery.postAuditLog(uuid, {timeoutMs: 1000}).then((res) => {
1000
+ expect(res.statusCode).equal(400);
1001
+ });
1002
+ });
1003
+ });
1004
+
1005
+ describe('_getReportIdFromUrl Tests', () => {
1006
+ it('_getReportIdFromUrl of report url', async () => {
1007
+ const url =
1008
+ 'https://ediscovery-intb.ciscospark.com/ediscovery/api/v1/reports/16bf0d01-b1f7-483b-89a2-915144158fb9';
1009
+
1010
+ const uuid = webex.internal.ediscovery._getReportIdFromUrl(url);
1011
+
1012
+ expect(uuid).equal('16bf0d01-b1f7-483b-89a2-915144158fb9');
1013
+ });
1014
+
1015
+ it('_createRequestOptions of report url with multiple uuids', async () => {
1016
+ const url =
1017
+ 'https://ediscovery-intb.ciscospark.com/ediscovery/api/v1/reports/16bf0d01-b1f7-483b-89a2-915144158fb9/contents/0498830f-1d63-4faa-b53b-35e1b12ccf9f';
1018
+
1019
+ const uuid = webex.internal.ediscovery._getReportIdFromUrl(url);
1020
+
1021
+ expect(uuid).equal('16bf0d01-b1f7-483b-89a2-915144158fb9');
1022
+ });
1023
+ });
1024
+
1025
+ describe('_isUrl Tests', () => {
1026
+ it('_isUrl with a url', async () => {
1027
+ const url =
1028
+ 'https://ediscovery-intb.ciscospark.com/ediscovery/api/v1/reports/16bf0d01-b1f7-483b-89a2-915144158fb9';
1029
+
1030
+ assert(webex.internal.ediscovery._isUrl(url));
1031
+ });
1032
+
1033
+ it('_isUrl with a uuid', async () => {
1034
+ assert(!webex.internal.ediscovery._isUrl('16bf0d01-b1f7-483b-89a2-915144158fb9'));
1035
+ });
1036
+
1037
+ it('_isUrl with a string', async () => {
1038
+ assert(!webex.internal.ediscovery._isUrl('abcdefghij'));
1039
+ });
1040
+ });
1041
+
1042
+ describe('_createRequestOptions Tests', () => {
1043
+ it('_createRequestOptions with uuid', async () => {
1044
+ const uuid = '16bf0d01-b1f7-483b-89a2-915144158fb9';
1045
+ const resource = '/my/extra/resource/path';
1046
+ const [options, returnedUUID] = webex.internal.ediscovery._createRequestOptions(
1047
+ uuid,
1048
+ resource
1049
+ );
1050
+
1051
+ expect(uuid).equal(returnedUUID);
1052
+ expect(options.service).equal('ediscovery');
1053
+ expect(options.resource).equal(`reports/${uuid}/${resource}`);
1054
+ });
1055
+
1056
+ it('_createRequestOptions with url', async () => {
1057
+ const url =
1058
+ 'https://ediscovery-intb.ciscospark.com/ediscovery/api/v1/reports/16bf0d01-b1f7-483b-89a2-915144158fb9';
1059
+ const resource = '/my/extra/resource/path';
1060
+ const [options, returnedUUID] = webex.internal.ediscovery._createRequestOptions(
1061
+ url,
1062
+ resource
1063
+ );
1064
+
1065
+ expect(returnedUUID).equal('16bf0d01-b1f7-483b-89a2-915144158fb9');
1066
+ expect(options.url).equal(url + resource);
1067
+ });
1068
+
1069
+ it('_createRequestOptions with url with details after the uuid', async () => {
1070
+ const url =
1071
+ 'https://ediscovery-intb.ciscospark.com/ediscovery/api/v1/reports/16bf0d01-b1f7-483b-89a2-915144158fb9';
1072
+ const urlPlus =
1073
+ 'https://ediscovery-intb.ciscospark.com/ediscovery/api/v1/reports/16bf0d01-b1f7-483b-89a2-915144158fb9/contents/and/more';
1074
+ const resource = '/my/extra/resource/path';
1075
+ const [options, returnedUUID] = webex.internal.ediscovery._createRequestOptions(
1076
+ urlPlus,
1077
+ resource
1078
+ );
1079
+
1080
+ expect(returnedUUID).equal('16bf0d01-b1f7-483b-89a2-915144158fb9');
1081
+ expect(options.url).equal(url + resource);
1082
+ });
1083
+ });
1084
+ });