@webex/webex-core 3.9.0-next.3 → 3.9.0-next.4

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.
@@ -394,13 +394,13 @@ describe('webex-core', () => {
394
394
  );
395
395
 
396
396
  it('resolves to an authed u2c hostmap when no params specified', () => {
397
- assert.typeOf(fullRemoteHM, 'array');
398
- assert.isAbove(fullRemoteHM.length, 0);
397
+ assert.typeOf(fullRemoteHM.services, 'array');
398
+ assert.isAbove(fullRemoteHM.services.length, 0);
399
399
  });
400
400
 
401
401
  it('resolves to a limited u2c hostmap when params specified', () => {
402
- assert.typeOf(limitedRemoteHM, 'array');
403
- assert.isAbove(limitedRemoteHM.length, 0);
402
+ assert.typeOf(limitedRemoteHM.services, 'array');
403
+ assert.isAbove(limitedRemoteHM.services.length, 0);
404
404
  });
405
405
 
406
406
  it('rejects if the params provided are invalid', () =>
@@ -449,7 +449,7 @@ describe('webex-core', () => {
449
449
  catalog
450
450
  .waitForCatalog('postauth', 1)
451
451
  .then(() => assert(true, 'promise resolved'))
452
- .finally(() => catalog.updateServiceGroups('postauth', formattedHM));
452
+ .finally(() => catalog.updateServiceGroups('postauth', formattedHM.services));
453
453
  });
454
454
  });
455
455
 
@@ -463,7 +463,7 @@ describe('webex-core', () => {
463
463
  });
464
464
 
