@webex/internal-plugin-calendar 2.59.3-next.1 → 2.59.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.
- package/.eslintrc.js +6 -6
- package/README.md +42 -42
- package/babel.config.js +3 -3
- package/dist/calendar.decrypt.helper.js +10 -10
- package/dist/calendar.decrypt.helper.js.map +1 -1
- package/dist/calendar.encrypt.helper.js +11 -11
- package/dist/calendar.encrypt.helper.js.map +1 -1
- package/dist/calendar.js +131 -131
- package/dist/calendar.js.map +1 -1
- package/dist/collection.js +40 -40
- package/dist/collection.js.map +1 -1
- package/dist/config.js +2 -2
- package/dist/config.js.map +1 -1
- package/dist/constants.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/util.js +7 -7
- package/dist/util.js.map +1 -1
- package/jest.config.js +3 -3
- package/package.json +16 -17
- package/process +1 -1
- package/src/calendar.decrypt.helper.js +121 -121
- package/src/calendar.encrypt.helper.js +98 -98
- package/src/calendar.js +490 -490
- package/src/collection.js +100 -100
- package/src/config.js +10 -10
- package/src/constants.js +6 -6
- package/src/index.js +241 -241
- package/src/util.js +22 -22
- package/test/integration/spec/calendar.js +624 -624
- package/test/unit/spec/calendar.decrypt.helper.js +145 -145
- package/test/unit/spec/calendar.encrypt.helper.js +52 -52
- package/test/unit/spec/calendar.js +446 -446
- package/test/unit/spec/utils.js +16 -16
|
@@ -1,446 +1,446 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { assert, expect } from "@webex/test-helper-chai";
|
|
6
|
-
import Calendar from '@webex/internal-plugin-calendar';
|
|
7
|
-
import MockWebex from '@webex/test-helper-mock-webex';
|
|
8
|
-
import { base64 } from "@webex/common";
|
|
9
|
-
import sinon from 'sinon';
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
CALENDAR_REGISTERED,
|
|
13
|
-
CALENDAR_UPDATED,
|
|
14
|
-
CALENDAR_DELETE,
|
|
15
|
-
CALENDAR_CREATE,
|
|
16
|
-
CALENDAR_UNREGISTERED,
|
|
17
|
-
} from '../../../src/constants';
|
|
18
|
-
|
|
19
|
-
describe('internal-plugin-calendar', () => {
|
|
20
|
-
describe('Calendar Apis', () => {
|
|
21
|
-
let webex;
|
|
22
|
-
|
|
23
|
-
beforeEach(async () => {
|
|
24
|
-
webex = new MockWebex({
|
|
25
|
-
children: {
|
|
26
|
-
calendar: Calendar,
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
webex.canAuthorize = true;
|
|
31
|
-
webex.internal.device = {
|
|
32
|
-
register: sinon.stub().returns(Promise.resolve()),
|
|
33
|
-
unregister: sinon.stub().returns(Promise.resolve()),
|
|
34
|
-
};
|
|
35
|
-
webex.internal.mercury = {
|
|
36
|
-
connect: sinon.stub().returns(Promise.resolve()),
|
|
37
|
-
disconnect: sinon.stub().returns(Promise.resolve()),
|
|
38
|
-
on: sinon.stub().callsFake((event, callback) => {
|
|
39
|
-
if (event === 'event:calendar.meeting.update') {
|
|
40
|
-
callback({data: {calendarMeetingExternal: {id: 'calendarId1'}}});
|
|
41
|
-
}
|
|
42
|
-
if (event === 'event:calendar.meeting.delete') {
|
|
43
|
-
callback({data: {calendarMeetingExternal: {id: 'calendarId1'}}});
|
|
44
|
-
}
|
|
45
|
-
if (event === 'event:calendar.meeting.create') {
|
|
46
|
-
callback({data: {calendarMeetingExternal: {id: 'calendarId1'}}});
|
|
47
|
-
}
|
|
48
|
-
}),
|
|
49
|
-
off: sinon.spy(),
|
|
50
|
-
};
|
|
51
|
-
webex.internal.encryption = {
|
|
52
|
-
kms: {
|
|
53
|
-
createUnboundKeys: sinon.stub().resolves([{
|
|
54
|
-
uri: "kms://kms-us-int.wbx2.com/keys/xxxx-xxxx-xxxx-xxxx"
|
|
55
|
-
}])
|
|
56
|
-
},
|
|
57
|
-
encryptText: sinon.stub().resolves("encryptedText")
|
|
58
|
-
};
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
describe('Public Api Contract', () => {
|
|
62
|
-
describe('#register()', () => {
|
|
63
|
-
it('on calendar register call mercury registration', async () => {
|
|
64
|
-
await webex.internal.calendar.register();
|
|
65
|
-
assert.calledOnce(webex.internal.device.register);
|
|
66
|
-
assert.callCount(webex.internal.mercury.on, 6);
|
|
67
|
-
assert.equal(webex.internal.calendar.registered, true);
|
|
68
|
-
});
|
|
69
|
-
it('should trigger `calendar:register` event', async () => {
|
|
70
|
-
const spy = sinon.spy();
|
|
71
|
-
|
|
72
|
-
webex.internal.calendar.on(CALENDAR_REGISTERED, spy);
|
|
73
|
-
await webex.internal.calendar.register();
|
|
74
|
-
assert.calledOnce(spy);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
describe('Events', () => {
|
|
78
|
-
it('trigger `calendar:update` event', async () => {
|
|
79
|
-
const spy = sinon.spy();
|
|
80
|
-
|
|
81
|
-
webex.internal.calendar.on(CALENDAR_UPDATED, spy);
|
|
82
|
-
await webex.internal.calendar.register();
|
|
83
|
-
assert.calledOnce(spy);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('trigger `calendar:create` event', async () => {
|
|
87
|
-
const spy = sinon.spy();
|
|
88
|
-
|
|
89
|
-
webex.internal.calendar.on(CALENDAR_CREATE, spy);
|
|
90
|
-
await webex.internal.calendar.register();
|
|
91
|
-
assert.calledOnce(spy);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('trigger `calendar:delete` event', async () => {
|
|
95
|
-
const spy = sinon.spy();
|
|
96
|
-
|
|
97
|
-
webex.internal.calendar.on(CALENDAR_DELETE, spy);
|
|
98
|
-
await webex.internal.calendar.register();
|
|
99
|
-
assert.calledOnce(spy);
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
describe('#unregister()', () => {
|
|
105
|
-
it('should call `mercury.unregister` and `device.unregister`', async () => {
|
|
106
|
-
await webex.internal.calendar.register();
|
|
107
|
-
await webex.internal.calendar.unregister();
|
|
108
|
-
assert.callCount(webex.internal.mercury.off, 6);
|
|
109
|
-
assert.calledOnce(webex.internal.mercury.disconnect);
|
|
110
|
-
assert.calledOnce(webex.internal.device.unregister);
|
|
111
|
-
});
|
|
112
|
-
it('should trigger `calendar:unregister` event', async () => {
|
|
113
|
-
const spy = sinon.spy();
|
|
114
|
-
|
|
115
|
-
// reseting the state back
|
|
116
|
-
await webex.internal.calendar.register();
|
|
117
|
-
webex.internal.calendar.on(CALENDAR_UNREGISTERED, spy);
|
|
118
|
-
await webex.internal.calendar.unregister();
|
|
119
|
-
assert.calledOnce(spy);
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
describe('#syncCalendar()', () => {
|
|
124
|
-
it('should sync from calendar service', async () => {
|
|
125
|
-
webex.request = sinon
|
|
126
|
-
.stub()
|
|
127
|
-
.returns(Promise.resolve({body: {items: [{id: 'calendar1'}, {id: 'calendar2'}]}}));
|
|
128
|
-
webex.request = sinon.stub().returns(
|
|
129
|
-
Promise.resolve({
|
|
130
|
-
body: {
|
|
131
|
-
items: [
|
|
132
|
-
{
|
|
133
|
-
id: 'calendar1',
|
|
134
|
-
encryptedNotes: 'notes1',
|
|
135
|
-
encryptedParticipants: ['participant1'],
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
id: 'calendar2',
|
|
139
|
-
encryptedNotes: 'notes2',
|
|
140
|
-
encryptedParticipants: ['participant2'],
|
|
141
|
-
},
|
|
142
|
-
],
|
|
143
|
-
},
|
|
144
|
-
})
|
|
145
|
-
);
|
|
146
|
-
await webex.internal.calendar.syncCalendar({fromDate: 'xx-xx', toDate: 'xx-nn'});
|
|
147
|
-
assert.calledWith(webex.request, {
|
|
148
|
-
method: 'GET',
|
|
149
|
-
service: 'calendar',
|
|
150
|
-
resource: 'calendarEvents',
|
|
151
|
-
qs: {fromDate: 'xx-xx', toDate: 'xx-nn'},
|
|
152
|
-
});
|
|
153
|
-
assert.equal(webex.internal.calendar.getAll().length, 2);
|
|
154
|
-
assert.equal(webex.internal.calendar.getAll()[0].id, 'calendar1');
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
describe('#list()', () => {
|
|
159
|
-
it('should fetch the calendar list', async () => {
|
|
160
|
-
webex.request = sinon.stub().returns(
|
|
161
|
-
Promise.resolve({
|
|
162
|
-
body: {
|
|
163
|
-
items: [
|
|
164
|
-
{
|
|
165
|
-
id: 'calendar1',
|
|
166
|
-
encryptedNotes: 'notes1',
|
|
167
|
-
encryptedParticipants: ['participant1'],
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
id: 'calendar2',
|
|
171
|
-
encryptedNotes: 'notes2',
|
|
172
|
-
encryptedParticipants: ['participant2'],
|
|
173
|
-
},
|
|
174
|
-
],
|
|
175
|
-
},
|
|
176
|
-
})
|
|
177
|
-
);
|
|
178
|
-
const res = await webex.internal.calendar.list({fromDate: 'xx-xx', toDate: 'xx-nn'});
|
|
179
|
-
|
|
180
|
-
assert.equal(res.length, 2);
|
|
181
|
-
assert.calledWith(webex.request, {
|
|
182
|
-
method: 'GET',
|
|
183
|
-
service: 'calendar',
|
|
184
|
-
resource: 'calendarEvents',
|
|
185
|
-
qs: {fromDate: 'xx-xx', toDate: 'xx-nn'},
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it('should fetch the calendar list and resolves with null encryptedNotes', async () => {
|
|
190
|
-
const webexRequestStub = sinon.stub();
|
|
191
|
-
|
|
192
|
-
// calendar list stub
|
|
193
|
-
webexRequestStub
|
|
194
|
-
.withArgs({
|
|
195
|
-
method: 'GET',
|
|
196
|
-
service: 'calendar',
|
|
197
|
-
resource: 'calendarEvents',
|
|
198
|
-
qs: {fromDate: 'xx-xx', toDate: 'xx-nn'},
|
|
199
|
-
})
|
|
200
|
-
.returns(
|
|
201
|
-
Promise.resolve({
|
|
202
|
-
body: {
|
|
203
|
-
items: [
|
|
204
|
-
{id: 'calendar1', encryptedParticipants: ['participant1']},
|
|
205
|
-
{
|
|
206
|
-
id: 'calendar2',
|
|
207
|
-
encryptedNotes: 'notes2',
|
|
208
|
-
encryptedParticipants: ['participant2'],
|
|
209
|
-
},
|
|
210
|
-
],
|
|
211
|
-
},
|
|
212
|
-
})
|
|
213
|
-
);
|
|
214
|
-
|
|
215
|
-
// Assign webexRequestStub to webex.request
|
|
216
|
-
webex.request = webexRequestStub;
|
|
217
|
-
|
|
218
|
-
const res = await webex.internal.calendar.list({fromDate: 'xx-xx', toDate: 'xx-nn'});
|
|
219
|
-
|
|
220
|
-
assert.equal(res.length, 2);
|
|
221
|
-
assert.deepEqual(res, [
|
|
222
|
-
{id: 'calendar1', encryptedParticipants: ['participant1']},
|
|
223
|
-
{id: 'calendar2', encryptedNotes: 'notes2', encryptedParticipants: ['participant2']},
|
|
224
|
-
]);
|
|
225
|
-
assert.calledWith(webex.request, {
|
|
226
|
-
method: 'GET',
|
|
227
|
-
service: 'calendar',
|
|
228
|
-
resource: 'calendarEvents',
|
|
229
|
-
qs: {fromDate: 'xx-xx', toDate: 'xx-nn'},
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it('should fetch the calendar list and resolves with fetched encryptedNotes', async () => {
|
|
234
|
-
const webexRequestStub = sinon.stub();
|
|
235
|
-
|
|
236
|
-
// calendar list stub
|
|
237
|
-
webexRequestStub
|
|
238
|
-
.withArgs({
|
|
239
|
-
method: 'GET',
|
|
240
|
-
service: 'calendar',
|
|
241
|
-
resource: 'calendarEvents',
|
|
242
|
-
qs: {fromDate: 'xx-xx', toDate: 'xx-nn'},
|
|
243
|
-
})
|
|
244
|
-
.returns(
|
|
245
|
-
Promise.resolve({
|
|
246
|
-
body: {
|
|
247
|
-
items: [
|
|
248
|
-
{id: 'calendar1', encryptedNotes: 'notes1', encryptedParticipants: ['participant1']},
|
|
249
|
-
{
|
|
250
|
-
id: 'calendar2',
|
|
251
|
-
encryptedNotes: 'notes2',
|
|
252
|
-
encryptedParticipants: ['participant2'],
|
|
253
|
-
},
|
|
254
|
-
],
|
|
255
|
-
},
|
|
256
|
-
})
|
|
257
|
-
);
|
|
258
|
-
|
|
259
|
-
// Assign webexRequestStub to webex.request
|
|
260
|
-
webex.request = webexRequestStub;
|
|
261
|
-
|
|
262
|
-
const res = await webex.internal.calendar.list({fromDate: 'xx-xx', toDate: 'xx-nn'});
|
|
263
|
-
|
|
264
|
-
assert.equal(res.length, 2);
|
|
265
|
-
assert.deepEqual(res, [
|
|
266
|
-
{id: 'calendar1', encryptedNotes: 'notes1', encryptedParticipants: ['participant1']},
|
|
267
|
-
{id: 'calendar2', encryptedNotes: 'notes2', encryptedParticipants: ['participant2']},
|
|
268
|
-
]);
|
|
269
|
-
assert.calledWith(webex.request, {
|
|
270
|
-
method: 'GET',
|
|
271
|
-
service: 'calendar',
|
|
272
|
-
resource: 'calendarEvents',
|
|
273
|
-
qs: {fromDate: 'xx-xx', toDate: 'xx-nn'},
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
describe('#getNotes()', () => {
|
|
279
|
-
it('should fetch the meeting notes', async () => {
|
|
280
|
-
const id = 'meetingId123';
|
|
281
|
-
|
|
282
|
-
webex.request = sinon.stub().returns(
|
|
283
|
-
Promise.resolve({
|
|
284
|
-
body: {
|
|
285
|
-
encryptedNotes: 'notes1',
|
|
286
|
-
},
|
|
287
|
-
})
|
|
288
|
-
);
|
|
289
|
-
|
|
290
|
-
const res = await webex.internal.calendar.getNotes(id);
|
|
291
|
-
|
|
292
|
-
assert.equal(res.body.encryptedNotes, 'notes1');
|
|
293
|
-
assert.calledWith(webex.request, {
|
|
294
|
-
method: 'GET',
|
|
295
|
-
service: 'calendar',
|
|
296
|
-
resource: `calendarEvents/${base64.encode(id)}/notes`,
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
describe('#getParticipants()', () => {
|
|
302
|
-
const id = 'meetingId123';
|
|
303
|
-
|
|
304
|
-
it('should fetch the meeting participants', async () => {
|
|
305
|
-
webex.request = sinon.stub().returns(
|
|
306
|
-
Promise.resolve({
|
|
307
|
-
body: {
|
|
308
|
-
encryptedParticipants: ['participant1'],
|
|
309
|
-
},
|
|
310
|
-
})
|
|
311
|
-
);
|
|
312
|
-
|
|
313
|
-
const res = await webex.internal.calendar.getParticipants(id);
|
|
314
|
-
|
|
315
|
-
assert.equal(res.body.encryptedParticipants.length, 1);
|
|
316
|
-
assert.calledWith(webex.request, {
|
|
317
|
-
method: 'GET',
|
|
318
|
-
service: 'calendar',
|
|
319
|
-
resource: `calendarEvents/${base64.encode(id)}/participants`,
|
|
320
|
-
});
|
|
321
|
-
});
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
describe("#getSchedulerData()", () => {
|
|
325
|
-
it("should fetch meeting calendar data", async () => {
|
|
326
|
-
const query = {
|
|
327
|
-
siteName: "scheduler01.dmz.webex.com",
|
|
328
|
-
clientMeetingId: "YWJjZGFiY2QtYWJjZC1hYmNkLWFiY2QtMDAwMDAwMDA"
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
webex.request = sinon.stub().resolves({
|
|
332
|
-
body: {
|
|
333
|
-
encryptedSubject: "My Meeting 1",
|
|
334
|
-
schedulerPreferences: {
|
|
335
|
-
uiControlAttributes: {
|
|
336
|
-
displayHostSaveMeetingTemplate: true
|
|
337
|
-
},
|
|
338
|
-
webexOptions: {
|
|
339
|
-
sessionTypeId: 3
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
const res = await webex.internal.calendar.getSchedulerData(query);
|
|
346
|
-
|
|
347
|
-
expect(res.body.encryptedSubject).to.equal("My Meeting 1");
|
|
348
|
-
expect(res.body.schedulerPreferences.uiControlAttributes.displayHostSaveMeetingTemplate).to.be.true;
|
|
349
|
-
expect(res.body.schedulerPreferences.webexOptions.sessionTypeId).to.equal(3);
|
|
350
|
-
assert.calledWith(webex.request, {
|
|
351
|
-
method: "GET",
|
|
352
|
-
service: "calendar",
|
|
353
|
-
resource: "schedulerData",
|
|
354
|
-
qs: {
|
|
355
|
-
siteName: query.siteName,
|
|
356
|
-
clientMeetingId: query.clientMeetingId
|
|
357
|
-
}
|
|
358
|
-
});
|
|
359
|
-
});
|
|
360
|
-
});
|
|
361
|
-
|
|
362
|
-
describe("#createCalendarEvent()", () => {
|
|
363
|
-
it("should create an calendar event", async () => {
|
|
364
|
-
const data = {
|
|
365
|
-
encryptionKeyUrl: "kms://kms-us-int.wbx2.com/keys/d1c14fc5-be10-4389-ae83-9521f92fbfd3",
|
|
366
|
-
notes: "This is Agenda",
|
|
367
|
-
subject: "My Meeting 1",
|
|
368
|
-
webexOptions: "{}"
|
|
369
|
-
};
|
|
370
|
-
const query = {};
|
|
371
|
-
|
|
372
|
-
webex.request = sinon.stub().resolves({
|
|
373
|
-
body: {
|
|
374
|
-
meetingId: "abcdabcd-abcd-abcd-abcd-00000000",
|
|
375
|
-
globalMeetingId: "xxxx-xxxx-xxxx-xxxx"
|
|
376
|
-
}
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
const res = await webex.internal.calendar.createCalendarEvent(data);
|
|
380
|
-
|
|
381
|
-
expect(res.body.meetingId).to.equal("abcdabcd-abcd-abcd-abcd-00000000");
|
|
382
|
-
expect(res.body.globalMeetingId).to.equal("xxxx-xxxx-xxxx-xxxx");
|
|
383
|
-
assert.calledWith(webex.request, {
|
|
384
|
-
method: "POST",
|
|
385
|
-
service: "calendar",
|
|
386
|
-
body: data,
|
|
387
|
-
resource: "calendarEvents/sync",
|
|
388
|
-
qs: query
|
|
389
|
-
});
|
|
390
|
-
});
|
|
391
|
-
});
|
|
392
|
-
|
|
393
|
-
describe("#updateCalendarEvent()", () => {
|
|
394
|
-
it("should update a calendar event", async () => {
|
|
395
|
-
const id = "abcdabcd-abcd-abcd-abcd-00000000";
|
|
396
|
-
const data = {
|
|
397
|
-
encryptionKeyUrl: "kms://kms-us-int.wbx2.com/keys/d1c14fc5-be10-4389-ae83-9521f92fbfd3",
|
|
398
|
-
notes: "This is Agenda",
|
|
399
|
-
subject: "My Meeting 1",
|
|
400
|
-
webexOptions: "{}"
|
|
401
|
-
};
|
|
402
|
-
const query = {};
|
|
403
|
-
|
|
404
|
-
webex.request = sinon.stub().resolves({
|
|
405
|
-
body: {
|
|
406
|
-
meetingId: "abcdabcd-abcd-abcd-abcd-00000000",
|
|
407
|
-
globalMeetingId: "xxxx-xxxx-xxxx-xxxx"
|
|
408
|
-
}
|
|
409
|
-
});
|
|
410
|
-
|
|
411
|
-
const res = await webex.internal.calendar.updateCalendarEvent(id, data);
|
|
412
|
-
|
|
413
|
-
expect(res.body.meetingId).to.equal("abcdabcd-abcd-abcd-abcd-00000000");
|
|
414
|
-
expect(res.body.globalMeetingId).to.equal("xxxx-xxxx-xxxx-xxxx");
|
|
415
|
-
assert.calledWith(webex.request, {
|
|
416
|
-
method: "PATCH",
|
|
417
|
-
service: "calendar",
|
|
418
|
-
body: data,
|
|
419
|
-
resource: `calendarEvents/${base64.encode(id)}/sync`,
|
|
420
|
-
qs: query
|
|
421
|
-
});
|
|
422
|
-
});
|
|
423
|
-
});
|
|
424
|
-
|
|
425
|
-
describe("#deleteCalendarEvent()", () => {
|
|
426
|
-
it("should delete a calendar event", async () => {
|
|
427
|
-
const id = "abcdabcd-abcd-abcd-abcd-00000000";
|
|
428
|
-
const query = {};
|
|
429
|
-
|
|
430
|
-
webex.request = sinon.stub().resolves({
|
|
431
|
-
body: {}
|
|
432
|
-
});
|
|
433
|
-
|
|
434
|
-
await webex.internal.calendar.deleteCalendarEvent(id, query);
|
|
435
|
-
|
|
436
|
-
assert.calledWith(webex.request, {
|
|
437
|
-
method: "DELETE",
|
|
438
|
-
service: "calendar",
|
|
439
|
-
resource: `calendarEvents/${base64.encode(id)}/sync`,
|
|
440
|
-
qs: query
|
|
441
|
-
});
|
|
442
|
-
});
|
|
443
|
-
});
|
|
444
|
-
});
|
|
445
|
-
});
|
|
446
|
-
});
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { assert, expect } from "@webex/test-helper-chai";
|
|
6
|
+
import Calendar from '@webex/internal-plugin-calendar';
|
|
7
|
+
import MockWebex from '@webex/test-helper-mock-webex';
|
|
8
|
+
import { base64 } from "@webex/common";
|
|
9
|
+
import sinon from 'sinon';
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
CALENDAR_REGISTERED,
|
|
13
|
+
CALENDAR_UPDATED,
|
|
14
|
+
CALENDAR_DELETE,
|
|
15
|
+
CALENDAR_CREATE,
|
|
16
|
+
CALENDAR_UNREGISTERED,
|
|
17
|
+
} from '../../../src/constants';
|
|
18
|
+
|
|
19
|
+
describe('internal-plugin-calendar', () => {
|
|
20
|
+
describe('Calendar Apis', () => {
|
|
21
|
+
let webex;
|
|
22
|
+
|
|
23
|
+
beforeEach(async () => {
|
|
24
|
+
webex = new MockWebex({
|
|
25
|
+
children: {
|
|
26
|
+
calendar: Calendar,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
webex.canAuthorize = true;
|
|
31
|
+
webex.internal.device = {
|
|
32
|
+
register: sinon.stub().returns(Promise.resolve()),
|
|
33
|
+
unregister: sinon.stub().returns(Promise.resolve()),
|
|
34
|
+
};
|
|
35
|
+
webex.internal.mercury = {
|
|
36
|
+
connect: sinon.stub().returns(Promise.resolve()),
|
|
37
|
+
disconnect: sinon.stub().returns(Promise.resolve()),
|
|
38
|
+
on: sinon.stub().callsFake((event, callback) => {
|
|
39
|
+
if (event === 'event:calendar.meeting.update') {
|
|
40
|
+
callback({data: {calendarMeetingExternal: {id: 'calendarId1'}}});
|
|
41
|
+
}
|
|
42
|
+
if (event === 'event:calendar.meeting.delete') {
|
|
43
|
+
callback({data: {calendarMeetingExternal: {id: 'calendarId1'}}});
|
|
44
|
+
}
|
|
45
|
+
if (event === 'event:calendar.meeting.create') {
|
|
46
|
+
callback({data: {calendarMeetingExternal: {id: 'calendarId1'}}});
|
|
47
|
+
}
|
|
48
|
+
}),
|
|
49
|
+
off: sinon.spy(),
|
|
50
|
+
};
|
|
51
|
+
webex.internal.encryption = {
|
|
52
|
+
kms: {
|
|
53
|
+
createUnboundKeys: sinon.stub().resolves([{
|
|
54
|
+
uri: "kms://kms-us-int.wbx2.com/keys/xxxx-xxxx-xxxx-xxxx"
|
|
55
|
+
}])
|
|
56
|
+
},
|
|
57
|
+
encryptText: sinon.stub().resolves("encryptedText")
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('Public Api Contract', () => {
|
|
62
|
+
describe('#register()', () => {
|
|
63
|
+
it('on calendar register call mercury registration', async () => {
|
|
64
|
+
await webex.internal.calendar.register();
|
|
65
|
+
assert.calledOnce(webex.internal.device.register);
|
|
66
|
+
assert.callCount(webex.internal.mercury.on, 6);
|
|
67
|
+
assert.equal(webex.internal.calendar.registered, true);
|
|
68
|
+
});
|
|
69
|
+
it('should trigger `calendar:register` event', async () => {
|
|
70
|
+
const spy = sinon.spy();
|
|
71
|
+
|
|
72
|
+
webex.internal.calendar.on(CALENDAR_REGISTERED, spy);
|
|
73
|
+
await webex.internal.calendar.register();
|
|
74
|
+
assert.calledOnce(spy);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('Events', () => {
|
|
78
|
+
it('trigger `calendar:update` event', async () => {
|
|
79
|
+
const spy = sinon.spy();
|
|
80
|
+
|
|
81
|
+
webex.internal.calendar.on(CALENDAR_UPDATED, spy);
|
|
82
|
+
await webex.internal.calendar.register();
|
|
83
|
+
assert.calledOnce(spy);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('trigger `calendar:create` event', async () => {
|
|
87
|
+
const spy = sinon.spy();
|
|
88
|
+
|
|
89
|
+
webex.internal.calendar.on(CALENDAR_CREATE, spy);
|
|
90
|
+
await webex.internal.calendar.register();
|
|
91
|
+
assert.calledOnce(spy);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('trigger `calendar:delete` event', async () => {
|
|
95
|
+
const spy = sinon.spy();
|
|
96
|
+
|
|
97
|
+
webex.internal.calendar.on(CALENDAR_DELETE, spy);
|
|
98
|
+
await webex.internal.calendar.register();
|
|
99
|
+
assert.calledOnce(spy);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe('#unregister()', () => {
|
|
105
|
+
it('should call `mercury.unregister` and `device.unregister`', async () => {
|
|
106
|
+
await webex.internal.calendar.register();
|
|
107
|
+
await webex.internal.calendar.unregister();
|
|
108
|
+
assert.callCount(webex.internal.mercury.off, 6);
|
|
109
|
+
assert.calledOnce(webex.internal.mercury.disconnect);
|
|
110
|
+
assert.calledOnce(webex.internal.device.unregister);
|
|
111
|
+
});
|
|
112
|
+
it('should trigger `calendar:unregister` event', async () => {
|
|
113
|
+
const spy = sinon.spy();
|
|
114
|
+
|
|
115
|
+
// reseting the state back
|
|
116
|
+
await webex.internal.calendar.register();
|
|
117
|
+
webex.internal.calendar.on(CALENDAR_UNREGISTERED, spy);
|
|
118
|
+
await webex.internal.calendar.unregister();
|
|
119
|
+
assert.calledOnce(spy);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe('#syncCalendar()', () => {
|
|
124
|
+
it('should sync from calendar service', async () => {
|
|
125
|
+
webex.request = sinon
|
|
126
|
+
.stub()
|
|
127
|
+
.returns(Promise.resolve({body: {items: [{id: 'calendar1'}, {id: 'calendar2'}]}}));
|
|
128
|
+
webex.request = sinon.stub().returns(
|
|
129
|
+
Promise.resolve({
|
|
130
|
+
body: {
|
|
131
|
+
items: [
|
|
132
|
+
{
|
|
133
|
+
id: 'calendar1',
|
|
134
|
+
encryptedNotes: 'notes1',
|
|
135
|
+
encryptedParticipants: ['participant1'],
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
id: 'calendar2',
|
|
139
|
+
encryptedNotes: 'notes2',
|
|
140
|
+
encryptedParticipants: ['participant2'],
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
},
|
|
144
|
+
})
|
|
145
|
+
);
|
|
146
|
+
await webex.internal.calendar.syncCalendar({fromDate: 'xx-xx', toDate: 'xx-nn'});
|
|
147
|
+
assert.calledWith(webex.request, {
|
|
148
|
+
method: 'GET',
|
|
149
|
+
service: 'calendar',
|
|
150
|
+
resource: 'calendarEvents',
|
|
151
|
+
qs: {fromDate: 'xx-xx', toDate: 'xx-nn'},
|
|
152
|
+
});
|
|
153
|
+
assert.equal(webex.internal.calendar.getAll().length, 2);
|
|
154
|
+
assert.equal(webex.internal.calendar.getAll()[0].id, 'calendar1');
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe('#list()', () => {
|
|
159
|
+
it('should fetch the calendar list', async () => {
|
|
160
|
+
webex.request = sinon.stub().returns(
|
|
161
|
+
Promise.resolve({
|
|
162
|
+
body: {
|
|
163
|
+
items: [
|
|
164
|
+
{
|
|
165
|
+
id: 'calendar1',
|
|
166
|
+
encryptedNotes: 'notes1',
|
|
167
|
+
encryptedParticipants: ['participant1'],
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
id: 'calendar2',
|
|
171
|
+
encryptedNotes: 'notes2',
|
|
172
|
+
encryptedParticipants: ['participant2'],
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
},
|
|
176
|
+
})
|
|
177
|
+
);
|
|
178
|
+
const res = await webex.internal.calendar.list({fromDate: 'xx-xx', toDate: 'xx-nn'});
|
|
179
|
+
|
|
180
|
+
assert.equal(res.length, 2);
|
|
181
|
+
assert.calledWith(webex.request, {
|
|
182
|
+
method: 'GET',
|
|
183
|
+
service: 'calendar',
|
|
184
|
+
resource: 'calendarEvents',
|
|
185
|
+
qs: {fromDate: 'xx-xx', toDate: 'xx-nn'},
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it('should fetch the calendar list and resolves with null encryptedNotes', async () => {
|
|
190
|
+
const webexRequestStub = sinon.stub();
|
|
191
|
+
|
|
192
|
+
// calendar list stub
|
|
193
|
+
webexRequestStub
|
|
194
|
+
.withArgs({
|
|
195
|
+
method: 'GET',
|
|
196
|
+
service: 'calendar',
|
|
197
|
+
resource: 'calendarEvents',
|
|
198
|
+
qs: {fromDate: 'xx-xx', toDate: 'xx-nn'},
|
|
199
|
+
})
|
|
200
|
+
.returns(
|
|
201
|
+
Promise.resolve({
|
|
202
|
+
body: {
|
|
203
|
+
items: [
|
|
204
|
+
{id: 'calendar1', encryptedParticipants: ['participant1']},
|
|
205
|
+
{
|
|
206
|
+
id: 'calendar2',
|
|
207
|
+
encryptedNotes: 'notes2',
|
|
208
|
+
encryptedParticipants: ['participant2'],
|
|
209
|
+
},
|
|
210
|
+
],
|
|
211
|
+
},
|
|
212
|
+
})
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
// Assign webexRequestStub to webex.request
|
|
216
|
+
webex.request = webexRequestStub;
|
|
217
|
+
|
|
218
|
+
const res = await webex.internal.calendar.list({fromDate: 'xx-xx', toDate: 'xx-nn'});
|
|
219
|
+
|
|
220
|
+
assert.equal(res.length, 2);
|
|
221
|
+
assert.deepEqual(res, [
|
|
222
|
+
{id: 'calendar1', encryptedParticipants: ['participant1']},
|
|
223
|
+
{id: 'calendar2', encryptedNotes: 'notes2', encryptedParticipants: ['participant2']},
|
|
224
|
+
]);
|
|
225
|
+
assert.calledWith(webex.request, {
|
|
226
|
+
method: 'GET',
|
|
227
|
+
service: 'calendar',
|
|
228
|
+
resource: 'calendarEvents',
|
|
229
|
+
qs: {fromDate: 'xx-xx', toDate: 'xx-nn'},
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('should fetch the calendar list and resolves with fetched encryptedNotes', async () => {
|
|
234
|
+
const webexRequestStub = sinon.stub();
|
|
235
|
+
|
|
236
|
+
// calendar list stub
|
|
237
|
+
webexRequestStub
|
|
238
|
+
.withArgs({
|
|
239
|
+
method: 'GET',
|
|
240
|
+
service: 'calendar',
|
|
241
|
+
resource: 'calendarEvents',
|
|
242
|
+
qs: {fromDate: 'xx-xx', toDate: 'xx-nn'},
|
|
243
|
+
})
|
|
244
|
+
.returns(
|
|
245
|
+
Promise.resolve({
|
|
246
|
+
body: {
|
|
247
|
+
items: [
|
|
248
|
+
{id: 'calendar1', encryptedNotes: 'notes1', encryptedParticipants: ['participant1']},
|
|
249
|
+
{
|
|
250
|
+
id: 'calendar2',
|
|
251
|
+
encryptedNotes: 'notes2',
|
|
252
|
+
encryptedParticipants: ['participant2'],
|
|
253
|
+
},
|
|
254
|
+
],
|
|
255
|
+
},
|
|
256
|
+
})
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
// Assign webexRequestStub to webex.request
|
|
260
|
+
webex.request = webexRequestStub;
|
|
261
|
+
|
|
262
|
+
const res = await webex.internal.calendar.list({fromDate: 'xx-xx', toDate: 'xx-nn'});
|
|
263
|
+
|
|
264
|
+
assert.equal(res.length, 2);
|
|
265
|
+
assert.deepEqual(res, [
|
|
266
|
+
{id: 'calendar1', encryptedNotes: 'notes1', encryptedParticipants: ['participant1']},
|
|
267
|
+
{id: 'calendar2', encryptedNotes: 'notes2', encryptedParticipants: ['participant2']},
|
|
268
|
+
]);
|
|
269
|
+
assert.calledWith(webex.request, {
|
|
270
|
+
method: 'GET',
|
|
271
|
+
service: 'calendar',
|
|
272
|
+
resource: 'calendarEvents',
|
|
273
|
+
qs: {fromDate: 'xx-xx', toDate: 'xx-nn'},
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
describe('#getNotes()', () => {
|
|
279
|
+
it('should fetch the meeting notes', async () => {
|
|
280
|
+
const id = 'meetingId123';
|
|
281
|
+
|
|
282
|
+
webex.request = sinon.stub().returns(
|
|
283
|
+
Promise.resolve({
|
|
284
|
+
body: {
|
|
285
|
+
encryptedNotes: 'notes1',
|
|
286
|
+
},
|
|
287
|
+
})
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
const res = await webex.internal.calendar.getNotes(id);
|
|
291
|
+
|
|
292
|
+
assert.equal(res.body.encryptedNotes, 'notes1');
|
|
293
|
+
assert.calledWith(webex.request, {
|
|
294
|
+
method: 'GET',
|
|
295
|
+
service: 'calendar',
|
|
296
|
+
resource: `calendarEvents/${base64.encode(id)}/notes`,
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
describe('#getParticipants()', () => {
|
|
302
|
+
const id = 'meetingId123';
|
|
303
|
+
|
|
304
|
+
it('should fetch the meeting participants', async () => {
|
|
305
|
+
webex.request = sinon.stub().returns(
|
|
306
|
+
Promise.resolve({
|
|
307
|
+
body: {
|
|
308
|
+
encryptedParticipants: ['participant1'],
|
|
309
|
+
},
|
|
310
|
+
})
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
const res = await webex.internal.calendar.getParticipants(id);
|
|
314
|
+
|
|
315
|
+
assert.equal(res.body.encryptedParticipants.length, 1);
|
|
316
|
+
assert.calledWith(webex.request, {
|
|
317
|
+
method: 'GET',
|
|
318
|
+
service: 'calendar',
|
|
319
|
+
resource: `calendarEvents/${base64.encode(id)}/participants`,
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
describe("#getSchedulerData()", () => {
|
|
325
|
+
it("should fetch meeting calendar data", async () => {
|
|
326
|
+
const query = {
|
|
327
|
+
siteName: "scheduler01.dmz.webex.com",
|
|
328
|
+
clientMeetingId: "YWJjZGFiY2QtYWJjZC1hYmNkLWFiY2QtMDAwMDAwMDA"
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
webex.request = sinon.stub().resolves({
|
|
332
|
+
body: {
|
|
333
|
+
encryptedSubject: "My Meeting 1",
|
|
334
|
+
schedulerPreferences: {
|
|
335
|
+
uiControlAttributes: {
|
|
336
|
+
displayHostSaveMeetingTemplate: true
|
|
337
|
+
},
|
|
338
|
+
webexOptions: {
|
|
339
|
+
sessionTypeId: 3
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
const res = await webex.internal.calendar.getSchedulerData(query);
|
|
346
|
+
|
|
347
|
+
expect(res.body.encryptedSubject).to.equal("My Meeting 1");
|
|
348
|
+
expect(res.body.schedulerPreferences.uiControlAttributes.displayHostSaveMeetingTemplate).to.be.true;
|
|
349
|
+
expect(res.body.schedulerPreferences.webexOptions.sessionTypeId).to.equal(3);
|
|
350
|
+
assert.calledWith(webex.request, {
|
|
351
|
+
method: "GET",
|
|
352
|
+
service: "calendar",
|
|
353
|
+
resource: "schedulerData",
|
|
354
|
+
qs: {
|
|
355
|
+
siteName: query.siteName,
|
|
356
|
+
clientMeetingId: query.clientMeetingId
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
describe("#createCalendarEvent()", () => {
|
|
363
|
+
it("should create an calendar event", async () => {
|
|
364
|
+
const data = {
|
|
365
|
+
encryptionKeyUrl: "kms://kms-us-int.wbx2.com/keys/d1c14fc5-be10-4389-ae83-9521f92fbfd3",
|
|
366
|
+
notes: "This is Agenda",
|
|
367
|
+
subject: "My Meeting 1",
|
|
368
|
+
webexOptions: "{}"
|
|
369
|
+
};
|
|
370
|
+
const query = {};
|
|
371
|
+
|
|
372
|
+
webex.request = sinon.stub().resolves({
|
|
373
|
+
body: {
|
|
374
|
+
meetingId: "abcdabcd-abcd-abcd-abcd-00000000",
|
|
375
|
+
globalMeetingId: "xxxx-xxxx-xxxx-xxxx"
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
const res = await webex.internal.calendar.createCalendarEvent(data);
|
|
380
|
+
|
|
381
|
+
expect(res.body.meetingId).to.equal("abcdabcd-abcd-abcd-abcd-00000000");
|
|
382
|
+
expect(res.body.globalMeetingId).to.equal("xxxx-xxxx-xxxx-xxxx");
|
|
383
|
+
assert.calledWith(webex.request, {
|
|
384
|
+
method: "POST",
|
|
385
|
+
service: "calendar",
|
|
386
|
+
body: data,
|
|
387
|
+
resource: "calendarEvents/sync",
|
|
388
|
+
qs: query
|
|
389
|
+
});
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
describe("#updateCalendarEvent()", () => {
|
|
394
|
+
it("should update a calendar event", async () => {
|
|
395
|
+
const id = "abcdabcd-abcd-abcd-abcd-00000000";
|
|
396
|
+
const data = {
|
|
397
|
+
encryptionKeyUrl: "kms://kms-us-int.wbx2.com/keys/d1c14fc5-be10-4389-ae83-9521f92fbfd3",
|
|
398
|
+
notes: "This is Agenda",
|
|
399
|
+
subject: "My Meeting 1",
|
|
400
|
+
webexOptions: "{}"
|
|
401
|
+
};
|
|
402
|
+
const query = {};
|
|
403
|
+
|
|
404
|
+
webex.request = sinon.stub().resolves({
|
|
405
|
+
body: {
|
|
406
|
+
meetingId: "abcdabcd-abcd-abcd-abcd-00000000",
|
|
407
|
+
globalMeetingId: "xxxx-xxxx-xxxx-xxxx"
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
const res = await webex.internal.calendar.updateCalendarEvent(id, data);
|
|
412
|
+
|
|
413
|
+
expect(res.body.meetingId).to.equal("abcdabcd-abcd-abcd-abcd-00000000");
|
|
414
|
+
expect(res.body.globalMeetingId).to.equal("xxxx-xxxx-xxxx-xxxx");
|
|
415
|
+
assert.calledWith(webex.request, {
|
|
416
|
+
method: "PATCH",
|
|
417
|
+
service: "calendar",
|
|
418
|
+
body: data,
|
|
419
|
+
resource: `calendarEvents/${base64.encode(id)}/sync`,
|
|
420
|
+
qs: query
|
|
421
|
+
});
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
describe("#deleteCalendarEvent()", () => {
|
|
426
|
+
it("should delete a calendar event", async () => {
|
|
427
|
+
const id = "abcdabcd-abcd-abcd-abcd-00000000";
|
|
428
|
+
const query = {};
|
|
429
|
+
|
|
430
|
+
webex.request = sinon.stub().resolves({
|
|
431
|
+
body: {}
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
await webex.internal.calendar.deleteCalendarEvent(id, query);
|
|
435
|
+
|
|
436
|
+
assert.calledWith(webex.request, {
|
|
437
|
+
method: "DELETE",
|
|
438
|
+
service: "calendar",
|
|
439
|
+
resource: `calendarEvents/${base64.encode(id)}/sync`,
|
|
440
|
+
qs: query
|
|
441
|
+
});
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
});
|