@webex/internal-plugin-calendar 3.0.0-beta.31 → 3.0.0-beta.310

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.
@@ -2,10 +2,10 @@
2
2
  * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
3
  */
4
4
 
5
- import {assert} from '@webex/test-helper-chai';
5
+ import { assert, expect } from "@webex/test-helper-chai";
6
6
  import Calendar from '@webex/internal-plugin-calendar';
7
7
  import MockWebex from '@webex/test-helper-mock-webex';
8
- import btoa from 'btoa';
8
+ import { base64 } from "@webex/common";
9
9
  import sinon from 'sinon';
10
10
 
11
11
  import {
@@ -48,6 +48,14 @@ describe('internal-plugin-calendar', () => {
48
48
  }),
49
49
  off: sinon.spy(),
50
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
+ };
51
59
  });
52
60
 
53
61
  describe('Public Api Contract', () => {
@@ -55,7 +63,7 @@ describe('internal-plugin-calendar', () => {
55
63
  it('on calendar register call mercury registration', async () => {
56
64
  await webex.internal.calendar.register();
57
65
  assert.calledOnce(webex.internal.device.register);
58
- assert.callCount(webex.internal.mercury.on, 5);
66
+ assert.callCount(webex.internal.mercury.on, 6);
59
67
  assert.equal(webex.internal.calendar.registered, true);
60
68
  });
61
69
  it('should trigger `calendar:register` event', async () => {
@@ -97,7 +105,7 @@ describe('internal-plugin-calendar', () => {
97
105
  it('should call `mercury.unregister` and `device.unregister`', async () => {
98
106
  await webex.internal.calendar.register();
99
107
  await webex.internal.calendar.unregister();
100
- assert.callCount(webex.internal.mercury.off, 5);
108
+ assert.callCount(webex.internal.mercury.off, 6);
101
109
  assert.calledOnce(webex.internal.mercury.disconnect);
102
110
  assert.calledOnce(webex.internal.device.unregister);
103
111
  });
@@ -203,18 +211,6 @@ describe('internal-plugin-calendar', () => {
203
211
  },
204
212
  })
205
213
  );
206
- // getNotes stub
207
- webexRequestStub
208
- .withArgs({
209
- method: 'GET',
210
- service: 'calendar',
211
- resource: `calendarEvents/${btoa('calendar1')}/notes`,
212
- })
213
- .returns(
214
- Promise.resolve({
215
- body: null,
216
- })
217
- );
218
214
 
219
215
  // Assign webexRequestStub to webex.request
220
216
  webex.request = webexRequestStub;
@@ -223,7 +219,7 @@ describe('internal-plugin-calendar', () => {
223
219
 
224
220
  assert.equal(res.length, 2);
225
221
  assert.deepEqual(res, [
226
- {id: 'calendar1', encryptedNotes: null, encryptedParticipants: ['participant1']},
222
+ {id: 'calendar1', encryptedParticipants: ['participant1']},
227
223
  {id: 'calendar2', encryptedNotes: 'notes2', encryptedParticipants: ['participant2']},
228
224
  ]);
229
225
  assert.calledWith(webex.request, {
@@ -232,11 +228,6 @@ describe('internal-plugin-calendar', () => {
232
228
  resource: 'calendarEvents',
233
229
  qs: {fromDate: 'xx-xx', toDate: 'xx-nn'},
234
230
  });
235
- assert.calledWith(webex.request, {
236
- method: 'GET',
237
- service: 'calendar',
238
- resource: `calendarEvents/${btoa('calendar1')}/notes`,
239
- });
240
231
  });
241
232
 
242
233
  it('should fetch the calendar list and resolves with fetched encryptedNotes', async () => {
@@ -254,7 +245,7 @@ describe('internal-plugin-calendar', () => {
254
245
  Promise.resolve({
255
246
  body: {
256
247
  items: [
257
- {id: 'calendar1', encryptedParticipants: ['participant1']},
248
+ {id: 'calendar1', encryptedNotes: 'notes1', encryptedParticipants: ['participant1']},
258
249
  {
259
250
  id: 'calendar2',
260
251
  encryptedNotes: 'notes2',
@@ -264,20 +255,6 @@ describe('internal-plugin-calendar', () => {
264
255
  },
265
256
  })
266
257
  );
267
- // getNotes stub
268
- webexRequestStub
269
- .withArgs({
270
- method: 'GET',
271
- service: 'calendar',
272
- resource: `calendarEvents/${btoa('calendar1')}/notes`,
273
- })
274
- .returns(
275
- Promise.resolve({
276
- body: {
277
- encryptedNotes: 'notes1',
278
- },
279
- })
280
- );
281
258
 
282
259
  // Assign webexRequestStub to webex.request
283
260
  webex.request = webexRequestStub;
@@ -295,11 +272,6 @@ describe('internal-plugin-calendar', () => {
295
272
  resource: 'calendarEvents',
296
273
  qs: {fromDate: 'xx-xx', toDate: 'xx-nn'},
297
274
  });
298
- assert.calledWith(webex.request, {
299
- method: 'GET',
300
- service: 'calendar',
301
- resource: `calendarEvents/${btoa('calendar1')}/notes`,
302
- });
303
275
  });
304
276
  });
305
277
 
@@ -321,13 +293,13 @@ describe('internal-plugin-calendar', () => {
321
293
  assert.calledWith(webex.request, {
322
294
  method: 'GET',
323
295
  service: 'calendar',
324
- resource: `calendarEvents/${btoa(id)}/notes`,
296
+ resource: `calendarEvents/${base64.encode(id)}/notes`,
325
297
  });
326
298
  });
327
299
  });
328
300
 
329
301
  describe('#getParticipants()', () => {
330
- const id = 'meetingId123';
302
+ const uri = 'participantsUrl';
331
303
 
332
304
  it('should fetch the meeting participants', async () => {
333
305
  webex.request = sinon.stub().returns(
@@ -338,13 +310,155 @@ describe('internal-plugin-calendar', () => {
338
310
  })
339
311
  );
340
312
 
341
- const res = await webex.internal.calendar.getParticipants(id);
313
+ const res = await webex.internal.calendar.getParticipants(uri);
342
314
 
343
315
  assert.equal(res.body.encryptedParticipants.length, 1);
344
316
  assert.calledWith(webex.request, {
345
317
  method: 'GET',
346
- service: 'calendar',
347
- resource: `calendarEvents/${btoa(id)}/participants`,
318
+ uri,
319
+ });
320
+ });
321
+ });
322
+
323
+ describe('#getNotesByUrl()', () => {
324
+ const uri = 'notesUrl';
325
+
326
+ it('should fetch the meeting notes', async () => {
327
+ webex.request = sinon.stub().returns(
328
+ Promise.resolve({
329
+ body: {
330
+ encryptedParticipants: ['participant1'],
331
+ },
332
+ })
333
+ );
334
+
335
+ const res = await webex.internal.calendar.getNotesByUrl(uri);
336
+
337
+ assert.equal(res.body.encryptedParticipants.length, 1);
338
+ assert.calledWith(webex.request, {
339
+ method: 'GET',
340
+ uri,
341
+ });
342
+ });
343
+ });
344
+
345
+ describe("#getSchedulerData()", () => {
346
+ it("should fetch meeting calendar data", async () => {
347
+ const query = {
348
+ siteName: "scheduler01.dmz.webex.com",
349
+ clientMeetingId: "YWJjZGFiY2QtYWJjZC1hYmNkLWFiY2QtMDAwMDAwMDA"
350
+ };
351
+
352
+ webex.request = sinon.stub().resolves({
353
+ body: {
354
+ encryptedSubject: "My Meeting 1",
355
+ schedulerPreferences: {
356
+ uiControlAttributes: {
357
+ displayHostSaveMeetingTemplate: true
358
+ },
359
+ webexOptions: {
360
+ sessionTypeId: 3
361
+ }
362
+ }
363
+ }
364
+ });
365
+
366
+ const res = await webex.internal.calendar.getSchedulerData(query);
367
+
368
+ expect(res.body.encryptedSubject).to.equal("My Meeting 1");
369
+ expect(res.body.schedulerPreferences.uiControlAttributes.displayHostSaveMeetingTemplate).to.be.true;
370
+ expect(res.body.schedulerPreferences.webexOptions.sessionTypeId).to.equal(3);
371
+ assert.calledWith(webex.request, {
372
+ method: "GET",
373
+ service: "calendar",
374
+ resource: "schedulerData",
375
+ qs: {
376
+ siteName: query.siteName,
377
+ clientMeetingId: query.clientMeetingId
378
+ }
379
+ });
380
+ });
381
+ });
382
+
383
+ describe("#createCalendarEvent()", () => {
384
+ it("should create an calendar event", async () => {
385
+ const data = {
386
+ encryptionKeyUrl: "kms://kms-us-int.wbx2.com/keys/d1c14fc5-be10-4389-ae83-9521f92fbfd3",
387
+ notes: "This is Agenda",
388
+ subject: "My Meeting 1",
389
+ webexOptions: "{}"
390
+ };
391
+ const query = {};
392
+
393
+ webex.request = sinon.stub().resolves({
394
+ body: {
395
+ meetingId: "abcdabcd-abcd-abcd-abcd-00000000",
396
+ globalMeetingId: "xxxx-xxxx-xxxx-xxxx"
397
+ }
398
+ });
399
+
400
+ const res = await webex.internal.calendar.createCalendarEvent(data);
401
+
402
+ expect(res.body.meetingId).to.equal("abcdabcd-abcd-abcd-abcd-00000000");
403
+ expect(res.body.globalMeetingId).to.equal("xxxx-xxxx-xxxx-xxxx");
404
+ assert.calledWith(webex.request, {
405
+ method: "POST",
406
+ service: "calendar",
407
+ body: data,
408
+ resource: "calendarEvents/sync",
409
+ qs: query
410
+ });
411
+ });
412
+ });
413
+
414
+ describe("#updateCalendarEvent()", () => {
415
+ it("should update a calendar event", async () => {
416
+ const id = "abcdabcd-abcd-abcd-abcd-00000000";
417
+ const data = {
418
+ encryptionKeyUrl: "kms://kms-us-int.wbx2.com/keys/d1c14fc5-be10-4389-ae83-9521f92fbfd3",
419
+ notes: "This is Agenda",
420
+ subject: "My Meeting 1",
421
+ webexOptions: "{}"
422
+ };
423
+ const query = {};
424
+
425
+ webex.request = sinon.stub().resolves({
426
+ body: {
427
+ meetingId: "abcdabcd-abcd-abcd-abcd-00000000",
428
+ globalMeetingId: "xxxx-xxxx-xxxx-xxxx"
429
+ }
430
+ });
431
+
432
+ const res = await webex.internal.calendar.updateCalendarEvent(id, data);
433
+
434
+ expect(res.body.meetingId).to.equal("abcdabcd-abcd-abcd-abcd-00000000");
435
+ expect(res.body.globalMeetingId).to.equal("xxxx-xxxx-xxxx-xxxx");
436
+ assert.calledWith(webex.request, {
437
+ method: "PATCH",
438
+ service: "calendar",
439
+ body: data,
440
+ resource: `calendarEvents/${base64.encode(id)}/sync`,
441
+ qs: query
442
+ });
443
+ });
444
+ });
445
+
446
+ describe("#deleteCalendarEvent()", () => {
447
+ it("should delete a calendar event", async () => {
448
+ const id = "abcdabcd-abcd-abcd-abcd-00000000";
449
+ const query = {};
450
+
451
+ webex.request = sinon.stub().resolves({
452
+ body: {}
453
+ });
454
+
455
+ await webex.internal.calendar.deleteCalendarEvent(id, query);
456
+
457
+ assert.calledWith(webex.request, {
458
+ method: "DELETE",
459
+ service: "calendar",
460
+ resource: `calendarEvents/${base64.encode(id)}/sync`,
461
+ qs: query
348
462
  });
349
463
  });
350
464
  });