@webex/internal-plugin-calendar 3.0.0-beta.39 → 3.0.0-beta.391

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,63 @@ 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
+ };
59
+ });
60
+
61
+ describe('Private API', () => {
62
+ describe('#prefetchEncryptionKey', () => {
63
+ it('waits for the ability to authorize before doing anything', () => {
64
+ webex.canAuthorize = false;
65
+
66
+ webex.internal.calendar.prefetchEncryptionKey();
67
+
68
+ assert.notCalled(webex.internal.encryption.kms.createUnboundKeys);
69
+
70
+ // Behaviour when the user can authorize is tested elsewhere, so just ensure it gets called again
71
+ const prefetchEncryptionKeyStub = sinon.stub(webex.internal.calendar, 'prefetchEncryptionKey');
72
+
73
+ webex.trigger('change:canAuthorize');
74
+
75
+ assert.calledOnce(prefetchEncryptionKeyStub);
76
+ assert.calledWith(prefetchEncryptionKeyStub);
77
+ });
78
+
79
+ it('does nothing when the current user is an unverified guest', () => {
80
+ webex.credentials.isUnverifiedGuest = true;
81
+
82
+ webex.internal.calendar.prefetchEncryptionKey();
83
+
84
+ assert.notCalled(webex.internal.encryption.kms.createUnboundKeys);
85
+ });
86
+
87
+ it('creates an encryption key when the current user can authorize', () => {
88
+ webex.internal.calendar.prefetchEncryptionKey();
89
+
90
+ assert.calledOnce(webex.internal.encryption.kms.createUnboundKeys);
91
+ assert.calledWith(webex.internal.encryption.kms.createUnboundKeys, {count: 1});
92
+ });
93
+ });
94
+
95
+ describe('#initialize', () => {
96
+ it('adds relevant handlers when webex is ready', () => {
97
+ const prefetchEncryptionKeyStub = sinon.stub(webex.internal.calendar, 'prefetchEncryptionKey');
98
+
99
+ assert.notCalled(prefetchEncryptionKeyStub);
100
+
101
+ // Initialize should have already run, so there should be an event handler already
102
+ webex.trigger('ready');
103
+
104
+ assert.calledOnce(prefetchEncryptionKeyStub);
105
+ assert.calledWith(prefetchEncryptionKeyStub);
106
+ });
107
+ });
51
108
  });
52
109
 
