@webex/plugin-rooms 3.0.0-beta.9 → 3.0.0-bnr.0

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.
@@ -8,11 +8,7 @@ import '@webex/plugin-rooms';
8
8
  import '@webex/plugin-memberships';
9
9
  import '@webex/plugin-messages';
10
10
  import WebexCore, {WebexHttpError} from '@webex/webex-core';
11
- import {
12
- SDK_EVENT,
13
- hydraTypes,
14
- constructHydraId
15
- } from '@webex/common';
11
+ import {SDK_EVENT, hydraTypes, constructHydraId} from '@webex/common';
16
12
  import {assert} from '@webex/test-helper-chai';
17
13
  import sinon from 'sinon';
18
14
  import testUsers from '@webex/test-helper-test-users';
@@ -24,21 +20,21 @@ describe('plugin-rooms', function () {
24
20
 
25
21
  let webex, actor;
26
22
 
27
- before(() => testUsers.create({count: 1})
28
- .then(async ([user]) => {
23
+ before(() =>
24
+ testUsers.create({count: 1}).then(async ([user]) => {
29
25
  // Pause for 5 seconds for CI
30
26
  await new Promise((done) => setTimeout(done, 5000));
31
27
 
32
28
  webex = new WebexCore({credentials: user.token});
33
29
 
34
- return webex.people.get('me')
35
- .then((person) => {
36
- actor = person;
37
- debug('SDK User (Actor) for tests:');
38
- debug(`- name: ${actor.displayName}`);
39
- debug(`- id: ${actor.id}`);
40
- });
41
- }));
30
+ return webex.people.get('me').then((person) => {
31
+ actor = person;
32
+ debug('SDK User (Actor) for tests:');
33
+ debug(`- name: ${actor.displayName}`);
34
+ debug(`- id: ${actor.id}`);
35
+ });
36
+ })
37
+ );
42
38
 
43
39
  describe('#rooms', () => {
44
40
  const rooms = [];
@@ -48,15 +44,17 @@ describe('plugin-rooms', function () {
48
44
  webex.rooms.off('created');
49
45
  webex.rooms.off('updated');
50
46
 
51
- return Promise.all(rooms.map((room) => webex.rooms.remove(room)
52
- .catch((reason) => {
53
- console.error('Failed to delete room', reason);
54
- })))
55
- .then(() => {
56
- while (rooms.length) {
57
- rooms.pop();
58
- }
59
- });
47
+ return Promise.all(
48
+ rooms.map((room) =>
49
+ webex.rooms.remove(room).catch((reason) => {
50
+ console.error('Failed to delete room', reason);
51
+ })
52
+ )
53
+ ).then(() => {
54
+ while (rooms.length) {
55
+ rooms.pop();
56
+ }
57
+ });
60
58
  });
61
59
 
62
60
  describe('#create()', () => {
@@ -68,23 +66,23 @@ describe('plugin-rooms', function () {
68
66
  });
69
67
  });
70
68
 
71
- return webex.rooms.listen()
72
- .then(() => webex.rooms.create({title: 'Webex Test Room'})
73
- .then(async (room) => {
74
- assert.isRoom(room);
75
- rooms.push(room); // for future cleanup
76
- const event = await createdEventPromise;
69
+ return webex.rooms.listen().then(() =>
70
+ webex.rooms.create({title: 'Webex Test Room'}).then(async (room) => {
71
+ assert.isRoom(room);
72
+ rooms.push(room); // for future cleanup
73
+ const event = await createdEventPromise;
77
74
 
78
- validateRoomEvent(event, room, actor);
79
- }));
75
+ validateRoomEvent(event, room, actor);
76
+ })
77
+ );
80
78
  });
81
79
  });
82
80
 
