@webex/webex-core 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.
Files changed (189) hide show
  1. package/.eslintrc.js +6 -6
  2. package/README.md +79 -79
  3. package/babel.config.js +3 -3
  4. package/dist/config.js +24 -24
  5. package/dist/config.js.map +1 -1
  6. package/dist/credentials-config.js +56 -56
  7. package/dist/credentials-config.js.map +1 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/interceptors/auth.js +28 -28
  10. package/dist/interceptors/auth.js.map +1 -1
  11. package/dist/interceptors/default-options.js +24 -24
  12. package/dist/interceptors/default-options.js.map +1 -1
  13. package/dist/interceptors/embargo.js +9 -9
  14. package/dist/interceptors/embargo.js.map +1 -1
  15. package/dist/interceptors/network-timing.js +19 -19
  16. package/dist/interceptors/network-timing.js.map +1 -1
  17. package/dist/interceptors/payload-transformer.js +19 -19
  18. package/dist/interceptors/payload-transformer.js.map +1 -1
  19. package/dist/interceptors/rate-limit.js +40 -40
  20. package/dist/interceptors/rate-limit.js.map +1 -1
  21. package/dist/interceptors/redirect.js +13 -13
  22. package/dist/interceptors/redirect.js.map +1 -1
  23. package/dist/interceptors/request-event.js +23 -23
  24. package/dist/interceptors/request-event.js.map +1 -1
  25. package/dist/interceptors/request-logger.js +13 -13
  26. package/dist/interceptors/request-logger.js.map +1 -1
  27. package/dist/interceptors/request-timing.js +23 -23
  28. package/dist/interceptors/request-timing.js.map +1 -1
  29. package/dist/interceptors/response-logger.js +19 -19
  30. package/dist/interceptors/response-logger.js.map +1 -1
  31. package/dist/interceptors/user-agent.js +29 -29
  32. package/dist/interceptors/user-agent.js.map +1 -1
  33. package/dist/interceptors/webex-tracking-id.js +15 -15
  34. package/dist/interceptors/webex-tracking-id.js.map +1 -1
  35. package/dist/interceptors/webex-user-agent.js +13 -13
  36. package/dist/interceptors/webex-user-agent.js.map +1 -1
  37. package/dist/lib/batcher.js +83 -83
  38. package/dist/lib/batcher.js.map +1 -1
  39. package/dist/lib/credentials/credentials.js +103 -103
  40. package/dist/lib/credentials/credentials.js.map +1 -1
  41. package/dist/lib/credentials/grant-errors.js +17 -17
  42. package/dist/lib/credentials/grant-errors.js.map +1 -1
  43. package/dist/lib/credentials/index.js +2 -2
  44. package/dist/lib/credentials/index.js.map +1 -1
  45. package/dist/lib/credentials/scope.js +11 -11
  46. package/dist/lib/credentials/scope.js.map +1 -1
  47. package/dist/lib/credentials/token-collection.js +2 -2
  48. package/dist/lib/credentials/token-collection.js.map +1 -1
  49. package/dist/lib/credentials/token.js +145 -145
  50. package/dist/lib/credentials/token.js.map +1 -1
  51. package/dist/lib/page.js +49 -49
  52. package/dist/lib/page.js.map +1 -1
  53. package/dist/lib/services/constants.js.map +1 -1
  54. package/dist/lib/services/index.js +2 -2
  55. package/dist/lib/services/index.js.map +1 -1
  56. package/dist/lib/services/interceptors/server-error.js +9 -9
  57. package/dist/lib/services/interceptors/server-error.js.map +1 -1
  58. package/dist/lib/services/interceptors/service.js +24 -24
  59. package/dist/lib/services/interceptors/service.js.map +1 -1
  60. package/dist/lib/services/metrics.js.map +1 -1
  61. package/dist/lib/services/service-catalog.js +104 -104
  62. package/dist/lib/services/service-catalog.js.map +1 -1
  63. package/dist/lib/services/service-fed-ramp.js.map +1 -1
  64. package/dist/lib/services/service-host.js +134 -134
  65. package/dist/lib/services/service-host.js.map +1 -1
  66. package/dist/lib/services/service-registry.js +175 -175
  67. package/dist/lib/services/service-registry.js.map +1 -1
  68. package/dist/lib/services/service-state.js +38 -38
  69. package/dist/lib/services/service-state.js.map +1 -1
  70. package/dist/lib/services/service-url.js +31 -31
  71. package/dist/lib/services/service-url.js.map +1 -1
  72. package/dist/lib/services/services.js +245 -245
  73. package/dist/lib/services/services.js.map +1 -1
  74. package/dist/lib/stateless-webex-plugin.js +28 -28
  75. package/dist/lib/stateless-webex-plugin.js.map +1 -1
  76. package/dist/lib/storage/decorators.js +27 -27
  77. package/dist/lib/storage/decorators.js.map +1 -1
  78. package/dist/lib/storage/errors.js +4 -4
  79. package/dist/lib/storage/errors.js.map +1 -1
  80. package/dist/lib/storage/index.js.map +1 -1
  81. package/dist/lib/storage/make-webex-plugin-store.js +44 -44
  82. package/dist/lib/storage/make-webex-plugin-store.js.map +1 -1
  83. package/dist/lib/storage/make-webex-store.js +40 -40
  84. package/dist/lib/storage/make-webex-store.js.map +1 -1
  85. package/dist/lib/storage/memory-store-adapter.js +9 -9
  86. package/dist/lib/storage/memory-store-adapter.js.map +1 -1
  87. package/dist/lib/webex-core-plugin-mixin.js +13 -13
  88. package/dist/lib/webex-core-plugin-mixin.js.map +1 -1
  89. package/dist/lib/webex-http-error.js +9 -9
  90. package/dist/lib/webex-http-error.js.map +1 -1
  91. package/dist/lib/webex-internal-core-plugin-mixin.js +13 -13
  92. package/dist/lib/webex-internal-core-plugin-mixin.js.map +1 -1
  93. package/dist/lib/webex-plugin.js +36 -36
  94. package/dist/lib/webex-plugin.js.map +1 -1
  95. package/dist/plugins/logger.js +9 -9
  96. package/dist/plugins/logger.js.map +1 -1
  97. package/dist/webex-core.js +104 -104
  98. package/dist/webex-core.js.map +1 -1
  99. package/dist/webex-internal-core.js +12 -12
  100. package/dist/webex-internal-core.js.map +1 -1
  101. package/jest.config.js +3 -3
  102. package/package.json +20 -19
  103. package/process +1 -1
  104. package/src/config.js +90 -90
  105. package/src/credentials-config.js +212 -212
  106. package/src/index.js +62 -62
  107. package/src/interceptors/auth.js +186 -186
  108. package/src/interceptors/default-options.js +55 -55
  109. package/src/interceptors/embargo.js +43 -43
  110. package/src/interceptors/network-timing.js +54 -54
  111. package/src/interceptors/payload-transformer.js +55 -55
  112. package/src/interceptors/rate-limit.js +169 -169
  113. package/src/interceptors/redirect.js +106 -106
  114. package/src/interceptors/request-event.js +93 -93
  115. package/src/interceptors/request-logger.js +78 -78
  116. package/src/interceptors/request-timing.js +65 -65
  117. package/src/interceptors/response-logger.js +98 -98
  118. package/src/interceptors/user-agent.js +77 -77
  119. package/src/interceptors/webex-tracking-id.js +73 -73
  120. package/src/interceptors/webex-user-agent.js +79 -79
  121. package/src/lib/batcher.js +307 -307
  122. package/src/lib/credentials/credentials.js +552 -552
  123. package/src/lib/credentials/grant-errors.js +92 -92
  124. package/src/lib/credentials/index.js +16 -16
  125. package/src/lib/credentials/scope.js +34 -34
  126. package/src/lib/credentials/token-collection.js +17 -17
  127. package/src/lib/credentials/token.js +559 -559
  128. package/src/lib/page.js +159 -159
  129. package/src/lib/services/constants.js +9 -9
  130. package/src/lib/services/index.js +26 -26
  131. package/src/lib/services/interceptors/server-error.js +48 -48
  132. package/src/lib/services/interceptors/service.js +101 -101
  133. package/src/lib/services/metrics.js +4 -4
  134. package/src/lib/services/service-catalog.js +435 -435
  135. package/src/lib/services/service-fed-ramp.js +4 -4
  136. package/src/lib/services/service-host.js +267 -267
  137. package/src/lib/services/service-registry.js +465 -465
  138. package/src/lib/services/service-state.js +78 -78
  139. package/src/lib/services/service-url.js +124 -124
  140. package/src/lib/services/services.js +1018 -1018
  141. package/src/lib/stateless-webex-plugin.js +98 -98
  142. package/src/lib/storage/decorators.js +220 -220
  143. package/src/lib/storage/errors.js +15 -15
  144. package/src/lib/storage/index.js +10 -10
  145. package/src/lib/storage/make-webex-plugin-store.js +211 -211
  146. package/src/lib/storage/make-webex-store.js +140 -140
  147. package/src/lib/storage/memory-store-adapter.js +79 -79
  148. package/src/lib/webex-core-plugin-mixin.js +114 -114
  149. package/src/lib/webex-http-error.js +61 -61
  150. package/src/lib/webex-internal-core-plugin-mixin.js +107 -107
  151. package/src/lib/webex-plugin.js +222 -222
  152. package/src/plugins/logger.js +60 -60
  153. package/src/webex-core.js +745 -745
  154. package/src/webex-internal-core.js +46 -46
  155. package/test/integration/spec/credentials/credentials.js +139 -139
  156. package/test/integration/spec/credentials/token.js +102 -102
  157. package/test/integration/spec/services/service-catalog.js +838 -838
  158. package/test/integration/spec/services/services.js +1221 -1221
  159. package/test/integration/spec/webex-core.js +178 -178
  160. package/test/unit/spec/_setup.js +44 -44
  161. package/test/unit/spec/credentials/credentials.js +1017 -1017
  162. package/test/unit/spec/credentials/token.js +441 -441
  163. package/test/unit/spec/interceptors/auth.js +521 -521
  164. package/test/unit/spec/interceptors/default-options.js +84 -84
  165. package/test/unit/spec/interceptors/embargo.js +144 -144
  166. package/test/unit/spec/interceptors/network-timing.js +49 -49
  167. package/test/unit/spec/interceptors/payload-transformer.js +155 -155
  168. package/test/unit/spec/interceptors/rate-limit.js +302 -302
  169. package/test/unit/spec/interceptors/redirect.js +102 -102
  170. package/test/unit/spec/interceptors/request-timing.js +92 -92
  171. package/test/unit/spec/interceptors/user-agent.js +76 -76
  172. package/test/unit/spec/interceptors/webex-tracking-id.js +76 -76
  173. package/test/unit/spec/interceptors/webex-user-agent.js +159 -159
  174. package/test/unit/spec/lib/batcher.js +330 -330
  175. package/test/unit/spec/lib/page.js +148 -148
  176. package/test/unit/spec/lib/webex-plugin.js +48 -48
  177. package/test/unit/spec/services/interceptors/server-error.js +204 -204
  178. package/test/unit/spec/services/interceptors/service.js +188 -188
  179. package/test/unit/spec/services/service-catalog.js +194 -194
  180. package/test/unit/spec/services/service-host.js +260 -260
  181. package/test/unit/spec/services/service-registry.js +747 -747
  182. package/test/unit/spec/services/service-state.js +60 -60
  183. package/test/unit/spec/services/service-url.js +258 -258
  184. package/test/unit/spec/services/services.js +348 -348
  185. package/test/unit/spec/storage/persist.js +50 -50
  186. package/test/unit/spec/storage/storage-adapter.js +12 -12
  187. package/test/unit/spec/storage/wait-for-value.js +81 -81
  188. package/test/unit/spec/webex-core.js +253 -253
  189. package/test/unit/spec/webex-internal-core.js +91 -91
