@webex/internal-plugin-metrics 3.3.1-next.5 → 3.3.1-next.7

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.
@@ -0,0 +1,164 @@
1
+ import sinon from 'sinon';
2
+ import {assert} from '@webex/test-helper-chai';
3
+ import {BrowserDetection} from '@webex/common';
4
+ import {BehavioralMetrics, config, getOSNameInternal} from '@webex/internal-plugin-metrics';
5
+ import uuid from 'uuid';
6
+ import {merge} from 'lodash';
7
+
8
+ //@ts-ignore
9
+ global.window = {location: {hostname: 'whatever'}, navigator: {language: 'language'}};
10
+ process.env.NODE_ENV = 'test';
11
+
12
+ const {getOSVersion, getBrowserName, getBrowserVersion} = BrowserDetection();
13
+
14
+ describe('internal-plugin-metrics', () => {
15
+ describe('BehavioralMetrics', () => {
16
+ let webex;
17
+ let now;
18
+ let behavioralMetrics: BehavioralMetrics;
19
+
20
+ const tags = {key: 'val'};
21
+
22
+ beforeEach(() => {
23
+ now = new Date();
24
+
25
+ webex = {
26
+ canAuthorize: true,
27
+ version: 'webex-version',
28
+ internal: {
29
+ services: {
30
+ get: () => 'locus-url',
31
+ },
32
+ metrics: {
33
+ submitClientMetrics: sinon.stub(),
34
+ config: {...config.metrics},
35
+ },
36
+ newMetrics: {},
37
+ device: {
38
+ userId: 'userId',
39
+ url: 'https://wdm-intb.ciscospark.com/wdm/api/v1/devices/deviceId',
40
+ orgId: 'orgId',
41
+ },
42
+ },
43
+ meetings: {
44
+ config: {
45
+ metrics: {
46
+ clientType: 'TEAMS_CLIENT',
47
+ subClientType: 'WEB_APP',
48
+ clientName: 'Cantina',
49
+ },
50
+ },
51
+ geoHintInfo: {
52
+ clientAddress: '1.3.4.5',
53
+ countryCode: 'UK',
54
+ },
55
+ },
56
+ credentials: {
57
+ isUnverifiedGuest: false,
58
+ },
59
+ prepareFetchOptions: sinon.stub().callsFake((opts: any) => ({...opts, foo: 'bar'})),
60
+ request: sinon.stub().resolves({body: {}}),
61
+ logger: {
62
+ log: sinon.stub(),
63
+ error: sinon.stub(),
64
+ },
65
+ };
66
+
67
+ sinon.createSandbox();
68
+ sinon.useFakeTimers(now.getTime());
69
+ behavioralMetrics = new BehavioralMetrics({}, {parent: webex});
70
+ sinon.stub(uuid, 'v4').returns('my-fake-id');
71
+ });
72
+
73
+ afterEach(() => {
74
+ sinon.restore();
75
+ });
76
+
77
+ describe('#getContext', () => {
78
+ it('should build context correctly', () => {
79
+ const res = behavioralMetrics.getContext();
80
+
81
+ assert.deepEqual(res, {
82
+ app: {
83
+ version: 'webex-version',
84
+ },
85
+ device: {
86
+ id: 'deviceId',
87
+ },
88
+ locale: 'language',
89
+ os: {
90
+ name: getOSNameInternal(),
91
+ version: getOSVersion(),
92
+ },
93
+ });
94
+ });
95
+ });
96
+
97
+ describe('#getDefaultTags', () => {
98
+ it('should build tags correctly', () => {
99
+ const res = behavioralMetrics.getDefaultTags();
100
+
101
+ assert.deepEqual(res, {
102
+ browser: getBrowserName(),
103
+ browserHeight: window.innerHeight,
104
+ browserVersion: getBrowserVersion(),
105
+ browserWidth: window.innerWidth,
106
+ domain: window.location.hostname,
107
+ inIframe: false,
108
+ locale: window.navigator.language,
109
+ os: getOSNameInternal(),
110
+ });
111
+ });
112
+ });
113
+
114
+ describe('#isReadyToSubmitBehavioralEvents', () => {
115
+ it('should return true when we have a deviceId, false when deviceId is empty or undefined', async () => {
116
+ assert.equal(true, behavioralMetrics.isReadyToSubmitBehavioralEvents());
117
+
118
+ webex.internal.device.url = "";
119
+ assert.equal(false, behavioralMetrics.isReadyToSubmitBehavioralEvents());
120
+
121
+ delete webex.internal.device.url;
122
+ assert.equal(false, behavioralMetrics.isReadyToSubmitBehavioralEvents());
123
+ });
124
+ });
125
+
126
+ describe('#createEventObject', () => {
127
+ it('should build event object correctly', async () => {
128
+ const res = behavioralMetrics.createEventObject({
129
+ product: 'webex',
130
+ agent: 'user',
131
+ target: 'target',
132
+ verb: 'create',
133
+ payload: tags,
134
+ });
135
+
136
+ assert.deepEqual(res, {
137
+ context: {
138
+ app: {
139
+ version: 'webex-version',
140
+ },
141
+ device: {
142
+ id: 'deviceId',
143
+ },
144
+ locale: 'language',
145
+ os: {
146
+ name: getOSNameInternal(),
147
+ version: getOSVersion(),
148
+ },
149
+ },
150
+ metricName: 'webex.user.target.create',
151
+ tags: merge(tags, {
152
+ browser: getBrowserName(),
153
+ browserVersion: getBrowserVersion(),
154
+ domain: window.location.hostname,
155
+ locale: window.navigator.language,
156
+ os: getOSNameInternal(),
157
+ }),
158
+ timestamp: res.timestamp,
159
+ type: ['behavioral'],
160
+ });
161
+ });
162
+ });
163
+ });
164
+ });
@@ -7,6 +7,7 @@ import CallDiagnosticLatencies from '../../../../src/call-diagnostic/call-diagno
7
7
  import {
8
8
  DTLS_HANDSHAKE_FAILED_CLIENT_CODE,
9
9
  ICE_FAILED_WITHOUT_TURN_TLS_CLIENT_CODE,
10
+ ICE_AND_REACHABILITY_FAILED_CLIENT_CODE,
10
11
  ICE_FAILED_WITH_TURN_TLS_CLIENT_CODE,
11
12
  MISSING_ROAP_ANSWER_CLIENT_CODE,
12
13
  } from '../../../../src/call-diagnostic/config';