83
81
  describe('#one-on-one()', () => {
84
82
  let user1, room;
85
83
 
86
- before(() => testUsers.create({count: 1})
87
- .then(async (users) => {
84
+ before(() =>
85
+ testUsers.create({count: 1}).then(async (users) => {
88
86
  // Pause for 5 seconds for CI
89
87
  await new Promise((done) => setTimeout(done, 5000));
90
88
 
@@ -92,7 +90,8 @@ describe('plugin-rooms', function () {
92
90
  debug('Test User for One-on-One room:');
93
91
  debug(`- name: ${user1.displayName}`);
94
92
  debug(`- id: ${constructHydraId(hydraTypes.PEOPLE, user1.id)}`);
95
- }));
93
+ })
94
+ );
96
95
 
97
96
  // We need a one-on-on space for this test
98
97
  // We create it by sending a message to the test user
@@ -105,11 +104,12 @@ describe('plugin-rooms', function () {
105
104
  });
106
105
  });
107
106
 
108
- return webex.rooms.listen()
109
- .then(() => webex.messages.create({
110
- toPersonId: user1.id,
111
- text: 'Message to start a one-on-on space'
112
- })
107
+ return webex.rooms.listen().then(() =>
108
+ webex.messages
109
+ .create({
110
+ toPersonId: user1.id,
111
+ text: 'Message to start a one-on-on space',
112
+ })
113
113
  .then((message) => {
114
114
  assert.exists(message.roomId);
115
115
 
@@ -121,27 +121,28 @@ describe('plugin-rooms', function () {
121
121
  const event = await createdEventPromise;
122
122
 
123
123
  validateRoomEvent(event, room, actor);
124
- }));
124
+ })
125
+ );
125
126
  });
126
127
  });
127
128
 
