@webex/plugin-presence 0.0.0-ipv6-multi-turn-urls.1

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,213 @@
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import '@webex/internal-plugin-mercury';
6
+ import '@webex/plugin-presence';
7
+
8
+ import {assert} from '@webex/test-helper-chai';
9
+ import WebexCore from '@webex/webex-core';
10
+ import testUsers from '@webex/test-helper-test-users';
11
+ import {expectEvent} from '@webex/test-helper-mocha';
12
+ import sinon from 'sinon';
13
+
14
+ // SPARK-413317
15
+ describe.skip('plugin-presence', function () {
16
+ this.timeout(10000);
17
+ describe('Presence', () => {
18
+ let mccoy, spock;
19
+
20
+ beforeEach('create users', () =>
21
+ testUsers.create({count: 2}).then((users) => {
22
+ [spock, mccoy] = users;
23
+ spock.webex = new WebexCore({
24
+ credentials: {
25
+ authorization: users[0].token,
26
+ },
27
+ });
28
+ mccoy.webex = new WebexCore({
29
+ credentials: {
30
+ authorization: users[1].token,
31
+ },
32
+ });
33
+ })
34
+ );
35
+
36
+ beforeEach('register with wdm', () =>
37
+ Promise.all([spock.webex.internal.device.register(), mccoy.webex.internal.device.register()])
38
+ );
39
+
40
+ beforeEach('register spock with mercury', () => spock.webex.internal.mercury.connect());
41
+
42
+ afterEach('deregister spock with mercury', () => spock.webex.internal.mercury.disconnect());
43
+
44
+ describe('#enable()', () => {
45
+ it('enables presence', () =>
46
+ spock.webex.presence
47
+ .enable()
48
+ .then((isEnabled) => {
49
+ assert.equal(isEnabled, true);
50
+ })
51
+ .then(() => spock.webex.presence.isEnabled())
52
+ .then((isEnabled) => {
53
+ assert.equal(isEnabled, true);
54
+ }));
55
+ });
56
+
57
+ describe('#disable()', () => {
58
+ it('disables presence', () =>
59
+ spock.webex.presence
60
+ .disable()
61
+ .then((isEnabled) => {
62
+ assert.equal(isEnabled, false);
63
+ })
64
+ .then(() => spock.webex.presence.isEnabled())
65
+ .then((isEnabled) => {
66
+ assert.equal(isEnabled, false);
67
+ }));
68
+ });
69
+
70
+ describe('#isEnabled()', () => {
71
+ it('returns true when presence is enabled', () =>
72
+ spock.webex.presence
73
+ .enable()
74
+ .then(() => spock.webex.presence.isEnabled())
75
+ .then((isEnabled) => {
76
+ assert.equal(isEnabled, true);
77
+ }));
78
+
79
+ it('returns false when presence is disabled', () =>
80
+ spock.webex.presence
81
+ .disable()
82
+ .then(() => spock.webex.presence.isEnabled())
83
+ .then((isEnabled) => {
84
+ assert.equal(isEnabled, false);
85
+ }));
86
+ });
87
+
88
+ describe('#get()', () => {
89
+ it("gets a person's status by id", () =>
90
+ spock.webex.presence.get(mccoy.id).then((presenceResponse) => {
91
+ assert.property(presenceResponse, 'subject');
92
+ assert.equal(presenceResponse.subject, mccoy.id);
93
+ }));
94
+ });
95
+
96
+ describe('#list()', () => {
97
+ it('returns an object with the status of all requested people', () =>
98
+ spock.webex.presence.list([mccoy.id, spock.id]).then((presenceResponse) => {
99
+ assert.equal(presenceResponse.statusList.length, 2);
100
+ assert.property(presenceResponse.statusList[0], 'subject');
101
+ assert.equal(presenceResponse.statusList[0].subject, mccoy.id);
102
+ assert.property(presenceResponse.statusList[1], 'subject');
103
+ assert.equal(presenceResponse.statusList[1].subject, spock.id);
104
+ }));
105
+
106
+ describe('batching of presence requests', () => {
107
+ let batchTestUsers;
108
+
109
+ beforeEach('create more users', () =>
110
+ testUsers.create({count: 6}).then((users) => {
111
+ batchTestUsers = users;
112
+ })
113
+ );
114
+
115
+ it('executes network requests for max limit', () => {
116
+ spock.webex.presence.config.batcherMaxCalls = 2;
117
+ sinon.spy(spock.webex.presence.batcher, 'submitHttpRequest');
118
+
119
+ return spock.webex.presence
120
+ .list(batchTestUsers.map((user) => user.id))
121
+ .then((presenceResponse) => {
122
+ assert.equal(presenceResponse.statusList.length, 6);
123
+ assert.calledThrice(spock.webex.presence.batcher.submitHttpRequest);
124
+ spock.webex.presence.batcher.submitHttpRequest.restore();
125
+ });
126
+ });
127
+ });
128
+ });
129
+
130
+ describe('#subscribe', () => {
131
+ afterEach(
132
+ () => spock && spock.webex && spock.webex.presence.unsubscribe([mccoy.id, spock.id])
133
+ );
134
+
135
+ it('subscribes to a person id and returns subscription status', () =>
136
+ spock.webex.presence.subscribe(mccoy.id).then((presenceResponse) => {
137
+ assert.property(presenceResponse, 'responses');
138
+ assert.equal(presenceResponse.responses.length, 1);
139
+ assert.equal(presenceResponse.responses[0].subject, mccoy.id);
140
+ }));
141
+
142
+ it('subscribes and returns subscription status of a list of people ids', () =>
143
+ spock.webex.presence.subscribe([mccoy.id, spock.id]).then((presenceResponse) => {
144
+ assert.property(presenceResponse, 'responses');
145
+ assert.equal(presenceResponse.responses.length, 2);
146
+ assert.equal(presenceResponse.responses[0].subject, mccoy.id);
147
+ assert.equal(presenceResponse.responses[1].subject, spock.id);
148
+ }));
149
+
150
+ // Note: The presence service no longer accepts setting status to "inactive".
151
+ // Inactivity is now determined by a "last active time" of greater than 10 minutes.
152
+ it("should receive a mercury event for a subscribed person's change", () =>
153
+ spock.webex.presence
154
+ .subscribe(mccoy.id)
155
+ // 'active' status
156
+ .then(() =>
157
+ Promise.all([
158
+ expectEvent(
159
+ 10000,
160
+ 'event:apheleia.subscription_update',
161
+ spock.webex.internal.mercury,
162
+ 'spock should get the presence active event'
163
+ ),
164
+ mccoy.webex.presence.setStatus('active', 1500),
165
+ ])
166
+ )
167
+ .then(([event]) =>
168
+ assert.equal(
169
+ event.data.status,
170
+ 'active',
171
+ 'mccoy presence event status should be active'
172
+ )
173
+ )
174
+ // 'dnd' status
175
+ .then(() =>
176
+ Promise.all([
177
+ expectEvent(
178
+ 10000,
179
+ 'event:apheleia.subscription_update',
180
+ spock.webex.internal.mercury,
181
+ 'spock should get the presence dnd event'
182
+ ),
183
+ mccoy.webex.presence.setStatus('dnd', 1500),
184
+ ])
185
+ )
186
+ .then(([event]) =>
187
+ assert.equal(event.data.status, 'dnd', 'mccoy presence event status should be dnd')
188
+ ));
189
+ });
190
+
191
+ describe('#unsubscribe', () => {
192
+ it('unsubscribes to presence updates of a single person id', () =>
193
+ spock.webex.presence.unsubscribe(mccoy.id).then((res) => assert.statusCode(res, 200)));
194
+
195
+ it('unsubscribes to presence updates of a list of people ids', () =>
196
+ spock.webex.presence
197
+ .unsubscribe([mccoy.id, spock.id])
198
+ .then((res) => assert.statusCode(res, 200)));
199
+ });
200
+
201
+ describe('#setStatus', () => {
202
+ it('sets the presence status of the current user', () =>
203
+ spock.webex.presence.setStatus('dnd', 1500).then((statusResponse) => {
204
+ assert.property(statusResponse, 'subject');
205
+ assert.property(statusResponse, 'status');
206
+ assert.property(statusResponse, 'label');
207
+ assert.equal(statusResponse.subject, spock.id);
208
+ assert.equal(statusResponse.status, 'dnd');
209
+ assert.equal(statusResponse.subject, spock.id);
210
+ }));
211
+ });
212
+ });
213
+ });
@@ -0,0 +1,262 @@
1
+ import {assert} from '@webex/test-helper-chai';
2
+ import sinon from 'sinon';
3
+ import Mercury from '@webex/internal-plugin-mercury';
4
+ import Presence from '@webex/plugin-presence';
5
+ import MockWebex from '@webex/test-helper-mock-webex';
6
+
7
+ import PresenceWorker from '../../../src/presence-worker';
8
+ import CONFIG from '../../../src/config';
9
+
10
+ const round = (time) => Math.floor(time / 1000);
11
+
12
+ describe('presence-worker', () => {
13
+ describe('PresenceWorker', () => {
14
+ let webex;
15
+ let worker;
16
+ const id = '1234';
17
+
18
+ beforeEach(() => {
19
+ webex = new MockWebex({
20
+ children: {
21
+ mercury: Mercury,
22
+ presence: Presence,
23
+ },
24
+ config: {...CONFIG},
25
+ });
26
+ worker = new PresenceWorker();
27
+ worker.webex = webex;
28
+ });
29
+
30
+ describe('#initialize()', () => {
31
+ it('requires webex', () =>
32
+ expect(() => worker.initialize()).toThrow(/Must initialize Presence Worker with webex!/));
33
+ it('requires webex internal', () =>
34
+ expect(() => worker.initialize({})).toThrow(/Must initialize Presence Worker with webex!/));
35
+ });
36
+
37
+ describe('#enqueue()', () => {
38
+ it('increments watchers count', () => {
39
+ worker.enqueue(id);
40
+ assert.equal(worker.watchers[id], 1);
41
+ worker.enqueue(id);
42
+ assert.equal(worker.watchers[id], 2);
43
+ });
44
+
45
+ it('only increments watcher if subscribed', () => {
46
+ worker.subscribers[id] = true;
47
+
48
+ worker.enqueue(id);
49
+ assert.equal(worker.watchers[id], 1);
50
+ assert.notExists(worker.campers[id]);
51
+ });
52
+
53
+ it('set camper time to now', () => {
54
+ const now = new Date().getTime();
55
+
56
+ worker.enqueue(id);
57
+ assert.equal(round(worker.campers[id]), round(now));
58
+ });
59
+
60
+ it('add fetcher', () => {
61
+ worker.enqueue(id);
62
+ assert.exists(worker.fetchers[id]);
63
+ });
64
+
65
+ it('stop fetch if there is already a flight', () => {
66
+ worker.flights[id] = true;
67
+
68
+ worker.enqueue(id);
69
+ assert.notExists(worker.fetchers[id]);
70
+ });
71
+
72
+ it('add fetch if there is an old presence', () => {
73
+ const past = new Date().getTime() - 100000;
74
+
75
+ worker.presences[id] = past;
76
+
77
+ worker.enqueue(id);
78
+ assert.exists(worker.fetchers[id]);
79
+ });
80
+
81
+ it('stop fetch if there is a recent presence', () => {
82
+ const now = new Date().getTime();
83
+
84
+ worker.presences[id] = now;
85
+
86
+ worker.enqueue(id);
87
+ assert.notExists(worker.fetchers[id]);
88
+ });
89
+ });
90
+
91
+ describe('#dequeue()', () => {
92
+ it('does nothing if there are no watchers', () => {
93
+ worker.dequeue(id);
94
+ assert.isUndefined(worker.watchers[id]);
95
+ });
96
+
97
+ it('delete values when reached zero', () => {
98
+ worker.watchers[id] = 1;
99
+ worker.fetchers[id] = 1;
100
+ worker.campers[id] = 1;
101
+
102
+ worker.dequeue(id);
103
+ assert.isUndefined(worker.watchers[id]);
104
+ assert.isUndefined(worker.fetchers[id]);
105
+ assert.isUndefined(worker.campers[id]);
106
+ });
107
+
108
+ it('decrement watchers by one', () => {
109
+ worker.watchers[id] = 5;
110
+
111
+ worker.dequeue(id);
112
+ assert.equal(worker.watchers[id], 4);
113
+ });
114
+ });
115
+
116
+ describe('#checkFetchers()', () => {
117
+ const boarding = {
118
+ pam: true,
119
+ jim: true,
120
+ dwight: true,
121
+ };
122
+
123
+ it('moves fetchers to flights', () => {
124
+ webex.presence.list = sinon.stub().returns(Promise.resolve({statusList: []}));
125
+
126
+ worker.fetchers = boarding;
127
+
128
+ worker.checkFetchers();
129
+ assert.isEmpty(worker.fetchers);
130
+ assert.deepEqual(worker.flights, boarding);
131
+ });
132
+
133
+ it('calls presence.list', async () => {
134
+ const response = [{subject: 'pam'}, {subject: 'jim'}, {subject: 'dwight'}];
135
+
136
+ webex.presence.list = sinon.stub().returns(Promise.resolve({statusList: response}));
137
+ webex.presence.emitEvent = sinon.stub();
138
+
139
+ worker.fetchers = boarding;
140
+
141
+ await worker.checkFetchers();
142
+
143
+ assert.calledWith(webex.presence.list, Object.keys(boarding));
144
+ assert.isEmpty(worker.flights);
145
+ assert.deepEqual(Object.keys(worker.presences), Object.keys(boarding));
146
+ assert.calledWith(webex.presence.emitEvent, 'updated', {
147
+ type: 'presence',
148
+ payload: {statusList: response},
149
+ });
150
+ });
151
+ });
152
+
153
+ describe('#checkCampers()', () => {
154
+ it('moves campers to subscribers', () => {
155
+ const now = new Date().getTime();
156
+ const scouts = {
157
+ pam: now - 60001, // move them back a little over a minute
158
+ jim: now - 60001,
159
+ dwight: now,
160
+ };
161
+
162
+ worker.campers = scouts;
163
+
164
+ const subbies = worker.checkCampers();
165
+
166
+ assert.deepEqual(subbies, ['pam', 'jim']);
167
+ });
168
+ });
169
+
170
+ describe('#checkSubscriptions()', () => {
171
+ it('resubscribe to expiring subscriptions', () => {
172
+ const now = new Date().getTime();
173
+ const subbies = {
174
+ pam: now,
175
+ jim: now + 61000, // move forward a little over a minute
176
+ dwight: now,
177
+ };
178
+ const watching = {
179
+ pam: 1,
180
+ jim: 1,
181
+ };
182
+
183
+ worker.watchers = watching;
184
+ worker.subscribers = subbies;
185
+
186
+ const renewals = worker.checkSubscriptions();
187
+
188
+ assert.deepEqual(renewals, ['pam']);
189
+ });
190
+
191
+ it('delete expired subscriptions', () => {
192
+ const now = new Date().getTime();
193
+ const subbies = {
194
+ pam: now + 600000, // move forward 10 minutes
195
+ jim: now - 20000, // move back 20 seconds
196
+ dwight: now - 60000, // move back 1 minute
197
+ };
198
+
199
+ worker.subscribers = subbies;
200
+
201
+ const renewals = worker.checkSubscriptions();
202
+
203
+ assert.deepEqual(renewals, []);
204
+ assert.deepEqual(Object.keys(worker.subscribers), ['pam']);
205
+ });
206
+ });
207
+
208
+ describe('#cleanPresences()', () => {
209
+ it('deletes expired presences', () => {
210
+ const now = new Date().getTime();
211
+ const presences = {
212
+ pam: now - 300000, // 5 minutes ago
213
+ jim: now - 600001, // little over 10 minutes ago
214
+ dwight: now - 1200000, // 20 minutes ago
215
+ };
216
+
217
+ webex.presence.emitEvent = sinon.stub();
218
+ worker.presences = presences;
219
+
220
+ worker.cleanPresences();
221
+
222
+ assert.calledWith(webex.presence.emitEvent, 'updated', {
223
+ type: 'delete',
224
+ payload: ['jim', 'dwight'],
225
+ });
226
+ });
227
+ });
228
+
229
+ describe('#groundskeeper()', () => {
230
+ it('renews subscriptions', async () => {
231
+ webex.presence.subscribe = sinon.stub().returns(
232
+ Promise.resolve({
233
+ responses: [
234
+ {
235
+ responseCode: 200,
236
+ subscriptionTtl: 600,
237
+ subject: 'pam',
238
+ status: {
239
+ subject: 'pam',
240
+ },
241
+ },
242
+ {
243
+ responseCode: 500,
244
+ subject: 'jim',
245
+ },
246
+ ],
247
+ })
248
+ );
249
+ worker.checkCampers = sinon.stub().returns(['pam']);
250
+ worker.checkSubscriptions = sinon.stub().returns(['jim']);
251
+ worker.cleanPresences = sinon.stub();
252
+
253
+ await worker.groundskeeper();
254
+
255
+ assert.calledWith(webex.presence.subscribe, ['pam', 'jim']);
256
+ assert.deepEqual(Object.keys(worker.subscribers), ['pam', 'jim']);
257
+ assert.deepEqual(Object.keys(worker.presences), ['pam']);
258
+ assert.called(worker.cleanPresences);
259
+ });
260
+ });
261
+ });
262
+ });
@@ -0,0 +1,128 @@
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import {assert} from '@webex/test-helper-chai';
6
+ import sinon from 'sinon';
7
+ import Presence from '@webex/plugin-presence';
8
+ import MockWebex from '@webex/test-helper-mock-webex';
9
+
10
+ describe('plugin-presence', () => {
11
+ describe('Presence', () => {
12
+ let webex;
13
+
14
+ beforeEach(() => {
15
+ webex = new MockWebex({
16
+ children: {
17
+ presence: Presence,
18
+ },
19
+ });
20
+ webex.config.presence = {};
21
+ });
22
+
23
+ describe('#get()', () => {
24
+ it('requires a person id parameter', () => {
25
+ assert.isRejected(webex.presence.get(), /A person id is required/);
26
+ });
27
+ });
28
+
29
+ describe('#list()', () => {
30
+ it('requires a parameter', () =>
31
+ assert.isRejected(webex.presence.list(), /An array of person ids is required/));
32
+
33
+ it('requires a person array parameter', () =>
34
+ assert.isRejected(webex.presence.list('abc'), /An array of person ids is required/));
35
+ });
36
+
37
+ describe('#subscribe()', () => {
38
+ it('requires a person parameter', () =>
39
+ assert.isRejected(webex.presence.subscribe(), /A person id is required/));
40
+ it('subscription request called twice with batch of 100 ids', () => {
41
+ const ids = [...Array(100).keys()];
42
+
43
+ webex.request = function (options) {
44
+ return Promise.resolve({
45
+ statusCode: 204,
46
+ body: [],
47
+ options,
48
+ });
49
+ };
50
+ sinon.spy(webex, 'request');
51
+
52
+ webex.presence.subscribe(ids);
53
+ assert.calledTwice(webex.request);
54
+ });
55
+ });
56
+
57
+ describe('#unsubscribe()', () => {
58
+ it('requires a person parameter', () =>
59
+ assert.isRejected(webex.presence.unsubscribe(), /A person id is required/));
60
+ });
61
+
62
+ describe('#setStatus()', () => {
63
+ it('requires a status', () =>
64
+ assert.isRejected(webex.presence.setStatus(), /A status is required/));
65
+
66
+ it('passes a label to the API', () => {
67
+ const testGuid = 'test-guid';
68
+
69
+ webex.internal.device.userId = testGuid;
70
+
71
+ webex.request = function (options) {
72
+ return Promise.resolve({
73
+ statusCode: 204,
74
+ body: [],
75
+ options,
76
+ });
77
+ };
78
+ sinon.spy(webex, 'request');
79
+
80
+ webex.presence.setStatus('active');
81
+
82
+ assert.calledOnce(webex.request);
83
+
84
+ const request = webex.request.getCall(0);
85
+
86
+ assert.equal(request.args[0].body.label, testGuid);
87
+ });
88
+
89
+ it('does not pass a label to the API if the status is DND', () => {
90
+ const testGuid = 'test-guid';
91
+
92
+ webex.internal.device.userId = testGuid;
93
+
94
+ webex.request = function (options) {
95
+ return Promise.resolve({
96
+ statusCode: 204,
97
+ body: [],
98
+ options,
99
+ });
100
+ };
101
+ sinon.spy(webex, 'request');
102
+
103
+ webex.presence.setStatus('dnd');
104
+
105
+ assert.calledOnce(webex.request);
106
+
107
+ const request = webex.request.getCall(0);
108
+
109
+ assert.notProperty(request.args[0].body, 'label');
110
+ });
111
+ });
112
+
113
+ describe('#initializeWorker()', () => {
114
+ it('initializes the worker once webex is ready', () => {
115
+ webex.presence.worker = {initialize: sinon.spy()};
116
+ webex.presence.config.initializeWorker = false;
117
+
118
+ webex.presence.initializeWorker();
119
+
120
+ assert.notCalled(webex.presence.worker.initialize);
121
+
122
+ webex.trigger('ready');
123
+
124
+ assert.calledOnce(webex.presence.worker.initialize);
125
+ });
126
+ });
127
+ });
128
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "include": ["src"],
4
+ "typedocOptions": {
5
+ "entryPoints": [
6
+ "./src/interface.ts"
7
+ ],
8
+ "sort": [
9
+ "source-order"
10
+ ],
11
+ "name": "Presence (@webex/plugin-presence)",
12
+ "disableSources": "true",
13
+ "entryPointStrategy": "expand",
14
+ "excludeExternals": "true",
15
+ "excludePrivate": "true",
16
+ "hideGenerator": "true",
17
+ },
18
+ }