@@ -616,32 +617,44 @@ describe('internal-plugin-metrics', () => {
616
617
  iceConnected: false,
617
618
  turnServerUsed: true,
618
619
  errorCode: MISSING_ROAP_ANSWER_CLIENT_CODE,
620
+ unreachable: false,
619
621
  },
620
622
  {
621
623
  signalingState: 'stable',
622
624
  iceConnected: true,
623
625
  turnServerUsed: true,
624
626
  errorCode: DTLS_HANDSHAKE_FAILED_CLIENT_CODE,
627
+ unreachable: false,
625
628
  },
626
629
  {
627
630
  signalingState: 'stable',
628
631
  iceConnected: false,
629
632
  turnServerUsed: true,
630
633
  errorCode: ICE_FAILED_WITH_TURN_TLS_CLIENT_CODE,
634
+ unreachable: false,
635
+ },
636
+ {
637
+ signalingState: 'stable',
638
+ iceConnected: false,
639
+ turnServerUsed: true,
640
+ errorCode: ICE_AND_REACHABILITY_FAILED_CLIENT_CODE,
641
+ unreachable: true,
631
642
  },
632
643
  {
633
644
  signalingState: 'stable',
634
645
  iceConnected: false,
635
646
  turnServerUsed: false,
636
647
  errorCode: ICE_FAILED_WITHOUT_TURN_TLS_CLIENT_CODE,
648
+ unreachable: false,
637
649
  },
638
- ].forEach(({signalingState, iceConnected, turnServerUsed, errorCode}: any) => {
650
+ ].forEach(({signalingState, iceConnected, turnServerUsed, errorCode, unreachable}: any) => {
639
651
  it('returns expected result', () => {
640
652
  assert.deepEqual(
641
653
  generateClientErrorCodeForIceFailure({
642
654
  signalingState,
643
655
  iceConnected,
644
656
  turnServerUsed,
657
+ unreachable,
645
658
  }),
646
659
  errorCode
647
660
  );