128
129
  describe('#get()', () => {
129
130
  let room0;
130
131
 
131
- beforeEach(() => Promise.all([
132
- webex.rooms.create({title: 'Webex Test Room 1'})
133
- .then((room) => {
132
+ beforeEach(() =>
133
+ Promise.all([
134
+ webex.rooms.create({title: 'Webex Test Room 1'}).then((room) => {
134
135
  rooms.push(room);
135
136
  }),
136
- webex.rooms.create({title: 'Webex Test Room 0'})
137
- .then((room) => {
137
+ webex.rooms.create({title: 'Webex Test Room 0'}).then((room) => {
138
138
  rooms.push(room);
139
139
  room0 = room;
140
- })
141
- ]));
140
+ }),
141
+ ])
142
+ );
142
143
 
143
- it('retrieves a specific room', () => webex.rooms.get(room0)
144
- .then((room) => {
144
+ it('retrieves a specific room', () =>
145
+ webex.rooms.get(room0).then((room) => {
145
146
  assert.isRoom(room);
146
147
 
147
148
  assert.equal(room.id, room0.id);
@@ -154,33 +155,36 @@ describe('plugin-rooms', function () {
154
155
  // the tests rely on ordering.
155
156
  let room0, room1;
156
157
 
157
- beforeEach(() => webex.rooms.create({title: 'Webex Test Room 1'})
158
- .then((room) => {
158
+ beforeEach(() =>
159
+ webex.rooms.create({title: 'Webex Test Room 1'}).then((room) => {
159
160
  rooms.push(room);
160
161
  room1 = room;
161
- }));
162
+ })
163
+ );
162
164
 
163
- beforeEach(() => webex.rooms.create({title: 'Webex Test Room 0'})
164
- .then((room) => {
165
+ beforeEach(() =>
166
+ webex.rooms.create({title: 'Webex Test Room 0'}).then((room) => {
165
167
  rooms.push(room);
166
168
  room0 = room;
167
- }));
169
+ })
170
+ );
168
171
 
169
- it('retrieves all the rooms to which I have access', () => webex.rooms.list()
170
- .then((rooms) => {
172
+ it('retrieves all the rooms to which I have access', () =>
173
+ webex.rooms.list().then((rooms) => {
171
174
  for (const room of rooms) {
172
175
  assert.isRoom(room);
173
176
  }
174
- assert.equal(rooms.items[0].id, room0.id, 'Room 0\'s id matches');
175
- assert.equal(rooms.items[0].title, room0.title, 'Room 0\'s title matches');
176
- assert.equal(rooms.items[1].id, room1.id, 'Room 1\'s id matches');
177
- assert.equal(rooms.items[1].title, room1.title, 'Room 1\'s title matches');
177
+ assert.equal(rooms.items[0].id, room0.id, "Room 0's id matches");
178
+ assert.equal(rooms.items[0].title, room0.title, "Room 0's title matches");
179
+ assert.equal(rooms.items[1].id, room1.id, "Room 1's id matches");
180
+ assert.equal(rooms.items[1].title, room1.title, "Room 1's title matches");
178
181
  }));
179
182
 
180
183
  it('retrieves a bounded, pageable set of rooms to which I have access', () => {
181
184
  const spy = sinon.spy();
182
185
 
183
- return webex.rooms.list({max: 1})
186
+ return webex.rooms
187
+ .list({max: 1})
184
188
  .then((rooms) => {
185
189
  assert.lengthOf(rooms, 1);
186
190
 
@@ -194,7 +198,7 @@ describe('plugin-rooms', function () {
194
198
  }
195
199
 
196
200
  return Promise.resolve();
197
- }(rooms));
201
+ })(rooms);
198
202
  })
199
203
  .then(() => {
200
204
  assert.isAbove(spy.callCount, 1);
@@ -207,46 +211,56 @@ describe('plugin-rooms', function () {
207
211
  describe('#getWithReadStatus()', () => {
208
212
  let room1, user2;
209
213
 
210
- before(() => testUsers.create({count: 1})
211
- .then(async ([user]) => {
214
+ before(() =>
215
+ testUsers.create({count: 1}).then(async ([user]) => {
212
216
  // Pause for 5 seconds for CI
213
217
  await new Promise((done) => setTimeout(done, 5000));
214
218
 
215
219
  user2 = user;
216
220
  user2.webex = new WebexCore({credentials: user2.token});
217
- }));
221
+ })
222
+ );
218
223
 
219
224
  // Create a space with one user who is "caught up" and another "behind"
220
- beforeEach(() => webex.rooms.create({title: 'Space to get Read Status from'})
221
- .then((room) => {
222
- rooms.push(room);
223
- room1 = room;
225
+ beforeEach(() =>
226
+ webex.rooms
227
+ .create({title: 'Space to get Read Status from'})
228
+ .then((room) => {
229
+ rooms.push(room);
230
+ room1 = room;
224
231
 
225
- return webex.memberships.create({
226
- roomId: room1.id,
227
- personId: user2.id
228
- });
229
- })
230
- // User 1 will post a message, that user2 won't have seen
231
- .then(() => webex.messages.create({
232
- roomId: room1.id,
233
- text: 'First message in room 1 from User 1'
234
- })));
235
-
236
- it('gets the read status for new room for user1', () => webex.rooms.getWithReadStatus(room1.id)
237
- .then((roomInfo) => {
238
- assert.equal(roomInfo.id, room1.id, 'Room 1\'s title matches');
239
- assert.equal(roomInfo.title, room1.title, 'Room 1\'s title matches');
240
- assert.isTrue(roomInfo.lastSeenActivityDate >= roomInfo.lastActivityDate,
241
- 'Room 1 is read for User 1');
232
+ return webex.memberships.create({
233
+ roomId: room1.id,
234
+ personId: user2.id,
235
+ });
236
+ })
237
+ // User 1 will post a message, that user2 won't have seen
238
+ .then(() =>
239
+ webex.messages.create({
240
+ roomId: room1.id,
241
+ text: 'First message in room 1 from User 1',
242
+ })
243
+ )
244
+ );
245
+
246
+ it('gets the read status for new room for user1', () =>
247
+ webex.rooms.getWithReadStatus(room1.id).then((roomInfo) => {
248
+ assert.equal(roomInfo.id, room1.id, "Room 1's title matches");
249
+ assert.equal(roomInfo.title, room1.title, "Room 1's title matches");
250
+ assert.isTrue(
251
+ roomInfo.lastSeenActivityDate >= roomInfo.lastActivityDate,
252
+ 'Room 1 is read for User 1'
253
+ );
242
254
  }));
243
255
 
244
- it('gets the read status for a new room for user2', () => user2.webex.rooms.getWithReadStatus(room1.id)
245
- .then((roomInfo) => {
246
- assert.equal(roomInfo.id, room1.id, 'Room 1\'s title matches');
247
- assert.equal(roomInfo.title, room1.title, 'Room 1\'s title matches');
248
- assert.isTrue(roomInfo.lastSeenActivityDate < roomInfo.lastActivityDate,
249
- 'Room 1 is unread for User 2');
256
+ it('gets the read status for a new room for user2', () =>
257
+ user2.webex.rooms.getWithReadStatus(room1.id).then((roomInfo) => {
258
+ assert.equal(roomInfo.id, room1.id, "Room 1's title matches");
259
+ assert.equal(roomInfo.title, room1.title, "Room 1's title matches");
260
+ assert.isTrue(
261
+ roomInfo.lastSeenActivityDate < roomInfo.lastActivityDate,
262
+ 'Room 1 is unread for User 2'
263
+ );
250
264
  }));
251
265
  });
252
266
 
@@ -255,83 +269,100 @@ describe('plugin-rooms', function () {
255
269
  // the tests rely on ordering.
256
270
  let room1, room2, user2;
257
271
 
258
- before(() => testUsers.create({count: 1})
259
- .then(async ([user]) => {
272
+ before(() =>
273
+ testUsers.create({count: 1}).then(async ([user]) => {
260
274
  // Pause for 5 seconds for CI
261
275
  await new Promise((done) => setTimeout(done, 5000));
262
276
 
263
277
  user2 = user;
264
278
  user2.webex = new WebexCore({credentials: user2.token});
265
- }));
279
+ })
280
+ );
266
281
 
267
282
  // Create two spaces with a message from each user in one of them
268
- beforeEach(() => webex.rooms.create({title: 'Unread Message for User 2'})
269
- .then((room) => {
270
- rooms.push(room);
271
- room1 = room;
283
+ beforeEach(() =>
284
+ webex.rooms
285
+ .create({title: 'Unread Message for User 2'})
286
+ .then((room) => {
287
+ rooms.push(room);
288
+ room1 = room;
272
289
 
273
- return webex.memberships.create({
274
- roomId: room1.id,
275
- personId: user2.id
276
- });
277
- })
278
- // User 1 will post a message, that user2 won't have seen
279
- .then(() => webex.messages.create({
280
- roomId: room1.id,
281
- text: 'First message in room 1 from User 1'
282
- }))
283
- // Now create the second space with the two members
284
- .then(() => webex.rooms.create({title: 'Unread Message for User 1'}))
285
- .then((room) => {
286
- rooms.push(room);
287
- room2 = room;
288
- })
289
- .then(() => webex.memberships.create({
290
- roomId: room2.id,
291
- personId: user2.id
292
- }))
293
- // User 2 will post a message, that User 1 won't have seen
294
- .then(() => user2.webex.messages.create({
295
- roomId: room2.id,
296
- text: 'First message in room 2 from User 2'
297
- })));
298
-
299
- it('gets the read status for all rooms User 1 is in', () => webex.rooms.listWithReadStatus()
300
- .then((roomList) => {
301
- assert.isArray(roomList.items,
302
- 'Expect a list or rooms from listWithReadStatus()');
303
- assert.isAbove(roomList.items.length, 1,
304
- 'Expected two or more rooms from listWithReadStatus()');
290
+ return webex.memberships.create({
291
+ roomId: room1.id,
292
+ personId: user2.id,
293
+ });
294
+ })
295
+ // User 1 will post a message, that user2 won't have seen
296
+ .then(() =>
297
+ webex.messages.create({
298
+ roomId: room1.id,
299
+ text: 'First message in room 1 from User 1',
300
+ })
301
+ )
302
+ // Now create the second space with the two members
303
+ .then(() => webex.rooms.create({title: 'Unread Message for User 1'}))
304
+ .then((room) => {
305
+ rooms.push(room);
306
+ room2 = room;
307
+ })
308
+ .then(() =>
309
+ webex.memberships.create({
310
+ roomId: room2.id,
311
+ personId: user2.id,
312
+ })
313
+ )
314
+ // User 2 will post a message, that User 1 won't have seen
315
+ .then(() =>
316
+ user2.webex.messages.create({
317
+ roomId: room2.id,
318
+ text: 'First message in room 2 from User 2',
319
+ })
320
+ )
321
+ );
322
+
323
+ it('gets the read status for all rooms User 1 is in', () =>
324
+ webex.rooms.listWithReadStatus().then((roomList) => {
325
+ assert.isArray(roomList.items, 'Expect a list or rooms from listWithReadStatus()');
326
+ assert.isAbove(
327
+ roomList.items.length,
328
+ 1,
329
+ 'Expected two or more rooms from listWithReadStatus()'
330
+ );
305
331
  for (const room of roomList.items) {
306
332
  if (room.id === room1.id) {
307
- assert.equal(room.title, room1.title, 'Room 1\'s title matches');
308
- assert.isTrue(room.lastSeenActivityDate >= room.lastActivityDate,
309
- 'Room 1 is read for User 1');
333
+ assert.equal(room.title, room1.title, "Room 1's title matches");
334
+ assert.isTrue(
335
+ room.lastSeenActivityDate >= room.lastActivityDate,
336
+ 'Room 1 is read for User 1'
337
+ );
310
338
  }
311
339
  if (room.id === room2.id) {
312
- assert.equal(room.title, room2.title, 'Room 2\'s title matches');
313
- assert.isTrue(room.lastSeenActivityDate < room.lastActivityDate,
314
- 'Room 2 is unread for User 1');
340
+ assert.equal(room.title, room2.title, "Room 2's title matches");
341
+ assert.isTrue(
342
+ room.lastSeenActivityDate < room.lastActivityDate,
343
+ 'Room 2 is unread for User 1'
344
+ );
315
345
  }
316
346
  }
317
347
  }));
318
348
 
319
- it('gets the read status for all rooms User 2 is in', () => user2.webex.rooms.listWithReadStatus()
320
- .then((roomList) => {
321
- assert.isArray(roomList.items,
322
- 'Expect a list or rooms from listWithReadStatus()');
323
- assert.equal(roomList.items.length, 2,
324
- 'Expected two rooms from listWithReadStatus()');
349
+ it('gets the read status for all rooms User 2 is in', () =>
350
+ user2.webex.rooms.listWithReadStatus().then((roomList) => {
351
+ assert.isArray(roomList.items, 'Expect a list or rooms from listWithReadStatus()');
352
+ assert.equal(roomList.items.length, 2, 'Expected two rooms from listWithReadStatus()');
325
353
  for (const room of roomList.items) {
326
354
  if (room.id === room1.id) {
327
- assert.equal(room.title, room1.title, 'Room 1\'s title matches');
328
- assert.isTrue(room.lastSeenActivityDate < room.lastActivityDate,
329
- 'Room 1 is unread for User 2');
330
- }
331
- else {
332
- assert.equal(room.title, room2.title, 'Room 2\'s title matches');
333
- assert.isTrue(room.lastSeenActivityDate >= room.lastActivityDate,
334
- 'Room 2 is read for User 2');
355
+ assert.equal(room.title, room1.title, "Room 1's title matches");
356
+ assert.isTrue(
357
+ room.lastSeenActivityDate < room.lastActivityDate,
358
+ 'Room 1 is unread for User 2'
359
+ );
360
+ } else {
361
+ assert.equal(room.title, room2.title, "Room 2's title matches");
362
+ assert.isTrue(
363
+ room.lastSeenActivityDate >= room.lastActivityDate,
364
+ 'Room 2 is read for User 2'
365
+ );
335
366
  }
336
367
  }
337
368
  }));
@@ -340,14 +371,15 @@ describe('plugin-rooms', function () {
340
371
  describe('#update()', () => {
341
372
  let room;
342
373
 
343
- beforeEach(() => webex.rooms.create({title: 'Webex Test Room'})
344
- .then((r) => {
374
+ beforeEach(() =>
375
+ webex.rooms.create({title: 'Webex Test Room'}).then((r) => {
345
376
  room = r;
346
377
  rooms.push(room);
347
378
  assert.property(room, 'id');
348
- }));
379
+ })
380
+ );
349
381
 
350
- it('updates a single room\'s title and validates a room:updated event', () => {
382
+ it("updates a single room's title and validates a room:updated event", () => {
351
383
  const r = Object.assign({}, room, {title: 'Webex Test Room with New Title'});
352
384
  const updatedEventPromise = new Promise((resolve) => {
353
385
  webex.rooms.on('updated', (event) => {
@@ -356,36 +388,39 @@ describe('plugin-rooms', function () {
356
388
  });
357
389
  });
358
390
 
359
- return webex.rooms.listen()
360
- .then(() => webex.rooms.update(r)
361
- .then(async (room) => {
362
- assert.isRoom(room);
363
- assert.deepEqual(room, r);
364
- const event = await updatedEventPromise;
391
+ return webex.rooms.listen().then(() =>
392
+ webex.rooms.update(r).then(async (room) => {
393
+ assert.isRoom(room);
394
+ assert.deepEqual(room, r);
395
+ const event = await updatedEventPromise;
365
396
 
366
- validateRoomEvent(event, room, actor);
367
- }));
397
+ validateRoomEvent(event, room, actor);
398
+ })
399
+ );
368
400
  });
369
401
  });
370
402
 
371
403
  describe('#remove()', () => {
372
404
  let room;
373
405
 
374
- beforeEach(() => webex.rooms.create({title: 'Webex Test Room'})
375
- .then((r) => {
406
+ beforeEach(() =>
407
+ webex.rooms.create({title: 'Webex Test Room'}).then((r) => {
376
408
  room = r;
377
409
  assert.property(room, 'id');
378
- }));
410
+ })
411
+ );
379
412
 
380
- it('deletes a single room', () => webex.rooms.remove(room)
381
- .then((body) => {
382
- assert.notOk(body);
413
+ it('deletes a single room', () =>
414
+ webex.rooms
415
+ .remove(room)
416
+ .then((body) => {
417
+ assert.notOk(body);
383
418
 
384
- return assert.isRejected(webex.rooms.get(room));
385
- })
386
- .then((reason) => {
387
- assert.instanceOf(reason, WebexHttpError.NotFound);
388
- }));
419
+ return assert.isRejected(webex.rooms.get(room));
420
+ })
421
+ .then((reason) => {
422
+ assert.instanceOf(reason, WebexHttpError.NotFound);
423
+ }));
389
424
  });
390
425
  });
391
426
  });
@@ -398,26 +433,19 @@ describe('plugin-rooms', function () {
398
433
  * @returns {void}
399
434
  */
400
435
  function validateRoomEvent(event, room, actor) {
401
- assert.isTrue(event.resource === SDK_EVENT.EXTERNAL.RESOURCE.ROOMS,
402
- 'not a room event');
436
+ assert.isTrue(event.resource === SDK_EVENT.EXTERNAL.RESOURCE.ROOMS, 'not a room event');
403
437
  assert.isDefined(event.event, 'room event type not set');
404
438
  assert.isDefined(event.created, 'event listener created date not set');
405
- assert.equal(event.createdBy, actor.id,
406
- 'event listener createdBy not set to our actor');
407
- assert.equal(event.orgId, actor.orgId,
408
- 'event listener orgId not === to our actor\'s');
439
+ assert.equal(event.createdBy, actor.id, 'event listener createdBy not set to our actor');
440
+ assert.equal(event.orgId, actor.orgId, "event listener orgId not === to our actor's");
409
441
  assert.equal(event.ownedBy, 'creator', 'event listener not owned by creator');
410
442
  assert.equal(event.status, 'active', 'event listener status not active');
411
- assert.equal(event.actorId, actor.id,
412
- 'event actorId not equal to our actor\'s id');
443
+ assert.equal(event.actorId, actor.id, "event actorId not equal to our actor's id");
413
444
 
414
445
  // Ensure event data matches data returned from function call
415
446
  // Skip this until we figure out how conversations converts the internal test user UUID
416
- assert.equal(event.data.id, room.id,
417
- 'event/room.id not equal');
418
- assert.equal(event.data.isLocked, room.isLocked,
419
- 'event/room.isLocked not equal');
420
- assert.equal(event.data.type, room.type,
421
- 'event/room.type not equal');
447
+ assert.equal(event.data.id, room.id, 'event/room.id not equal');
448
+ assert.equal(event.data.isLocked, room.isLocked, 'event/room.isLocked not equal');
449
+ assert.equal(event.data.type, room.type, 'event/room.type not equal');
422
450
  debug(`rooms:${event.event} event validated`);
423
451
  }