@webex/internal-plugin-metrics 3.0.0-beta.31 → 3.0.0-beta.310

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