@webex/internal-plugin-metrics 3.12.0-webex-services-ready.2 → 3.12.0-webex-services-ready.4

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 (38) hide show
  1. package/dist/automated-user.js +19 -0
  2. package/dist/automated-user.js.map +1 -0
  3. package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js +0 -23
  4. package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js.map +1 -1
  5. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js +571 -15
  6. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js.map +1 -1
  7. package/dist/call-diagnostic/call-diagnostic-metrics.js +51 -26
  8. package/dist/call-diagnostic/call-diagnostic-metrics.js.map +1 -1
  9. package/dist/index.js +15 -0
  10. package/dist/index.js.map +1 -1
  11. package/dist/metrics.js +1 -1
  12. package/dist/metrics.types.js +4 -0
  13. package/dist/metrics.types.js.map +1 -1
  14. package/dist/new-metrics.js +16 -6
  15. package/dist/new-metrics.js.map +1 -1
  16. package/dist/prelogin-metrics-batcher.js +0 -23
  17. package/dist/prelogin-metrics-batcher.js.map +1 -1
  18. package/dist/types/automated-user.d.ts +2 -0
  19. package/dist/types/call-diagnostic/call-diagnostic-metrics-latencies.d.ts +199 -5
  20. package/dist/types/call-diagnostic/call-diagnostic-metrics.d.ts +27 -2
  21. package/dist/types/index.d.ts +5 -3
  22. package/dist/types/metrics.types.d.ts +4 -2
  23. package/dist/types/new-metrics.d.ts +4 -0
  24. package/package.json +12 -11
  25. package/src/automated-user.ts +16 -0
  26. package/src/call-diagnostic/call-diagnostic-metrics-batcher.ts +0 -26
  27. package/src/call-diagnostic/call-diagnostic-metrics-latencies.ts +661 -5
  28. package/src/call-diagnostic/call-diagnostic-metrics.ts +40 -18
  29. package/src/index.ts +5 -0
  30. package/src/metrics.types.ts +15 -2
  31. package/src/new-metrics.ts +12 -4
  32. package/src/prelogin-metrics-batcher.ts +0 -26
  33. package/test/unit/spec/automated-user.ts +43 -0
  34. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-batcher.ts +0 -136
  35. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-latencies.ts +1192 -16
  36. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +75 -11
  37. package/test/unit/spec/new-metrics.ts +13 -2
  38. package/test/unit/spec/prelogin-metrics-batcher.ts +1 -120
@@ -6,6 +6,7 @@ import uuid from 'uuid';
6
6
  import {merge} from 'lodash';
7
7
  import {StatelessWebexPlugin} from '@webex/webex-core';
8
8
  import {getOSNameInternal} from '../metrics';
9
+ import * as AutomatedUserUtils from '../automated-user';
9
10
 
