@webex/internal-plugin-metrics 3.11.0-next.2 → 3.11.0-next.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.
@@ -79,7 +79,7 @@ export default abstract class GenericMetrics extends StatelessWebexPlugin {
79
79
  device: {
80
80
  id: this.getDeviceId(),
81
81
  },
82
- locale: window.navigator.language,
82
+ locale: window?.navigator.language,
83
83
  os: {
84
84
  name: getOSNameInternal(),
85
85
  version: getOSVersion(),
@@ -94,12 +94,12 @@ export default abstract class GenericMetrics extends StatelessWebexPlugin {
94
94
  protected getBrowserDetails(): object {
95
95
  return {
96
96
  browser: getBrowserName(),
97
- browserHeight: window.innerHeight,
97
+ browserHeight: window?.innerHeight,
98
98
  browserVersion: getBrowserVersion(),
99
- browserWidth: window.innerWidth,
100
- domain: window.location.hostname,
101
- inIframe: window.self !== window.top,
102
- locale: window.navigator.language,
99
+ browserWidth: window?.innerWidth,
100
+ domain: window?.location.hostname,
101
+ inIframe: window?.self !== window?.top,
102
+ locale: window?.navigator.language,
103
103
  os: getOSNameInternal(),
104
104
  };
105
105
  }
package/src/index.ts CHANGED
@@ -28,6 +28,7 @@ import BehavioralMetrics from './behavioral-metrics';
28
28
  import OperationalMetrics from './operational-metrics';
29
29
  import BusinessMetrics from './business-metrics';
30
30
  import RtcMetrics from './rtcMetrics';
31
+ import PreLoginMetrics from './prelogin-metrics';
31
32
 
32
33
  registerInternalPlugin('metrics', Metrics, {
33
34
  config,
@@ -51,6 +52,7 @@ export {
51
52
  OperationalMetrics,
52
53
  BusinessMetrics,
53
54
  RtcMetrics,
55
+ PreLoginMetrics,
54
56
  };
55
57
  export type {
56
58
  ClientEvent,
@@ -197,7 +197,7 @@ export interface BusinessEventPayload {
197
197
  metricName: string;
198
198
  timestamp: number;
199
199
  context: DeviceContext;
200
- browserDetails: EventPayload;
200
+ browserDetails: object;
201
201
  value: EventPayload;
202
202
  }
203
203
 
@@ -9,6 +9,8 @@ import CallDiagnosticMetrics from './call-diagnostic/call-diagnostic-metrics';
9
9
  import BehavioralMetrics from './behavioral-metrics';
10
10
  import OperationalMetrics from './operational-metrics';
11
11
  import BusinessMetrics from './business-metrics';
12
+ import PreLoginMetrics from './prelogin-metrics';
13
+ import PreLoginMetricsBatcher from './prelogin-metrics-batcher';
12
14
  import {
13
15
  RecursivePartial,
14
16
  MetricEventProduct,
@@ -45,6 +47,7 @@ class Metrics extends WebexPlugin {
45
47
  behavioralMetrics: BehavioralMetrics;
46
48
  operationalMetrics: OperationalMetrics;
47
49
  businessMetrics: BusinessMetrics;
50
+ preLoginMetrics: PreLoginMetrics;
48
51
  isReady = false;
49
52
 
50
53
  /**
@@ -87,6 +90,13 @@ class Metrics extends WebexPlugin {
87
90
  this.webex.once('ready', () => {
88
91
  // @ts-ignore
89
92
  this.callDiagnosticMetrics = new CallDiagnosticMetrics({}, {parent: this.webex});
93
+ this.preLoginMetrics = new PreLoginMetrics(
94
+ // @ts-ignore
95
+ new PreLoginMetricsBatcher({}, {parent: this.webex}),
96
+ {},
97
+ // @ts-ignore
98
+ {parent: this.webex}
99
+ );
90
100
  this.isReady = true;
91
101
  this.setDelaySubmitClientEvents({
92
102
  shouldDelay: this.delaySubmitClientEvents,
@@ -251,6 +261,38 @@ class Metrics extends WebexPlugin {
251
261
  return this.businessMetrics.submitBusinessEvent({name, payload, table, metadata});
252
262
  }
253
263
 
264
+ /**
265
+ * Call Analyzer: Pre-Login Event
266
+ * @param args
267
+ */
268
+ submitPreLoginEvent({
269
+ name,
270
+ preLoginId,
271
+ payload,
272
+ metadata,
273
+ }: {
274
+ name: string;
275
+ preLoginId: string;
276
+ payload: EventPayload;
277
+ metadata?: EventPayload;
278
+ }): Promise<void> {
279
+ if (!this.isReady) {
280
+ // @ts-ignore
281
+ this.webex.logger.log(
282
+ `NewMetrics: @submitPreLoginEvent. Attempted to submit before webex.ready: ${name}`
283
+ );
284
+
285
+ return Promise.resolve();
286
+ }
287
+
288
+ return this.preLoginMetrics.submitPreLoginEvent({
289
+ name,
290
+ preLoginId,
291
+ payload,
292
+ metadata,
293
+ });
294
+ }
295
+
254
296
  /**
255
297
  * Call Analyzer: Media Quality Event
256
298
  * @param args
@@ -0,0 +1,94 @@
1
+ import GenericMetrics from './generic-metrics';
2
+ import {BusinessEvent, EventPayload} from './metrics.types';
3
+ import PreLoginMetricsBatcher from './prelogin-metrics-batcher';
4
+
5
+ /**
6
+ * @description Util class to handle PreLogin Metrics
7
+ * @export
8
+ * @class PreLoginMetrics
9
+ */
10
+ export default class PreLoginMetrics extends GenericMetrics {
11
+ private preLoginMetricsBatcher: typeof PreLoginMetricsBatcher;
12
+
13
+ /**
14
+ * Constructor
15
+ * @param {PreLoginMetricsBatcher} preLoginMetricsBatcher - Pre-login metrics batcher
16
+ * @param {any} attrs - Attributes
17
+ * @param {any} options - Options
18
+ * @constructor
19
+ */
20
+ constructor(
21
+ preLoginMetricsBatcher: typeof PreLoginMetricsBatcher,
22
+ attrs: any = {},
23
+ options: {parent?: any} = {}
24
+ ) {
25
+ super(attrs, options);
26
+ this.preLoginMetricsBatcher = preLoginMetricsBatcher;
27
+ }
28
+
29
+ /**
30
+ * Submit a business metric to our metrics endpoint.
31
+ * Routes to the correct table with the correct schema payload by table.
32
+ * @see https://confluence-eng-gpk2.cisco.com/conf/display/WAP/Business+metrics++-%3E+ROMA
33
+ * @param {Object} options - The options object
34
+ * @param {string} options.name - Name of the metric
35
+ * @param {string} options.preLoginId - ID to identify pre-login user
36
+ * @param {EventPayload} options.payload - User payload of the metric
37
+ * @param {EventPayload} [options.metadata] - Optional metadata to include outside of eventPayload.value
38
+ * @returns {Promise<void>} Promise that resolves when the metric is submitted
39
+ */
40
+ public submitPreLoginEvent({
41
+ name,
42
+ preLoginId,
43
+ payload,
44
+ metadata,
45
+ }: {
46
+ name: string;
47
+ preLoginId: string;
48
+ payload: EventPayload;
49
+ metadata?: EventPayload;
50
+ }): Promise<void> {
51
+ if (!metadata) {
52
+ metadata = {};
53
+ }
54
+ if (!metadata.appType) {
55
+ metadata.appType = 'Web Client';
56
+ }
57
+
58
+ const finalEvent = this.buildEvent(name, preLoginId, payload, metadata);
59
+
60
+ this.preLoginMetricsBatcher.savePreLoginId(preLoginId);
61
+
62
+ return this.preLoginMetricsBatcher.request(finalEvent);
63
+ }
64
+
65
+ /**
66
+ * Builds a formatted event object for metrics submission.
67
+ * @param {string} metricName - Metric name
68
+ * @param {string} preLoginId - Pre-login user identifier
69
+ * @param {EventPayload} payload - Metric payload data
70
+ * @param {EventPayload} metadata - Additional metadata to include in the event
71
+ * @returns {object} Formatted metrics event object with type, eventPayload, and timestamp
72
+ */
73
+ private buildEvent(
74
+ metricName: string,
75
+ preLoginId: string,
76
+ payload: EventPayload,
77
+ metadata: EventPayload
78
+ ): BusinessEvent {
79
+ return {
80
+ type: ['business'],
81
+ eventPayload: {
82
+ metricName,
83
+ browserDetails: this.getBrowserDetails(),
84
+ context: this.getContext(),
85
+ timestamp: new Date().getTime(),
86
+ value: {
87
+ preLoginId,
88
+ ...metadata,
89
+ ...payload,
90
+ },
91
+ },
92
+ };
93
+ }
94
+ }
@@ -44,6 +44,7 @@ describe('internal-plugin-metrics', () => {
44
44
  locusInfo: {
45
45
  fullState: {
46
46
  lastActive: 'lastActive',
47
+ sessionId: 'locusSessionId',
47
48
  },
48
49
  },
49
50
  meetingInfo: {},
@@ -431,6 +432,7 @@ describe('internal-plugin-metrics', () => {
431
432
  correlationId: 'correlationId',
432
433
  deviceId: 'deviceUrl',
433
434
  locusId: 'url',
435
+ locusSessionId: 'locusSessionId',
434
436
  locusStartTime: 'lastActive',
435
437
  locusUrl: 'locus/url',
436
438
  machineId: 'installationId',
@@ -460,6 +462,7 @@ describe('internal-plugin-metrics', () => {
460
462
  correlationId: 'correlationId',
461
463
  deviceId: 'deviceUrl',
462
464
  locusId: 'url',
465
+ locusSessionId: 'locusSessionId',
463
466
  locusStartTime: 'lastActive',
464
467
  locusUrl: 'locus/url',
465
468
  machineId: 'installationId',
@@ -490,6 +493,7 @@ describe('internal-plugin-metrics', () => {
490
493
  sessionCorrelationId: 'sessionCorrelationId',
491
494
  deviceId: 'deviceUrl',
492
495
  locusId: 'url',
496
+ locusSessionId: 'locusSessionId',
493
497
  locusStartTime: 'lastActive',
494
498
  locusUrl: 'locus/url',
495
499
  machineId: 'installationId',
@@ -519,6 +523,7 @@ describe('internal-plugin-metrics', () => {
519
523
  sessionCorrelationId: 'sessionCorrelationId',
520
524
  deviceId: 'deviceUrl',
521
525
  locusId: 'url',
526
+ locusSessionId: 'locusSessionId',
522
527
  locusStartTime: 'lastActive',
523
528
  locusUrl: 'locus/url',
524
529
  machineId: 'installationId',
@@ -554,6 +559,7 @@ describe('internal-plugin-metrics', () => {
554
559
  globalMeetingId: 'globalMeetingId1',
555
560
  deviceId: 'deviceUrl',
556
561
  locusId: 'url',
562
+ locusSessionId: 'locusSessionId',
557
563
  locusStartTime: 'lastActive',
558
564
  locusUrl: 'locus/url',
559
565
  mediaAgentAlias: 'mediaAgentAlias',
@@ -586,6 +592,7 @@ describe('internal-plugin-metrics', () => {
586
592
  globalMeetingId: 'globalMeetingId1',
587
593
  deviceId: 'deviceUrl',
588
594
  locusId: 'url',
595
+ locusSessionId: 'locusSessionId',
589
596
  locusStartTime: 'lastActive',
590
597
  locusUrl: 'locus/url',
591
598
  mediaAgentAlias: 'mediaAgentAlias',
@@ -620,6 +627,7 @@ describe('internal-plugin-metrics', () => {
620
627
  deviceId: 'deviceUrl',
621
628
  locusId: 'url',
622
629
  locusStartTime: 'lastActive',
630
+ locusSessionId: 'locusSessionId',
623
631
  locusUrl: 'locus/url',
624
632
  mediaAgentAlias: 'mediaAgentAlias',
625
633
  mediaAgentGroupId: 'mediaAgentGroupId',
@@ -655,6 +663,7 @@ describe('internal-plugin-metrics', () => {
655
663
  globalMeetingId: 'globalMeetingId1',
656
664
  deviceId: 'deviceUrl',
657
665
  locusId: 'url',
666
+ locusSessionId: 'locusSessionId',
658
667
  locusStartTime: 'lastActive',
659
668
  locusUrl: 'locus/url',
660
669
  mediaAgentAlias: 'mediaAgentAlias',
@@ -889,6 +898,7 @@ describe('internal-plugin-metrics', () => {
889
898
  correlationId: 'correlationId',
890
899
  deviceId: 'deviceUrl',
891
900
  locusId: 'url',
901
+ locusSessionId: 'locusSessionId',
892
902
  locusStartTime: 'lastActive',
893
903
  locusUrl: 'locus/url',
894
904
  mediaAgentAlias: 'alias',
@@ -916,6 +926,7 @@ describe('internal-plugin-metrics', () => {
916
926
  correlationId: 'correlationId',
917
927
  deviceId: 'deviceUrl',
918
928
  locusId: 'url',
929
+ locusSessionId: 'locusSessionId',
919
930
  locusStartTime: 'lastActive',
920
931
  locusUrl: 'locus/url',
921
932
  mediaAgentAlias: 'alias',
@@ -954,6 +965,7 @@ describe('internal-plugin-metrics', () => {
954
965
  correlationId: 'correlationId',
955
966
  deviceId: 'deviceUrl',
956
967
  locusId: 'url',
968
+ locusSessionId: 'locusSessionId',
957
969
  locusStartTime: 'lastActive',
958
970
  locusUrl: 'locus/url',
959
971
  mediaAgentAlias: 'alias',
@@ -1028,6 +1040,7 @@ describe('internal-plugin-metrics', () => {
1028
1040
  correlationId: 'correlationId',
1029
1041
  deviceId: 'deviceUrl',
1030
1042
  locusId: 'url',
1043
+ locusSessionId: 'locusSessionId',
1031
1044
  locusStartTime: 'lastActive',
1032
1045
  locusUrl: 'locus/url',
1033
1046
  mediaAgentAlias: 'alias',
@@ -1055,6 +1068,7 @@ describe('internal-plugin-metrics', () => {
1055
1068
  correlationId: 'correlationId',
1056
1069
  deviceId: 'deviceUrl',
1057
1070
  locusId: 'url',
1071
+ locusSessionId: 'locusSessionId',
1058
1072
  locusStartTime: 'lastActive',
1059
1073
  locusUrl: 'locus/url',
1060
1074
  mediaAgentAlias: 'alias',
@@ -1093,6 +1107,7 @@ describe('internal-plugin-metrics', () => {
1093
1107
  correlationId: 'correlationId',
1094
1108
  deviceId: 'deviceUrl',
1095
1109
  locusId: 'url',
1110
+ locusSessionId: 'locusSessionId',
1096
1111
  locusStartTime: 'lastActive',
1097
1112
  locusUrl: 'locus/url',
1098
1113
  mediaAgentAlias: 'alias',
@@ -1168,6 +1183,7 @@ describe('internal-plugin-metrics', () => {
1168
1183
  sessionCorrelationId: 'sessionCorrelationId3',
1169
1184
  deviceId: 'deviceUrl',
1170
1185
  locusId: 'url',
1186
+ locusSessionId: 'locusSessionId',
1171
1187
  locusStartTime: 'lastActive',
1172
1188
  locusUrl: 'locus/url',
1173
1189
  mediaAgentAlias: 'alias',
@@ -1196,6 +1212,7 @@ describe('internal-plugin-metrics', () => {
1196
1212
  sessionCorrelationId: 'sessionCorrelationId3',
1197
1213
  deviceId: 'deviceUrl',
1198
1214
  locusId: 'url',
1215
+ locusSessionId: 'locusSessionId',
1199
1216
  locusStartTime: 'lastActive',
1200
1217
  locusUrl: 'locus/url',
1201
1218
  mediaAgentAlias: 'alias',
@@ -1235,6 +1252,7 @@ describe('internal-plugin-metrics', () => {
1235
1252
  sessionCorrelationId: 'sessionCorrelationId3',
1236
1253
  deviceId: 'deviceUrl',
1237
1254
  locusId: 'url',
1255
+ locusSessionId: 'locusSessionId',
1238
1256
  locusStartTime: 'lastActive',
1239
1257
  locusUrl: 'locus/url',
1240
1258
  mediaAgentAlias: 'alias',
@@ -1309,6 +1327,7 @@ describe('internal-plugin-metrics', () => {
1309
1327
  correlationId: 'correlationId',
1310
1328
  deviceId: 'deviceUrl',
1311
1329
  locusId: 'url',
1330
+ locusSessionId: 'locusSessionId',
1312
1331
  locusStartTime: 'lastActive',
1313
1332
  locusUrl: 'locus/url',
1314
1333
  mediaAgentAlias: 'alias',
@@ -1337,6 +1356,7 @@ describe('internal-plugin-metrics', () => {
1337
1356
  correlationId: 'correlationId',
1338
1357
  deviceId: 'deviceUrl',
1339
1358
  locusId: 'url',
1359
+ locusSessionId: 'locusSessionId',
1340
1360
  locusStartTime: 'lastActive',
1341
1361
  locusUrl: 'locus/url',
1342
1362
  mediaAgentAlias: 'alias',
@@ -1376,6 +1396,7 @@ describe('internal-plugin-metrics', () => {
1376
1396
  correlationId: 'correlationId',
1377
1397
  deviceId: 'deviceUrl',
1378
1398
  locusId: 'url',
1399
+ locusSessionId: 'locusSessionId',
1379
1400
  locusStartTime: 'lastActive',
1380
1401
  locusUrl: 'locus/url',
1381
1402
  mediaAgentAlias: 'alias',
@@ -1450,6 +1471,7 @@ describe('internal-plugin-metrics', () => {
1450
1471
  sessionCorrelationId: 'sessionCorrelationId5',
1451
1472
  deviceId: 'deviceUrl',
1452
1473
  locusId: 'url',
1474
+ locusSessionId: 'locusSessionId',
1453
1475
  locusStartTime: 'lastActive',
1454
1476
  locusUrl: 'locus/url',
1455
1477
  mediaAgentAlias: 'alias',
@@ -1480,6 +1502,7 @@ describe('internal-plugin-metrics', () => {
1480
1502
  sessionCorrelationId: 'sessionCorrelationId5',
1481
1503
  deviceId: 'deviceUrl',
1482
1504
  locusId: 'url',
1505
+ locusSessionId: 'locusSessionId',
1483
1506
  locusStartTime: 'lastActive',
1484
1507
  locusUrl: 'locus/url',
1485
1508
  mediaAgentAlias: 'alias',
@@ -1521,6 +1544,7 @@ describe('internal-plugin-metrics', () => {
1521
1544
  sessionCorrelationId: 'sessionCorrelationId5',
1522
1545
  deviceId: 'deviceUrl',
1523
1546
  locusId: 'url',
1547
+ locusSessionId: 'locusSessionId',
1524
1548
  locusStartTime: 'lastActive',
1525
1549
  locusUrl: 'locus/url',
1526
1550
  mediaAgentAlias: 'alias',
@@ -1911,6 +1935,7 @@ describe('internal-plugin-metrics', () => {
1911
1935
  correlationId: 'correlationId2',
1912
1936
  deviceId: 'deviceUrl',
1913
1937
  locusId: 'url',
1938
+ locusSessionId: 'locusSessionId',
1914
1939
  locusStartTime: 'lastActive',
1915
1940
  locusUrl: 'locus/url',
1916
1941
  mediaAgentAlias: 'alias',
@@ -1965,6 +1990,7 @@ describe('internal-plugin-metrics', () => {
1965
1990
  sessionCorrelationId: 'sessionCorrelationId1',
1966
1991
  deviceId: 'deviceUrl',
1967
1992
  locusId: 'url',
1993
+ locusSessionId: 'locusSessionId',
1968
1994
  locusStartTime: 'lastActive',
1969
1995
  locusUrl: 'locus/url',
1970
1996
  mediaAgentAlias: 'alias',
@@ -2106,6 +2132,7 @@ describe('internal-plugin-metrics', () => {
2106
2132
  globalMeetingId: 'globalMeetingId1',
2107
2133
  deviceId: 'deviceUrl',
2108
2134
  locusId: 'url',
2135
+ locusSessionId: 'locusSessionId',
2109
2136
  locusStartTime: 'lastActive',
2110
2137
  locusUrl: 'locus/url',
2111
2138
  mediaAgentAlias: 'alias',
@@ -2184,6 +2211,7 @@ describe('internal-plugin-metrics', () => {
2184
2211
  correlationId: 'correlationId',
2185
2212
  deviceId: 'deviceUrl',
2186
2213
  locusId: 'url',
2214
+ locusSessionId: 'locusSessionId',
2187
2215
  locusStartTime: 'lastActive',
2188
2216
  locusUrl: 'locus/url',
2189
2217
  mediaAgentAlias: 'alias',
@@ -2423,6 +2451,7 @@ describe('internal-plugin-metrics', () => {
2423
2451
  correlationId: 'correlationId',
2424
2452
  deviceId: 'deviceUrl',
2425
2453
  locusId: 'url',
2454
+ locusSessionId: 'locusSessionId',
2426
2455
  locusStartTime: 'lastActive',
2427
2456
  locusUrl: 'locus/url',
2428
2457
  mediaAgentAlias: 'alias',
@@ -2784,6 +2813,7 @@ describe('internal-plugin-metrics', () => {
2784
2813
  orgId: 'orgId',
2785
2814
  locusUrl: 'locus/url',
2786
2815
  locusId: 'url',
2816
+ locusSessionId: 'locusSessionId',
2787
2817
  locusStartTime: 'lastActive',
2788
2818
  },
2789
2819
  eventData: {webClientDomain: 'whatever'},
@@ -2823,6 +2853,7 @@ describe('internal-plugin-metrics', () => {
2823
2853
  orgId: 'orgId',
2824
2854
  locusUrl: 'locus/url',
2825
2855
  locusId: 'url',
2856
+ locusSessionId: 'locusSessionId',
2826
2857
  locusStartTime: 'lastActive',
2827
2858
  },
2828
2859
  eventData: {webClientDomain: 'whatever'},
@@ -2860,6 +2891,7 @@ describe('internal-plugin-metrics', () => {
2860
2891
  orgId: 'orgId',
2861
2892
  locusUrl: 'locus/url',
2862
2893
  locusId: 'url',
2894
+ locusSessionId: 'locusSessionId',
2863
2895
  locusStartTime: 'lastActive',
2864
2896
  },
2865
2897
  eventData: {webClientDomain: 'whatever'},
@@ -3701,6 +3733,7 @@ describe('internal-plugin-metrics', () => {
3701
3733
  correlationId: 'correlationId',
3702
3734
  deviceId: 'deviceUrl',
3703
3735
  locusId: 'url',
3736
+ locusSessionId: 'locusSessionId',
3704
3737
  locusStartTime: 'lastActive',
3705
3738
  locusUrl: 'locus/url',
3706
3739
  orgId: 'orgId',
@@ -4104,6 +4137,7 @@ describe('internal-plugin-metrics', () => {
4104
4137
  orgId: 'orgId',
4105
4138
  locusUrl: 'locus/url',
4106
4139
  locusId: 'url',
4140
+ locusSessionId: 'locusSessionId',
4107
4141
  locusStartTime: 'lastActive',
4108
4142
  },
4109
4143
  eventData: { webClientDomain: 'whatever'},
@@ -4141,6 +4175,7 @@ describe('internal-plugin-metrics', () => {
4141
4175
  locusId: 'url',
4142
4176
  locusStartTime: 'lastActive',
4143
4177
  locusUrl: 'locus/url',
4178
+ locusSessionId: 'locusSessionId',
4144
4179
  orgId: 'orgId',
4145
4180
  userId: 'userId',
4146
4181
  },
@@ -0,0 +1,132 @@
1
+ import PreLoginMetricsBatcher from '../../../src/prelogin-metrics-batcher';
2
+ import {PreLoginMetrics} from '@webex/internal-plugin-metrics';
3
+ import {assert} from '@webex/test-helper-chai';
4
+ import MockWebex from '@webex/test-helper-mock-webex';
5
+ import sinon from 'sinon';
6
+
7
+ describe('internal-plugin-metrics', () => {
8
+ const mockedWebex: MockWebex = new MockWebex();
9
+ const fakedPreLoginMetricsBatcher: typeof PreLoginMetricsBatcher = new PreLoginMetricsBatcher({}, {parent: mockedWebex});
10
+
11
+ describe('prelogin-metrics', () => {
12
+ afterEach(() => {
13
+ sinon.restore();
14
+ });
15
+
16
+ it('Should send metrics to preloginMetricsBatcher', async () => {
17
+ const testEvent = 'test';
18
+ const testId = 'abc123';
19
+ const preLoginMetrics = new PreLoginMetrics(fakedPreLoginMetricsBatcher, {}, {parent: mockedWebex});
20
+
21
+ sinon.stub(fakedPreLoginMetricsBatcher, 'savePreLoginId');
22
+ const requestSpy = sinon.stub(fakedPreLoginMetricsBatcher, 'request');
23
+
24
+ await preLoginMetrics.submitPreLoginEvent({name: testEvent, preLoginId: testId, payload: {}});
25
+
26
+ assert.calledOnceWithMatch(requestSpy, {
27
+ type: ['business'],
28
+ eventPayload: {metricName: testEvent, value: {preLoginId: testId}},
29
+ });
30
+ });
31
+
32
+ it('Should send metadata to preloginMetricsBatcher', async () => {
33
+ const testEvent = 'test';
34
+ const testId = 'abc123';
35
+ const testMetadata = { 'testKey': 'test-value' };
36
+ const preLoginMetrics = new PreLoginMetrics(fakedPreLoginMetricsBatcher, {}, {parent: mockedWebex});
37
+
38
+ sinon.stub(fakedPreLoginMetricsBatcher, 'savePreLoginId');
39
+ const requestSpy = sinon.stub(fakedPreLoginMetricsBatcher, 'request');
40
+
41
+ await preLoginMetrics.submitPreLoginEvent({name: testEvent, preLoginId: testId, payload: {}, metadata: testMetadata});
42
+
43
+ assert.calledOnceWithMatch(requestSpy, {
44
+ type: ['business'],
45
+ eventPayload: {metricName: testEvent, value: {preLoginId: testId, ...testMetadata}},
46
+ });
47
+ });
48
+
49
+ it('Should send payload to preloginMetricsBatcher', async () => {
50
+ const testEvent = 'test';
51
+ const testId = 'abc123';
52
+ const testPayload = { 'testKey': 'test-value' };
53
+ const preLoginMetrics = new PreLoginMetrics(fakedPreLoginMetricsBatcher, {}, {parent: mockedWebex});
54
+
55
+ sinon.stub(fakedPreLoginMetricsBatcher, 'savePreLoginId');
56
+ const requestSpy = sinon.stub(fakedPreLoginMetricsBatcher, 'request');
57
+
58
+ await preLoginMetrics.submitPreLoginEvent({name: testEvent, preLoginId: testId, payload: testPayload});
59
+
60
+ assert.calledOnceWithMatch(requestSpy, {
61
+ type: ['business'],
62
+ eventPayload: {metricName: testEvent, value: {preLoginId: testId, ...testPayload}},
63
+ });
64
+ });
65
+
66
+ it('Should fill appType if not defined', async () => {
67
+ const testEvent = 'test';
68
+ const preLoginMetrics = new PreLoginMetrics(fakedPreLoginMetricsBatcher, {}, {parent: mockedWebex});
69
+
70
+ sinon.stub(fakedPreLoginMetricsBatcher, 'savePreLoginId');
71
+ const requestSpy = sinon.stub(fakedPreLoginMetricsBatcher, 'request');
72
+
73
+ await preLoginMetrics.submitPreLoginEvent({name: testEvent, preLoginId: 'abc123', payload: {}});
74
+
75
+ assert.calledOnceWithMatch(requestSpy, {
76
+ type: ['business'],
77
+ eventPayload: {metricName: testEvent, value: {appType: 'Web Client'}},
78
+ });
79
+ });
80
+
81
+ it('Should add browser details', async () => {
82
+ const testEvent = 'test';
83
+ const testBrowserDetails = { browser: 'Firefox', domain: 'test.example.com' };
84
+ const preLoginMetrics = new PreLoginMetrics(fakedPreLoginMetricsBatcher, {}, {parent: mockedWebex});
85
+
86
+ sinon.stub(preLoginMetrics, 'getBrowserDetails').returns(testBrowserDetails);
87
+ sinon.stub(fakedPreLoginMetricsBatcher, 'savePreLoginId');
88
+ const requestSpy = sinon.stub(fakedPreLoginMetricsBatcher, 'request');
89
+
90
+ await preLoginMetrics.submitPreLoginEvent({name: testEvent, preLoginId: 'abc123', payload: {}});
91
+
92
+ assert.calledOnceWithMatch(requestSpy, {
93
+ type: ['business'],
94
+ eventPayload: {browserDetails: testBrowserDetails, metricName: testEvent},
95
+ });
96
+ });
97
+
98
+ it('Should add context', async () => {
99
+ const testEvent = 'test';
100
+ const testContext = { device: { id: 'abc123' }};
101
+ const preLoginMetrics = new PreLoginMetrics(fakedPreLoginMetricsBatcher, {}, {parent: mockedWebex});
102
+
103
+ sinon.stub(preLoginMetrics, 'getContext').returns(testContext);
104
+ sinon.stub(fakedPreLoginMetricsBatcher, 'savePreLoginId');
105
+ const requestSpy = sinon.stub(fakedPreLoginMetricsBatcher, 'request');
106
+
107
+ await preLoginMetrics.submitPreLoginEvent({name: testEvent, preLoginId: 'abc123', payload: {}});
108
+
109
+ assert.calledOnceWithMatch(requestSpy, {
110
+ type: ['business'],
111
+ eventPayload: {context: testContext, metricName: testEvent},
112
+ });
113
+ });
114
+
115
+ it('Should add timestamp', async () => {
116
+ const testEvent = 'test';
117
+ const testTime = 1234;
118
+ const preLoginMetrics = new PreLoginMetrics(fakedPreLoginMetricsBatcher, {}, {parent: mockedWebex});
119
+
120
+ sinon.useFakeTimers(testTime);
121
+ sinon.stub(fakedPreLoginMetricsBatcher, 'savePreLoginId');
122
+ const requestSpy = sinon.stub(fakedPreLoginMetricsBatcher, 'request');
123
+
124
+ await preLoginMetrics.submitPreLoginEvent({name: testEvent, preLoginId: 'abc123', payload: {}});
125
+
126
+ assert.calledOnceWithMatch(requestSpy, {
127
+ type: ['business'],
128
+ eventPayload: {metricName: testEvent, timestamp: testTime},
129
+ });
130
+ });
131
+ });
132
+ });