@webex/internal-plugin-metrics 3.0.0-beta.32 → 3.0.0-beta.320

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 (68) hide show
  1. package/dist/batcher.js +2 -1
  2. package/dist/batcher.js.map +1 -1
  3. package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js +65 -0
  4. package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js.map +1 -0
  5. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js +456 -0
  6. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js.map +1 -0
  7. package/dist/call-diagnostic/call-diagnostic-metrics.js +819 -0
  8. package/dist/call-diagnostic/call-diagnostic-metrics.js.map +1 -0
  9. package/dist/call-diagnostic/call-diagnostic-metrics.util.js +337 -0
  10. package/dist/call-diagnostic/call-diagnostic-metrics.util.js.map +1 -0
  11. package/dist/call-diagnostic/config.js +610 -0
  12. package/dist/call-diagnostic/config.js.map +1 -0
  13. package/dist/client-metrics-batcher.js +2 -1
  14. package/dist/client-metrics-batcher.js.map +1 -1
  15. package/dist/config.js +22 -2
  16. package/dist/config.js.map +1 -1
  17. package/dist/index.js +30 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/metrics.js +30 -30
  20. package/dist/metrics.js.map +1 -1
  21. package/dist/metrics.types.js +7 -0
  22. package/dist/metrics.types.js.map +1 -0
  23. package/dist/new-metrics.js +333 -0
  24. package/dist/new-metrics.js.map +1 -0
  25. package/dist/types/batcher.d.ts +2 -0
  26. package/dist/types/call-diagnostic/call-diagnostic-metrics-batcher.d.ts +2 -0
  27. package/dist/types/call-diagnostic/call-diagnostic-metrics-latencies.d.ts +194 -0
  28. package/dist/types/call-diagnostic/call-diagnostic-metrics.d.ts +417 -0
  29. package/dist/types/call-diagnostic/call-diagnostic-metrics.util.d.ts +96 -0
  30. package/dist/types/call-diagnostic/config.d.ts +172 -0
  31. package/dist/types/client-metrics-batcher.d.ts +2 -0
  32. package/dist/types/config.d.ts +36 -0
  33. package/dist/types/index.d.ts +13 -0
  34. package/dist/types/metrics.d.ts +3 -0
  35. package/dist/types/metrics.types.d.ts +104 -0
  36. package/dist/types/new-metrics.d.ts +139 -0
  37. package/dist/types/utils.d.ts +6 -0
  38. package/dist/utils.js +27 -0
  39. package/dist/utils.js.map +1 -0
  40. package/package.json +13 -8
  41. package/src/batcher.js +1 -0
  42. package/src/call-diagnostic/call-diagnostic-metrics-batcher.ts +75 -0
  43. package/src/call-diagnostic/call-diagnostic-metrics-latencies.ts +419 -0
  44. package/src/call-diagnostic/call-diagnostic-metrics.ts +861 -0
  45. package/src/call-diagnostic/call-diagnostic-metrics.util.ts +362 -0
  46. package/src/call-diagnostic/config.ts +666 -0
  47. package/src/client-metrics-batcher.js +1 -0
  48. package/src/config.js +20 -0
  49. package/src/index.ts +43 -0
  50. package/src/metrics.js +25 -27
  51. package/src/metrics.types.ts +160 -0
  52. package/src/new-metrics.ts +317 -0
  53. package/src/utils.ts +17 -0
  54. package/test/unit/spec/batcher.js +2 -0
  55. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-batcher.ts +452 -0
  56. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-latencies.ts +506 -0
  57. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +1973 -0
  58. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.util.ts +565 -0
  59. package/test/unit/spec/client-metrics-batcher.js +2 -0
  60. package/test/unit/spec/metrics.js +66 -97
  61. package/test/unit/spec/new-metrics.ts +267 -0
  62. package/test/unit/spec/utils.ts +22 -0
  63. package/tsconfig.json +6 -0
  64. package/dist/call-diagnostic-events-batcher.js +0 -60
  65. package/dist/call-diagnostic-events-batcher.js.map +0 -1
  66. package/src/call-diagnostic-events-batcher.js +0 -62
  67. package/src/index.js +0 -17
  68. package/test/unit/spec/call-diagnostic-events-batcher.js +0 -195