53
110
  describe('Public Api Contract', () => {
@@ -55,7 +112,7 @@ describe('internal-plugin-calendar', () => {
55
112
  it('on calendar register call mercury registration', async () => {
56
113
  await webex.internal.calendar.register();
57
114
  assert.calledOnce(webex.internal.device.register);
58
- assert.callCount(webex.internal.mercury.on, 5);
115
+ assert.callCount(webex.internal.mercury.on, 6);
59
116
  assert.equal(webex.internal.calendar.registered, true);
60
117
  });
61
118
  it('should trigger `calendar:register` event', async () => {
@@ -97,7 +154,7 @@ describe('internal-plugin-calendar', () => {
97
154
  it('should call `mercury.unregister` and `device.unregister`', async () => {
98
155
  await webex.internal.calendar.register();
99
156
  await webex.internal.calendar.unregister();
100
- assert.callCount(webex.internal.mercury.off, 5);
157
+ assert.callCount(webex.internal.mercury.off, 6);
101
158
  assert.calledOnce(webex.internal.mercury.disconnect);
102
159
  assert.calledOnce(webex.internal.device.unregister);
103
160
  });
@@ -203,18 +260,6 @@ describe('internal-plugin-calendar', () => {
203
260
  },
204
261
  })
205
262
  );
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
263
 
219
264
  // Assign webexRequestStub to webex.request
220
265
  webex.request = webexRequestStub;
@@ -223,7 +268,7 @@ describe('internal-plugin-calendar', () => {
223
268
 
224
269
  assert.equal(res.length, 2);
225
270
  assert.deepEqual(res, [
226
- {id: 'calendar1', encryptedNotes: null, encryptedParticipants: ['participant1']},
271
+ {id: 'calendar1', encryptedParticipants: ['participant1']},
227
272
  {id: 'calendar2', encryptedNotes: 'notes2', encryptedParticipants: ['participant2']},
228
273
  ]);
229
274
  assert.calledWith(webex.request, {
@@ -232,11 +277,6 @@ describe('internal-plugin-calendar', () => {
232
277
  resource: 'calendarEvents',
233
278
  qs: {fromDate: 'xx-xx', toDate: 'xx-nn'},
234
279
  });
235
- assert.calledWith(webex.request, {
236
- method: 'GET',
237
- service: 'calendar',
238
- resource: `calendarEvents/${btoa('calendar1')}/notes`,
239
- });
240
280
  });
241
281
 
242
282
  it('should fetch the calendar list and resolves with fetched encryptedNotes', async () => {
@@ -254,7 +294,7 @@ describe('internal-plugin-calendar', () => {
254
294
  Promise.resolve({
255
295
  body: {
256
296
  items: [
257
- {id: 'calendar1', encryptedParticipants: ['participant1']},
297
+ {id: 'calendar1', encryptedNotes: 'notes1', encryptedParticipants: ['participant1']},
258
298
  {
259
299
  id: 'calendar2',
260
300
  encryptedNotes: 'notes2',
@@ -264,20 +304,6 @@ describe('internal-plugin-calendar', () => {
264
304
  },
265
305
  })
266
306
  );
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
307
 
282
308
  // Assign webexRequestStub to webex.request
283
309
  webex.request = webexRequestStub;
@@ -295,11 +321,6 @@ describe('internal-plugin-calendar', () => {
295
321
  resource: 'calendarEvents',
296
322
  qs: {fromDate: 'xx-xx', toDate: 'xx-nn'},
297
323
  });
298
- assert.calledWith(webex.request, {
299
- method: 'GET',
300
- service: 'calendar',
301
- resource: `calendarEvents/${btoa('calendar1')}/notes`,
302
- });
303
324
  });
304
325
  });
305
326
 
@@ -321,13 +342,13 @@ describe('internal-plugin-calendar', () => {
321
342
  assert.calledWith(webex.request, {
322
343
  method: 'GET',
323
344
  service: 'calendar',
324
- resource: `calendarEvents/${btoa(id)}/notes`,
345
+ resource: `calendarEvents/${base64.encode(id)}/notes`,
325
346
  });
326
347
  });
327
348
  });
328
349
 
329
350
  describe('#getParticipants()', () => {
330
- const id = 'meetingId123';
351
+ const uri = 'participantsUrl';
331
352
 
332
353
  it('should fetch the meeting participants', async () => {
333
354
  webex.request = sinon.stub().returns(
@@ -338,13 +359,155 @@ describe('internal-plugin-calendar', () => {
338
359
  })
339
360
  );
340
361
 
341
- const res = await webex.internal.calendar.getParticipants(id);
362
+ const res = await webex.internal.calendar.getParticipants(uri);
342
363
 
343
364
  assert.equal(res.body.encryptedParticipants.length, 1);
344
365
  assert.calledWith(webex.request, {
345
366
  method: 'GET',
346
- service: 'calendar',
347
- resource: `calendarEvents/${btoa(id)}/participants`,
367
+ uri,
368
+ });
369
+ });
370
+ });
371
+
372
+ describe('#getNotesByUrl()', () => {
373
+ const uri = 'notesUrl';
374
+
375
+ it('should fetch the meeting notes', async () => {
376
+ webex.request = sinon.stub().returns(
377
+ Promise.resolve({
378
+ body: {
379
+ encryptedParticipants: ['participant1'],
380
+ },
381
+ })
382
+ );
383
+
384
+ const res = await webex.internal.calendar.getNotesByUrl(uri);
385
+
386
+ assert.equal(res.body.encryptedParticipants.length, 1);
387
+ assert.calledWith(webex.request, {
388
+ method: 'GET',
389
+ uri,
390
+ });
391
+ });
392
+ });
393
+
394
+ describe("#getSchedulerData()", () => {
395
+ it("should fetch meeting calendar data", async () => {
396
+ const query = {
397
+ siteName: "scheduler01.dmz.webex.com",
398
+ clientMeetingId: "YWJjZGFiY2QtYWJjZC1hYmNkLWFiY2QtMDAwMDAwMDA"
399
+ };
400
+
401
+ webex.request = sinon.stub().resolves({
402
+ body: {
403
+ encryptedSubject: "My Meeting 1",
404
+ schedulerPreferences: {
405
+ uiControlAttributes: {
406
+ displayHostSaveMeetingTemplate: true
407
+ },
408
+ webexOptions: {
409
+ sessionTypeId: 3
410
+ }
411
+ }
412
+ }
413
+ });
414
+
415
+ const res = await webex.internal.calendar.getSchedulerData(query);
416
+
417
+ expect(res.body.encryptedSubject).to.equal("My Meeting 1");
418
+ expect(res.body.schedulerPreferences.uiControlAttributes.displayHostSaveMeetingTemplate).to.be.true;
419
+ expect(res.body.schedulerPreferences.webexOptions.sessionTypeId).to.equal(3);
420
+ assert.calledWith(webex.request, {
421
+ method: "GET",
422
+ service: "calendar",
423
+ resource: "schedulerData",
424
+ qs: {
425
+ siteName: query.siteName,
426
+ clientMeetingId: query.clientMeetingId
427
+ }
428
+ });
429
+ });
430
+ });
431
+
432
+ describe("#createCalendarEvent()", () => {
433
+ it("should create an calendar event", async () => {
434
+ const data = {
435
+ encryptionKeyUrl: "kms://kms-us-int.wbx2.com/keys/d1c14fc5-be10-4389-ae83-9521f92fbfd3",
436
+ notes: "This is Agenda",
437
+ subject: "My Meeting 1",
438
+ webexOptions: "{}"
439
+ };
440
+ const query = {};
441
+
442
+ webex.request = sinon.stub().resolves({
443
+ body: {
444
+ meetingId: "abcdabcd-abcd-abcd-abcd-00000000",
445
+ globalMeetingId: "xxxx-xxxx-xxxx-xxxx"
446
+ }
447
+ });
448
+
449
+ const res = await webex.internal.calendar.createCalendarEvent(data);
450
+
451
+ expect(res.body.meetingId).to.equal("abcdabcd-abcd-abcd-abcd-00000000");
452
+ expect(res.body.globalMeetingId).to.equal("xxxx-xxxx-xxxx-xxxx");
453
+ assert.calledWith(webex.request, {
454
+ method: "POST",
455
+ service: "calendar",
456
+ body: data,
457
+ resource: "calendarEvents/sync",
458
+ qs: query
459
+ });
460
+ });
461
+ });
462
+
463
+ describe("#updateCalendarEvent()", () => {
464
+ it("should update a calendar event", async () => {
465
+ const id = "abcdabcd-abcd-abcd-abcd-00000000";
466
+ const data = {
467
+ encryptionKeyUrl: "kms://kms-us-int.wbx2.com/keys/d1c14fc5-be10-4389-ae83-9521f92fbfd3",
468
+ notes: "This is Agenda",
469
+ subject: "My Meeting 1",
470
+ webexOptions: "{}"
471
+ };
472
+ const query = {};
473
+
474
+ webex.request = sinon.stub().resolves({
475
+ body: {
476
+ meetingId: "abcdabcd-abcd-abcd-abcd-00000000",
477
+ globalMeetingId: "xxxx-xxxx-xxxx-xxxx"
478
+ }
479
+ });
480
+
481
+ const res = await webex.internal.calendar.updateCalendarEvent(id, data);
482
+
483
+ expect(res.body.meetingId).to.equal("abcdabcd-abcd-abcd-abcd-00000000");
484
+ expect(res.body.globalMeetingId).to.equal("xxxx-xxxx-xxxx-xxxx");
485
+ assert.calledWith(webex.request, {
486
+ method: "PATCH",
487
+ service: "calendar",
488
+ body: data,
489
+ resource: `calendarEvents/${base64.encode(id)}/sync`,
490
+ qs: query
491
+ });
492
+ });
493
+ });
494
+
495
+ describe("#deleteCalendarEvent()", () => {
496
+ it("should delete a calendar event", async () => {
497
+ const id = "abcdabcd-abcd-abcd-abcd-00000000";
498
+ const query = {};
499
+
500
+ webex.request = sinon.stub().resolves({
501
+ body: {}
502
+ });
503
+
504
+ await webex.internal.calendar.deleteCalendarEvent(id, query);
505
+
506
+ assert.calledWith(webex.request, {
507
+ method: "DELETE",
508
+ service: "calendar",
509
+ resource: `calendarEvents/${base64.encode(id)}/sync`,
510
+ qs: query
348
511
  });
349
512
  });
350
513
  });