@webex/plugin-presence 0.0.0-next.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.
- package/.eslintrc.js +6 -0
- package/README.md +40 -0
- package/babel.config.js +3 -0
- package/dist/config.js +18 -0
- package/dist/config.js.map +1 -0
- package/dist/constants.js +26 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/interface.js +7 -0
- package/dist/interface.js.map +1 -0
- package/dist/presence-batcher.js +102 -0
- package/dist/presence-batcher.js.map +1 -0
- package/dist/presence-worker.js +277 -0
- package/dist/presence-worker.js.map +1 -0
- package/dist/presence.js +260 -0
- package/dist/presence.js.map +1 -0
- package/jest.config.js +3 -0
- package/package.json +57 -0
- package/process +1 -0
- package/src/config.ts +11 -0
- package/src/constants.ts +19 -0
- package/src/index.ts +42 -0
- package/src/interface.ts +72 -0
- package/src/presence-batcher.ts +101 -0
- package/src/presence-worker.ts +277 -0
- package/src/presence.ts +266 -0
- package/test/integration/spec/presence.ts +211 -0
- package/test/unit/spec/presence-worker.ts +262 -0
- package/test/unit/spec/presence.ts +66 -0
- package/tsconfig.json +4 -0
|
@@ -0,0 +1,211 @@
|
|
|
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.equal(statusResponse.subject, spock.id);
|
|
207
|
+
assert.equal(statusResponse.status, 'dnd');
|
|
208
|
+
}));
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
});
|
|
@@ -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,66 @@
|
|
|
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
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('#get()', () => {
|
|
23
|
+
it('requires a person id parameter', () => {
|
|
24
|
+
assert.isRejected(webex.presence.get(), /A person id is required/);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('#list()', () => {
|
|
29
|
+
it('requires a parameter', () =>
|
|
30
|
+
assert.isRejected(webex.presence.list(), /An array of person ids is required/));
|
|
31
|
+
|
|
32
|
+
it('requires a person array parameter', () =>
|
|
33
|
+
assert.isRejected(webex.presence.list('abc'), /An array of person ids is required/));
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('#subscribe()', () => {
|
|
37
|
+
it('requires a person parameter', () =>
|
|
38
|
+
assert.isRejected(webex.presence.subscribe(), /A person id is required/));
|
|
39
|
+
it('subscription request called twice with batch of 100 ids', () => {
|
|
40
|
+
const ids = [...Array(100).keys()];
|
|
41
|
+
|
|
42
|
+
webex.request = function (options) {
|
|
43
|
+
return Promise.resolve({
|
|
44
|
+
statusCode: 204,
|
|
45
|
+
body: [],
|
|
46
|
+
options,
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
sinon.spy(webex, 'request');
|
|
50
|
+
|
|
51
|
+
webex.presence.subscribe(ids);
|
|
52
|
+
assert.calledTwice(webex.request);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('#unsubscribe()', () => {
|
|
57
|
+
it('requires a person parameter', () =>
|
|
58
|
+
assert.isRejected(webex.presence.unsubscribe(), /A person id is required/));
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('#setStatus()', () => {
|
|
62
|
+
it('requires a status', () =>
|
|
63
|
+
assert.isRejected(webex.presence.setStatus(), /A status is required/));
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
package/tsconfig.json
ADDED