10
11
  import {
11
12
  anonymizeIPAddress,
@@ -99,7 +100,12 @@ export default class CallDiagnosticMetrics extends StatelessWebexPlugin {
99
100
  // @ts-ignore
100
101
  private preLoginMetricsBatcher: PreLoginMetricsBatcher;
101
102
 
102
- private logger: any; // to avoid adding @ts-ignore everywhere
103
+ // lazy getter to avoid @ts-ignore on every call site
104
+ private get logger(): any {
105
+ // @ts-ignore
106
+ return this.webex.logger;
107
+ }
108
+
103
109
  private hasLoggedBrowserSerial: boolean;
104
110
  private device: any;
105
111
  private delayedClientEvents: DelayedClientEvent[] = [];
@@ -126,8 +132,6 @@ export default class CallDiagnosticMetrics extends StatelessWebexPlugin {
126
132
  constructor(...args) {
127
133
  super(...args);
128
134
  // @ts-ignore
129
- this.logger = this.webex.logger;
130
- // @ts-ignore
131
135
  this.callDiagnosticEventsBatcher = new CallDiagnosticEventsBatcher({}, {parent: this.webex});
132
136
  // @ts-ignore
133
137
  this.preLoginMetricsBatcher = new PreLoginMetricsBatcher({}, {parent: this.webex});
@@ -147,6 +151,27 @@ export default class CallDiagnosticMetrics extends StatelessWebexPlugin {
147
151
  return null;
148
152
  }
149
153
 
154
+ /**
155
+ * Returns the user activation state reported from the browser's navigator.userActivation API
156
+ * @returns object with hasBeenActive and isActive booleans, or undefined if unavailable
157
+ */
158
+ getUserActivation(): {hasBeenActive: boolean; isActive: boolean} | undefined {
159
+ const userActivation =
160
+ typeof navigator !== 'undefined'
161
+ ? (navigator as {userActivation?: {hasBeenActive: boolean; isActive: boolean}})
162
+ .userActivation
163
+ : undefined;
164
+
165
+ if (userActivation) {
166
+ return {
167
+ hasBeenActive: userActivation.hasBeenActive,
168
+ isActive: userActivation.isActive,
169
+ };
170
+ }
171
+
172
+ return undefined;
173
+ }
174
+
150
175
  /**
151
176
  * Returns the telemetryOptOut value of the current user
152
177
  * @returns one of 'manual', 'automatic', undefined
@@ -251,12 +276,12 @@ export default class CallDiagnosticMetrics extends StatelessWebexPlugin {
251
276
  getOrigin(options: GetOriginOptions, meetingId?: string) {
252
277
  const defaultClientType: ClientType =
253
278
  // @ts-ignore
254
- this.webex.meetings.config?.metrics?.clientType;
279
+ this.webex.meetings?.config?.metrics?.clientType;
255
280
  const defaultSubClientType: SubClientType =
256
281
  // @ts-ignore
257
- this.webex.meetings.config?.metrics?.subClientType;
282
+ this.webex.meetings?.config?.metrics?.subClientType;
258
283
  // @ts-ignore
259
- const providedClientVersion: string = this.webex.meetings.config?.metrics?.clientVersion;
284
+ const providedClientVersion: string = this.webex.meetings?.config?.metrics?.clientVersion;
260
285
  // @ts-ignore
261
286
  const defaultSDKClientVersion = `${CLIENT_NAME}/${this.webex.version}`;
262
287
 
@@ -296,12 +321,12 @@ export default class CallDiagnosticMetrics extends StatelessWebexPlugin {
296
321
  ...versionMetadata,
297
322
  publicNetworkPrefix:
298
323
  // @ts-ignore
299
- anonymizeIPAddress(this.webex.meetings.geoHintInfo?.clientAddress) || undefined,
324
+ anonymizeIPAddress(this.webex.meetings?.geoHintInfo?.clientAddress) || undefined,
300
325
  localNetworkPrefix:
301
326
  anonymizeIPAddress(
302
327
  // @ts-ignore
303
- this.webex.meetings.meetingCollection
304
- .get(meetingId)
328
+ this.webex.meetings?.meetingCollection
329
+ ?.get(meetingId)
305
330
  ?.statsAnalyzer?.getLocalIpAddress()
306
331
  ) || undefined,
307
332
  osVersion: getOSVersion() || 'unknown',
@@ -464,7 +489,7 @@ export default class CallDiagnosticMetrics extends StatelessWebexPlugin {
464
489
  sent: 'not_defined_yet',
465
490
  },
466
491
  // @ts-ignore
467
- senderCountryCode: this.webex.meetings.geoHintInfo?.countryCode,
492
+ senderCountryCode: this.webex.meetings?.geoHintInfo?.countryCode,
468
493
  event: eventData,
469
494
  };
470
495
 
@@ -1046,8 +1071,8 @@ export default class CallDiagnosticMetrics extends StatelessWebexPlugin {
1046
1071
  // @ts-ignore
1047
1072
  webClientPreload: this.webex.meetings?.config?.metrics?.webClientPreload,
1048
1073
  isVipMeeting: meeting?.meetingInfo?.vipmeeting || false,
1049
- isAutomatedUser:
1050
- typeof window !== 'undefined' && typeof navigator !== 'undefined' && !!navigator?.webdriver, // if webdriver is true, it's most likely in a test environment
1074
+ isAutomatedUser: AutomatedUserUtils.isAutomatedUser(),
1075
+ userActivation: this.getUserActivation(),
1051
1076
  };
1052
1077
 
1053
1078
  const joinFlowVersion = options.joinFlowVersion ?? meeting.callStateForMetrics?.joinFlowVersion;
@@ -1170,8 +1195,8 @@ export default class CallDiagnosticMetrics extends StatelessWebexPlugin {
1170
1195
  telemetryOptOut: this.getTelemetryOptOut(),
1171
1196
  // @ts-ignore
1172
1197
  webClientPreload: this.webex.meetings?.config?.metrics?.webClientPreload,
1173
- isAutomatedUser:
1174
- typeof window !== 'undefined' && typeof navigator !== 'undefined' && !!navigator?.webdriver, // if webdriver is true, it's most likely in a test environment
1198
+ isAutomatedUser: AutomatedUserUtils.isAutomatedUser(),
1199
+ userActivation: this.getUserActivation(),
1175
1200
  };
1176
1201
 
1177
1202
  if (options.joinFlowVersion) {
@@ -1364,7 +1389,6 @@ export default class CallDiagnosticMetrics extends StatelessWebexPlugin {
1364
1389
  const finalEvent = {
1365
1390
  eventPayload: event,
1366
1391
  type: ['diagnostic-event'],
1367
- markTelemetryOptOutOnResponse: true,
1368
1392
  };
1369
1393
 
1370
1394
  return this.callDiagnosticEventsBatcher.request(finalEvent);
@@ -1374,7 +1398,6 @@ export default class CallDiagnosticMetrics extends StatelessWebexPlugin {
1374
1398
  * Prepare the event and send the request to metrics-a service, pre login.
1375
1399
  * @param event
1376
1400
  * @param preLoginId
1377
- * @param markTelemetryOptOutOnResponse
1378
1401
  * @returns
1379
1402
  */
1380
1403
  submitToCallDiagnosticsPreLogin = (event: Event, preLoginId?: string): Promise<any> => {
@@ -1382,7 +1405,6 @@ export default class CallDiagnosticMetrics extends StatelessWebexPlugin {
1382
1405
  const finalEvent = {
1383
1406
  eventPayload: event,
1384
1407
  type: ['diagnostic-event'],
1385
- markTelemetryOptOutOnResponse: true,
1386
1408
  };
1387
1409
 
1388
1410
  this.preLoginMetricsBatcher.savePreLoginId(preLoginId);
@@ -1432,7 +1454,7 @@ export default class CallDiagnosticMetrics extends StatelessWebexPlugin {
1432
1454
  },
1433
1455
  headers: {},
1434
1456
  // @ts-ignore
1435
- waitForServiceTimeout: this.webex.internal.metrics.config.waitForServiceTimeout,
1457
+ waitForServiceTimeout: this.webex.internal.metrics?.config?.waitForServiceTimeout,
1436
1458
  };
1437
1459
 
1438
1460
  if (options.preLoginId) {
package/src/index.ts CHANGED
@@ -8,6 +8,7 @@ import Metrics from './metrics';
8
8
  import config from './config';
9
9
  import NewMetrics from './new-metrics';
10
10
  import * as Utils from './utils';
11
+ import * as AutomatedUserUtils from './automated-user';
11
12
  import {
12
13
  ClientEvent,
13
14
  ClientEventLeaveReason,
@@ -19,6 +20,7 @@ import {
19
20
  SubmitMQE,
20
21
  PreComputedLatencies,
21
22
  SubmitFeatureEvent,
23
+ LocusSyncLatencyEventName,
22
24
  } from './metrics.types';
23
25
  import * as CALL_DIAGNOSTIC_CONFIG from './call-diagnostic/config';
24
26
  import * as CallDiagnosticUtils from './call-diagnostic/call-diagnostic-metrics.util';
@@ -43,6 +45,7 @@ export {default, getOSNameInternal} from './metrics';
43
45
  export {
44
46
  config,
45
47
  CALL_DIAGNOSTIC_CONFIG,
48
+ AutomatedUserUtils,
46
49
  NewMetrics,
47
50
  Utils,
48
51
  CallDiagnosticUtils,
@@ -54,6 +57,7 @@ export {
54
57
  RtcMetrics,
55
58
  PreLoginMetrics,
56
59
  };
60
+ export {isAutomatedUser, isAutomatedUserAgent} from './automated-user';
57
61
  export type {
58
62
  ClientEvent,
59
63
  ClientEventLeaveReason,
@@ -65,4 +69,5 @@ export type {
65
69
  SubmitBusinessEvent,
66
70
  PreComputedLatencies,
67
71
  SubmitFeatureEvent,
72
+ LocusSyncLatencyEventName,
68
73
  };
@@ -149,6 +149,17 @@ export type SubmitMQEOptions = {
149
149
  globalMeetingId?: string;
150
150
  };
151
151
 
152
+ export const LOCUS_SYNC_LATENCY_EVENT_NAMES = [
153
+ 'internal.client.locus.sync.start',
154
+ 'internal.client.locus.hashtree.request',
155
+ 'internal.client.locus.hashtree.response',
156
+ 'internal.client.locus.sync.request',
157
+ 'internal.client.locus.sync.response',
158
+ 'internal.client.locus.sync.message.received',
159
+ ] as const;
160
+
161
+ export type LocusSyncLatencyEventName = (typeof LOCUS_SYNC_LATENCY_EVENT_NAMES)[number];
162
+
152
163
  export type InternalEvent = {
153
164
  name:
154
165
  | 'internal.client.meetinginfo.request'
@@ -162,7 +173,8 @@ export type InternalEvent = {
162
173
  | 'internal.client.add-media.turn-discovery.start'
163
174
  | 'internal.client.add-media.turn-discovery.end'
164
175
  | 'internal.client.share.initiated'
165
- | 'internal.client.share.stopped';
176
+ | 'internal.client.share.stopped'
177
+ | LocusSyncLatencyEventName;
166
178
 
167
179
  payload?: never;
168
180
  options?: never;
@@ -324,7 +336,8 @@ export type PreComputedLatencies =
324
336
  | 'internal.get.u2c.time'
325
337
  | 'internal.call.init.join.req'
326
338
  | 'internal.other.app.api.time'
327
- | 'internal.api.fetch.intelligence.models';
339
+ | 'internal.api.fetch.intelligence.models'
340
+ | 'internal.client.locus.sync.random.backoff';
328
341
 
329
342
  export interface IdType {
330
343
  meetingId?: string;
@@ -30,6 +30,7 @@ import {
30
30
  import CallDiagnosticLatencies from './call-diagnostic/call-diagnostic-metrics-latencies';
31
31
  import {setMetricTimings} from './call-diagnostic/call-diagnostic-metrics.util';
32
32
  import {generateCommonErrorMetadata} from './utils';
33
+ import {isAutomatedUser as detectAutomatedUser} from './automated-user';
33
34
 
34
35
  /**
35
36
  * Metrics plugin to centralize all types of metrics.
@@ -79,6 +80,8 @@ class Metrics extends WebexPlugin {
79
80
 
80
81
  // @ts-ignore
81
82
  this.callDiagnosticLatencies = new CallDiagnosticLatencies({}, {parent: this.webex});
83
+ // @ts-ignore
84
+ this.callDiagnosticMetrics = new CallDiagnosticMetrics({}, {parent: this.webex});
82
85
  this.onReady();
83
86
  }
84
87
 
@@ -88,8 +91,6 @@ class Metrics extends WebexPlugin {
88
91
  private onReady() {
89
92
  // @ts-ignore
90
93
  this.webex.once('ready', () => {
91
- // @ts-ignore
92
- this.callDiagnosticMetrics = new CallDiagnosticMetrics({}, {parent: this.webex});
93
94
  this.preLoginMetrics = new PreLoginMetrics(
94
95
  // @ts-ignore
95
96
  new PreLoginMetricsBatcher({}, {parent: this.webex}),
@@ -182,6 +183,13 @@ class Metrics extends WebexPlugin {
182
183
  return this.businessMetrics?.isReadyToSubmitEvents() ?? false;
183
184
  }
184
185
 
186
+ /**
187
+ * @returns whether the current user agent belongs to an automated user
188
+ */
189
+ isAutomatedUser() {
190
+ return detectAutomatedUser();
191
+ }
192
+
185
193
  /**
186
194
  * Behavioral event
187
195
  * @param args
@@ -325,7 +333,7 @@ class Metrics extends WebexPlugin {
325
333
  payload?: RecursivePartial<FeatureEvent['payload']>;
326
334
  options: any;
327
335
  }) {
328
- if (!this.callDiagnosticLatencies || !this.callDiagnosticMetrics) {
336
+ if (!this.isReady) {
329
337
  // @ts-ignore
330
338
  this.webex.logger.log(
331
339
  `NewMetrics: @submitFeatureEvent. Attempted to submit before webex.ready. Event name: ${name}`
@@ -360,7 +368,7 @@ class Metrics extends WebexPlugin {
360
368
  payload?: RecursivePartial<ClientEvent['payload']>;
361
369
  options?: SubmitClientEventOptions;
362
370
  }): Promise<any> {
363
- if (!this.callDiagnosticLatencies || !this.callDiagnosticMetrics) {
371
+ if (!this.isReady) {
364
372
  // @ts-ignore
365
373
  this.webex.logger.log(
366
374
  `NewMetrics: @submitClientEvent. Attempted to submit before webex.ready. Event name: ${name}`
@@ -78,8 +78,6 @@ const PreLoginMetricsBatcher = Batcher.extend({
78
78
  `PreLoginMetricsBatcher: @submitHttpRequest#${batchId}. Request successful.`
79
79
  );
80
80
 
81
- this.handleHttpResponseStatus(res?.statusCode, payload);
82
-
83
81
  return res;
84
82
  })
85
83
  .catch((err) => {
@@ -89,33 +87,9 @@ const PreLoginMetricsBatcher = Batcher.extend({
89
87
  `error: ${generateCommonErrorMetadata(err)}`
90
88
  );
91
89
 
92
- this.handleHttpResponseStatus(err?.statusCode, payload);
93
-
94
90
  return Promise.reject(err);
95
91
  });
96
92
  },
97
-
98
- /**
99
- * React to the HTTP status code returned by the prelogin metrics endpoint.
100
- * Only items submitted with `markTelemetryOptOutOnResponse: true` opt into
101
- * this behavior.
102
- * @param {number | undefined} statusCode
103
- * @param {any[]} payload Items flushed in this HTTP batch.
104
- * @returns {void}
105
- */
106
- handleHttpResponseStatus(statusCode: number | undefined, payload: any[]) {
107
- const shouldMark =
108
- Array.isArray(payload) &&
109
- payload.some((item) => item?.markTelemetryOptOutOnResponse === true);
110
-
111
- if (!shouldMark) {
112
- return;
113
- }
114
-
115
- if (statusCode === 200) {
116
- this.webex.internal.newMetrics?.callDiagnosticMetrics?.setIsTelemetryOptOutAutomatic(true);
117
- }
118
- },
119
93
  });
120
94
 
121
95
  export default PreLoginMetricsBatcher;
@@ -0,0 +1,43 @@
1
+ import {assert} from '@webex/test-helper-chai';
2
+
3
+ import {isAutomatedUser, isAutomatedUserAgent} from '../../../src/automated-user';
4
+
5
+ describe('automated user detection', () => {
6
+ [
7
+ {userAgent: 'SkypeUriPreview', expected: true},
8
+ {userAgent: 'skypeuripreview', expected: true},
9
+ {userAgent: 'Mozilla/5.0 (compatible; SkypeUriPreview/0.1)', expected: true},
10
+ {userAgent: 'Googlebot/2.1 (+http://www.google.com/bot.html)', expected: true},
11
+ {
12
+ userAgent:
13
+ 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 Chrome/126.0.0.0 Safari/537.36',
14
+ expected: false,
15
+ },
16
+ {userAgent: undefined, expected: false},
17
+ ].forEach(({userAgent, expected}) => {
18
+ it(`returns ${expected} for ${userAgent || 'an undefined user agent'}`, () => {
19
+ assert.equal(isAutomatedUserAgent(userAgent), expected);
20
+ });
21
+ });
22
+
23
+ it('returns the cached classification when navigator changes', () => {
24
+ const cachedResult = isAutomatedUser();
25
+ const originalDescriptor = Object.getOwnPropertyDescriptor(global, 'navigator');
26
+
27
+ Object.defineProperty(global, 'navigator', {
28
+ value: cachedResult
29
+ ? {userAgent: 'Mozilla/5.0', webdriver: false}
30
+ : {userAgent: 'SkypeUriPreview', webdriver: true},
31
+ configurable: true,
32
+ writable: true,
33
+ });
34
+
35
+ assert.equal(isAutomatedUser(), cachedResult);
36
+
37
+ if (originalDescriptor) {
38
+ Object.defineProperty(global, 'navigator', originalDescriptor);
39
+ } else {
40
+ delete (global as any).navigator;
41
+ }
42
+ });
43
+ });
@@ -516,141 +516,5 @@ describe('plugin-metrics', () => {
516
516
  assert.deepEqual(prepareDiagnosticMetricItemCalls[0].args[1].type, ['diagnostic-event']);
517
517
  });
518
518
  });
519
-
520
- describe('#submitHttpRequest', () => {
521
- it('calls handleHttpResponseStatus with response status on success', async () => {
522
- const payload = [
523
- {
524
- eventPayload: {event: 'my.event'},
525
- type: ['diagnostic-event'],
526
- },
527
- ];
528
-
529
- webex.request = sinon.stub().resolves({statusCode: 200});
530
-
531
- const handleHttpResponseStatusSpy = sinon.spy(
532
- webex.internal.newMetrics.callDiagnosticMetrics.callDiagnosticEventsBatcher,
533
- 'handleHttpResponseStatus'
534
- );
535
-
536
- const promise =
537
- webex.internal.newMetrics.callDiagnosticMetrics.callDiagnosticEventsBatcher.submitHttpRequest(
538
- payload
539
- );
540
-
541
- assert.deepEqual(handleHttpResponseStatusSpy.getCalls().length, 0);
542
-
543
- await flushPromises();
544
- clock.tick(config.metrics.batcherWait);
545
-
546
- await promise;
547
-
548
- assert.calledOnce(webex.request);
549
- assert.deepEqual(handleHttpResponseStatusSpy.getCalls().length, 1);
550
- assert.deepEqual(handleHttpResponseStatusSpy.args[0][0], 200);
551
- assert.deepEqual(handleHttpResponseStatusSpy.args[0][1], payload);
552
- });
553
-
554
- it('calls handleHttpResponseStatus with error status on failure', async () => {
555
- const payload = [
556
- {
557
- eventPayload: {event: 'my.event'},
558
- type: ['diagnostic-event'],
559
- },
560
- ];
561
-
562
- webex.request = sinon.stub().rejects({statusCode: 503});
563
-
564
- const handleHttpResponseStatusSpy = sinon.spy(
565
- webex.internal.newMetrics.callDiagnosticMetrics.callDiagnosticEventsBatcher,
566
- 'handleHttpResponseStatus'
567
- );
568
-
569
- const promise =
570
- webex.internal.newMetrics.callDiagnosticMetrics.callDiagnosticEventsBatcher.submitHttpRequest(
571
- payload
572
- );
573
-
574
- assert.deepEqual(handleHttpResponseStatusSpy.getCalls().length, 0);
575
-
576
- await flushPromises();
577
- clock.tick(config.metrics.batcherWait);
578
-
579
- let error: any;
580
-
581
- try {
582
- await promise;
583
- } catch (err) {
584
- error = err;
585
- }
586
-
587
- assert.deepEqual(error.statusCode, 503);
588
- assert.calledOnce(webex.request);
589
- assert.deepEqual(handleHttpResponseStatusSpy.getCalls().length, 1);
590
- assert.deepEqual(handleHttpResponseStatusSpy.args[0][0], 503);
591
- assert.deepEqual(handleHttpResponseStatusSpy.args[0][1], payload);
592
- });
593
- });
594
-
595
- describe('#handleHttpResponseStatus', () => {
596
- let setIsTelemetryOptOutAutomaticStub;
597
-
598
- beforeEach(() => {
599
- setIsTelemetryOptOutAutomaticStub = sinon.stub(
600
- webex.internal.newMetrics.callDiagnosticMetrics,
601
- 'setIsTelemetryOptOutAutomatic'
602
- );
603
- });
604
-
605
- [201, 400, 503, undefined].forEach((statusCode) => {
606
- it(`does not call setIsTelemetryOptOutAutomatic() when statusCode is ${statusCode} and markTelemetryOptOutOnResponse is true`, () => {
607
- webex.internal.newMetrics.callDiagnosticMetrics.callDiagnosticEventsBatcher.handleHttpResponseStatus(
608
- statusCode,
609
- [{markTelemetryOptOutOnResponse: true}]
610
- );
611
-
612
- assert.notCalled(setIsTelemetryOptOutAutomaticStub);
613
- });
614
- });
615
-
616
- it('calls setIsTelemetryOptOutAutomatic(true) when statusCode is 200 and markTelemetryOptOutOnResponse is true', () => {
617
- webex.internal.newMetrics.callDiagnosticMetrics.callDiagnosticEventsBatcher.handleHttpResponseStatus(
618
- 200,
619
- [{markTelemetryOptOutOnResponse: true}]
620
- );
621
-
622
- assert.calledOnce(setIsTelemetryOptOutAutomaticStub);
623
- assert.calledWithExactly(setIsTelemetryOptOutAutomaticStub, true);
624
- });
625
-
626
- [200, 201, 400, 503, undefined].forEach((statusCode) => {
627
- it(`does not call setIsTelemetryOptOutAutomatic when shouldMark is false (statusCode: ${statusCode})`, () => {
628
- webex.internal.newMetrics.callDiagnosticMetrics.callDiagnosticEventsBatcher.handleHttpResponseStatus(
629
- statusCode,
630
- [{markTelemetryOptOutOnResponse: false}]
631
- );
632
-
633
- assert.notCalled(setIsTelemetryOptOutAutomaticStub);
634
- });
635
- });
636
-
637
- it('does not call setIsTelemetryOptOutAutomatic when payload is empty', () => {
638
- webex.internal.newMetrics.callDiagnosticMetrics.callDiagnosticEventsBatcher.handleHttpResponseStatus(
639
- 200,
640
- []
641
- );
642
-
643
- assert.notCalled(setIsTelemetryOptOutAutomaticStub);
644
- });
645
-
646
- it('does not call setIsTelemetryOptOutAutomatic when payload is not an array', () => {
647
- webex.internal.newMetrics.callDiagnosticMetrics.callDiagnosticEventsBatcher.handleHttpResponseStatus(
648
- 200,
649
- null
650
- );
651
-
652
- assert.notCalled(setIsTelemetryOptOutAutomaticStub);
653
- });
654
- });
655
519
  });
656
520
  });