@webex/plugin-meetings 3.5.0-next.7 → 3.5.0-next.8

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.
@@ -1,154 +0,0 @@
1
- import 'jsdom-global/register';
2
- import RtcMetrics from '@webex/plugin-meetings/src/rtcMetrics';
3
- import MockWebex from '@webex/test-helper-mock-webex';
4
- import {assert} from '@webex/test-helper-chai';
5
- import sinon from 'sinon';
6
- import RTC_METRICS from '../../../../src/rtcMetrics/constants';
7
-
8
- const FAKE_METRICS_ITEM = {payload: ['{"type":"string","value":"fake-metrics","id":""}']};
9
- const FAILURE_METRICS_ITEM = {
10
- name: "onconnectionstatechange",
11
- payload: ['{"type":"string","value":"failed","id":""}'],
12
- timestamp: 1707929986667
13
- };
14
-
15
- const STATS_WITH_IP = '{"id":"RTCIceCandidate_/kQs0ZNU","type":"remote-candidate","transportId":"RTCTransport_0_1","isRemote":true,"ip":"11.22.111.255","address":"11.22.111.255","port":5004,"protocol":"udp","candidateType":"host","priority":2130706431}';
16
- const STATS_WITH_IP_RESULT = '{"id":"RTCIceCandidate_/kQs0ZNU","type":"remote-candidate","transportId":"RTCTransport_0_1","isRemote":true,"ip":"11.22.111.240","address":"11.22.111.240","port":5004,"protocol":"udp","candidateType":"host","priority":2130706431}';
17
-
18
- describe('RtcMetrics', () => {
19
- let metrics: RtcMetrics;
20
- let webex: MockWebex;
21
- let clock;
22
- let anonymizeIpSpy;
23
-
24
- const sandbox = sinon.createSandbox();
25
-
26
- beforeEach(() => {
27
- clock = sinon.useFakeTimers();
28
- webex = new MockWebex();
29
- metrics = new RtcMetrics(webex, 'mock-meeting-id', 'mock-correlation-id');
30
- anonymizeIpSpy = sandbox.spy(metrics, 'anonymizeIp');
31
- });
32
-
33
- afterEach(() => {
34
- sandbox.restore();
35
- });
36
-
37
- it('sendMetrics should send a webex request', () => {
38
- assert.notCalled(webex.request);
39
-
40
- metrics.addMetrics(FAKE_METRICS_ITEM);
41
- (metrics as any).sendMetrics();
42
-
43
- assert.callCount(webex.request, 1);
44
- assert.calledWithMatch(webex.request, sinon.match.has('headers', {
45
- type: 'webrtcMedia',
46
- appId: RTC_METRICS.APP_ID,
47
- }));
48
- assert.calledWithMatch(webex.request, sinon.match.hasNested('body.metrics[0].data[0].payload', FAKE_METRICS_ITEM.payload));
49
- assert.calledWithMatch(webex.request, sinon.match.hasNested('body.metrics[0].meetingId', 'mock-meeting-id'));
50
- assert.calledWithMatch(webex.request, sinon.match.hasNested('body.metrics[0].correlationId', 'mock-correlation-id'));
51
- });
52
-
53
- it('should have a defined sendMetricsInQueue function which is public', () => {
54
- assert.isDefined(metrics.sendMetricsInQueue);
55
- assert.isFunction(metrics.sendMetricsInQueue);
56
- });
57
-
58
- it('should send metrics requests over time', () => {
59
- assert.notCalled(webex.request);
60
-
61
- metrics.addMetrics(FAKE_METRICS_ITEM);
62
- assert.deepEqual(metrics.metricsQueue, [FAKE_METRICS_ITEM]);
63
- clock.tick(60 * 1000);
64
-
65
- assert.callCount(webex.request, 1);
66
- });
67
-
68
- it('should not send requests with no items in the queue', () => {
69
- clock.tick(60 * 1000);
70
- assert.notCalled(webex.request);
71
- });
72
-
73
- it('sendMetricsInQueue should send metrics if any exist in the queue', () => {
74
- assert.notCalled(webex.request);
75
-
76
- metrics.addMetrics(FAKE_METRICS_ITEM);
77
- (metrics as any).sendMetricsInQueue();
78
-
79
- assert.callCount(webex.request, 1);
80
- });
81
-
82
- it('should clear out metrics on close', () => {
83
- assert.notCalled(webex.request);
84
-
85
- metrics.addMetrics(FAKE_METRICS_ITEM);
86
- metrics.closeMetrics();
87
-
88
- assert.callCount(webex.request, 1);
89
- });
90
-
91
- it('should clear out metrics on failure', () => {
92
- assert.notCalled(webex.request);
93
-
94
- metrics.addMetrics(FAILURE_METRICS_ITEM);
95
-
96
- assert.callCount(webex.request, 1);
97
- });
98
-
99
- it('should have the same connectionId on success', () => {
100
- const originalId = metrics.connectionId;
101
-
102
- metrics.addMetrics(FAKE_METRICS_ITEM);
103
-
104
- assert.strictEqual(originalId, metrics.connectionId);
105
- });
106
-
107
- it('should have a new connectionId on failure', () => {
108
- const originalId = metrics.connectionId;
109
-
110
- metrics.addMetrics(FAILURE_METRICS_ITEM);
111
-
112
- assert.notEqual(originalId, metrics.connectionId);
113
- });
114
-
115
- it('should anonymize IP addresses', () => {
116
- assert.strictEqual(metrics.anonymizeIp(STATS_WITH_IP), STATS_WITH_IP_RESULT);
117
- });
118
-
119
- it('should call anonymizeIp', () => {
120
- metrics.addMetrics({ name: 'stats-report', payload: [STATS_WITH_IP] });
121
- assert.calledOnce(anonymizeIpSpy);
122
- })
123
-
124
- it('should send metrics on first stats-report', () => {
125
- assert.callCount(webex.request, 0);
126
-
127
- metrics.addMetrics(FAKE_METRICS_ITEM);
128
- assert.callCount(webex.request, 0);
129
-
130
- // first stats-report should trigger a call to webex.request
131
- metrics.addMetrics({ name: 'stats-report', payload: [STATS_WITH_IP] });
132
- assert.callCount(webex.request, 1);
133
- });
134
-
135
- it('should send metrics on first stats-report after a new connection', () => {
136
- assert.callCount(webex.request, 0);
137
-
138
- // first stats-report should trigger a call to webex.request
139
- metrics.addMetrics({ name: 'stats-report', payload: [STATS_WITH_IP] });
140
- assert.callCount(webex.request, 1);
141
-
142
- // subsequent stats-report doesn't trigger it
143
- metrics.addMetrics({ name: 'stats-report', payload: [STATS_WITH_IP] });
144
- assert.callCount(webex.request, 1);
145
-
146
- // now, simulate a failure - that triggers a new connection and upload of the metrics
147
- metrics.addMetrics(FAILURE_METRICS_ITEM);
148
- assert.callCount(webex.request, 2);
149
-
150
- // and another stats-report should trigger another upload of the metrics
151
- metrics.addMetrics({ name: 'stats-report', payload: [STATS_WITH_IP] });
152
- assert.callCount(webex.request, 3);
153
- });
154
- });