@webex/internal-plugin-calendar 3.0.0-bnr.5 → 3.0.0-next.2

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,64 @@ 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
+ getKey: sinon.stub().resolves(undefined),
59
+ };
60
+ });
61
+
62
+ describe('Private API', () => {
63
+ describe('#prefetchEncryptionKey', () => {
64
+ it('waits for the ability to authorize before doing anything', () => {
65
+ webex.canAuthorize = false;
66
+
67
+ webex.internal.calendar.prefetchEncryptionKey();
68
+
69
+ assert.notCalled(webex.internal.encryption.kms.createUnboundKeys);
70
+
71
+ // Behaviour when the user can authorize is tested elsewhere, so just ensure it gets called again
72
+ const prefetchEncryptionKeyStub = sinon.stub(webex.internal.calendar, 'prefetchEncryptionKey');
73
+
74
+ webex.trigger('change:canAuthorize');
75
+
76
+ assert.calledOnce(prefetchEncryptionKeyStub);
77
+ assert.calledWith(prefetchEncryptionKeyStub);
78
+ });
79
+
80
+ it('does nothing when the current user is an unverified guest', () => {
81
+ webex.credentials.isUnverifiedGuest = true;
82
+
83
+ webex.internal.calendar.prefetchEncryptionKey();
84
+
85
+ assert.notCalled(webex.internal.encryption.kms.createUnboundKeys);
86
+ });
87
+
88
+ it('creates an encryption key when the current user can authorize', () => {
89
+ webex.internal.calendar.prefetchEncryptionKey();
90
+
91
+ assert.calledOnce(webex.internal.encryption.kms.createUnboundKeys);
92
+ assert.calledWith(webex.internal.encryption.kms.createUnboundKeys, {count: 1});
93
+ });
94
+ });
95
+
96
+ describe('#initialize', () => {
97
+ it('adds relevant handlers when webex is ready', () => {
98
+ const prefetchEncryptionKeyStub = sinon.stub(webex.internal.calendar, 'prefetchEncryptionKey');
99
+
100
+ assert.notCalled(prefetchEncryptionKeyStub);
101
+
102
+ // Initialize should have already run, so there should be an event handler already
103
+ webex.trigger('ready');
104
+
105
+ assert.calledOnce(prefetchEncryptionKeyStub);
106
+ assert.calledWith(prefetchEncryptionKeyStub);
107
+ });
108
+ });
51
109
  });
52
110
 
