@webex/internal-plugin-metrics 3.0.0-beta.27 → 3.0.0-beta.271

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