@@ -0,0 +1,1973 @@
1
+ import sinon from 'sinon';
2
+ import {assert} from '@webex/test-helper-chai';
3
+ import {WebexHttpError} from '@webex/webex-core';
4
+
5
+ import CallDiagnosticMetrics from '../../../../src/call-diagnostic/call-diagnostic-metrics';
6
+ import CallDiagnosticLatencies from '../../../../src/call-diagnostic/call-diagnostic-metrics-latencies';
7
+ import * as Utils from '../../../../src/call-diagnostic/call-diagnostic-metrics.util';
8
+ import {BrowserDetection} from '@webex/common';
9
+ import {getOSNameInternal} from '@webex/internal-plugin-metrics';
10
+ import uuid from 'uuid';
11
+ import {omit} from 'lodash';
12
+ import CONFIG from '../../../../src/config';
13
+
14
+ //@ts-ignore
15
+ global.window = {location: {hostname: 'whatever'}};
16
+
17
+ const {getOSName, getOSVersion, getBrowserName, getBrowserVersion} = BrowserDetection();
18
+ const userAgent = `webex-js-sdk/test-webex-version client=Cantina; (os=${getOSName()}/${
19
+ getOSVersion().split('.')[0]
20
+ })`;
21
+
22
+ describe.only('internal-plugin-metrics', () => {
23
+ describe('CallDiagnosticMetrics', () => {
24
+ var now = new Date();
25
+
26
+ let cd: CallDiagnosticMetrics;
27
+
28
+ const fakeMeeting = {
29
+ id: '1',
30
+ correlationId: 'correlationId',
31
+ environment: 'meeting_evn',
32
+ locusUrl: 'locus/url',
33
+ locusInfo: {
34
+ fullState: {
35
+ lastActive: 'lastActive',
36
+ },
37
+ },
38
+ meetingInfo: {},
39
+ getCurUserType: () => 'host',
40
+ };
41
+
42
+ let webex;
43
+
44
+ beforeEach(() => {
45
+ webex = {
46
+ canAuthorize: true,
47
+ version: 'webex-version',
48
+ internal: {
49
+ services: {
50
+ get: () => 'locus-url',
51
+ },
52
+ metrics: {
53
+ submitClientMetrics: sinon.stub(),
54
+ config: {...CONFIG.metrics},
55
+ },
56
+ newMetrics: {
57
+ postPreLoginMetric: sinon.stub(),
58
+ },
59
+ device: {
60
+ userId: 'userId',
61
+ url: 'deviceUrl',
62
+ orgId: 'orgId',
63
+ },
64
+ },
65
+ meetings: {
66
+ config: {
67
+ metrics: {
68
+ clientType: 'TEAMS_CLIENT',
69
+ subClientType: 'WEB_APP',
70
+ clientName: 'Cantina',
71
+ },
72
+ },
73
+ meetingCollection: {
74
+ get: () => fakeMeeting,
75
+ },
76
+ geoHintInfo: {
77
+ clientAddress: '1.3.4.5',
78
+ countryCode: 'UK',
79
+ },
80
+ },
81
+ credentials: {
82
+ isUnverifiedGuest: false,
83
+ },
84
+ prepareFetchOptions: sinon.stub().callsFake((opts: any) => ({...opts, foo: 'bar'})),
85
+ request: sinon.stub().resolves({body: {}}),
86
+ logger: {
87
+ log: sinon.stub(),
88
+ error: sinon.stub(),
89
+ },
90
+ };
91
+
92
+ webex.internal.newMetrics.callDiagnosticLatencies = new CallDiagnosticLatencies(
93
+ {},
94
+ {parent: webex}
95
+ );
96
+
97
+ sinon.createSandbox();
98
+ sinon.useFakeTimers(now.getTime());
99
+ cd = new CallDiagnosticMetrics({}, {parent: webex});
100
+ sinon.stub(uuid, 'v4').returns('my-fake-id');
101
+ });
102
+
103
+ afterEach(() => {
104
+ sinon.restore();
105
+ });
106
+
107
+ describe('#validator', () => {
108
+ it('should have a validator function defined', () => {
109
+ assert.isDefined(cd.validator);
110
+ });
111
+ });
112
+
113
+ describe('#getOrigin', () => {
114
+ it('should build origin correctly', () => {
115
+ sinon.stub(Utils, 'anonymizeIPAddress').returns('1.1.1.1');
116
+
117
+ //@ts-ignore
118
+ const res = cd.getOrigin(
119
+ {subClientType: 'WEB_APP', clientType: 'TEAMS_CLIENT'},
120
+ fakeMeeting.id
121
+ );
122
+
123
+ assert.deepEqual(res, {
124
+ clientInfo: {
125
+ browser: getBrowserName(),
126
+ browserVersion: getBrowserVersion(),
127
+ clientType: 'TEAMS_CLIENT',
128
+ clientVersion: 'webex-js-sdk/webex-version',
129
+ localNetworkPrefix: '1.1.1.1',
130
+ os: getOSNameInternal(),
131
+ osVersion: getOSVersion(),
132
+ subClientType: 'WEB_APP',
133
+ },
134
+ environment: 'meeting_evn',
135
+ name: 'endpoint',
136
+ networkType: 'unknown',
137
+ userAgent,
138
+ });
139
+ });
140
+
141
+ it('should build origin correctly with newEnvironment and createLaunchMethod', () => {
142
+ sinon.stub(Utils, 'anonymizeIPAddress').returns('1.1.1.1');
143
+
144
+ //@ts-ignore
145
+ const res = cd.getOrigin(
146
+ {
147
+ subClientType: 'WEB_APP',
148
+ clientType: 'TEAMS_CLIENT',
149
+ newEnvironment: 'test-new-env',
150
+ clientLaunchMethod: 'url-handler',
151
+ },
152
+ fakeMeeting.id
153
+ );
154
+
155
+ assert.deepEqual(res, {
156
+ clientInfo: {
157
+ browser: getBrowserName(),
158
+ browserVersion: getBrowserVersion(),
159
+ clientType: 'TEAMS_CLIENT',
160
+ clientVersion: 'webex-js-sdk/webex-version',
161
+ localNetworkPrefix: '1.1.1.1',
162
+ os: getOSNameInternal(),
163
+ osVersion: getOSVersion(),
164
+ subClientType: 'WEB_APP',
165
+ clientLaunchMethod: 'url-handler',
166
+ },
167
+ environment: 'meeting_evn',
168
+ newEnvironment: 'test-new-env',
169
+ name: 'endpoint',
170
+ networkType: 'unknown',
171
+ userAgent,
172
+ });
173
+ });
174
+
175
+ it('should build origin correctly and environment can be passed in options', () => {
176
+ sinon.stub(Utils, 'anonymizeIPAddress').returns('1.1.1.1');
177
+
178
+ //@ts-ignore
179
+ const res = cd.getOrigin(
180
+ {
181
+ subClientType: 'WEB_APP',
182
+ clientType: 'TEAMS_CLIENT',
183
+ clientLaunchMethod: 'url-handler',
184
+ environment: 'test-env',
185
+ },
186
+ fakeMeeting.id
187
+ );
188
+
189
+ assert.deepEqual(res, {
190
+ clientInfo: {
191
+ browser: getBrowserName(),
192
+ browserVersion: getBrowserVersion(),
193
+ clientType: 'TEAMS_CLIENT',
194
+ clientVersion: 'webex-js-sdk/webex-version',
195
+ localNetworkPrefix: '1.1.1.1',
196
+ os: getOSNameInternal(),
197
+ osVersion: getOSVersion(),
198
+ subClientType: 'WEB_APP',
199
+ clientLaunchMethod: 'url-handler',
200
+ },
201
+ environment: 'test-env',
202
+ name: 'endpoint',
203
+ networkType: 'unknown',
204
+ userAgent,
205
+ });
206
+ });
207
+
208
+ it('should build origin correctly with no meeting', () => {
209
+ sinon.stub(Utils, 'anonymizeIPAddress').returns('1.1.1.1');
210
+
211
+ //@ts-ignore
212
+ const res = cd.getOrigin();
213
+
214
+ assert.deepEqual(res, {
215
+ clientInfo: {
216
+ browser: getBrowserName(),
217
+ browserVersion: getBrowserVersion(),
218
+ clientType: 'TEAMS_CLIENT',
219
+ clientVersion: 'webex-js-sdk/webex-version',
220
+ localNetworkPrefix: '1.1.1.1',
221
+ os: getOSNameInternal(),
222
+ osVersion: getOSVersion(),
223
+ subClientType: 'WEB_APP',
224
+ },
225
+ name: 'endpoint',
226
+ networkType: 'unknown',
227
+ userAgent,
228
+ });
229
+ });
230
+
231
+ it('builds origin correctly, when overriding clientVersion', () => {
232
+ webex.meetings.config.metrics.clientVersion = '43.9.0.1234';
233
+
234
+ //@ts-ignore
235
+ const res = cd.getOrigin(
236
+ {subClientType: 'WEB_APP', clientType: 'TEAMS_CLIENT'},
237
+ fakeMeeting.id
238
+ );
239
+
240
+ assert.deepEqual(res, {
241
+ clientInfo: {
242
+ browser: getBrowserName(),
243
+ browserVersion: getBrowserVersion(),
244
+ clientType: 'TEAMS_CLIENT',
245
+ clientVersion: '43.9.0.1234',
246
+ localNetworkPrefix: '1.3.4.0',
247
+ majorVersion: 43,
248
+ minorVersion: 9,
249
+ os: getOSNameInternal(),
250
+ osVersion: getOSVersion(),
251
+ subClientType: 'WEB_APP',
252
+ },
253
+ environment: 'meeting_evn',
254
+ name: 'endpoint',
255
+ networkType: 'unknown',
256
+ userAgent,
257
+ });
258
+ });
259
+ });
260
+
261
+ describe('#getIdentifiers', () => {
262
+ it('should build identifiers correctly', () => {
263
+ const res = cd.getIdentifiers({
264
+ mediaConnections: [
265
+ {mediaAgentAlias: 'mediaAgentAlias', mediaAgentGroupId: 'mediaAgentGroupId'},
266
+ ],
267
+ meeting: fakeMeeting,
268
+ });
269
+
270
+ assert.deepEqual(res, {
271
+ correlationId: 'correlationId',
272
+ deviceId: 'deviceUrl',
273
+ locusId: 'url',
274
+ locusStartTime: 'lastActive',
275
+ locusUrl: 'locus/url',
276
+ mediaAgentAlias: 'mediaAgentAlias',
277
+ mediaAgentGroupId: 'mediaAgentGroupId',
278
+ orgId: 'orgId',
279
+ userId: 'userId',
280
+ });
281
+ });
282
+
283
+ it('should build identifiers correctly with a meeting that has meetingInfo with a webexConferenceIdStr and globalMeetingId, and that should take precedence over the options passed to it', () => {
284
+ const res = cd.getIdentifiers({
285
+ mediaConnections: [
286
+ {mediaAgentAlias: 'mediaAgentAlias', mediaAgentGroupId: 'mediaAgentGroupId'},
287
+ ],
288
+ webexConferenceIdStr: 'webexConferenceIdStr',
289
+ globalMeetingId: 'globalMeetingId',
290
+ meeting: {
291
+ ...fakeMeeting,
292
+ meetingInfo: {
293
+ ...fakeMeeting.meetingInfo,
294
+ confID: 'webexConferenceIdStr1',
295
+ meetingId: 'globalMeetingId1',
296
+ },
297
+ },
298
+ });
299
+
300
+ assert.deepEqual(res, {
301
+ correlationId: 'correlationId',
302
+ webexConferenceIdStr: 'webexConferenceIdStr1',
303
+ globalMeetingId: 'globalMeetingId1',
304
+ deviceId: 'deviceUrl',
305
+ locusId: 'url',
306
+ locusStartTime: 'lastActive',
307
+ locusUrl: 'locus/url',
308
+ mediaAgentAlias: 'mediaAgentAlias',
309
+ mediaAgentGroupId: 'mediaAgentGroupId',
310
+ orgId: 'orgId',
311
+ userId: 'userId',
312
+ });
313
+ });
314
+
315
+ it('should build identifiers correctly with a meeting that has meetingInfo with a webexConferenceIdStr and globalMeetingId, and that should take precedence over the options passed to it', () => {
316
+ const res = cd.getIdentifiers({
317
+ mediaConnections: [
318
+ {mediaAgentAlias: 'mediaAgentAlias', mediaAgentGroupId: 'mediaAgentGroupId'},
319
+ ],
320
+ webexConferenceIdStr: 'webexConferenceIdStr',
321
+ globalMeetingId: 'globalMeetingId',
322
+ meeting: {
323
+ ...fakeMeeting,
324
+ meetingInfo: {
325
+ ...fakeMeeting.meetingInfo,
326
+ confIdStr: 'webexConferenceIdStr1',
327
+ meetingId: 'globalMeetingId1',
328
+ },
329
+ },
330
+ });
331
+
332
+ assert.deepEqual(res, {
333
+ correlationId: 'correlationId',
334
+ webexConferenceIdStr: 'webexConferenceIdStr1',
335
+ globalMeetingId: 'globalMeetingId1',
336
+ deviceId: 'deviceUrl',
337
+ locusId: 'url',
338
+ locusStartTime: 'lastActive',
339
+ locusUrl: 'locus/url',
340
+ mediaAgentAlias: 'mediaAgentAlias',
341
+ mediaAgentGroupId: 'mediaAgentGroupId',
342
+ orgId: 'orgId',
343
+ userId: 'userId',
344
+ });
345
+ });
346
+
347
+ it('should build identifiers correctly with a meeting that has meetingInfo with siteName', () => {
348
+ const res = cd.getIdentifiers({
349
+ mediaConnections: [
350
+ {mediaAgentAlias: 'mediaAgentAlias', mediaAgentGroupId: 'mediaAgentGroupId'},
351
+ ],
352
+ webexConferenceIdStr: 'webexConferenceIdStr',
353
+ globalMeetingId: 'globalMeetingId',
354
+ meeting: {
355
+ ...fakeMeeting,
356
+ meetingInfo: {
357
+ ...fakeMeeting.meetingInfo,
358
+ confIdStr: 'webexConferenceIdStr1',
359
+ meetingId: 'globalMeetingId1',
360
+ siteName: 'siteName1',
361
+ },
362
+ },
363
+ });
364
+
365
+ assert.deepEqual(res, {
366
+ correlationId: 'correlationId',
367
+ webexConferenceIdStr: 'webexConferenceIdStr1',
368
+ globalMeetingId: 'globalMeetingId1',
369
+ deviceId: 'deviceUrl',
370
+ locusId: 'url',
371
+ locusStartTime: 'lastActive',
372
+ locusUrl: 'locus/url',
373
+ mediaAgentAlias: 'mediaAgentAlias',
374
+ mediaAgentGroupId: 'mediaAgentGroupId',
375
+ orgId: 'orgId',
376
+ userId: 'userId',
377
+ webexSiteName: 'siteName1',
378
+ });
379
+ });
380
+
381
+ it('should build identifiers correctly given webexConferenceIdStr', () => {
382
+ const res = cd.getIdentifiers({
383
+ correlationId: 'correlationId',
384
+ webexConferenceIdStr: 'webexConferenceIdStr1',
385
+ });
386
+
387
+ assert.deepEqual(res, {
388
+ correlationId: 'correlationId',
389
+ webexConferenceIdStr: 'webexConferenceIdStr1',
390
+ deviceId: 'deviceUrl',
391
+ locusUrl: 'locus-url',
392
+ orgId: 'orgId',
393
+ userId: 'userId',
394
+ });
395
+ });
396
+
397
+ it('should build identifiers correctly given globalMeetingId', () => {
398
+ const res = cd.getIdentifiers({
399
+ correlationId: 'correlationId',
400
+ globalMeetingId: 'globalMeetingId1',
401
+ });
402
+
403
+ assert.deepEqual(res, {
404
+ correlationId: 'correlationId',
405
+ globalMeetingId: 'globalMeetingId1',
406
+ deviceId: 'deviceUrl',
407
+ locusUrl: 'locus-url',
408
+ orgId: 'orgId',
409
+ userId: 'userId',
410
+ });
411
+ });
412
+
413
+ it('should build identifiers correctly given correlationId', () => {
414
+ const res = cd.getIdentifiers({
415
+ correlationId: 'correlationId',
416
+ });
417
+
418
+ assert.deepEqual(res, {
419
+ correlationId: 'correlationId',
420
+ deviceId: 'deviceUrl',
421
+ locusUrl: 'locus-url',
422
+ orgId: 'orgId',
423
+ userId: 'userId',
424
+ });
425
+ });
426
+
427
+ it('should throw Error if correlationId is missing', () => {
428
+ assert.throws(() =>
429
+ cd.getIdentifiers({
430
+ mediaConnections: [
431
+ {mediaAgentAlias: 'mediaAgentAlias', mediaAgentGroupId: 'mediaAgentGroupId'},
432
+ ],
433
+ meeting: {...fakeMeeting, correlationId: undefined},
434
+ })
435
+ );
436
+ });
437
+
438
+ it('should build identifiers correctly given preLoginId and no device userId available', () => {
439
+ webex.internal.device.userId = undefined;
440
+
441
+ const res = cd.getIdentifiers({
442
+ correlationId: 'correlationId',
443
+ preLoginId: 'preLoginId',
444
+ });
445
+
446
+ assert.deepEqual(res, {
447
+ correlationId: 'correlationId',
448
+ locusUrl: 'locus-url',
449
+ deviceId: 'deviceUrl',
450
+ orgId: 'orgId',
451
+ userId: 'preLoginId',
452
+ });
453
+ });
454
+ });
455
+
456
+ it('should prepare diagnostic event successfully', () => {
457
+ const options = {meetingId: fakeMeeting.id};
458
+ const getOriginStub = sinon.stub(cd, 'getOrigin').returns({origin: 'fake-origin'});
459
+ const clearEmptyKeysRecursivelyStub = sinon.stub(Utils, 'clearEmptyKeysRecursively');
460
+
461
+ const res = cd.prepareDiagnosticEvent(
462
+ {
463
+ canProceed: false,
464
+ identifiers: {
465
+ correlationId: 'id',
466
+ webexConferenceIdStr: 'webexConferenceIdStr1',
467
+ globalMeetingId: 'globalMeetingId1',
468
+ },
469
+ name: 'client.alert.displayed',
470
+ },
471
+ options
472
+ );
473
+
474
+ assert.calledWith(getOriginStub, options, options.meetingId);
475
+ assert.calledOnce(clearEmptyKeysRecursivelyStub);
476
+ assert.deepEqual(res, {
477
+ event: {
478
+ canProceed: false,
479
+ identifiers: {
480
+ correlationId: 'id',
481
+ webexConferenceIdStr: 'webexConferenceIdStr1',
482
+ globalMeetingId: 'globalMeetingId1',
483
+ },
484
+ name: 'client.alert.displayed',
485
+ },
486
+ eventId: 'my-fake-id',
487
+ origin: {
488
+ origin: 'fake-origin',
489
+ },
490
+ originTime: {
491
+ sent: 'not_defined_yet',
492
+ triggered: now.toISOString(),
493
+ },
494
+ senderCountryCode: 'UK',
495
+ version: 1,
496
+ });
497
+ });
498
+
499
+ describe('#submitClientEvent', () => {
500
+ it('should submit client event successfully with meetingId', () => {
501
+ const prepareDiagnosticEventSpy = sinon.spy(cd, 'prepareDiagnosticEvent');
502
+ const submitToCallDiagnosticsSpy = sinon.spy(cd, 'submitToCallDiagnostics');
503
+ const generateClientEventErrorPayloadSpy = sinon.spy(cd, 'generateClientEventErrorPayload');
504
+ const getIdentifiersSpy = sinon.spy(cd, 'getIdentifiers');
505
+ const getSubServiceTypeSpy = sinon.spy(cd, 'getSubServiceType');
506
+ sinon.stub(cd, 'getOrigin').returns({origin: 'fake-origin'});
507
+ const validatorSpy = sinon.spy(cd, 'validator');
508
+ const options = {
509
+ meetingId: fakeMeeting.id,
510
+ mediaConnections: [{mediaAgentAlias: 'alias', mediaAgentGroupId: '1'}],
511
+ };
512
+
513
+ cd.submitClientEvent({
514
+ name: 'client.alert.displayed',
515
+ options,
516
+ });
517
+
518
+ assert.calledWith(getIdentifiersSpy, {
519
+ meeting: fakeMeeting,
520
+ mediaConnections: [{mediaAgentAlias: 'alias', mediaAgentGroupId: '1'}],
521
+ webexConferenceIdStr: undefined,
522
+ globalMeetingId: undefined,
523
+ });
524
+ assert.notCalled(generateClientEventErrorPayloadSpy);
525
+ assert.calledWith(
526
+ prepareDiagnosticEventSpy,
527
+ {
528
+ canProceed: true,
529
+ eventData: {
530
+ webClientDomain: 'whatever',
531
+ },
532
+ identifiers: {
533
+ correlationId: 'correlationId',
534
+ deviceId: 'deviceUrl',
535
+ locusId: 'url',
536
+ locusStartTime: 'lastActive',
537
+ locusUrl: 'locus/url',
538
+ mediaAgentAlias: 'alias',
539
+ mediaAgentGroupId: '1',
540
+ orgId: 'orgId',
541
+ userId: 'userId',
542
+ },
543
+ loginType: 'login-ci',
544
+ name: 'client.alert.displayed',
545
+ userType: 'host',
546
+ isConvergedArchitectureEnabled: undefined,
547
+ webexSubServiceType: undefined,
548
+ },
549
+ options
550
+ );
551
+ assert.calledWith(submitToCallDiagnosticsSpy, {
552
+ event: {
553
+ canProceed: true,
554
+ eventData: {
555
+ webClientDomain: 'whatever',
556
+ },
557
+ identifiers: {
558
+ correlationId: 'correlationId',
559
+ deviceId: 'deviceUrl',
560
+ locusId: 'url',
561
+ locusStartTime: 'lastActive',
562
+ locusUrl: 'locus/url',
563
+ mediaAgentAlias: 'alias',
564
+ mediaAgentGroupId: '1',
565
+ orgId: 'orgId',
566
+ userId: 'userId',
567
+ },
568
+ loginType: 'login-ci',
569
+ name: 'client.alert.displayed',
570
+ userType: 'host',
571
+ isConvergedArchitectureEnabled: undefined,
572
+ webexSubServiceType: undefined,
573
+ },
574
+ eventId: 'my-fake-id',
575
+ origin: {
576
+ origin: 'fake-origin',
577
+ },
578
+ originTime: {
579
+ sent: 'not_defined_yet',
580
+ triggered: now.toISOString(),
581
+ },
582
+ senderCountryCode: 'UK',
583
+ version: 1,
584
+ });
585
+ assert.calledWith(validatorSpy, {
586
+ type: 'ce',
587
+ event: {
588
+ event: {
589
+ canProceed: true,
590
+ eventData: {
591
+ webClientDomain: 'whatever',
592
+ },
593
+ identifiers: {
594
+ correlationId: 'correlationId',
595
+ deviceId: 'deviceUrl',
596
+ locusId: 'url',
597
+ locusStartTime: 'lastActive',
598
+ locusUrl: 'locus/url',
599
+ mediaAgentAlias: 'alias',
600
+ mediaAgentGroupId: '1',
601
+ orgId: 'orgId',
602
+ userId: 'userId',
603
+ },
604
+ loginType: 'login-ci',
605
+ name: 'client.alert.displayed',
606
+ userType: 'host',
607
+ isConvergedArchitectureEnabled: undefined,
608
+ webexSubServiceType: undefined,
609
+ },
610
+ eventId: 'my-fake-id',
611
+ origin: {
612
+ origin: 'fake-origin',
613
+ },
614
+ originTime: {
615
+ sent: 'not_defined_yet',
616
+ triggered: now.toISOString(),
617
+ },
618
+ senderCountryCode: 'UK',
619
+ version: 1,
620
+ },
621
+ });
622
+
623
+ const webexLoggerLogCalls = webex.logger.log.getCalls();
624
+ assert.deepEqual(webexLoggerLogCalls[0].args, [
625
+ 'call-diagnostic-events -> ',
626
+ 'CallDiagnosticMetrics: @submitClientEvent. Submit Client Event CA event.',
627
+ `name: client.alert.displayed`,
628
+ ]);
629
+ });
630
+
631
+ it('should submit client event successfully with correlationId, webexConferenceIdStr and globalMeetingId', () => {
632
+ const prepareDiagnosticEventSpy = sinon.spy(cd, 'prepareDiagnosticEvent');
633
+ const submitToCallDiagnosticsSpy = sinon.spy(cd, 'submitToCallDiagnostics');
634
+ const generateClientEventErrorPayloadSpy = sinon.spy(cd, 'generateClientEventErrorPayload');
635
+ const getIdentifiersSpy = sinon.spy(cd, 'getIdentifiers');
636
+ sinon.stub(cd, 'getOrigin').returns({origin: 'fake-origin'});
637
+
638
+ const options = {
639
+ correlationId: 'correlationId',
640
+ webexConferenceIdStr: 'webexConferenceIdStr1',
641
+ globalMeetingId: 'globalMeetingId1',
642
+ };
643
+
644
+ cd.submitClientEvent({
645
+ name: 'client.alert.displayed',
646
+ options,
647
+ });
648
+
649
+ assert.calledWith(getIdentifiersSpy, {
650
+ correlationId: 'correlationId',
651
+ webexConferenceIdStr: 'webexConferenceIdStr1',
652
+ globalMeetingId: 'globalMeetingId1',
653
+ preLoginId: undefined,
654
+ });
655
+
656
+ assert.notCalled(generateClientEventErrorPayloadSpy);
657
+ assert.calledWith(
658
+ prepareDiagnosticEventSpy,
659
+ {
660
+ canProceed: true,
661
+ eventData: {
662
+ webClientDomain: 'whatever',
663
+ },
664
+ identifiers: {
665
+ correlationId: 'correlationId',
666
+ webexConferenceIdStr: 'webexConferenceIdStr1',
667
+ globalMeetingId: 'globalMeetingId1',
668
+ deviceId: 'deviceUrl',
669
+ locusUrl: 'locus-url',
670
+ orgId: 'orgId',
671
+ userId: 'userId',
672
+ },
673
+ loginType: 'login-ci',
674
+ name: 'client.alert.displayed',
675
+ },
676
+ options
677
+ );
678
+ assert.calledWith(submitToCallDiagnosticsSpy, {
679
+ event: {
680
+ canProceed: true,
681
+ eventData: {
682
+ webClientDomain: 'whatever',
683
+ },
684
+ identifiers: {
685
+ correlationId: 'correlationId',
686
+ webexConferenceIdStr: 'webexConferenceIdStr1',
687
+ globalMeetingId: 'globalMeetingId1',
688
+ deviceId: 'deviceUrl',
689
+ locusUrl: 'locus-url',
690
+ orgId: 'orgId',
691
+ userId: 'userId',
692
+ },
693
+ loginType: 'login-ci',
694
+ name: 'client.alert.displayed',
695
+ },
696
+ eventId: 'my-fake-id',
697
+ origin: {
698
+ origin: 'fake-origin',
699
+ },
700
+ originTime: {
701
+ sent: 'not_defined_yet',
702
+ triggered: now.toISOString(),
703
+ },
704
+ senderCountryCode: 'UK',
705
+ version: 1,
706
+ });
707
+
708
+ const webexLoggerLogCalls = webex.logger.log.getCalls();
709
+
710
+ assert.deepEqual(webexLoggerLogCalls[0].args, [
711
+ 'call-diagnostic-events -> ',
712
+ 'CallDiagnosticMetrics: @submitClientEvent. Submit Client Event CA event.',
713
+ `name: client.alert.displayed`,
714
+ ]);
715
+ });
716
+
717
+ it('should submit client event successfully with preLoginId', () => {
718
+ webex.internal.device.userId = undefined;
719
+
720
+ const prepareDiagnosticEventSpy = sinon.spy(cd, 'prepareDiagnosticEvent');
721
+ const submitToCallDiagnosticsPreLoginSpy = sinon.spy(cd, 'submitToCallDiagnosticsPreLogin');
722
+ const submitToCallDiagnosticsSpy = sinon.spy(cd, 'submitToCallDiagnostics');
723
+ const generateClientEventErrorPayloadSpy = sinon.spy(cd, 'generateClientEventErrorPayload');
724
+ const getIdentifiersSpy = sinon.spy(cd, 'getIdentifiers');
725
+ sinon.stub(cd, 'getOrigin').returns({origin: 'fake-origin'});
726
+
727
+ const options = {
728
+ correlationId: 'correlationId',
729
+ webexConferenceIdStr: 'webexConferenceIdStr1',
730
+ globalMeetingId: 'globalMeetingId1',
731
+ preLoginId: 'myPreLoginId',
732
+ };
733
+
734
+ cd.submitClientEvent({
735
+ name: 'client.alert.displayed',
736
+ options,
737
+ });
738
+
739
+ assert.calledWith(getIdentifiersSpy, {
740
+ correlationId: 'correlationId',
741
+ webexConferenceIdStr: 'webexConferenceIdStr1',
742
+ globalMeetingId: 'globalMeetingId1',
743
+ preLoginId: 'myPreLoginId',
744
+ });
745
+
746
+ assert.notCalled(generateClientEventErrorPayloadSpy);
747
+ assert.calledWith(
748
+ prepareDiagnosticEventSpy,
749
+ {
750
+ canProceed: true,
751
+ eventData: {
752
+ webClientDomain: 'whatever',
753
+ },
754
+ identifiers: {
755
+ correlationId: 'correlationId',
756
+ webexConferenceIdStr: 'webexConferenceIdStr1',
757
+ globalMeetingId: 'globalMeetingId1',
758
+ deviceId: 'deviceUrl',
759
+ locusUrl: 'locus-url',
760
+ orgId: 'orgId',
761
+ userId: 'myPreLoginId',
762
+ },
763
+ loginType: 'login-ci',
764
+ name: 'client.alert.displayed',
765
+ },
766
+ options
767
+ );
768
+ assert.notCalled(submitToCallDiagnosticsSpy);
769
+ assert.calledWith(submitToCallDiagnosticsPreLoginSpy, {
770
+ event: {
771
+ canProceed: true,
772
+ eventData: {
773
+ webClientDomain: 'whatever',
774
+ },
775
+ identifiers: {
776
+ correlationId: 'correlationId',
777
+ webexConferenceIdStr: 'webexConferenceIdStr1',
778
+ globalMeetingId: 'globalMeetingId1',
779
+ deviceId: 'deviceUrl',
780
+ locusUrl: 'locus-url',
781
+ orgId: 'orgId',
782
+ userId: 'myPreLoginId',
783
+ },
784
+ loginType: 'login-ci',
785
+ name: 'client.alert.displayed',
786
+ },
787
+ eventId: 'my-fake-id',
788
+ origin: {buildType: 'test', networkType: 'unknown', origin: 'fake-origin'},
789
+ originTime: {
790
+ triggered: now.toISOString(),
791
+ sent: now.toISOString(),
792
+ },
793
+ senderCountryCode: 'UK',
794
+ version: 1,
795
+ });
796
+ });
797
+
798
+ it('it should include errors if provided with meetingId', () => {
799
+ sinon.stub(cd, 'getOrigin').returns({origin: 'fake-origin'});
800
+ const submitToCallDiagnosticsSpy = sinon.spy(cd, 'submitToCallDiagnostics');
801
+
802
+ const options = {
803
+ meetingId: fakeMeeting.id,
804
+ webexConferenceIdStr: 'webexConferenceIdStr1',
805
+ globalMeetingId: 'globalMeetingId1',
806
+ mediaConnections: [{mediaAgentAlias: 'alias', mediaAgentGroupId: '1'}],
807
+ rawError: {
808
+ body: {
809
+ errorCode: 2409005,
810
+ },
811
+ },
812
+ };
813
+
814
+ cd.submitClientEvent({
815
+ name: 'client.alert.displayed',
816
+ options,
817
+ });
818
+
819
+ assert.calledWith(submitToCallDiagnosticsSpy, {
820
+ event: {
821
+ canProceed: true,
822
+ eventData: {
823
+ webClientDomain: 'whatever',
824
+ },
825
+ identifiers: {
826
+ correlationId: 'correlationId',
827
+ webexConferenceIdStr: 'webexConferenceIdStr1',
828
+ globalMeetingId: 'globalMeetingId1',
829
+ deviceId: 'deviceUrl',
830
+ locusId: 'url',
831
+ locusStartTime: 'lastActive',
832
+ locusUrl: 'locus/url',
833
+ mediaAgentAlias: 'alias',
834
+ mediaAgentGroupId: '1',
835
+ orgId: 'orgId',
836
+ userId: 'userId',
837
+ },
838
+ errors: [
839
+ {
840
+ category: 'expected',
841
+ errorDescription: 'StartRecordingFailed',
842
+ fatal: true,
843
+ name: 'other',
844
+ shownToUser: false,
845
+ serviceErrorCode: 2409005,
846
+ errorCode: 4029,
847
+ rawErrorMessage: undefined,
848
+ },
849
+ ],
850
+ loginType: 'login-ci',
851
+ name: 'client.alert.displayed',
852
+ userType: 'host',
853
+ isConvergedArchitectureEnabled: undefined,
854
+ webexSubServiceType: undefined,
855
+ },
856
+ eventId: 'my-fake-id',
857
+ origin: {
858
+ origin: 'fake-origin',
859
+ },
860
+ originTime: {
861
+ sent: 'not_defined_yet',
862
+ triggered: now.toISOString(),
863
+ },
864
+ senderCountryCode: 'UK',
865
+ version: 1,
866
+ });
867
+
868
+ const webexLoggerLogCalls = webex.logger.log.getCalls();
869
+ assert.deepEqual(webexLoggerLogCalls[0].args, [
870
+ 'call-diagnostic-events -> ',
871
+ 'CallDiagnosticMetrics: @submitClientEvent. Submit Client Event CA event.',
872
+ `name: client.alert.displayed`,
873
+ ]);
874
+
875
+ assert.deepEqual(webexLoggerLogCalls[1].args, [
876
+ 'call-diagnostic-events -> ',
877
+ 'CallDiagnosticMetrics: @prepareClientEvent. Generated errors:',
878
+ `generatedError: {"fatal":true,"shownToUser":false,"name":"other","category":"expected","errorCode":4029,"serviceErrorCode":2409005,"errorDescription":"StartRecordingFailed"}`,
879
+ ]);
880
+ });
881
+
882
+ it('it send the raw error message if meetingId provided', () => {
883
+ sinon.stub(cd, 'getOrigin').returns({origin: 'fake-origin'});
884
+ const submitToCallDiagnosticsSpy = sinon.spy(cd, 'submitToCallDiagnostics');
885
+
886
+ const options = {
887
+ meetingId: fakeMeeting.id,
888
+ mediaConnections: [{mediaAgentAlias: 'alias', mediaAgentGroupId: '1'}],
889
+ rawError: new Error('bad times'),
890
+ };
891
+
892
+ cd.submitClientEvent({
893
+ name: 'client.alert.displayed',
894
+ options,
895
+ });
896
+
897
+ console.log(submitToCallDiagnosticsSpy.getCalls()[0].args[0].event.errors);
898
+
899
+ assert.calledWith(submitToCallDiagnosticsSpy, {
900
+ event: {
901
+ canProceed: true,
902
+ eventData: {
903
+ webClientDomain: 'whatever',
904
+ },
905
+ identifiers: {
906
+ correlationId: 'correlationId',
907
+ deviceId: 'deviceUrl',
908
+ locusId: 'url',
909
+ locusStartTime: 'lastActive',
910
+ locusUrl: 'locus/url',
911
+ mediaAgentAlias: 'alias',
912
+ mediaAgentGroupId: '1',
913
+ orgId: 'orgId',
914
+ userId: 'userId',
915
+ },
916
+ errors: [
917
+ {
918
+ fatal: true,
919
+ shownToUser: false,
920
+ name: 'other',
921
+ category: 'other',
922
+ errorCode: 9999,
923
+ serviceErrorCode: 9999,
924
+ errorDescription: 'UnknownError',
925
+ rawErrorMessage: 'bad times',
926
+ },
927
+ ],
928
+ loginType: 'login-ci',
929
+ name: 'client.alert.displayed',
930
+ userType: 'host',
931
+ isConvergedArchitectureEnabled: undefined,
932
+ webexSubServiceType: undefined,
933
+ },
934
+ eventId: 'my-fake-id',
935
+ origin: {
936
+ origin: 'fake-origin',
937
+ },
938
+ originTime: {
939
+ sent: 'not_defined_yet',
940
+ triggered: now.toISOString(),
941
+ },
942
+ senderCountryCode: 'UK',
943
+ version: 1,
944
+ });
945
+
946
+ const webexLoggerLogCalls = webex.logger.log.getCalls();
947
+ assert.deepEqual(webexLoggerLogCalls[0].args, [
948
+ 'call-diagnostic-events -> ',
949
+ 'CallDiagnosticMetrics: @submitClientEvent. Submit Client Event CA event.',
950
+ `name: client.alert.displayed`,
951
+ ]);
952
+
953
+ assert.deepEqual(webexLoggerLogCalls[1].args, [
954
+ 'call-diagnostic-events -> ',
955
+ 'CallDiagnosticMetrics: @prepareClientEvent. Generated errors:',
956
+ `generatedError: {"fatal":true,"shownToUser":false,"name":"other","category":"other","errorCode":9999,"serviceErrorCode":9999,"rawErrorMessage":"bad times","errorDescription":"UnknownError"}`,
957
+ ]);
958
+ });
959
+
960
+ it('it should send the raw error message if provided with correlationId', () => {
961
+ sinon.stub(cd, 'getOrigin').returns({origin: 'fake-origin'});
962
+ const submitToCallDiagnosticsSpy = sinon.spy(cd, 'submitToCallDiagnostics');
963
+
964
+ const options = {
965
+ correlationId: 'correlationId',
966
+ rawError: new Error('bad times'),
967
+ };
968
+
969
+ cd.submitClientEvent({
970
+ name: 'client.alert.displayed',
971
+ options,
972
+ });
973
+
974
+ assert.calledWith(submitToCallDiagnosticsSpy, {
975
+ event: {
976
+ canProceed: true,
977
+ eventData: {
978
+ webClientDomain: 'whatever',
979
+ },
980
+ identifiers: {
981
+ correlationId: 'correlationId',
982
+ deviceId: 'deviceUrl',
983
+ locusUrl: 'locus-url',
984
+ orgId: 'orgId',
985
+ userId: 'userId',
986
+ },
987
+ errors: [
988
+ {
989
+ fatal: true,
990
+ shownToUser: false,
991
+ name: 'other',
992
+ category: 'other',
993
+ errorCode: 9999,
994
+ serviceErrorCode: 9999,
995
+ errorDescription: 'UnknownError',
996
+ rawErrorMessage: 'bad times',
997
+ },
998
+ ],
999
+ loginType: 'login-ci',
1000
+ name: 'client.alert.displayed',
1001
+ },
1002
+ eventId: 'my-fake-id',
1003
+ origin: {
1004
+ origin: 'fake-origin',
1005
+ },
1006
+ originTime: {
1007
+ sent: 'not_defined_yet',
1008
+ triggered: now.toISOString(),
1009
+ },
1010
+ senderCountryCode: 'UK',
1011
+ version: 1,
1012
+ });
1013
+
1014
+ const webexLoggerLogCalls = webex.logger.log.getCalls();
1015
+
1016
+ assert.deepEqual(webexLoggerLogCalls[0].args, [
1017
+ 'call-diagnostic-events -> ',
1018
+ 'CallDiagnosticMetrics: @submitClientEvent. Submit Client Event CA event.',
1019
+ `name: client.alert.displayed`,
1020
+ ]);
1021
+
1022
+ assert.deepEqual(webexLoggerLogCalls[1].args, [
1023
+ 'call-diagnostic-events -> ',
1024
+ 'CallDiagnosticMetrics: @prepareClientEvent. Generated errors:',
1025
+ `generatedError: {"fatal":true,"shownToUser":false,"name":"other","category":"other","errorCode":9999,"serviceErrorCode":9999,"rawErrorMessage":"bad times","errorDescription":"UnknownError"}`,
1026
+ ]);
1027
+ });
1028
+
1029
+ it('it should include errors if provided with correlationId', () => {
1030
+ sinon.stub(cd, 'getOrigin').returns({origin: 'fake-origin'});
1031
+ const submitToCallDiagnosticsSpy = sinon.spy(cd, 'submitToCallDiagnostics');
1032
+
1033
+ const options = {
1034
+ correlationId: 'correlationId',
1035
+ rawError: {
1036
+ body: {
1037
+ errorCode: 2409005,
1038
+ },
1039
+ },
1040
+ };
1041
+
1042
+ cd.submitClientEvent({
1043
+ name: 'client.alert.displayed',
1044
+ options,
1045
+ });
1046
+
1047
+ assert.calledWith(submitToCallDiagnosticsSpy, {
1048
+ event: {
1049
+ canProceed: true,
1050
+ eventData: {
1051
+ webClientDomain: 'whatever',
1052
+ },
1053
+ identifiers: {
1054
+ correlationId: 'correlationId',
1055
+ deviceId: 'deviceUrl',
1056
+ locusUrl: 'locus-url',
1057
+ orgId: 'orgId',
1058
+ userId: 'userId',
1059
+ },
1060
+ errors: [
1061
+ {
1062
+ category: 'expected',
1063
+ errorDescription: 'StartRecordingFailed',
1064
+ fatal: true,
1065
+ name: 'other',
1066
+ shownToUser: false,
1067
+ serviceErrorCode: 2409005,
1068
+ errorCode: 4029,
1069
+ rawErrorMessage: undefined,
1070
+ },
1071
+ ],
1072
+ loginType: 'login-ci',
1073
+ name: 'client.alert.displayed',
1074
+ },
1075
+ eventId: 'my-fake-id',
1076
+ origin: {
1077
+ origin: 'fake-origin',
1078
+ },
1079
+ originTime: {
1080
+ sent: 'not_defined_yet',
1081
+ triggered: now.toISOString(),
1082
+ },
1083
+ senderCountryCode: 'UK',
1084
+ version: 1,
1085
+ });
1086
+
1087
+ const webexLoggerLogCalls = webex.logger.log.getCalls();
1088
+
1089
+ assert.deepEqual(webexLoggerLogCalls[0].args, [
1090
+ 'call-diagnostic-events -> ',
1091
+ 'CallDiagnosticMetrics: @submitClientEvent. Submit Client Event CA event.',
1092
+ `name: client.alert.displayed`,
1093
+ ]);
1094
+
1095
+ assert.deepEqual(webexLoggerLogCalls[1].args, [
1096
+ 'call-diagnostic-events -> ',
1097
+ 'CallDiagnosticMetrics: @prepareClientEvent. Generated errors:',
1098
+ `generatedError: {"fatal":true,"shownToUser":false,"name":"other","category":"expected","errorCode":4029,"serviceErrorCode":2409005,"errorDescription":"StartRecordingFailed"}`,
1099
+ ]);
1100
+ });
1101
+
1102
+ it('should include errors in payload if provided via payload', () => {
1103
+ sinon.stub(cd, 'getOrigin').returns({origin: 'fake-origin'});
1104
+ const submitToCallDiagnosticsSpy = sinon.spy(cd, 'submitToCallDiagnostics');
1105
+
1106
+ const options = {
1107
+ meetingId: fakeMeeting.id,
1108
+ mediaConnections: [{mediaAgentAlias: 'alias', mediaAgentGroupId: '1'}],
1109
+ };
1110
+
1111
+ cd.submitClientEvent({
1112
+ name: 'client.alert.displayed',
1113
+ payload: {
1114
+ errors: [
1115
+ {
1116
+ name: 'locus.response',
1117
+ fatal: true,
1118
+ category: 'signaling',
1119
+ shownToUser: false,
1120
+ },
1121
+ ],
1122
+ },
1123
+ options,
1124
+ });
1125
+
1126
+ assert.calledWith(submitToCallDiagnosticsSpy, {
1127
+ event: {
1128
+ canProceed: true,
1129
+ eventData: {
1130
+ webClientDomain: 'whatever',
1131
+ },
1132
+ identifiers: {
1133
+ correlationId: 'correlationId',
1134
+ deviceId: 'deviceUrl',
1135
+ locusId: 'url',
1136
+ locusStartTime: 'lastActive',
1137
+ locusUrl: 'locus/url',
1138
+ mediaAgentAlias: 'alias',
1139
+ mediaAgentGroupId: '1',
1140
+ orgId: 'orgId',
1141
+ userId: 'userId',
1142
+ },
1143
+ errors: [
1144
+ {
1145
+ name: 'locus.response',
1146
+ fatal: true,
1147
+ category: 'signaling',
1148
+ shownToUser: false,
1149
+ },
1150
+ ],
1151
+ loginType: 'login-ci',
1152
+ name: 'client.alert.displayed',
1153
+ userType: 'host',
1154
+ isConvergedArchitectureEnabled: undefined,
1155
+ webexSubServiceType: undefined,
1156
+ },
1157
+ eventId: 'my-fake-id',
1158
+ origin: {
1159
+ origin: 'fake-origin',
1160
+ },
1161
+ originTime: {
1162
+ sent: 'not_defined_yet',
1163
+ triggered: now.toISOString(),
1164
+ },
1165
+ senderCountryCode: 'UK',
1166
+ version: 1,
1167
+ });
1168
+ });
1169
+
1170
+ it('should throw if meetingId nor correlationId not provided', () => {
1171
+ assert.throws(() =>
1172
+ cd.submitClientEvent({
1173
+ name: 'client.alert.displayed',
1174
+ })
1175
+ );
1176
+ });
1177
+
1178
+ it('should send behavioral event if meetingId provided but meeting is undefined', () => {
1179
+ webex.meetings.meetingCollection.get = sinon.stub().returns(undefined);
1180
+ cd.submitClientEvent({name: 'client.alert.displayed', options: {meetingId: 'meetingId'}});
1181
+ assert.calledWith(
1182
+ webex.internal.metrics.submitClientMetrics,
1183
+ 'js_sdk_call_diagnostic_event_failed_to_send',
1184
+ {
1185
+ fields: {meetingId: 'meetingId', name: 'client.alert.displayed'},
1186
+ }
1187
+ );
1188
+ });
1189
+
1190
+ it('should submit client to diagnostic when no preLoginId provided', () => {
1191
+ const testEvent = {name: 'client.alert.displayed', options: {meetingId: 'meetingId'}};
1192
+ sinon.stub(cd, 'prepareClientEvent').returns(testEvent);
1193
+ sinon.stub(cd, 'submitToCallDiagnostics');
1194
+ sinon.stub(cd, 'submitToCallDiagnosticsPreLogin');
1195
+ //@ts-ignore
1196
+ cd.submitClientEvent(testEvent);
1197
+ assert.calledWith(cd.submitToCallDiagnostics, testEvent);
1198
+ assert.notCalled(cd.submitToCallDiagnosticsPreLogin);
1199
+ });
1200
+
1201
+ it('should submit event to prelogin when preLoginId provided', () => {
1202
+ const testEvent = {name: 'client.alert.displayed', options: {preLoginId: 'preLoginId'}};
1203
+ sinon.stub(cd, 'prepareClientEvent').returns(testEvent);
1204
+ sinon.stub(cd, 'submitToCallDiagnosticsPreLogin');
1205
+ sinon.stub(cd, 'submitToCallDiagnostics');
1206
+ //@ts-ignore
1207
+ cd.submitClientEvent(testEvent);
1208
+ assert.calledWith(cd.submitToCallDiagnosticsPreLogin, testEvent);
1209
+ assert.notCalled(cd.submitToCallDiagnostics);
1210
+ });
1211
+ });
1212
+
1213
+ it('should send request to call diagnostic batcher', () => {
1214
+ const requestStub = sinon.stub();
1215
+ //@ts-ignore
1216
+ cd.callDiagnosticEventsBatcher = {request: requestStub};
1217
+ //@ts-ignore
1218
+ cd.submitToCallDiagnostics({event: 'test'});
1219
+ assert.calledWith(requestStub, {eventPayload: {event: 'test'}, type: ['diagnostic-event']});
1220
+ });
1221
+
1222
+ describe('#submitMQE', () => {
1223
+ it('submits the event correctly', () => {
1224
+ const prepareDiagnosticEventSpy = sinon.spy(cd, 'prepareDiagnosticEvent');
1225
+ const submitToCallDiagnosticsSpy = sinon.spy(cd, 'submitToCallDiagnostics');
1226
+ const getErrorPayloadForClientErrorCodeSpy = sinon.spy(
1227
+ cd,
1228
+ 'getErrorPayloadForClientErrorCode'
1229
+ );
1230
+ const validatorSpy = sinon.spy(cd, 'validator');
1231
+ const getIdentifiersSpy = sinon.spy(cd, 'getIdentifiers');
1232
+ sinon.stub(cd, 'getOrigin').returns({origin: 'fake-origin'});
1233
+ const options = {
1234
+ networkType: 'wifi' as const,
1235
+ meetingId: fakeMeeting.id,
1236
+ webexConferenceIdStr: 'webexConferenceIdStr1',
1237
+ globalMeetingId: 'globalMeetingId1',
1238
+ };
1239
+
1240
+ cd.submitMQE({
1241
+ name: 'client.mediaquality.event',
1242
+ payload: {
1243
+ //@ts-ignore
1244
+ intervals: [{}],
1245
+ },
1246
+ options,
1247
+ });
1248
+
1249
+ assert.calledWith(getIdentifiersSpy, {
1250
+ meeting: fakeMeeting,
1251
+ mediaConnections: undefined,
1252
+ webexConferenceIdStr: 'webexConferenceIdStr1',
1253
+ globalMeetingId: 'globalMeetingId1',
1254
+ });
1255
+ assert.notCalled(getErrorPayloadForClientErrorCodeSpy);
1256
+ assert.calledWith(
1257
+ prepareDiagnosticEventSpy,
1258
+ {
1259
+ name: 'client.mediaquality.event',
1260
+ canProceed: true,
1261
+ identifiers: {
1262
+ correlationId: 'correlationId',
1263
+ webexConferenceIdStr: 'webexConferenceIdStr1',
1264
+ globalMeetingId: 'globalMeetingId1',
1265
+ userId: 'userId',
1266
+ deviceId: 'deviceUrl',
1267
+ orgId: 'orgId',
1268
+ locusUrl: 'locus/url',
1269
+ locusId: 'url',
1270
+ locusStartTime: 'lastActive',
1271
+ },
1272
+ eventData: {webClientDomain: 'whatever'},
1273
+ intervals: [{}],
1274
+ sourceMetadata: {
1275
+ applicationSoftwareType: 'webex-js-sdk',
1276
+ applicationSoftwareVersion: 'webex-version',
1277
+ mediaEngineSoftwareType: 'browser',
1278
+ mediaEngineSoftwareVersion: getOSVersion(),
1279
+ startTime: now.toISOString(),
1280
+ },
1281
+ },
1282
+ options
1283
+ );
1284
+
1285
+ assert.calledWith(validatorSpy, {
1286
+ type: 'mqe',
1287
+ event: {
1288
+ eventId: 'my-fake-id',
1289
+ version: 1,
1290
+ origin: {origin: 'fake-origin'},
1291
+ originTime: {triggered: now.toISOString(), sent: 'not_defined_yet'},
1292
+ senderCountryCode: 'UK',
1293
+ event: {
1294
+ name: 'client.mediaquality.event',
1295
+ canProceed: true,
1296
+ identifiers: {
1297
+ correlationId: 'correlationId',
1298
+ webexConferenceIdStr: 'webexConferenceIdStr1',
1299
+ globalMeetingId: 'globalMeetingId1',
1300
+ userId: 'userId',
1301
+ deviceId: 'deviceUrl',
1302
+ orgId: 'orgId',
1303
+ locusUrl: 'locus/url',
1304
+ locusId: 'url',
1305
+ locusStartTime: 'lastActive',
1306
+ },
1307
+ eventData: {webClientDomain: 'whatever'},
1308
+ intervals: [{}],
1309
+ sourceMetadata: {
1310
+ applicationSoftwareType: 'webex-js-sdk',
1311
+ applicationSoftwareVersion: 'webex-version',
1312
+ mediaEngineSoftwareType: 'browser',
1313
+ mediaEngineSoftwareVersion: getOSVersion(),
1314
+ startTime: now.toISOString(),
1315
+ },
1316
+ },
1317
+ },
1318
+ });
1319
+
1320
+ assert.calledWith(submitToCallDiagnosticsSpy, {
1321
+ eventId: 'my-fake-id',
1322
+ version: 1,
1323
+ origin: {origin: 'fake-origin'},
1324
+ originTime: {triggered: now.toISOString(), sent: 'not_defined_yet'},
1325
+ senderCountryCode: 'UK',
1326
+ event: {
1327
+ name: 'client.mediaquality.event',
1328
+ canProceed: true,
1329
+ identifiers: {
1330
+ correlationId: 'correlationId',
1331
+ webexConferenceIdStr: 'webexConferenceIdStr1',
1332
+ globalMeetingId: 'globalMeetingId1',
1333
+ userId: 'userId',
1334
+ deviceId: 'deviceUrl',
1335
+ orgId: 'orgId',
1336
+ locusUrl: 'locus/url',
1337
+ locusId: 'url',
1338
+ locusStartTime: 'lastActive',
1339
+ },
1340
+ eventData: {webClientDomain: 'whatever'},
1341
+ intervals: [{}],
1342
+ sourceMetadata: {
1343
+ applicationSoftwareType: 'webex-js-sdk',
1344
+ applicationSoftwareVersion: 'webex-version',
1345
+ mediaEngineSoftwareType: 'browser',
1346
+ mediaEngineSoftwareVersion: getOSVersion(),
1347
+ startTime: now.toISOString(),
1348
+ },
1349
+ },
1350
+ });
1351
+ });
1352
+
1353
+ it('throws if meeting id not provided', () => {
1354
+ assert.throws(() =>
1355
+ cd.submitMQE({
1356
+ name: 'client.mediaquality.event',
1357
+ payload: {
1358
+ //@ts-ignore
1359
+ intervals: [{}],
1360
+ },
1361
+ //@ts-ignore
1362
+ options: {meetingId: undefined, networkType: 'wifi'},
1363
+ })
1364
+ );
1365
+ });
1366
+
1367
+ it('should send behavioral event if meeting is undefined', () => {
1368
+ webex.meetings.meetingCollection.get = sinon.stub().returns(undefined);
1369
+ cd.submitMQE({
1370
+ name: 'client.mediaquality.event',
1371
+ payload: {
1372
+ //@ts-ignore
1373
+ intervals: [{}],
1374
+ },
1375
+ options: {meetingId: 'meetingId'},
1376
+ });
1377
+ assert.calledWith(
1378
+ webex.internal.metrics.submitClientMetrics,
1379
+ 'js_sdk_call_diagnostic_event_failed_to_send',
1380
+ {
1381
+ fields: {meetingId: 'meetingId', name: 'client.mediaquality.event'},
1382
+ }
1383
+ );
1384
+ });
1385
+ });
1386
+
1387
+ describe('#getErrorPayloadForClientErrorCode', () => {
1388
+ it('it should grab the payload for client error code correctly', () => {
1389
+ const res = cd.getErrorPayloadForClientErrorCode({
1390
+ clientErrorCode: 4008,
1391
+ serviceErrorCode: 10000,
1392
+ });
1393
+ assert.deepEqual(res, {
1394
+ category: 'signaling',
1395
+ errorDescription: 'NewLocusError',
1396
+ fatal: true,
1397
+ name: 'other',
1398
+ shownToUser: false,
1399
+ errorCode: 4008,
1400
+ serviceErrorCode: 10000,
1401
+ rawErrorMessage: undefined,
1402
+ });
1403
+ });
1404
+
1405
+ it('should include rawErrorMessage if provided', () => {
1406
+ const res = cd.getErrorPayloadForClientErrorCode({
1407
+ clientErrorCode: 4008,
1408
+ serviceErrorCode: 10000,
1409
+ rawErrorMessage: 'bad times',
1410
+ });
1411
+ assert.deepEqual(res, {
1412
+ category: 'signaling',
1413
+ errorDescription: 'NewLocusError',
1414
+ fatal: true,
1415
+ name: 'other',
1416
+ shownToUser: false,
1417
+ errorCode: 4008,
1418
+ serviceErrorCode: 10000,
1419
+ rawErrorMessage: 'bad times',
1420
+ });
1421
+ });
1422
+
1423
+ it('should generate the correct payload for client error 4009', () => {
1424
+ const res = cd.getErrorPayloadForClientErrorCode({
1425
+ clientErrorCode: 4009,
1426
+ serviceErrorCode: undefined,
1427
+ });
1428
+ assert.deepEqual(res, {
1429
+ category: 'network',
1430
+ errorDescription: 'NetworkUnavailable',
1431
+ fatal: true,
1432
+ name: 'other',
1433
+ shownToUser: false,
1434
+ errorCode: 4009,
1435
+ serviceErrorCode: undefined,
1436
+ rawErrorMessage: undefined,
1437
+ });
1438
+ });
1439
+
1440
+ it('it should return undefined if trying to get payload for client error code that doesnt exist', () => {
1441
+ const res = cd.getErrorPayloadForClientErrorCode({
1442
+ clientErrorCode: 123456,
1443
+ serviceErrorCode: 100000,
1444
+ });
1445
+ assert.deepEqual(res, undefined);
1446
+ });
1447
+ });
1448
+
1449
+ describe('#generateClientEventErrorPayload', () => {
1450
+ const defaultExpectedRes = {
1451
+ category: 'expected',
1452
+ errorDescription: 'StartRecordingFailed',
1453
+ fatal: true,
1454
+ name: 'other',
1455
+ shownToUser: false,
1456
+ errorCode: 4029,
1457
+ serviceErrorCode: 2409005,
1458
+ rawErrorMessage: 'bad times',
1459
+ };
1460
+
1461
+ const checkNameError = (payload: any, isExpectedToBeCalled: boolean) => {
1462
+ const res = cd.generateClientEventErrorPayload(payload);
1463
+ const expectedResult = {
1464
+ category: 'expected',
1465
+ errorDescription: 'CameraPermissionDenied',
1466
+ fatal: true,
1467
+ name: 'other',
1468
+ shownToUser: false,
1469
+ serviceErrorCode: undefined,
1470
+ errorCode: 4032,
1471
+ errorData: {errorName: payload.name},
1472
+ rawErrorMessage: payload.message,
1473
+ };
1474
+
1475
+ if (isExpectedToBeCalled) {
1476
+ assert.deepEqual(res, expectedResult);
1477
+ } else {
1478
+ assert.notDeepEqual(res, expectedResult);
1479
+ }
1480
+ };
1481
+
1482
+ it('should generate media event error payload if rawError has a media error name', () => {
1483
+ checkNameError({name: 'PermissionDeniedError', message: 'bad times'}, true);
1484
+ });
1485
+
1486
+ it('should not generate media event error payload if rawError has a name that is not recognized', () => {
1487
+ checkNameError({name: 'SomeRandomError', message: 'bad times'}, false);
1488
+ });
1489
+
1490
+ const checkCodeError = (payload: any, expetedRes: any) => {
1491
+ const res = cd.generateClientEventErrorPayload(payload);
1492
+ assert.deepEqual(res, expetedRes);
1493
+ };
1494
+ it('should generate event error payload correctly', () => {
1495
+ checkCodeError({body: {errorCode: 2409005}, message: 'bad times'}, defaultExpectedRes);
1496
+ });
1497
+
1498
+ it('should generate event error payload correctly if rawError has body.code', () => {
1499
+ checkCodeError({body: {code: 2409005}, message: 'bad times'}, defaultExpectedRes);
1500
+ });
1501
+
1502
+ it('should generate event error payload correctly if rawError has body.reason.reasonCode', () => {
1503
+ checkCodeError(
1504
+ {body: {reason: {reasonCode: 2409005}}, message: 'bad times'},
1505
+ defaultExpectedRes
1506
+ );
1507
+ });
1508
+
1509
+ it('should generate event error payload correctly if rawError has error.body.errorCode', () => {
1510
+ checkCodeError(
1511
+ {error: {body: {errorCode: 2409005}}, message: 'bad times'},
1512
+ defaultExpectedRes
1513
+ );
1514
+ });
1515
+
1516
+ const checkLocusError = (payload: any, isExpectedToBeCalled: boolean) => {
1517
+ const res = cd.generateClientEventErrorPayload(payload);
1518
+ const expectedResult = {
1519
+ category: 'signaling',
1520
+ errorDescription: 'NewLocusError',
1521
+ fatal: true,
1522
+ name: 'other',
1523
+ shownToUser: false,
1524
+ serviceErrorCode: 2400000,
1525
+ errorCode: 4008,
1526
+ rawErrorMessage: 'bad times',
1527
+ };
1528
+
1529
+ if (isExpectedToBeCalled) {
1530
+ assert.deepEqual(res, expectedResult);
1531
+ } else {
1532
+ assert.notDeepEqual(res, expectedResult);
1533
+ }
1534
+ };
1535
+
1536
+ it('should return default new locus event error payload correctly if locus error is recognized', () => {
1537
+ checkLocusError({body: {errorCode: 2400000}, message: 'bad times'}, true);
1538
+ });
1539
+
1540
+ it('should not return default new locus event error payload correctly if locus is not recognized', () => {
1541
+ checkLocusError({body: {errorCode: 1400000}, message: 'bad times'}, false);
1542
+ });
1543
+
1544
+ const checkMeetingInfoError = (payload: any, isExpectedToBeCalled: boolean) => {
1545
+ const res = cd.generateClientEventErrorPayload(payload);
1546
+ const expectedResult = {
1547
+ category: 'signaling',
1548
+ errorDescription: 'MeetingInfoLookupError',
1549
+ fatal: true,
1550
+ name: 'other',
1551
+ shownToUser: false,
1552
+ serviceErrorCode: undefined,
1553
+ errorCode: 4100,
1554
+ rawErrorMessage: 'bad times',
1555
+ };
1556
+
1557
+ if (isExpectedToBeCalled) {
1558
+ assert.deepEqual(res, expectedResult);
1559
+ } else {
1560
+ assert.notDeepEqual(res, expectedResult);
1561
+ }
1562
+ };
1563
+
1564
+ it('should return default meeting info lookup error payload if data.meetingInfo was found on error body', () => {
1565
+ checkMeetingInfoError(
1566
+ {body: {data: {meetingInfo: 'something'}}, message: 'bad times'},
1567
+ true
1568
+ );
1569
+ });
1570
+
1571
+ it('should return default meeting info lookup error payload if body.url contains wbxappapi', () => {
1572
+ checkMeetingInfoError(
1573
+ {body: {url: '1234567-wbxappapiabcdefg'}, message: 'bad times'},
1574
+ true
1575
+ );
1576
+ });
1577
+
1578
+ it('should not return default meeting info lookup error payload if body.url does not contain wbxappapi and data.meetingInfo was not found on error body', () => {
1579
+ checkMeetingInfoError(
1580
+ {body: {data: '1234567-wbxappapiabcdefg'}, message: 'bad times'},
1581
+ false
1582
+ );
1583
+ });
1584
+
1585
+ it('should return NetworkError code for a NetworkOrCORSERror', () => {
1586
+ const res = cd.generateClientEventErrorPayload(
1587
+ new WebexHttpError.NetworkOrCORSError({
1588
+ url: 'https://example.com',
1589
+ statusCode: 0,
1590
+ body: {},
1591
+ options: {headers: {}, url: 'https://example.com'},
1592
+ })
1593
+ );
1594
+ assert.deepEqual(res, {
1595
+ category: 'network',
1596
+ errorDescription: 'NetworkError',
1597
+ fatal: true,
1598
+ name: 'other',
1599
+ shownToUser: false,
1600
+ serviceErrorCode: undefined,
1601
+ errorCode: 1026,
1602
+ rawErrorMessage: '{}\nundefined https://example.com\nWEBEX_TRACKING_ID: undefined\n',
1603
+ });
1604
+ });
1605
+
1606
+ it('should override custom properties for a NetworkOrCORSERror', () => {
1607
+ const error = new WebexHttpError.NetworkOrCORSError({
1608
+ url: 'https://example.com',
1609
+ statusCode: 0,
1610
+ body: {},
1611
+ options: {headers: {}, url: 'https://example.com'},
1612
+ });
1613
+
1614
+ error.payloadOverrides = {
1615
+ shownToUser: true,
1616
+ category: 'expected',
1617
+ };
1618
+
1619
+ const res = cd.generateClientEventErrorPayload(error);
1620
+ assert.deepEqual(res, {
1621
+ category: 'expected',
1622
+ errorDescription: 'NetworkError',
1623
+ fatal: true,
1624
+ name: 'other',
1625
+ shownToUser: true,
1626
+ serviceErrorCode: undefined,
1627
+ errorCode: 1026,
1628
+ rawErrorMessage: '{}\nundefined https://example.com\nWEBEX_TRACKING_ID: undefined\n',
1629
+ });
1630
+ });
1631
+
1632
+ it('should return AuthenticationFailed code for an Unauthorized error', () => {
1633
+ const res = cd.generateClientEventErrorPayload(
1634
+ new WebexHttpError.Unauthorized({
1635
+ url: 'https://example.com',
1636
+ statusCode: 0,
1637
+ body: {},
1638
+ options: {headers: {}, url: 'https://example.com'},
1639
+ })
1640
+ );
1641
+ assert.deepEqual(res, {
1642
+ category: 'network',
1643
+ errorDescription: 'AuthenticationFailed',
1644
+ fatal: true,
1645
+ name: 'other',
1646
+ shownToUser: false,
1647
+ serviceErrorCode: undefined,
1648
+ errorCode: 1010,
1649
+ rawErrorMessage: '{}\nundefined https://example.com\nWEBEX_TRACKING_ID: undefined\n',
1650
+ });
1651
+ });
1652
+
1653
+ it('should override custom properties for an Unauthorized error', () => {
1654
+ const error = new WebexHttpError.Unauthorized({
1655
+ url: 'https://example.com',
1656
+ statusCode: 0,
1657
+ body: {},
1658
+ options: {headers: {}, url: 'https://example.com'},
1659
+ });
1660
+
1661
+ error.payloadOverrides = {
1662
+ shownToUser: true,
1663
+ category: 'expected',
1664
+ };
1665
+
1666
+ const res = cd.generateClientEventErrorPayload(error);
1667
+ assert.deepEqual(res, {
1668
+ category: 'expected',
1669
+ errorDescription: 'AuthenticationFailed',
1670
+ fatal: true,
1671
+ name: 'other',
1672
+ shownToUser: true,
1673
+ serviceErrorCode: undefined,
1674
+ errorCode: 1010,
1675
+ rawErrorMessage: '{}\nundefined https://example.com\nWEBEX_TRACKING_ID: undefined\n',
1676
+ });
1677
+ });
1678
+
1679
+ it('should return unknown error otherwise', () => {
1680
+ const res = cd.generateClientEventErrorPayload({somethgin: 'new', message: 'bad times'});
1681
+ assert.deepEqual(res, {
1682
+ category: 'other',
1683
+ errorDescription: 'UnknownError',
1684
+ fatal: true,
1685
+ name: 'other',
1686
+ shownToUser: false,
1687
+ serviceErrorCode: 9999,
1688
+ errorCode: 9999,
1689
+ rawErrorMessage: 'bad times',
1690
+ });
1691
+ });
1692
+
1693
+ it('should generate event error payload correctly for locus error 2423012', () => {
1694
+ const res = cd.generateClientEventErrorPayload({
1695
+ body: {errorCode: 2423012},
1696
+ message: 'bad times',
1697
+ });
1698
+ assert.deepEqual(res, {
1699
+ category: 'expected',
1700
+ errorDescription: 'FraudDetection',
1701
+ fatal: true,
1702
+ name: 'locus.response',
1703
+ shownToUser: true,
1704
+ serviceErrorCode: 2423012,
1705
+ errorCode: 12000,
1706
+ rawErrorMessage: 'bad times',
1707
+ });
1708
+ });
1709
+ it('should generate event error payload correctly for locus error 2409062', () => {
1710
+ const res = cd.generateClientEventErrorPayload({
1711
+ body: {errorCode: 2409062},
1712
+ message: 'bad times',
1713
+ });
1714
+ assert.deepEqual(res, {
1715
+ category: 'expected',
1716
+ errorDescription: 'E2EENotSupported',
1717
+ fatal: true,
1718
+ name: 'locus.response',
1719
+ shownToUser: true,
1720
+ serviceErrorCode: 2409062,
1721
+ errorCode: 12002,
1722
+ rawErrorMessage: 'bad times',
1723
+ });
1724
+ });
1725
+
1726
+ it('should generate event error payload correctly for locus error 2423021', () => {
1727
+ const res = cd.generateClientEventErrorPayload({
1728
+ body: {errorCode: 2423021},
1729
+ message: 'bad times',
1730
+ });
1731
+ assert.deepEqual(res, {
1732
+ category: 'expected',
1733
+ errorDescription: 'LocusLobbyFullCMR',
1734
+ fatal: true,
1735
+ name: 'locus.response',
1736
+ shownToUser: true,
1737
+ serviceErrorCode: 2423021,
1738
+ errorCode: 12001,
1739
+ rawErrorMessage: 'bad times',
1740
+ });
1741
+ });
1742
+ });
1743
+
1744
+ describe('#getCurLoginType', () => {
1745
+ it('returns login-ci if not unverified guest', () => {
1746
+ webex.credentials.isUnverifiedGuest = false;
1747
+ assert.deepEqual(cd.getCurLoginType(), 'login-ci');
1748
+ });
1749
+ it('returns unverified guest', () => {
1750
+ webex.credentials.isUnverifiedGuest = true;
1751
+ assert.deepEqual(cd.getCurLoginType(), 'unverified-guest');
1752
+ });
1753
+ });
1754
+
1755
+ describe('#getSubServiceType', () => {
1756
+ it('returns subServicetype as PMR when PMR meeting', () => {
1757
+ fakeMeeting.meetingInfo = {
1758
+ webexScheduled: false,
1759
+ pmr: true,
1760
+ enableEvent: false,
1761
+ };
1762
+ assert.deepEqual(cd.getSubServiceType(fakeMeeting), 'PMR');
1763
+ });
1764
+
1765
+ it('returns subServicetype as ScheduledMeeting when regular meeting', () => {
1766
+ fakeMeeting.meetingInfo = {
1767
+ webexScheduled: true,
1768
+ pmr: false,
1769
+ enableEvent: false,
1770
+ };
1771
+ assert.deepEqual(cd.getSubServiceType(fakeMeeting), 'ScheduledMeeting');
1772
+ });
1773
+
1774
+ it('returns subServicetype as Webinar when meeting is Webinar', () => {
1775
+ fakeMeeting.meetingInfo = {
1776
+ webexScheduled: true,
1777
+ pmr: false,
1778
+ enableEvent: true,
1779
+ };
1780
+ assert.deepEqual(cd.getSubServiceType(fakeMeeting), 'Webinar');
1781
+ });
1782
+
1783
+ it('returns subServicetype as undefined when correct parameters are not found', () => {
1784
+ fakeMeeting.meetingInfo = {};
1785
+ assert.deepEqual(cd.getSubServiceType(fakeMeeting), undefined);
1786
+ });
1787
+ });
1788
+
1789
+ describe('#getIsConvergedArchitectureEnabled', () => {
1790
+ it('returns true if converged architecture is enabled', () => {
1791
+ fakeMeeting.meetingInfo = {enableConvergedArchitecture: true};
1792
+ assert.deepEqual(cd.getIsConvergedArchitectureEnabled({meetingId: fakeMeeting.id}), true);
1793
+ });
1794
+ it('returns false if converged architecture is not enabled', () => {
1795
+ fakeMeeting.meetingInfo = {enableConvergedArchitecture: false};
1796
+ assert.deepEqual(cd.getIsConvergedArchitectureEnabled({meetingId: fakeMeeting.id}), false);
1797
+ });
1798
+ it('returns undefined if converged architecture is not defined', () => {
1799
+ fakeMeeting.meetingInfo = {};
1800
+ assert.deepEqual(
1801
+ cd.getIsConvergedArchitectureEnabled({meetingId: fakeMeeting.id}),
1802
+ undefined
1803
+ );
1804
+ });
1805
+ });
1806
+
1807
+ describe('#buildClientEventFetchRequestOptions', () => {
1808
+ [undefined, 'myPreLoginId'].forEach((preLoginId) => {
1809
+ it('returns expected options without preLoginId', async () => {
1810
+ const options = {
1811
+ meetingId: fakeMeeting.id,
1812
+ preLoginId,
1813
+ };
1814
+
1815
+ const triggered = new Date();
1816
+ const fetchOptions = await cd.buildClientEventFetchRequestOptions({
1817
+ name: 'client.exit.app',
1818
+ payload: {trigger: 'user-interaction', canProceed: false},
1819
+ options,
1820
+ });
1821
+
1822
+ assert.deepEqual(fetchOptions.body, {
1823
+ metrics: [
1824
+ {
1825
+ eventPayload: {
1826
+ event: {
1827
+ canProceed: false,
1828
+ eventData: {
1829
+ webClientDomain: 'whatever',
1830
+ },
1831
+ identifiers: {
1832
+ correlationId: 'correlationId',
1833
+ deviceId: 'deviceUrl',
1834
+ locusId: 'url',
1835
+ locusStartTime: 'lastActive',
1836
+ locusUrl: 'locus/url',
1837
+ orgId: 'orgId',
1838
+ userId: 'userId',
1839
+ },
1840
+ loginType: 'login-ci',
1841
+ name: 'client.exit.app',
1842
+ trigger: 'user-interaction',
1843
+ userType: 'host',
1844
+ isConvergedArchitectureEnabled: undefined,
1845
+ webexSubServiceType: undefined,
1846
+ },
1847
+ eventId: 'my-fake-id',
1848
+ origin: {
1849
+ buildType: 'test',
1850
+ clientInfo: {
1851
+ clientType: 'TEAMS_CLIENT',
1852
+ clientVersion: 'webex-js-sdk/webex-version',
1853
+ localNetworkPrefix:
1854
+ Utils.anonymizeIPAddress(webex.meetings.geoHintInfo?.clientAddress) ||
1855
+ undefined,
1856
+ os: getOSNameInternal() || 'unknown',
1857
+ osVersion: getOSVersion(),
1858
+ subClientType: 'WEB_APP',
1859
+ },
1860
+ environment: 'meeting_evn',
1861
+ name: 'endpoint',
1862
+ networkType: 'unknown',
1863
+ userAgent,
1864
+ },
1865
+ originTime: {
1866
+ sent: 'not_defined_yet',
1867
+ triggered: triggered.toISOString(),
1868
+ },
1869
+ senderCountryCode: webex.meetings.geoHintInfo?.countryCode,
1870
+ version: 1,
1871
+ },
1872
+ type: ['diagnostic-event'],
1873
+ },
1874
+ ],
1875
+ });
1876
+
1877
+ const rest = omit(fetchOptions, 'body');
1878
+
1879
+ if (preLoginId) {
1880
+ assert.deepEqual(rest, {
1881
+ foo: 'bar',
1882
+ method: 'POST',
1883
+ resource: 'clientmetrics-prelogin',
1884
+ service: 'metrics',
1885
+ waitForServiceTimeout: CONFIG.metrics.waitForServiceTimeout,
1886
+ headers: {
1887
+ authorization: false,
1888
+ 'x-prelogin-userid': preLoginId,
1889
+ },
1890
+ });
1891
+ } else {
1892
+ assert.deepEqual(rest, {
1893
+ foo: 'bar',
1894
+ method: 'POST',
1895
+ resource: 'clientmetrics',
1896
+ service: 'metrics',
1897
+ headers: {},
1898
+ waitForServiceTimeout: CONFIG.metrics.waitForServiceTimeout,
1899
+ });
1900
+ }
1901
+
1902
+ const webexLoggerLogCalls = webex.logger.log.getCalls();
1903
+
1904
+ assert.deepEqual(webexLoggerLogCalls[0].args, [
1905
+ 'call-diagnostic-events -> ',
1906
+ 'CallDiagnosticMetrics: @buildClientEventFetchRequestOptions. Building request options object for fetch()...',
1907
+ `name: client.exit.app`,
1908
+ ]);
1909
+ });
1910
+ });
1911
+ });
1912
+
1913
+ describe('#submitToCallDiagnosticsPreLogin', async () => {
1914
+ it('should call webex.request with expected options', async () => {
1915
+ sinon.spy(Utils, 'prepareDiagnosticMetricItem');
1916
+ await cd.submitToCallDiagnosticsPreLogin(
1917
+ {
1918
+ //@ts-ignore
1919
+ event: {name: 'client.alert.displayed', canProceed: true},
1920
+ //@ts-ignore
1921
+ originTime: {triggered: 'now'},
1922
+ },
1923
+ 'my-id'
1924
+ );
1925
+
1926
+ assert.calledWith(Utils.prepareDiagnosticMetricItem, webex, {
1927
+ eventPayload: {
1928
+ event: {name: 'client.alert.displayed', canProceed: true},
1929
+ originTime: {triggered: 'now', sent: now.toISOString()},
1930
+ origin: {buildType: 'test', networkType: 'unknown'},
1931
+ },
1932
+ type: ['diagnostic-event'],
1933
+ });
1934
+
1935
+ assert.calledWith(
1936
+ webex.internal.newMetrics.postPreLoginMetric,
1937
+ {
1938
+ eventPayload: {
1939
+ event: {
1940
+ name: 'client.alert.displayed',
1941
+ canProceed: true,
1942
+ },
1943
+ originTime: {
1944
+ sent: now.toISOString(),
1945
+ triggered: 'now',
1946
+ },
1947
+ origin: {
1948
+ buildType: 'test',
1949
+ networkType: 'unknown',
1950
+ },
1951
+ },
1952
+ type: ['diagnostic-event'],
1953
+ },
1954
+ 'my-id'
1955
+ );
1956
+ });
1957
+ });
1958
+
1959
+ describe('#isServiceErrorExpected', () => {
1960
+ it('returns true for code mapped to "expected"', () => {
1961
+ assert.isTrue(cd.isServiceErrorExpected(2423012));
1962
+ });
1963
+
1964
+ it('returns false for code mapped to "signaling"', () => {
1965
+ assert.isFalse(cd.isServiceErrorExpected(400001));
1966
+ });
1967
+
1968
+ it('returns false for unmapped code', () => {
1969
+ assert.isFalse(cd.isServiceErrorExpected(999999));
1970
+ });
1971
+ });
1972
+ });
1973
+ });