53
111
  describe('Public Api Contract', () => {
@@ -55,7 +113,7 @@ describe('internal-plugin-calendar', () => {
55
113
  it('on calendar register call mercury registration', async () => {
56
114
  await webex.internal.calendar.register();
57
115
  assert.calledOnce(webex.internal.device.register);
58
- assert.callCount(webex.internal.mercury.on, 5);
116
+ assert.callCount(webex.internal.mercury.on, 6);
59
117
  assert.equal(webex.internal.calendar.registered, true);
60
118
  });
61
119
  it('should trigger `calendar:register` event', async () => {
@@ -97,7 +155,7 @@ describe('internal-plugin-calendar', () => {
97
155
  it('should call `mercury.unregister` and `device.unregister`', async () => {
98
156
  await webex.internal.calendar.register();
99
157
  await webex.internal.calendar.unregister();
100
- assert.callCount(webex.internal.mercury.off, 5);
158
+ assert.callCount(webex.internal.mercury.off, 6);
101
159
  assert.calledOnce(webex.internal.mercury.disconnect);
102
160
  assert.calledOnce(webex.internal.device.unregister);
103
161
  });
@@ -203,18 +261,6 @@ describe('internal-plugin-calendar', () => {
203
261
  },
204
262
  })
205
263
  );
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
264
 
219
265
  // Assign webexRequestStub to webex.request
220
266
  webex.request = webexRequestStub;
@@ -223,7 +269,7 @@ describe('internal-plugin-calendar', () => {
223
269
 
224
270
  assert.equal(res.length, 2);
225
271
  assert.deepEqual(res, [
226
- {id: 'calendar1', encryptedNotes: null, encryptedParticipants: ['participant1']},
272
+ {id: 'calendar1', encryptedParticipants: ['participant1']},
227
273
  {id: 'calendar2', encryptedNotes: 'notes2', encryptedParticipants: ['participant2']},
228
274
  ]);
229
275
  assert.calledWith(webex.request, {
@@ -232,11 +278,6 @@ describe('internal-plugin-calendar', () => {
232
278
  resource: 'calendarEvents',
233
279
  qs: {fromDate: 'xx-xx', toDate: 'xx-nn'},
234
280
  });
235
- assert.calledWith(webex.request, {
236
- method: 'GET',
237
- service: 'calendar',
238
- resource: `calendarEvents/${btoa('calendar1')}/notes`,
239
- });
240
281
  });
241
282
 
242
283
  it('should fetch the calendar list and resolves with fetched encryptedNotes', async () => {
@@ -254,7 +295,7 @@ describe('internal-plugin-calendar', () => {
254
295
  Promise.resolve({
255
296
  body: {
256
297
  items: [
257
- {id: 'calendar1', encryptedParticipants: ['participant1']},
298
+ {id: 'calendar1', encryptedNotes: 'notes1', encryptedParticipants: ['participant1']},
258
299
  {
259
300
  id: 'calendar2',
260
301
  encryptedNotes: 'notes2',
@@ -264,20 +305,6 @@ describe('internal-plugin-calendar', () => {
264
305
  },
265
306
  })
266
307
  );
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
308
 
282
309
  // Assign webexRequestStub to webex.request
283
310
  webex.request = webexRequestStub;
@@ -295,11 +322,6 @@ describe('internal-plugin-calendar', () => {
295
322
  resource: 'calendarEvents',
296
323
  qs: {fromDate: 'xx-xx', toDate: 'xx-nn'},
297
324
  });
298
- assert.calledWith(webex.request, {
299
- method: 'GET',
300
- service: 'calendar',
301
- resource: `calendarEvents/${btoa('calendar1')}/notes`,
302
- });
303
325
  });
304
326
  });
305
327
 
@@ -321,13 +343,13 @@ describe('internal-plugin-calendar', () => {
321
343
  assert.calledWith(webex.request, {
322
344
  method: 'GET',
323
345
  service: 'calendar',
324
- resource: `calendarEvents/${btoa(id)}/notes`,
346
+ resource: `calendarEvents/${base64.encode(id)}/notes`,
325
347
  });
326
348
  });
327
349
  });
328
350
 
329
351
  describe('#getParticipants()', () => {
330
- const id = 'meetingId123';
352
+ const uri = 'participantsUrl';
331
353
 
332
354
  it('should fetch the meeting participants', async () => {
333
355
  webex.request = sinon.stub().returns(
@@ -338,13 +360,155 @@ describe('internal-plugin-calendar', () => {
338
360
  })
339
361
  );
340
362
 
341
- const res = await webex.internal.calendar.getParticipants(id);
363
+ const res = await webex.internal.calendar.getParticipants(uri);
342
364
 
343
365
  assert.equal(res.body.encryptedParticipants.length, 1);
344
366
  assert.calledWith(webex.request, {
345
367
  method: 'GET',
346
- service: 'calendar',
347
- resource: `calendarEvents/${btoa(id)}/participants`,
368
+ uri,
369
+ });
370
+ });
371
+ });
372
+
373
+ describe('#getNotesByUrl()', () => {
374
+ const uri = 'notesUrl';
375
+
376
+ it('should fetch the meeting notes', async () => {
377
+ webex.request = sinon.stub().returns(
378
+ Promise.resolve({
379
+ body: {
380
+ encryptedParticipants: ['participant1'],
381
+ },
382
+ })
383
+ );
384
+
385
+ const res = await webex.internal.calendar.getNotesByUrl(uri);
386
+
387
+ assert.equal(res.body.encryptedParticipants.length, 1);
388
+ assert.calledWith(webex.request, {
389
+ method: 'GET',
390
+ uri,
391
+ });
392
+ });
393
+ });
394
+
395
+ describe("#getSchedulerData()", () => {
396
+ it("should fetch meeting calendar data", async () => {
397
+ const query = {
398
+ siteName: "scheduler01.dmz.webex.com",
399
+ clientMeetingId: "YWJjZGFiY2QtYWJjZC1hYmNkLWFiY2QtMDAwMDAwMDA"
400
+ };
401
+
402
+ webex.request = sinon.stub().resolves({
403
+ body: {
404
+ encryptedSubject: "My Meeting 1",
405
+ schedulerPreferences: {
406
+ uiControlAttributes: {
407
+ displayHostSaveMeetingTemplate: true
408
+ },
409
+ webexOptions: {
410
+ sessionTypeId: 3
411
+ }
412
+ }
413
+ }
414
+ });
415
+
416
+ const res = await webex.internal.calendar.getSchedulerData(query);
417
+
418
+ expect(res.body.encryptedSubject).to.equal("My Meeting 1");
419
+ expect(res.body.schedulerPreferences.uiControlAttributes.displayHostSaveMeetingTemplate).to.be.true;
420
+ expect(res.body.schedulerPreferences.webexOptions.sessionTypeId).to.equal(3);
421
+ assert.calledWith(webex.request, {
422
+ method: "GET",
423
+ service: "calendar",
424
+ resource: "schedulerData",
425
+ qs: {
426
+ siteName: query.siteName,
427
+ clientMeetingId: query.clientMeetingId
428
+ }
429
+ });
430
+ });
431
+ });
432
+
433
+ describe("#createCalendarEvent()", () => {
434
+ it("should create an calendar event", async () => {
435
+ const data = {
436
+ encryptionKeyUrl: "kms://kms-us-int.wbx2.com/keys/d1c14fc5-be10-4389-ae83-9521f92fbfd3",
437
+ notes: "This is Agenda",
438
+ subject: "My Meeting 1",
439
+ webexOptions: "{}"
440
+ };
441
+ const query = {};
442
+
443
+ webex.request = sinon.stub().resolves({
444
+ body: {
445
+ meetingId: "abcdabcd-abcd-abcd-abcd-00000000",
446
+ globalMeetingId: "xxxx-xxxx-xxxx-xxxx"
447
+ }
448
+ });
449
+
450
+ const res = await webex.internal.calendar.createCalendarEvent(data);
451
+
452
+ expect(res.body.meetingId).to.equal("abcdabcd-abcd-abcd-abcd-00000000");
453
+ expect(res.body.globalMeetingId).to.equal("xxxx-xxxx-xxxx-xxxx");
454
+ assert.calledWith(webex.request, {
455
+ method: "POST",
456
+ service: "calendar",
457
+ body: data,
458
+ resource: "calendarEvents/sync",
459
+ qs: query
460
+ });
461
+ });
462
+ });
463
+
464
+ describe("#updateCalendarEvent()", () => {
465
+ it("should update a calendar event", async () => {
466
+ const id = "abcdabcd-abcd-abcd-abcd-00000000";
467
+ const data = {
468
+ encryptionKeyUrl: "kms://kms-us-int.wbx2.com/keys/d1c14fc5-be10-4389-ae83-9521f92fbfd3",
469
+ notes: "This is Agenda",
470
+ subject: "My Meeting 1",
471
+ webexOptions: "{}"
472
+ };
473
+ const query = {};
474
+
475
+ webex.request = sinon.stub().resolves({
476
+ body: {
477
+ meetingId: "abcdabcd-abcd-abcd-abcd-00000000",
478
+ globalMeetingId: "xxxx-xxxx-xxxx-xxxx"
479
+ }
480
+ });
481
+
482
+ const res = await webex.internal.calendar.updateCalendarEvent(id, data);
483
+
484
+ expect(res.body.meetingId).to.equal("abcdabcd-abcd-abcd-abcd-00000000");
485
+ expect(res.body.globalMeetingId).to.equal("xxxx-xxxx-xxxx-xxxx");
486
+ assert.calledWith(webex.request, {
487
+ method: "PATCH",
488
+ service: "calendar",
489
+ body: data,
490
+ resource: `calendarEvents/${base64.encode(id)}/sync`,
491
+ qs: query
492
+ });
493
+ });
494
+ });
495
+
496
+ describe("#deleteCalendarEvent()", () => {
497
+ it("should delete a calendar event", async () => {
498
+ const id = "abcdabcd-abcd-abcd-abcd-00000000";
499
+ const query = {};
500
+
501
+ webex.request = sinon.stub().resolves({
502
+ body: {}
503
+ });
504
+
505
+ await webex.internal.calendar.deleteCalendarEvent(id, query);
506
+
507
+ assert.calledWith(webex.request, {
508
+ method: "DELETE",
509
+ service: "calendar",
510
+ resource: `calendarEvents/${base64.encode(id)}/sync`,
511
+ qs: query
348
512
  });
349
513
  });
350
514
  });
@@ -1,4 +0,0 @@
1
- declare const Calendar: any;
2
- export default Calendar;
3
-
4
- export { }
@@ -1,11 +0,0 @@
1
- // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
- // It should be published with your NPM package. It should not be tracked by Git.
3
- {
4
- "tsdocVersion": "0.12",
5
- "toolPackages": [
6
- {
7
- "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.34.4"
9
- }
10
- ]
11
- }
@@ -1,2 +0,0 @@
1
- export default Calendar;
2
- declare const Calendar: any;
@@ -1,58 +0,0 @@
1
- export default CalendarCollection;
2
- declare namespace CalendarCollection {
3
- export { CALENDAR as namespace };
4
- export const items: {};
5
- /**
6
- * @param {String} id calendar ID
7
- * @returns {Any} Calendar Item specifc to that id
8
- * @private
9
- * @memberof CalendarCollection
10
- */
11
- export function get(id: string): Any;
12
- /**
13
- * @param {String} key any key and the corresponding calendar Item
14
- * @param {String} value any values corresponding to calendar item
15
- * @returns {Any} returns whatever is being stuffed into the collection
16
- * @private
17
- * @memberof CalendarCollection
18
- */
19
- export function getBy(key: string, value: string): Any;
20
- /**
21
- * @param {Object} item CalendarObject passed to the collection
22
- * @returns {Any} returns calender id whats get set
23
- * @private
24
- * @memberof CalendarCollection
25
- */
26
- export function set(item: any): Any;
27
- /**
28
- * resets all the values in the calendarcollection
29
- * @returns {undefined}
30
- * @private
31
- * @memberof CalendarCollection
32
- */
33
- export function reset(): undefined;
34
- /**
35
- * @param {Id} id is the id for the calendar item to be removed
36
- * @returns {Any} calendar item which got removed
37
- * @private
38
- * @memberof CalendarCollection
39
- */
40
- export function remove(id: Id): Any;
41
- /**
42
- * sets all the item passed to the collection
43
- * @param {Array} items array of calendar items
44
- * @private
45
- * @returns {undefined}
46
- * @memberof CalendarCollection
47
- */
48
- export function setAll(items: any[]): undefined;
49
- /**
50
- * gets all the calendar stored in the collection
51
- * @param {Array} items array of calendar items
52
- * @private
53
- * @returns {Array} returns an array of calendar items
54
- * @memberof CalendarCollection
55
- */
56
- export function getAll(): any[];
57
- }
58
- import { CALENDAR } from "./constants";
@@ -1,7 +0,0 @@
1
- declare namespace _default {
2
- namespace calendar {
3
- const fromDate: Date;
4
- const toDate: Date;
5
- }
6
- }
7
- export default _default;
@@ -1,6 +0,0 @@
1
- export const CALENDAR_REGISTERED: "calendar:registered";
2
- export const CALENDAR_UNREGISTERED: "calendar:unregistered";
3
- export const CALENDAR_UPDATED: "calendar:update";
4
- export const CALENDAR_DELETE: "calendar:delete";
5
- export const CALENDAR_CREATE: "calendar:create";
6
- export const CALENDAR: "CALENDAR";
@@ -1 +0,0 @@
1
- export { default } from "./calendar";
@@ -1,15 +0,0 @@
1
- export default CalendarUtil;
2
- declare namespace CalendarUtil {
3
- /**
4
- * calculates the end time for meeting
5
- * @param {Object} item the locus.host property
6
- * @param {Object} item.start start time of the meeting
7
- * @param {Object} item.duration duration of the meeting
8
- * @returns {Object} end time of the meeting
9
- * @memberof CalendarUtil
10
- */
11
- function calculateEndTime(item: {
12
- start: any;
13
- duration: any;
14
- }): any;
15
- }