@@ -1,348 +1,348 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import {assert} from '@webex/test-helper-chai';
6
- import MockWebex from '@webex/test-helper-mock-webex';
7
- import sinon from 'sinon';
8
- import {Services, ServiceRegistry, ServiceState} from '@webex/webex-core';
9
-
10
- /* eslint-disable no-underscore-dangle */
11
- describe('webex-core', () => {
12
- describe('Services', () => {
13
- let webex;
14
- let services;
15
- let catalog;
16
-
17
- beforeAll(() => {
18
- webex = new MockWebex({
19
- children: {
20
- services: Services,
21
- },
22
- });
23
- services = webex.internal.services;
24
- catalog = services._getCatalog();
25
- });
26
-
27
- describe('class members', () => {
28
- describe('#registries', () => {
29
- it('should be a weakmap', () => {
30
- assert.instanceOf(services.registries, WeakMap);
31
- });
32
- });
33
-
34
- describe('#states', () => {
35
- it('should be a weakmap', () => {
36
- assert.instanceOf(services.states, WeakMap);
37
- });
38
- });
39
- });
40
-
41
- describe('class methods', () => {
42
- describe('#getRegistry', () => {
43
- it('should be a service registry', () => {
44
- assert.instanceOf(services.getRegistry(), ServiceRegistry);
45
- });
46
- });
47
-
48
- describe('#getState', () => {
49
- it('should be a service state', () => {
50
- assert.instanceOf(services.getState(), ServiceState);
51
- });
52
- });
53
- });
54
-
55
- describe('#namespace', () => {
56
- it('is accurate to plugin name', () => {
57
- assert.equal(services.namespace, 'Services');
58
- });
59
- });
60
-
61
- describe('#_catalogs', () => {
62
- it('is a weakmap', () => {
63
- assert.typeOf(services._catalogs, 'weakmap');
64
- });
65
- });
66
-
67
- describe('#validateDomains', () => {
68
- it('is a boolean', () => {
69
- assert.isBoolean(services.validateDomains);
70
- });
71
- });
72
-
73
- describe('#list()', () => {
74
- let serviceList;
75
-
76
- beforeEach(() => {
77
- serviceList = services.list();
78
- });
79
-
80
- it('must return an object', () => {
81
- assert.typeOf(serviceList, 'object');
82
- });
83
-
84
- it('returned list must be of shape {Record<string, string>}', () => {
85
- Object.keys(serviceList).forEach((key) => {
86
- assert.typeOf(key, 'string');
87
- assert.typeOf(serviceList[key], 'string');
88
- });
89
- });
90
- });
91
-
92
- describe('#fetchClientRegionInfo', () => {
93
- it('successfully resolves with undefined if fetch request failed', () => {
94
- webex.request = sinon.stub().returns(Promise.reject());
95
-
96
- return services.fetchClientRegionInfo().then((r) => {
97
- assert.isUndefined(r);
98
- });
99
- });
100
- });
101
-
102
- describe('#getMeetingPreferences', () => {
103
- it('Fetch login users information ', async () => {
104
- const userPreferences = {userPreferences: 'userPreferences'};
105
-
106
- webex.request = sinon.stub().returns(Promise.resolve({body: userPreferences}));
107
-
108
- const res = await services.getMeetingPreferences();
109
-
110
- assert.calledWith(webex.request, {
111
- method: 'GET',
112
- service: 'hydra',
113
- resource: 'meetingPreferences',
114
- });
115
- assert.isDefined(res);
116
- assert.equal(res, userPreferences);
117
- });
118
-
119
- it('Resolve getMeetingPreferences if the api request fails ', async () => {
120
- webex.request = sinon.stub().returns(Promise.reject());
121
-
122
- const res = await services.getMeetingPreferences();
123
-
124
- assert.calledWith(webex.request, {
125
- method: 'GET',
126
- service: 'hydra',
127
- resource: 'meetingPreferences',
128
- });
129
- assert.isUndefined(res);
130
- });
131
- });
132
-
133
- describe('#_formatReceivedHostmap()', () => {
134
- let serviceHostmap;
135
- let formattedHM;
136
-
137
- beforeEach(() => {
138
- serviceHostmap = {
139
- serviceLinks: {
140
- 'example-a': 'https://example-a.com/api/v1',
141
- 'example-b': 'https://example-b.com/api/v1',
142
- 'example-c': 'https://example-c.com/api/v1',
143
- 'example-d': 'https://example-d.com/api/v1',
144
- },
145
- hostCatalog: {
146
- 'example-a.com': [
147
- {
148
- host: 'example-a-1.com',
149
- ttl: -1,
150
- priority: 5,
151
- id: '0:0:0:example-a',
152
- },
153
- {
154
- host: 'example-a-2.com',
155
- ttl: -1,
156
- priority: 3,
157
- id: '0:0:0:example-a',
158
- },
159
- {
160
- host: 'example-a-3.com',
161
- ttl: -1,
162
- priority: 1,
163
- id: '0:0:0:example-a-x',
164
- },
165
- ],
166
- 'example-b.com': [
167
- {
168
- host: 'example-b-1.com',
169
- ttl: -1,
170
- priority: 5,
171
- id: '0:0:0:example-b',
172
- },
173
- {
174
- host: 'example-b-2.com',
175
- ttl: -1,
176
- priority: 3,
177
- id: '0:0:0:example-b',
178
- },
179
- {
180
- host: 'example-b-3.com',
181
- ttl: -1,
182
- priority: 1,
183
- id: '0:0:0:example-b-x',
184
- },
185
- ],
186
- 'example-c.com': [
187
- {
188
- host: 'example-c-1.com',
189
- ttl: -1,
190
- priority: 5,
191
- id: '0:0:0:example-c',
192
- },
193
- {
194
- host: 'example-c-2.com',
195
- ttl: -1,
196
- priority: 3,
197
- id: '0:0:0:example-c',
198
- },
199
- {
200
- host: 'example-c-3.com',
201
- ttl: -1,
202
- priority: 1,
203
- id: '0:0:0:example-c-x',
204
- },
205
- ],
206
- 'example-d.com': [
207
- {
208
- host: 'example-c-1.com',
209
- ttl: -1,
210
- priority: 5,
211
- id: '0:0:0:example-d',
212
- },
213
- {
214
- host: 'example-c-2.com',
215
- ttl: -1,
216
- priority: 3,
217
- id: '0:0:0:example-d',
218
- },
219
- {
220
- host: 'example-c-3.com',
221
- ttl: -1,
222
- priority: 1,
223
- id: '0:0:0:example-d-x',
224
- },
225
- ],
226
- },
227
- format: 'hostmap',
228
- };
229
- });
230
-
231
- it('creates a formmatted host map that contains the same amount of entries as the original received hostmap', () => {
232
- formattedHM = services._formatReceivedHostmap(serviceHostmap);
233
-
234
- assert(
235
- Object.keys(serviceHostmap.serviceLinks).length >= formattedHM.length,
236
- 'length is not equal or less than'
237
- );
238
- });
239
-
240
- it.skip('creates an array of equal or less length of hostMap', () => {
241
- formattedHM = services._formatReceivedHostmap(serviceHostmap);
242
-
243
- assert(
244
- Object.keys(serviceHostmap.hostCatalog).length >= formattedHM.length,
245
- 'length is not equal or less than'
246
- );
247
- });
248
-
249
- it('creates an array with matching url data', () => {
250
- formattedHM = services._formatReceivedHostmap(serviceHostmap);
251
-
252
- formattedHM.forEach((entry) => {
253
- assert.equal(serviceHostmap.serviceLinks[entry.name], entry.defaultUrl);
254
- });
255
- });
256
-
257
- it('has all keys in host map hosts', () => {
258
- formattedHM = services._formatReceivedHostmap(serviceHostmap);
259
-
260
- formattedHM.forEach((service) => {
261
- service.hosts.forEach((host) => {
262
- assert.hasAllKeys(
263
- host,
264
- ['homeCluster', 'host', 'id', 'priority', 'ttl'],
265
- `${service.name} has an invalid host shape`
266
- );
267
- });
268
- });
269
- });
270
-
271
- it('creates a formmated host map containing all received host map service entries', () => {
272
- formattedHM = services._formatReceivedHostmap(serviceHostmap);
273
-
274
- formattedHM.forEach((service) => {
275
- const foundServiceKey = Object.keys(serviceHostmap.serviceLinks).find(
276
- (key) => service.name === key
277
- );
278
-
279
- assert.isDefined(foundServiceKey);
280
- });
281
- });
282
-
283
- it('creates a formmated host map containing all received host map host entries', () => {
284
- formattedHM = services._formatReceivedHostmap(serviceHostmap);
285
-
286
- formattedHM.forEach((service) => {
287
- const foundHosts = serviceHostmap.hostCatalog[service.defaultHost];
288
-
289
- assert.isDefined(foundHosts);
290
- });
291
- });
292
-
293
- it('creates an array with matching names', () => {
294
- formattedHM = services._formatReceivedHostmap(serviceHostmap);
295
-
296
- assert.hasAllKeys(
297
- serviceHostmap.serviceLinks,
298
- formattedHM.map((item) => item.name)
299
- );
300
- });
301
- });
302
-
303
- describe('#updateCredentialsConfig()', () => {
304
- // updateCredentialsConfig must remove `/` if exist. so expected serviceList must be.
305
- const expectedServiceList = {
306
- idbroker: 'https://idbroker.webex.com',
307
- identity: 'https://identity.webex.com',
308
- };
309
-
310
- beforeEach(async () => {
311
- const servicesList = {
312
- idbroker: 'https://idbroker.webex.com',
313
- identity: 'https://identity.webex.com/',
314
- };
315
-
316
- catalog.list = sinon.stub().returns(servicesList);
317
- await services.updateCredentialsConfig();
318
- });
319
-
320
- it('sets the idbroker url properly when trailing slash is not present', () => {
321
- assert.equal(webex.config.credentials.idbroker.url, expectedServiceList.idbroker);
322
- });
323
-
324
- it('sets the identity url properly when a trailing slash is present', () => {
325
- assert.equal(webex.config.credentials.identity.url, expectedServiceList.identity);
326
- });
327
-
328
- it('sets the authorize url properly when authorization string is not provided', () => {
329
- assert.equal(
330
- webex.config.credentials.authorizeUrl,
331
- `${expectedServiceList.idbroker}/idb/oauth2/v1/authorize`
332
- );
333
- });
334
-
335
- it('should retain the authorize url property when authorization string is provided', () => {
336
- const authUrl = 'http://example-auth-url.com/resource';
337
-
338
- webex.config.credentials.authorizationString = authUrl;
339
- webex.config.credentials.authorizeUrl = authUrl;
340
-
341
- services.updateCredentialsConfig();
342
-
343
- assert.equal(webex.config.credentials.authorizeUrl, authUrl);
344
- });
345
- });
346
- });
347
- });
348
- /* eslint-enable no-underscore-dangle */
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import {assert} from '@webex/test-helper-chai';
6
+ import MockWebex from '@webex/test-helper-mock-webex';
7
+ import sinon from 'sinon';
8
+ import {Services, ServiceRegistry, ServiceState} from '@webex/webex-core';
9
+
10
+ /* eslint-disable no-underscore-dangle */
11
+ describe('webex-core', () => {
12
+ describe('Services', () => {
13
+ let webex;
14
+ let services;
15
+ let catalog;
16
+
17
+ beforeAll(() => {
18
+ webex = new MockWebex({
19
+ children: {
20
+ services: Services,
21
+ },
22
+ });
23
+ services = webex.internal.services;
24
+ catalog = services._getCatalog();
25
+ });
26
+
27
+ describe('class members', () => {
28
+ describe('#registries', () => {
29
+ it('should be a weakmap', () => {
30
+ assert.instanceOf(services.registries, WeakMap);
31
+ });
32
+ });
33
+
34
+ describe('#states', () => {
35
+ it('should be a weakmap', () => {
36
+ assert.instanceOf(services.states, WeakMap);
37
+ });
38
+ });
39
+ });
40
+
41
+ describe('class methods', () => {
42
+ describe('#getRegistry', () => {
43
+ it('should be a service registry', () => {
44
+ assert.instanceOf(services.getRegistry(), ServiceRegistry);
45
+ });
46
+ });
47
+
48
+ describe('#getState', () => {
49
+ it('should be a service state', () => {
50
+ assert.instanceOf(services.getState(), ServiceState);
51
+ });
52
+ });
53
+ });
54
+
55
+ describe('#namespace', () => {
56
+ it('is accurate to plugin name', () => {
57
+ assert.equal(services.namespace, 'Services');
58
+ });
59
+ });
60
+
61
+ describe('#_catalogs', () => {
62
+ it('is a weakmap', () => {
63
+ assert.typeOf(services._catalogs, 'weakmap');
64
+ });
65
+ });
66
+
67
+ describe('#validateDomains', () => {
68
+ it('is a boolean', () => {
69
+ assert.isBoolean(services.validateDomains);
70
+ });
71
+ });
72
+
73
+ describe('#list()', () => {
74
+ let serviceList;
75
+
76
+ beforeEach(() => {
77
+ serviceList = services.list();
78
+ });
79
+
80
+ it('must return an object', () => {
81
+ assert.typeOf(serviceList, 'object');
82
+ });
83
+
84
+ it('returned list must be of shape {Record<string, string>}', () => {
85
+ Object.keys(serviceList).forEach((key) => {
86
+ assert.typeOf(key, 'string');
87
+ assert.typeOf(serviceList[key], 'string');
88
+ });
89
+ });
90
+ });
91
+
92
+ describe('#fetchClientRegionInfo', () => {
93
+ it('successfully resolves with undefined if fetch request failed', () => {
94
+ webex.request = sinon.stub().returns(Promise.reject());
95
+
96
+ return services.fetchClientRegionInfo().then((r) => {
97
+ assert.isUndefined(r);
98
+ });
99
+ });
100
+ });
101
+
102
+ describe('#getMeetingPreferences', () => {
103
+ it('Fetch login users information ', async () => {
104
+ const userPreferences = {userPreferences: 'userPreferences'};
105
+
106
+ webex.request = sinon.stub().returns(Promise.resolve({body: userPreferences}));
107
+
108
+ const res = await services.getMeetingPreferences();
109
+
110
+ assert.calledWith(webex.request, {
111
+ method: 'GET',
112
+ service: 'hydra',
113
+ resource: 'meetingPreferences',
114
+ });
115
+ assert.isDefined(res);
116
+ assert.equal(res, userPreferences);
117
+ });
118
+
119
+ it('Resolve getMeetingPreferences if the api request fails ', async () => {
120
+ webex.request = sinon.stub().returns(Promise.reject());
121
+
122
+ const res = await services.getMeetingPreferences();
123
+
124
+ assert.calledWith(webex.request, {
125
+ method: 'GET',
126
+ service: 'hydra',
127
+ resource: 'meetingPreferences',
128
+ });
129
+ assert.isUndefined(res);
130
+ });
131
+ });
132
+
133
+ describe('#_formatReceivedHostmap()', () => {
134
+ let serviceHostmap;
135
+ let formattedHM;
136
+
137
+ beforeEach(() => {
138
+ serviceHostmap = {
139
+ serviceLinks: {
140
+ 'example-a': 'https://example-a.com/api/v1',
141
+ 'example-b': 'https://example-b.com/api/v1',
142
+ 'example-c': 'https://example-c.com/api/v1',
143
+ 'example-d': 'https://example-d.com/api/v1',
144
+ },
145
+ hostCatalog: {
146
+ 'example-a.com': [
147
+ {
148
+ host: 'example-a-1.com',
149
+ ttl: -1,
150
+ priority: 5,
151
+ id: '0:0:0:example-a',
152
+ },
153
+ {
154
+ host: 'example-a-2.com',
155
+ ttl: -1,
156
+ priority: 3,
157
+ id: '0:0:0:example-a',
158
+ },
159
+ {
160
+ host: 'example-a-3.com',
161
+ ttl: -1,
162
+ priority: 1,
163
+ id: '0:0:0:example-a-x',
164
+ },
165
+ ],
166
+ 'example-b.com': [
167
+ {
168
+ host: 'example-b-1.com',
169
+ ttl: -1,
170
+ priority: 5,
171
+ id: '0:0:0:example-b',
172
+ },
173
+ {
174
+ host: 'example-b-2.com',
175
+ ttl: -1,
176
+ priority: 3,
177
+ id: '0:0:0:example-b',
178
+ },
179
+ {
180
+ host: 'example-b-3.com',
181
+ ttl: -1,
182
+ priority: 1,
183
+ id: '0:0:0:example-b-x',
184
+ },
185
+ ],
186
+ 'example-c.com': [
187
+ {
188
+ host: 'example-c-1.com',
189
+ ttl: -1,
190
+ priority: 5,
191
+ id: '0:0:0:example-c',
192
+ },
193
+ {
194
+ host: 'example-c-2.com',
195
+ ttl: -1,
196
+ priority: 3,
197
+ id: '0:0:0:example-c',
198
+ },
199
+ {
200
+ host: 'example-c-3.com',
201
+ ttl: -1,
202
+ priority: 1,
203
+ id: '0:0:0:example-c-x',
204
+ },
205
+ ],
206
+ 'example-d.com': [
207
+ {
208
+ host: 'example-c-1.com',
209
+ ttl: -1,
210
+ priority: 5,
211
+ id: '0:0:0:example-d',
212
+ },
213
+ {
214
+ host: 'example-c-2.com',
215
+ ttl: -1,
216
+ priority: 3,
217
+ id: '0:0:0:example-d',
218
+ },
219
+ {
220
+ host: 'example-c-3.com',
221
+ ttl: -1,
222
+ priority: 1,
223
+ id: '0:0:0:example-d-x',
224
+ },
225
+ ],
226
+ },
227
+ format: 'hostmap',
228
+ };
229
+ });
230
+
231
+ it('creates a formmatted host map that contains the same amount of entries as the original received hostmap', () => {
232
+ formattedHM = services._formatReceivedHostmap(serviceHostmap);
233
+
234
+ assert(
235
+ Object.keys(serviceHostmap.serviceLinks).length >= formattedHM.length,
236
+ 'length is not equal or less than'
237
+ );
238
+ });
239
+
240
+ it.skip('creates an array of equal or less length of hostMap', () => {
241
+ formattedHM = services._formatReceivedHostmap(serviceHostmap);
242
+
243
+ assert(
244
+ Object.keys(serviceHostmap.hostCatalog).length >= formattedHM.length,
245
+ 'length is not equal or less than'
246
+ );
247
+ });
248
+
249
+ it('creates an array with matching url data', () => {
250
+ formattedHM = services._formatReceivedHostmap(serviceHostmap);
251
+
252
+ formattedHM.forEach((entry) => {
253
+ assert.equal(serviceHostmap.serviceLinks[entry.name], entry.defaultUrl);
254
+ });
255
+ });
256
+
257
+ it('has all keys in host map hosts', () => {
258
+ formattedHM = services._formatReceivedHostmap(serviceHostmap);
259
+
260
+ formattedHM.forEach((service) => {
261
+ service.hosts.forEach((host) => {
262
+ assert.hasAllKeys(
263
+ host,
264
+ ['homeCluster', 'host', 'id', 'priority', 'ttl'],
265
+ `${service.name} has an invalid host shape`
266
+ );
267
+ });
268
+ });
269
+ });
270
+
271
+ it('creates a formmated host map containing all received host map service entries', () => {
272
+ formattedHM = services._formatReceivedHostmap(serviceHostmap);
273
+
274
+ formattedHM.forEach((service) => {
275
+ const foundServiceKey = Object.keys(serviceHostmap.serviceLinks).find(
276
+ (key) => service.name === key
277
+ );
278
+
279
+ assert.isDefined(foundServiceKey);
280
+ });
281
+ });
282
+
283
+ it('creates a formmated host map containing all received host map host entries', () => {
284
+ formattedHM = services._formatReceivedHostmap(serviceHostmap);
285
+
286
+ formattedHM.forEach((service) => {
287
+ const foundHosts = serviceHostmap.hostCatalog[service.defaultHost];
288
+
289
+ assert.isDefined(foundHosts);
290
+ });
291
+ });
292
+
293
+ it('creates an array with matching names', () => {
294
+ formattedHM = services._formatReceivedHostmap(serviceHostmap);
295
+
296
+ assert.hasAllKeys(
297
+ serviceHostmap.serviceLinks,
298
+ formattedHM.map((item) => item.name)
299
+ );
300
+ });
301
+ });
302
+
303
+ describe('#updateCredentialsConfig()', () => {
304
+ // updateCredentialsConfig must remove `/` if exist. so expected serviceList must be.
305
+ const expectedServiceList = {
306
+ idbroker: 'https://idbroker.webex.com',
307
+ identity: 'https://identity.webex.com',
308
+ };
309
+
310
+ beforeEach(async () => {
311
+ const servicesList = {
312
+ idbroker: 'https://idbroker.webex.com',
313
+ identity: 'https://identity.webex.com/',
314
+ };
315
+
316
+ catalog.list = sinon.stub().returns(servicesList);
317
+ await services.updateCredentialsConfig();
318
+ });
319
+
320
+ it('sets the idbroker url properly when trailing slash is not present', () => {
321
+ assert.equal(webex.config.credentials.idbroker.url, expectedServiceList.idbroker);
322
+ });
323
+
324
+ it('sets the identity url properly when a trailing slash is present', () => {
325
+ assert.equal(webex.config.credentials.identity.url, expectedServiceList.identity);
326
+ });
327
+
328
+ it('sets the authorize url properly when authorization string is not provided', () => {
329
+ assert.equal(
330
+ webex.config.credentials.authorizeUrl,
331
+ `${expectedServiceList.idbroker}/idb/oauth2/v1/authorize`
332
+ );
333
+ });
334
+
335
+ it('should retain the authorize url property when authorization string is provided', () => {
336
+ const authUrl = 'http://example-auth-url.com/resource';
337
+
338
+ webex.config.credentials.authorizationString = authUrl;
339
+ webex.config.credentials.authorizeUrl = authUrl;
340
+
341
+ services.updateCredentialsConfig();
342
+
343
+ assert.equal(webex.config.credentials.authorizeUrl, authUrl);
344
+ });
345
+ });
346
+ });
347
+ });
348
+ /* eslint-enable no-underscore-dangle */