@webex/webex-core 3.0.0-beta.33 → 3.0.0-beta.331

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.
@@ -0,0 +1,55 @@
1
+ import {assert} from '@webex/test-helper-chai';
2
+ import {sortScope, filterScope, diffScopes} from '@webex/webex-core/src/lib/credentials/scope';
3
+
4
+ describe('webex-core', () => {
5
+ describe('scope utils', () => {
6
+ describe('sortScope', () => {
7
+ it('should sort scopes alphabetically', () => {
8
+ assert.equal(sortScope(undefined), '');
9
+ assert.equal(sortScope(''), '');
10
+ assert.equal(sortScope('a'), 'a');
11
+ assert.equal(sortScope('b c a'), 'a b c');
12
+ });
13
+ });
14
+
15
+ describe('filterScope', () => {
16
+ it('should filter out one scope from the original scope and sort the result', () => {
17
+ assert.equal(filterScope('a', undefined), '');
18
+ assert.equal(filterScope('a', ''), '');
19
+ assert.equal(filterScope('a', 'a'), '');
20
+ assert.equal(filterScope('a', 'a b c'), 'b c');
21
+ assert.equal(filterScope('c', 'a c b'), 'a b');
22
+ });
23
+
24
+ it('should filter out a list of scopes from the original scope and sort the result', () => {
25
+ assert.equal(filterScope([], 'a'), 'a');
26
+ assert.equal(filterScope(['a', 'b'], undefined), '');
27
+ assert.equal(filterScope(['a', 'b'], ''), '');
28
+ assert.equal(filterScope(['a', 'b'], 'a'), '');
29
+ assert.equal(filterScope(['a', 'b'], 'a b c'), 'c');
30
+ assert.equal(filterScope(['a', 'd'], 'a c a b'), 'b c');
31
+ });
32
+ });
33
+
34
+ describe('diffScopes', () => {
35
+ it('should return an empty string, if all items in the first scope are contained in the second scope', () => {
36
+ assert.deepEqual(diffScopes(undefined, undefined), '');
37
+ assert.deepEqual(diffScopes(undefined, ''), '');
38
+ assert.deepEqual(diffScopes('', undefined), '');
39
+ assert.deepEqual(diffScopes('', ''), '');
40
+ assert.deepEqual(diffScopes('a', 'a'), '');
41
+ assert.deepEqual(diffScopes('a b c', 'a b c'), '');
42
+ assert.deepEqual(diffScopes(undefined, 'a b c'), '');
43
+ assert.deepEqual(diffScopes('a b c', 'a b c d'), '');
44
+ });
45
+
46
+ it('should return a string containing all items in the first scope that are not in the second scope', () => {
47
+ assert.deepEqual(diffScopes('a', undefined), 'a');
48
+ assert.deepEqual(diffScopes('a', 'b'), 'a');
49
+ assert.deepEqual(diffScopes('a b c', 'a b'), 'c');
50
+ assert.deepEqual(diffScopes('a b c d', 'a b c'), 'd');
51
+ assert.deepEqual(diffScopes('a b c', undefined), 'a b c');
52
+ });
53
+ });
54
+ });
55
+ });
@@ -12,6 +12,7 @@ import Logger from '@webex/plugin-logger';
12
12
  import MockWebex from '@webex/test-helper-mock-webex';
13
13
  import {AuthInterceptor, config, Credentials, WebexHttpError, Token} from '@webex/webex-core';
14
14
  import {cloneDeep, merge} from 'lodash';
15
+ import Metrics from '@webex/internal-plugin-metrics';
15
16
 
16
17
  const {assert} = chai;
17
18
 
@@ -28,6 +29,7 @@ describe('webex-core', () => {
28
29
  children: {
29
30
  credentials: Credentials,
30
31
  logger: Logger,
32
+ metrics: Metrics,
31
33
  },
32
34
  config: merge(cloneDeep(config), {credentials: {client_secret: 'fake'}}),
33
35
  });
@@ -41,6 +43,7 @@ describe('webex-core', () => {
41
43
  );
42
44
 
43
45
  interceptor = Reflect.apply(AuthInterceptor.create, webex, []);
46
+ sinon.stub(webex.internal.metrics, 'submitClientMetrics').callsFake(() => {});
44
47
  });
45
48
 
46
49
  describe('#onRequest()', () => {
@@ -5,6 +5,7 @@ import chai from 'chai';
5
5
  import chaiAsPromised from 'chai-as-promised';
6
6
  import sinon from 'sinon';
7
7
  import {ServiceInterceptor} from '@webex/webex-core';
8
+ import CONFIG from '../../../../../src/config';
8
9
 
9
10
  const {assert} = chai;
10
11
 
@@ -26,6 +27,7 @@ describe('webex-core', () => {
26
27
  service: 'example',
27
28
  serviceUrl: 'https://www.example-service.com/',
28
29
  uri: 'https://www.example-uri.com/',
30
+ waitForServiceTimeout: 11,
29
31
  };
30
32
 
31
33
  options = {};
@@ -107,6 +109,7 @@ describe('webex-core', () => {
107
109
 
108
110
  options.service = fixture.service;
109
111
  options.resource = fixture.resource;
112
+ options.timeout = fixture.waitForServiceTimeout;
110
113
  });
111
114
 
112
115
  it('should normalize the options', () =>
@@ -116,9 +119,12 @@ describe('webex-core', () => {
116
119
  interceptor.onRequest(options).then(() => assert.called(interceptor.validateOptions)));
117
120
 
118
121
  it('should attempt to collect the service url', () =>
119
- interceptor
120
- .onRequest(options)
121
- .then(() => assert.calledWith(waitForService, {name: options.service})));
122
+ interceptor.onRequest(options).then(
123
+ assert.calledWith(waitForService, {
124
+ name: options.service,
125
+ timeout: options.waitForServiceTimeout,
126
+ })
127
+ ));
122
128
 
123
129
  describe('when the service url was collected successfully', () => {
124
130
  beforeEach('generate additional mocks', () => {});
@@ -298,6 +298,12 @@ describe('webex-core', () => {
298
298
  formattedHM.map((item) => item.name)
299
299
  );
300
300
  });
301
+
302
+ it('has hostCatalog updated', () => {
303
+ services._formatReceivedHostmap(serviceHostmap);
304
+
305
+ assert.deepStrictEqual(services._hostCatalog, serviceHostmap.hostCatalog);
306
+ });
301
307
  });
302
308
 
303
309
  describe('#updateCredentialsConfig()', () => {
@@ -54,6 +54,18 @@ describe('Webex', () => {
54
54
  });
55
55
  });
56
56
 
57
+ describe('#request', () => {
58
+ it('exists', () => {
59
+ assert.property(webex, 'request');
60
+ });
61
+ });
62
+
63
+ describe('#prepareFetchOptions', () => {
64
+ it('exists', () => {
65
+ assert.property(webex, 'prepareFetchOptions');
66
+ });
67
+ });
68
+
57
69
  describe('#initialize()', () => {
58
70
  it('initializes without arguments', () => {
59
71
  let webex;