@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
@@ -9,6 +9,7 @@ import {
9
9
  CallDiagnosticMetrics,
10
10
  getOSNameInternal,
11
11
  CallDiagnosticUtils,
12
+ AutomatedUserUtils,
12
13
  config,
13
14
  } from '@webex/internal-plugin-metrics';
14
15
  import uuid from 'uuid';
@@ -34,6 +35,7 @@ describe('internal-plugin-metrics', () => {
34
35
  var now = new Date();
35
36
 
36
37
  let cd: CallDiagnosticMetrics;
38
+ let isAutomatedUserStub: sinon.SinonStub;
37
39
 
38
40
  const fakeMeeting = {
39
41
  id: '1',
@@ -155,6 +157,7 @@ describe('internal-plugin-metrics', () => {
155
157
  sinon.useFakeTimers(now.getTime());
156
158
  cd = new CallDiagnosticMetrics({}, {parent: webex});
157
159
  sinon.stub(uuid, 'v4').returns('my-fake-id');
160
+ isAutomatedUserStub = sinon.stub(AutomatedUserUtils, 'isAutomatedUser').returns(false);
158
161
  cd.setDeviceInfo(webex.internal.device);
159
162
  });
160
163
 
@@ -868,6 +871,7 @@ describe('internal-plugin-metrics', () => {
868
871
  identifiers: {correlationId: 'test-id'},
869
872
  name: 'client.alert.displayed',
870
873
  isAutomatedUser: false,
874
+ userActivation: undefined,
871
875
  },
872
876
  options
873
877
  );
@@ -889,6 +893,7 @@ describe('internal-plugin-metrics', () => {
889
893
  identifiers: {correlationId: 'test-id'},
890
894
  name: 'client.alert.displayed',
891
895
  isAutomatedUser: false,
896
+ userActivation: undefined,
892
897
  },
893
898
  options
894
899
  );
@@ -898,14 +903,8 @@ describe('internal-plugin-metrics', () => {
898
903
  assert.isBoolean(res.event.isAutomatedUser, 'isAutomatedUser should be a boolean');
899
904
  });
900
905
 
901
- it('should set isAutomatedUser to true when navigator.webdriver is true', () => {
902
- const originalDescriptor = Object.getOwnPropertyDescriptor(global, 'navigator');
903
- Object.defineProperty(global, 'navigator', {
904
- value: {webdriver: true},
905
- configurable: true,
906
- writable: true,
907
- });
908
-
906
+ it('should set isAutomatedUser to true when the user is automated', () => {
907
+ isAutomatedUserStub.returns(true);
909
908
  const prepareDiagnosticEventSpy = sinon.spy(cd, 'prepareDiagnosticEvent');
910
909
  sinon.stub(cd, 'getOrigin').returns({origin: 'fake-origin'});
911
910
  cd.setMercuryConnectedStatus(true);
@@ -917,15 +916,45 @@ describe('internal-plugin-metrics', () => {
917
916
 
918
917
  assert.isTrue(
919
918
  prepareDiagnosticEventSpy.firstCall.args[0].isAutomatedUser,
920
- 'isAutomatedUser should be true when navigator.webdriver is set'
919
+ 'isAutomatedUser should be true for an automated user'
921
920
  );
921
+ });
922
+ });
922
923
 
924
+ describe('#getUserActivation', () => {
925
+ let originalDescriptor;
926
+
927
+ beforeEach(() => {
928
+ originalDescriptor = Object.getOwnPropertyDescriptor(global, 'navigator');
929
+ });
930
+
931
+ afterEach(() => {
923
932
  if (originalDescriptor) {
924
933
  Object.defineProperty(global, 'navigator', originalDescriptor);
925
934
  } else {
926
935
  delete (global as any).navigator;
927
936
  }
928
937
  });
938
+
939
+ it('should return the userActivation state when navigator.userActivation is available', () => {
940
+ Object.defineProperty(global, 'navigator', {
941
+ value: {userActivation: {hasBeenActive: true, isActive: false}},
942
+ configurable: true,
943
+ writable: true,
944
+ });
945
+
946
+ assert.deepEqual(cd.getUserActivation(), {hasBeenActive: true, isActive: false});
947
+ });
948
+
949
+ it('should return undefined when navigator.userActivation is not available', () => {
950
+ Object.defineProperty(global, 'navigator', {
951
+ value: {},
952
+ configurable: true,
953
+ writable: true,
954
+ });
955
+
956
+ assert.isUndefined(cd.getUserActivation());
957
+ });
929
958
  });
930
959
 
931
960
  describe('#submitClientEvent', () => {
@@ -986,6 +1015,7 @@ describe('internal-plugin-metrics', () => {
986
1015
  webClientPreload: undefined,
987
1016
  isVipMeeting: false,
988
1017
  isAutomatedUser: false,
1018
+ userActivation: undefined,
989
1019
  },
990
1020
  options
991
1021
  );
@@ -1017,6 +1047,7 @@ describe('internal-plugin-metrics', () => {
1017
1047
  webClientPreload: undefined,
1018
1048
  isVipMeeting: false,
1019
1049
  isAutomatedUser: false,
1050
+ userActivation: undefined,
1020
1051
  },
1021
1052
  eventId: 'my-fake-id',
1022
1053
  origin: {
@@ -1059,6 +1090,7 @@ describe('internal-plugin-metrics', () => {
1059
1090
  webClientPreload: undefined,
1060
1091
  isVipMeeting: false,
1061
1092
  isAutomatedUser: false,
1093
+ userActivation: undefined,
1062
1094
  },
1063
1095
  eventId: 'my-fake-id',
1064
1096
  origin: {
@@ -1137,6 +1169,7 @@ describe('internal-plugin-metrics', () => {
1137
1169
  webClientPreload: undefined,
1138
1170
  isVipMeeting: false,
1139
1171
  isAutomatedUser: false,
1172
+ userActivation: undefined,
1140
1173
  },
1141
1174
  options
1142
1175
  );
@@ -1168,6 +1201,7 @@ describe('internal-plugin-metrics', () => {
1168
1201
  webClientPreload: undefined,
1169
1202
  isVipMeeting: false,
1170
1203
  isAutomatedUser: false,
1204
+ userActivation: undefined,
1171
1205
  },
1172
1206
  eventId: 'my-fake-id',
1173
1207
  origin: {
@@ -1210,6 +1244,7 @@ describe('internal-plugin-metrics', () => {
1210
1244
  webClientPreload: undefined,
1211
1245
  isVipMeeting: false,
1212
1246
  isAutomatedUser: false,
1247
+ userActivation: undefined,
1213
1248
  },
1214
1249
  eventId: 'my-fake-id',
1215
1250
  origin: {
@@ -1289,6 +1324,7 @@ describe('internal-plugin-metrics', () => {
1289
1324
  webClientPreload: undefined,
1290
1325
  isVipMeeting: false,
1291
1326
  isAutomatedUser: false,
1327
+ userActivation: undefined,
1292
1328
  },
1293
1329
  options
1294
1330
  );
@@ -1321,6 +1357,7 @@ describe('internal-plugin-metrics', () => {
1321
1357
  webClientPreload: undefined,
1322
1358
  isVipMeeting: false,
1323
1359
  isAutomatedUser: false,
1360
+ userActivation: undefined,
1324
1361
  },
1325
1362
  eventId: 'my-fake-id',
1326
1363
  origin: {
@@ -1364,6 +1401,7 @@ describe('internal-plugin-metrics', () => {
1364
1401
  webClientPreload: undefined,
1365
1402
  isVipMeeting: false,
1366
1403
  isAutomatedUser: false,
1404
+ userActivation: undefined,
1367
1405
  },
1368
1406
  eventId: 'my-fake-id',
1369
1407
  origin: {
@@ -1442,6 +1480,7 @@ describe('internal-plugin-metrics', () => {
1442
1480
  webexSubServiceType: undefined,
1443
1481
  isVipMeeting: false,
1444
1482
  isAutomatedUser: false,
1483
+ userActivation: undefined,
1445
1484
  },
1446
1485
  options
1447
1486
  );
@@ -1474,6 +1513,7 @@ describe('internal-plugin-metrics', () => {
1474
1513
  webexSubServiceType: undefined,
1475
1514
  isVipMeeting: false,
1476
1515
  isAutomatedUser: false,
1516
+ userActivation: undefined,
1477
1517
  },
1478
1518
  eventId: 'my-fake-id',
1479
1519
  origin: {
@@ -1517,6 +1557,7 @@ describe('internal-plugin-metrics', () => {
1517
1557
  webexSubServiceType: undefined,
1518
1558
  isVipMeeting: false,
1519
1559
  isAutomatedUser: false,
1560
+ userActivation: undefined,
1520
1561
  },
1521
1562
  eventId: 'my-fake-id',
1522
1563
  origin: {
@@ -1597,6 +1638,7 @@ describe('internal-plugin-metrics', () => {
1597
1638
  webClientPreload: undefined,
1598
1639
  isVipMeeting: false,
1599
1640
  isAutomatedUser: false,
1641
+ userActivation: undefined,
1600
1642
  },
1601
1643
  options
1602
1644
  );
@@ -1631,6 +1673,7 @@ describe('internal-plugin-metrics', () => {
1631
1673
  webClientPreload: undefined,
1632
1674
  isVipMeeting: false,
1633
1675
  isAutomatedUser: false,
1676
+ userActivation: undefined,
1634
1677
  },
1635
1678
  eventId: 'my-fake-id',
1636
1679
  origin: {
@@ -1676,6 +1719,7 @@ describe('internal-plugin-metrics', () => {
1676
1719
  webClientPreload: undefined,
1677
1720
  isVipMeeting: false,
1678
1721
  isAutomatedUser: false,
1722
+ userActivation: undefined,
1679
1723
  },
1680
1724
  eventId: 'my-fake-id',
1681
1725
  origin: {
@@ -1804,6 +1848,7 @@ describe('internal-plugin-metrics', () => {
1804
1848
  name: 'client.alert.displayed',
1805
1849
  webClientPreload: undefined,
1806
1850
  isAutomatedUser: false,
1851
+ userActivation: undefined,
1807
1852
  },
1808
1853
  options
1809
1854
  );
@@ -1829,6 +1874,7 @@ describe('internal-plugin-metrics', () => {
1829
1874
  name: 'client.alert.displayed',
1830
1875
  webClientPreload: undefined,
1831
1876
  isAutomatedUser: false,
1877
+ userActivation: undefined,
1832
1878
  },
1833
1879
  eventId: 'my-fake-id',
1834
1880
  origin: {
@@ -1906,6 +1952,7 @@ describe('internal-plugin-metrics', () => {
1906
1952
  name: 'client.alert.displayed',
1907
1953
  webClientPreload: undefined,
1908
1954
  isAutomatedUser: false,
1955
+ userActivation: undefined,
1909
1956
  },
1910
1957
  options
1911
1958
  );
@@ -1936,6 +1983,7 @@ describe('internal-plugin-metrics', () => {
1936
1983
  telemetryOptOut: undefined,
1937
1984
  webClientPreload: undefined,
1938
1985
  isAutomatedUser: false,
1986
+ userActivation: undefined,
1939
1987
  },
1940
1988
  },
1941
1989
  options.preLoginId
@@ -2001,6 +2049,7 @@ describe('internal-plugin-metrics', () => {
2001
2049
  name: 'client.alert.displayed',
2002
2050
  webClientPreload: undefined,
2003
2051
  isAutomatedUser: false,
2052
+ userActivation: undefined,
2004
2053
  },
2005
2054
  options
2006
2055
  );
@@ -2033,6 +2082,7 @@ describe('internal-plugin-metrics', () => {
2033
2082
  emailInput: 'current',
2034
2083
  webClientPreload: undefined,
2035
2084
  isAutomatedUser: false,
2085
+ userActivation: undefined,
2036
2086
  },
2037
2087
  },
2038
2088
  options.preLoginId
@@ -2081,6 +2131,7 @@ describe('internal-plugin-metrics', () => {
2081
2131
  webClientPreload: undefined,
2082
2132
  isVipMeeting: false,
2083
2133
  isAutomatedUser: false,
2134
+ userActivation: undefined,
2084
2135
  },
2085
2136
  eventId: 'my-fake-id',
2086
2137
  origin: {
@@ -2139,6 +2190,7 @@ describe('internal-plugin-metrics', () => {
2139
2190
  webClientPreload: undefined,
2140
2191
  isVipMeeting: false,
2141
2192
  isAutomatedUser: false,
2193
+ userActivation: undefined,
2142
2194
  },
2143
2195
  eventId: 'my-fake-id',
2144
2196
  origin: {
@@ -2197,6 +2249,7 @@ describe('internal-plugin-metrics', () => {
2197
2249
  name: 'client.alert.displayed',
2198
2250
  webClientPreload: true,
2199
2251
  isAutomatedUser: false,
2252
+ userActivation: undefined,
2200
2253
  },
2201
2254
  options
2202
2255
  );
@@ -2222,6 +2275,7 @@ describe('internal-plugin-metrics', () => {
2222
2275
  name: 'client.alert.displayed',
2223
2276
  webClientPreload: true,
2224
2277
  isAutomatedUser: false,
2278
+ userActivation: undefined,
2225
2279
  },
2226
2280
  eventId: 'my-fake-id',
2227
2281
  origin: {
@@ -2293,6 +2347,7 @@ describe('internal-plugin-metrics', () => {
2293
2347
  webClientPreload: undefined,
2294
2348
  isVipMeeting: false,
2295
2349
  isAutomatedUser: false,
2350
+ userActivation: undefined,
2296
2351
  },
2297
2352
  options
2298
2353
  );
@@ -2325,6 +2380,7 @@ describe('internal-plugin-metrics', () => {
2325
2380
  webClientPreload: undefined,
2326
2381
  isVipMeeting: false,
2327
2382
  isAutomatedUser: false,
2383
+ userActivation: undefined,
2328
2384
  },
2329
2385
  eventId: 'my-fake-id',
2330
2386
  origin: {
@@ -2396,6 +2452,7 @@ describe('internal-plugin-metrics', () => {
2396
2452
  webClientPreload: undefined,
2397
2453
  isVipMeeting: true,
2398
2454
  isAutomatedUser: false,
2455
+ userActivation: undefined,
2399
2456
  },
2400
2457
  options
2401
2458
  );
@@ -2428,6 +2485,7 @@ describe('internal-plugin-metrics', () => {
2428
2485
  webClientPreload: undefined,
2429
2486
  isVipMeeting: true,
2430
2487
  isAutomatedUser: false,
2488
+ userActivation: undefined,
2431
2489
  },
2432
2490
  eventId: 'my-fake-id',
2433
2491
  origin: {
@@ -2505,6 +2563,7 @@ describe('internal-plugin-metrics', () => {
2505
2563
  webClientPreload: undefined,
2506
2564
  isVipMeeting: false,
2507
2565
  isAutomatedUser: false,
2566
+ userActivation: undefined,
2508
2567
  },
2509
2568
  eventId: 'my-fake-id',
2510
2569
  origin: {
@@ -2590,6 +2649,7 @@ describe('internal-plugin-metrics', () => {
2590
2649
  webClientPreload: undefined,
2591
2650
  isVipMeeting: false,
2592
2651
  isAutomatedUser: false,
2652
+ userActivation: undefined,
2593
2653
  },
2594
2654
  eventId: 'my-fake-id',
2595
2655
  origin: {
@@ -2665,6 +2725,7 @@ describe('internal-plugin-metrics', () => {
2665
2725
  name: 'client.alert.displayed',
2666
2726
  webClientPreload: undefined,
2667
2727
  isAutomatedUser: false,
2728
+ userActivation: undefined,
2668
2729
  },
2669
2730
  eventId: 'my-fake-id',
2670
2731
  origin: {
@@ -2742,6 +2803,7 @@ describe('internal-plugin-metrics', () => {
2742
2803
  name: 'client.alert.displayed',
2743
2804
  webClientPreload: undefined,
2744
2805
  isAutomatedUser: false,
2806
+ userActivation: undefined,
2745
2807
  },
2746
2808
  eventId: 'my-fake-id',
2747
2809
  origin: {
@@ -2830,6 +2892,7 @@ describe('internal-plugin-metrics', () => {
2830
2892
  webClientPreload: undefined,
2831
2893
  isVipMeeting: false,
2832
2894
  isAutomatedUser: false,
2895
+ userActivation: undefined,
2833
2896
  },
2834
2897
  eventId: 'my-fake-id',
2835
2898
  origin: {
@@ -3122,7 +3185,6 @@ describe('internal-plugin-metrics', () => {
3122
3185
  assert.calledWith(requestStub, {
3123
3186
  eventPayload: {event: 'test'},
3124
3187
  type: ['diagnostic-event'],
3125
- markTelemetryOptOutOnResponse: true,
3126
3188
  });
3127
3189
  });
3128
3190
  });
@@ -4252,6 +4314,7 @@ describe('internal-plugin-metrics', () => {
4252
4314
  webClientPreload: undefined,
4253
4315
  isVipMeeting: false,
4254
4316
  isAutomatedUser: false,
4317
+ userActivation: undefined,
4255
4318
  },
4256
4319
  eventId: 'my-fake-id',
4257
4320
  origin: {
@@ -4422,7 +4485,6 @@ describe('internal-plugin-metrics', () => {
4422
4485
  assert.calledWith(requestStub, {
4423
4486
  eventPayload: {event: 'test'},
4424
4487
  type: ['diagnostic-event'],
4425
- markTelemetryOptOutOnResponse: true,
4426
4488
  });
4427
4489
  });
4428
4490
  });
@@ -4661,6 +4723,7 @@ describe('internal-plugin-metrics', () => {
4661
4723
  webClientPreload: undefined,
4662
4724
  isVipMeeting: false,
4663
4725
  isAutomatedUser: false,
4726
+ userActivation: undefined,
4664
4727
  meetingSummaryInfo: {
4665
4728
  featureName: 'syncSystemMuteStatus',
4666
4729
  featureActions: [
@@ -4705,6 +4768,7 @@ describe('internal-plugin-metrics', () => {
4705
4768
  webClientPreload: undefined,
4706
4769
  isVipMeeting: false,
4707
4770
  isAutomatedUser: false,
4771
+ userActivation: undefined,
4708
4772
  meetingSummaryInfo: {
4709
4773
  featureName: 'syncSystemMuteStatus',
4710
4774
  featureActions: [
@@ -1,8 +1,12 @@
1
1
  import {assert} from '@webex/test-helper-chai';
2
- import {NewMetrics, CallDiagnosticLatencies} from '@webex/internal-plugin-metrics';
2
+ import {
3
+ NewMetrics,
4
+ CallDiagnosticLatencies,
5
+ AutomatedUserUtils,
6
+ Utils,
7
+ } from '@webex/internal-plugin-metrics';
3
8
  import MockWebex from '@webex/test-helper-mock-webex';
4
9
  import sinon from 'sinon';
5
- import {Utils} from '@webex/internal-plugin-metrics';
6
10
 
7
11
  describe('internal-plugin-metrics', () => {
8
12
 
@@ -110,6 +114,13 @@ describe('internal-plugin-metrics', () => {
110
114
  assert.isDefined(webex.internal.newMetrics.businessMetrics);
111
115
  })
112
116
 
117
+ it('returns the automated user classification', () => {
118
+ assert.strictEqual(
119
+ webex.internal.newMetrics.isAutomatedUser(),
120
+ AutomatedUserUtils.isAutomatedUser()
121
+ );
122
+ });
123
+
113
124
  it('passes the table through to the business metrics', () => {
114
125
  assert.isUndefined(webex.internal.newMetrics.businessMetrics)
115
126
  webex.internal.newMetrics.isReadyToSubmitBusinessEvents();
@@ -94,7 +94,6 @@ describe('internal-plugin-metrics', () => {
94
94
  },
95
95
  });
96
96
  assert.deepEqual(webexRequestArgs.body.metrics[0].type, ['diagnostic-event']);
97
- assert.equal(webexRequestArgs.body.metrics[0].markTelemetryOptOutOnResponse, true);
98
97
  assert.lengthOf(
99
98
  webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher.queue,
100
99
  0
@@ -314,7 +313,7 @@ describe('internal-plugin-metrics', () => {
314
313
  });
315
314
 
316
315
  describe('#submitHttpRequest', () => {
317
- it('calls webex.request with the correct parameters and then it calls handleHttpResponseStatus on success', async () => {
316
+ it('calls webex.request with the correct parameters', async () => {
318
317
  const payload = [
319
318
  {
320
319
  eventPayload: {event: 'my.event'},
@@ -327,18 +326,11 @@ describe('internal-plugin-metrics', () => {
327
326
  );
328
327
  webex.request = sinon.stub().resolves({statusCode: 200});
329
328
 
330
- const handleHttpResponseStatusSpy = sinon.spy(
331
- webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher,
332
- 'handleHttpResponseStatus'
333
- );
334
-
335
329
  const promise =
336
330
  webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher.submitHttpRequest(
337
331
  payload
338
332
  );
339
333
 
340
- assert.deepEqual(handleHttpResponseStatusSpy.getCalls().length, 0);
341
-
342
334
  await flushPromises();
343
335
 
344
336
  clock.tick(config.metrics.batcherWait);
@@ -361,117 +353,6 @@ describe('internal-plugin-metrics', () => {
361
353
  service: 'metrics',
362
354
  waitForServiceTimeout: 30,
363
355
  });
364
-
365
- assert.deepEqual(handleHttpResponseStatusSpy.getCalls().length, 1);
366
-
367
- assert.deepEqual(handleHttpResponseStatusSpy.args[0][0], 200);
368
- assert.deepEqual(handleHttpResponseStatusSpy.args[0][1], payload);
369
- });
370
-
371
- it('it calls handleHttpResponseStatus on failure', async () => {
372
- const payload = [
373
- {
374
- eventPayload: {event: 'my.event'},
375
- type: ['diagnostic-event'],
376
- },
377
- ];
378
-
379
- webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher.savePreLoginId(
380
- preLoginId
381
- );
382
- webex.request = sinon.stub().rejects({statusCode: 503});
383
-
384
- const handleHttpResponseStatusSpy = sinon.spy(
385
- webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher,
386
- 'handleHttpResponseStatus'
387
- );
388
-
389
- const promise =
390
- webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher.submitHttpRequest(
391
- payload
392
- );
393
-
394
- assert.deepEqual(handleHttpResponseStatusSpy.getCalls().length, 0);
395
-
396
- await flushPromises();
397
-
398
- clock.tick(config.metrics.batcherWait);
399
-
400
- let error;
401
-
402
- try {
403
- await promise;
404
- } catch (err) {
405
- error = err;
406
- }
407
-
408
- assert.deepEqual(error.statusCode, 503);
409
-
410
- assert.deepEqual(handleHttpResponseStatusSpy.getCalls().length, 1);
411
-
412
- assert.deepEqual(handleHttpResponseStatusSpy.args[0][0], 503);
413
- assert.deepEqual(handleHttpResponseStatusSpy.args[0][1], payload);
414
- });
415
- })
416
-
417
- describe('#handleHttpResponseStatus', () => {
418
- let setIsTelemetryOptOutAutomaticStub;
419
-
420
- beforeEach(() => {
421
- setIsTelemetryOptOutAutomaticStub = sinon.stub(
422
- webex.internal.newMetrics.callDiagnosticMetrics,
423
- 'setIsTelemetryOptOutAutomatic'
424
- );
425
- });
426
-
427
- [201, 400, 503, undefined].forEach((statusCode) => {
428
- it(`does not call setIsTelemetryOptOutAutomatic when shouldMark is true and statusCode is ${statusCode}`, () => {
429
- webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher.handleHttpResponseStatus(
430
- statusCode,
431
- [{markTelemetryOptOutOnResponse: true}]
432
- );
433
-
434
- assert.notCalled(setIsTelemetryOptOutAutomaticStub);
435
- });
436
- });
437
-
438
- it('calls setIsTelemetryOptOutAutomatic(true) when statusCode is 200 and markTelemetryOptOutOnResponse is true', () => {
439
- webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher.handleHttpResponseStatus(
440
- 200,
441
- [{markTelemetryOptOutOnResponse: true}]
442
- );
443
-
444
- assert.calledOnce(setIsTelemetryOptOutAutomaticStub);
445
- assert.calledWithExactly(setIsTelemetryOptOutAutomaticStub, true);
446
- });
447
-
448
- [200, 201, 400, 503, undefined].forEach((statusCode) => {
449
- it(`does not call setIsTelemetryOptOutAutomatic when shouldMark is false (statusCode: ${statusCode})`, () => {
450
- webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher.handleHttpResponseStatus(
451
- statusCode,
452
- [{markTelemetryOptOutOnResponse: false}]
453
- );
454
-
455
- assert.notCalled(setIsTelemetryOptOutAutomaticStub);
456
- });
457
- });
458
-
459
- it('does not call setIsTelemetryOptOutAutomatic when payload is empty', () => {
460
- webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher.handleHttpResponseStatus(
461
- 200,
462
- []
463
- );
464
-
465
- assert.notCalled(setIsTelemetryOptOutAutomaticStub);
466
- });
467
-
468
- it('does not call setIsTelemetryOptOutAutomatic when payload is not an array', () => {
469
- webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher.handleHttpResponseStatus(
470
- 200,
471
- null
472
- );
473
-
474
- assert.notCalled(setIsTelemetryOptOutAutomaticStub);
475
356
  });
476
357
  });
477
358
  });