465
465
  it('removes any unused urls from current services', () => {
466
- catalog.updateServiceGroups('preauth', formattedHM);
466
+ catalog.updateServiceGroups('preauth', formattedHM.services);
467
467
 
468
468
  const originalLength = catalog.serviceGroups.preauth.length;
469
469
 
@@ -473,9 +473,9 @@ describe('webex-core', () => {
473
473
  });
474
474
 
475
475
  it('updates the target catalog to contain the provided hosts', () => {
476
- catalog.updateServiceGroups('preauth', formattedHM);
476
+ catalog.updateServiceGroups('preauth', formattedHM.services);
477
477
 
478
- assert.equal(catalog.serviceGroups.preauth.length, formattedHM.length);
478
+ assert.equal(catalog.serviceGroups.preauth.length, formattedHM.services.length);
479
479
  });
480
480
 
481
481
  it('updates any existing ServiceUrls', () => {
@@ -601,21 +601,21 @@ describe('webex-core', () => {
601
601
  format: 'U2Cv2',
602
602
  };
603
603
 
604
- catalog.updateServiceGroups('preauth', formattedHM);
604
+ catalog.updateServiceGroups('preauth', formattedHM.services);
605
605
 
606
606
  const oldServiceDetails = catalog._getAllServiceDetails('preauth');
607
607
 
608
608
  const newFormattedHM = services._formatReceivedHostmap(newServiceHM);
609
609
 
610
- catalog.updateServiceGroups('preauth', newFormattedHM);
610
+ catalog.updateServiceGroups('preauth', newFormattedHM.services);
611
611
 
612
612
  oldServiceDetails.forEach((serviceDetail) =>
613
- assert.isTrue(!!formattedHM.find((service) => service.id === serviceDetail.id))
613
+ assert.isTrue(!!formattedHM.services.find((service) => service.id === serviceDetail.id))
614
614
  );
615
615
 
616
616
  const newServiceDetails = catalog._getAllServiceDetails('preauth');
617
617
 
618
- formattedHM.forEach((oldServiceDetail) =>
618
+ formattedHM.services.forEach((oldServiceDetail) =>
619
619
  assert.notEqual(
620
620
  oldServiceDetail.serviceUrls[0].baseUrl,
621
621
  newServiceDetails.find((service) => service.id === oldServiceDetail.id).get()
@@ -624,7 +624,7 @@ describe('webex-core', () => {
624
624
  });
625
625
 
626
626
  it('creates an array of equal length of active services', () => {
627
- assert.equal(serviceHostmap.services.length, formattedHM.length);
627
+ assert.equal(serviceHostmap.services.length, formattedHM.services.length);
628
628
  });
629
629
 
630
630
  it('creates an array with matching host data', () => {
@@ -646,7 +646,7 @@ describe('webex-core', () => {
646
646
  done();
647
647
  });
648
648
 
649
- catalog.updateServiceGroups('preauth', formattedHM);
649
+ catalog.updateServiceGroups('preauth', formattedHM.services);
650
650
  });
651
651
 
652
652
  it('updates the services list', (done) => {
@@ -657,7 +657,7 @@ describe('webex-core', () => {
657
657
  done();
658
658
  });
659
659
 
660
- catalog.updateServiceGroups('preauth', formattedHM);
660
+ catalog.updateServiceGroups('preauth', formattedHM.services);
661
661
  });
662
662
  });
663
663
  });
@@ -23,6 +23,7 @@ import {
23
23
  formattedServiceHostmapEntryConv,
24
24
  formattedServiceHostmapEntryMercury,
25
25
  formattedServiceHostmapEntryTest,
26
+ serviceHostmapV2
26
27
  } from '../../../fixtures/host-catalog-v2';
27
28
 
28
29
  // /* eslint-disable no-underscore-dangle */
@@ -389,6 +390,32 @@ describe('webex-core', () => {
389
390
  .then(() => assert.calledTwice(services.updateServices))
390
391
  );
391
392
  });
393
+
394
+ it('should call services#collectPreauthCatalog with the OrgId and forceRefresh is true', () => {
395
+ services.collectPreauthCatalog = sinon.stub().resolves();
396
+
397
+ return services.initServiceCatalogs(true).then(() =>
398
+ assert.calledWith(
399
+ services.collectPreauthCatalog,
400
+ sinon.match({
401
+ orgId: webex.credentials.getOrgId(),
402
+ }),
403
+ sinon.match(true)
404
+ )
405
+ );
406
+ });
407
+
408
+ it('should call services#updateServices() with forceRefresh is true', () => {
409
+ services.updateServices = sinon.stub().resolves();
410
+
411
+ return (
412
+ services
413
+ .initServiceCatalogs(true)
414
+ // services#updateServices() gets called once by the limited catalog
415
+ // retrieval and should get called again when authorized.
416
+ .then(() => assert.calledTwice(services.updateServices) && assert.calledWith(services.updateServices, sinon.match({forceRefresh: true})))
417
+ );
418
+ });
392
419
  });
393
420
 
394
421
  describe('#isAllowedDomainUrl()', () => {
@@ -513,6 +540,54 @@ describe('webex-core', () => {
513
540
  });
514
541
  });
515
542
 
543
+ describe('#switchActiveClusterIds', () => {
544
+ let requestStub;
545
+
546
+ beforeEach(() => {
547
+ services._formatReceivedHostmap(serviceHostmapV2);
548
+ });
549
+
550
+ afterEach(() => {
551
+ requestStub.restore();
552
+ });
553
+
554
+ it('fetches new catalog when id does not exist', () => {
555
+ requestStub = sinon
556
+ .stub(webex.internal.newMetrics.callDiagnosticLatencies, 'measureLatency')
557
+ .returns(
558
+ Promise.resolve({
559
+ body: {
560
+ activeServices: {
561
+ ...serviceHostmapV2.activeServices,
562
+ conversation: 'urn:TEAM:me-central-1_asdf:conversation',
563
+ },
564
+ services: [
565
+ ...serviceHostmapV2.services,
566
+ {
567
+ id: 'urn:TEAM:me-central-1_asdf:conversation',
568
+ serviceName: 'conversation',
569
+ serviceUrls: [{baseUrl: 'baseurl.com', priority: 1}],
570
+ },
571
+ ],
572
+ },
573
+ })
574
+ );
575
+
576
+ services
577
+ .switchActiveClusterIds({
578
+ conversation: 'urn:TEAM:me-central-1_asdf:conversation',
579
+ })
580
+ .then(() => {
581
+ assert.equal(
582
+ !!services._services.find(
583
+ (service) => service.id === 'urn:TEAM:me-central-1_asdf:conversation'
584
+ ),
585
+ true
586
+ );
587
+ });
588
+ });
589
+ });
590
+
516
591
  describe('#updateServices()', () => {
517
592
  it('returns a Promise that and resolves on success', (done) => {
518
593
  const servicesPromise = services.updateServices();
@@ -1034,13 +1109,13 @@ describe('webex-core', () => {
1034
1109
  );
1035
1110
 
1036
1111
  it('resolves to an authed u2c hostmap when no params specified', () => {
1037
- assert.typeOf(fullRemoteHM, 'array');
1038
- assert.isAbove(fullRemoteHM.length, 0);
1112
+ assert.typeOf(fullRemoteHM.services, 'array');
1113
+ assert.isAbove(fullRemoteHM.services.length, 0);
1039
1114
  });
1040
1115
 
1041
1116
  it('resolves to a limited u2c hostmap when params specified', () => {
1042
- assert.typeOf(limitedRemoteHM, 'array');
1043
- assert.isAbove(limitedRemoteHM.length, 0);
1117
+ assert.typeOf(limitedRemoteHM.services, 'array');
1118
+ assert.isAbove(limitedRemoteHM.services.length, 0);
1044
1119
  });
1045
1120
 
1046
1121
  it('rejects if the params provided are invalid', () =>
@@ -268,12 +268,58 @@ describe('webex-core', () => {
268
268
  });
269
269
  });
270
270
 
271
+ describe('#switchActiveClusterIds', () => {
272
+ let serviceHostmap;
273
+ let formattedHM;
274
+
275
+ beforeEach(() => {
276
+ serviceHostmap = serviceHostmapV2;
277
+ formattedHM = services._formatReceivedHostmap(serviceHostmap);
278
+
279
+ services.initServiceCatalogs = sinon.stub().returns(Promise.resolve());
280
+ services.webex.credentials = {
281
+ getOrgId: sinon.stub().returns('')
282
+ };
283
+ catalog.status = {};
284
+ });
285
+
286
+ it('switches properly when id exists', async () => {
287
+ services._updateActiveServices = sinon.stub().callsFake((data) => {
288
+ Object.assign(services._activeServices, data);
289
+ });
290
+
291
+ await services.switchActiveClusterIds({
292
+ conversation: 'urn:TEAM:me-central-1_d:conversation',
293
+ });
294
+
295
+ assert.notCalled(services.initServiceCatalogs);
296
+
297
+ assert.calledWith(services._updateActiveServices, {
298
+ conversation: 'urn:TEAM:me-central-1_d:conversation',
299
+ });
300
+
301
+ assert.equal(services._activeServices.conversation, 'urn:TEAM:me-central-1_d:conversation');
302
+ });
303
+
304
+ it('makes request to fetch when id does not exist', async () => {
305
+ services._updateActiveServices = sinon.stub().callsFake((data) => {
306
+ Object.assign(services._activeServices, data);
307
+ });
308
+
309
+ await services.switchActiveClusterIds({
310
+ conversation: 'urn:TEAM:me-central-1_asdf:conversation',
311
+ });
312
+
313
+ assert.calledOnce(services.initServiceCatalogs);
314
+ });
315
+ });
316
+
271
317
  describe('#updateCatalog', () => {
272
318
  it('updates the catalog', async () => {
273
319
  const serviceGroup = 'postauth';
274
- const hostmap = [{hostmap: 'hostmap'}];
320
+ const hostmap = {services: [{hostmap: 'hostmap'}]};
275
321
 
276
- services._formatReceivedHostmap = sinon.stub().returns([{some: 'hostmap'}]);
322
+ services._formatReceivedHostmap = sinon.stub().returns({services : [{some: 'hostmap'}]});
277
323
 
278
324
  catalog.updateServiceGroups = sinon.stub().returns(Promise.resolve([{some: 'value'}]));
279
325
 
@@ -401,7 +447,7 @@ describe('webex-core', () => {
401
447
  formattedHM = services._formatReceivedHostmap(serviceHostmap);
402
448
 
403
449
  assert(
404
- serviceHostmap.services.length >= formattedHM.length,
450
+ serviceHostmap.services.length >= formattedHM.services.length,
405
451
  'length is not equal or less than'
406
452
  );
407
453
  });
@@ -409,7 +455,7 @@ describe('webex-core', () => {
409
455
  it('has all keys in host map hosts', () => {
410
456
  formattedHM = services._formatReceivedHostmap(serviceHostmap);
411
457
 
412
- formattedHM.forEach((service) => {
458
+ formattedHM.services.forEach((service) => {
413
459
  assert.hasAllKeys(
414
460
  service,
415
461
  ['id', 'serviceName', 'serviceUrls'],
@@ -428,7 +474,7 @@ describe('webex-core', () => {
428
474
  it('creates a formmated host map containing all received host map service entries', () => {
429
475
  formattedHM = services._formatReceivedHostmap(serviceHostmap);
430
476
 
431
- formattedHM.forEach((service) => {
477
+ formattedHM.services.forEach((service) => {
432
478
  const foundServiceKey = Object.keys(serviceHostmap.activeServices).find(
433
479
  (key) => service.serviceName === key
434
480
  );
@@ -440,7 +486,7 @@ describe('webex-core', () => {
440
486
  it('creates the expected formatted host map', () => {
441
487
  formattedHM = services._formatReceivedHostmap(serviceHostmap);
442
488
 
443
- assert.deepEqual(formattedHM, formattedServiceHostmapV2);
489
+ assert.deepEqual(formattedHM.services, formattedServiceHostmapV2);
444
490
  });
445
491
 
446
492
  it('has hostCatalog updated', () => {
@@ -512,5 +558,142 @@ describe('webex-core', () => {
512
558
  assert.equal(webex.config.credentials.authorizeUrl, authUrl);
513
559
  });
514
560
  });
561
+
562
+ describe('#invalidateCache', () => {
563
+ beforeEach( () => {
564
+ services.initServiceCatalogs = sinon.stub().returns(Promise.resolve());
565
+ services.webex.credentials = {
566
+ getOrgId: sinon.stub().returns('')
567
+ };
568
+ catalog.status = {};
569
+ })
570
+ it('should log the timestamp parameter', async () => {
571
+ const timestamp = '1234567890';
572
+ services.logger.info = sinon.stub();
573
+ services._getCatalog = sinon.stub().returns({timestamp: '1234567880'});
574
+
575
+ await services.invalidateCache(timestamp);
576
+
577
+ assert.calledWith(services.logger.info, 'services: invalidate cache, timestamp:', timestamp);
578
+ });
579
+
580
+ it('should call initServiceCatalogs when invalidate timestamp is newer than catalog timestamp', async () => {
581
+ const newTimestamp = '1234567890';
582
+ const oldTimestamp = '1234567880';
583
+ services.logger.info = sinon.stub();
584
+ services._getCatalog = sinon.stub().returns({timestamp: oldTimestamp});
585
+
586
+ await services.invalidateCache(newTimestamp);
587
+
588
+ assert.calledOnce(services.initServiceCatalogs);
589
+ assert.calledWith(services.logger.info, 'services: invalidateCache, refresh services');
590
+ });
591
+
592
+ it('should not call initServiceCatalogs when invalidate timestamp is older than catalog timestamp', async () => {
593
+ const oldTimestamp = '1234567880';
594
+ const newTimestamp = '1234567890';
595
+ services._getCatalog = sinon.stub().returns({timestamp: newTimestamp});
596
+ await services.invalidateCache(oldTimestamp);
597
+
598
+ assert.notCalled(services.initServiceCatalogs);
599
+ });
600
+
601
+ it('should not call initServiceCatalogs when invalidate timestamp equals catalog timestamp', async () => {
602
+ const timestamp = '1234567890';
603
+ services._getCatalog = sinon.stub().returns({timestamp: timestamp});
604
+
605
+ await services.invalidateCache(timestamp);
606
+
607
+ assert.notCalled(services.initServiceCatalogs);
608
+ });
609
+
610
+ it('should handle numeric timestamp strings correctly', async () => {
611
+ const newTimestamp = '1700000000';
612
+ const oldTimestamp = '1600000000';
613
+ services._getCatalog = sinon.stub().returns({timestamp: oldTimestamp});
614
+
615
+ await services.invalidateCache(newTimestamp);
616
+
617
+ assert.calledOnce(services.initServiceCatalogs);
618
+ });
619
+
620
+ it('should handle undefined catalog gracefully', async () => {
621
+ const timestamp = '1234567890';
622
+ services._getCatalog = sinon.stub().returns(undefined);
623
+
624
+ await services.invalidateCache(timestamp);
625
+
626
+ assert.calledOnce(services.initServiceCatalogs);
627
+ });
628
+
629
+ it('should handle catalog without timestamp gracefully', async () => {
630
+ const timestamp = '1234567890';
631
+ services._getCatalog = sinon.stub().returns({});
632
+
633
+ await services.invalidateCache(timestamp);
634
+
635
+ assert.calledOnce(services.initServiceCatalogs);
636
+ });
637
+
638
+ it('should handle null catalog timestamp gracefully', async () => {
639
+ const timestamp = '1234567890';
640
+ services._getCatalog = sinon.stub().returns({timestamp: null});
641
+
642
+ await services.invalidateCache(timestamp);
643
+
644
+ assert.calledOnce(services.initServiceCatalogs);
645
+ });
646
+
647
+ it('should handle undefined timestamp parameter gracefully', async () => {
648
+ services._getCatalog = sinon.stub().returns({timestamp: '1234567890'});
649
+
650
+ await services.invalidateCache(undefined);
651
+
652
+ assert.notCalled(services.initServiceCatalogs);
653
+ });
654
+
655
+ it('should handle null timestamp parameter gracefully', async () => {
656
+ services._getCatalog = sinon.stub().returns({timestamp: '1234567890'});
657
+
658
+ await services.invalidateCache(null);
659
+
660
+ assert.notCalled(services.initServiceCatalogs);
661
+ });
662
+
663
+ it('should handle empty string timestamp parameter gracefully', async () => {
664
+ services._getCatalog = sinon.stub().returns({timestamp: '1234567890'});
665
+
666
+ await services.invalidateCache('');
667
+
668
+ assert.notCalled(services.initServiceCatalogs);
669
+ });
670
+
671
+ it('should handle non-numeric timestamp strings gracefully', async () => {
672
+ const invalidTimestamp = 'not-a-number';
673
+ services._getCatalog = sinon.stub().returns({timestamp: '1234567890'});
674
+
675
+ await services.invalidateCache(invalidTimestamp);
676
+
677
+ assert.notCalled(services.initServiceCatalogs);
678
+ });
679
+
680
+ it('should handle non-numeric catalog timestamp gracefully', async () => {
681
+ const timestamp = '1234567890';
682
+ services._getCatalog = sinon.stub().returns({timestamp: 'not-a-number'});
683
+
684
+ await services.invalidateCache(timestamp);
685
+
686
+ assert.calledOnce(services.initServiceCatalogs);
687
+ });
688
+
689
+ it('should return a resolved Promise', async () => {
690
+ const timestamp = '1234567890';
691
+ services._getCatalog = sinon.stub().returns({timestamp: '1234567880'});
692
+
693
+ const result = await services.invalidateCache(timestamp);
694
+
695
+ assert.isUndefined(result);
696
+ });
697
+ });
515
698
  });
516
699
  });