@webex/plugin-messages 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.
@@ -27,64 +27,62 @@ describe('plugin-messages', function () {
27
27
  let actor;
28
28
  let actorEU;
29
29
 
30
-
31
- before(() => Promise.all([
32
- testUsers.create({count: 1}),
33
- testUsers.create({count: 1, config: {orgId: process.env.EU_PRIMARY_ORG_ID}})
34
- ])
35
- .then(([user, usersEU]) => {
30
+ before(() =>
31
+ Promise.all([
32
+ testUsers.create({count: 1}),
33
+ testUsers.create({count: 1, config: {orgId: process.env.EU_PRIMARY_ORG_ID}}),
34
+ ]).then(([user, usersEU]) => {
36
35
  [actor] = user;
37
36
  [actorEU] = usersEU;
38
37
 
39
38
  webex = new WebexCore({credentials: actor.token});
40
39
  webexEU = new WebexCore({credentials: actorEU.token});
41
40
 
42
- webex.people.get('me')
43
- .then((person) => {
44
- actor = person;
45
- });
41
+ webex.people.get('me').then((person) => {
42
+ actor = person;
43
+ });
46
44
 
47
- webexEU.people.get('me')
48
- .then((person) => {
49
- actorEU = person;
50
- });
51
- }));
45
+ webexEU.people.get('me').then((person) => {
46
+ actorEU = person;
47
+ });
48
+ })
49
+ );
52
50
 
53
51
  describe('#messages', () => {
54
52
  let room;
55
53
  let roomEU;
56
54
 
57
- before(() => Promise.all([
58
- webex.rooms.create({title: 'Webex Test Room'}),
59
- webexEU.rooms.create({title: 'Webex Test Room for EU'})
60
- ])
61
- .then(([r, rEU]) => {
55
+ before(() =>
56
+ Promise.all([
57
+ webex.rooms.create({title: 'Webex Test Room'}),
58
+ webexEU.rooms.create({title: 'Webex Test Room for EU'}),
59
+ ]).then(([r, rEU]) => {
62
60
  room = r;
63
61
  roomEU = rEU;
64
62
  const text = 'First Message';
65
63
 
66
- webex.messages.create({
67
- roomId: room.id,
68
- text
69
- })
64
+ webex.messages
65
+ .create({
66
+ roomId: room.id,
67
+ text,
68
+ })
70
69
  .then((message) => {
71
70
  validateMessage(message, text);
72
71
  });
73
72
 
74
- webexEU.messages.create({
75
- roomId: roomEU.id,
76
- text
77
- })
73
+ webexEU.messages
74
+ .create({
75
+ roomId: roomEU.id,
76
+ text,
77
+ })
78
78
  .then((message) => {
79
79
  validateMessage(message, text);
80
80
  });
81
- }));
81
+ })
82
+ );
82
83
 
83
84
  // eslint-disable-next-line consistent-return
84
- after(() => Promise.all([
85
- webex.rooms.remove(room),
86
- webexEU.rooms.remove(roomEU)
87
- ]));
85
+ after(() => Promise.all([webex.rooms.remove(room), webexEU.rooms.remove(roomEU)]));
88
86
 
89
87
  afterEach(() => webex.messages.stopListening());
90
88
 
@@ -103,18 +101,20 @@ describe('plugin-messages', function () {
103
101
 
104
102
  const text = 'A test message';
105
103
 
106
- return webex.messages.listen()
107
- .then(() => webex.messages.create({
108
- roomId: room.id,
109
- text
110
- })
104
+ return webex.messages.listen().then(() =>
105
+ webex.messages
106
+ .create({
107
+ roomId: room.id,
108
+ text,
109
+ })
111
110
  .then(async (m) => {
112
111
  message = m;
113
112
  validateMessage(message, text);
114
113
  const event = await created;
115
114
 
116
115
  validateMessageEvent(event, message, actor);
117
- }));
116
+ })
117
+ );
118
118
  });
119
119
 
120
120
  it('posts a message by an EU user in a room and validates the messages:created event', () => {
@@ -131,21 +131,23 @@ describe('plugin-messages', function () {
131
131
 
132
132
  const text = 'A test message';
133
133
 
134
- return webexEU.messages.listen()
135
- .then(() => webexEU.messages.create({
136
- roomId: roomEU.id,
137
- text
138
- })
134
+ return webexEU.messages.listen().then(() =>
135
+ webexEU.messages
136
+ .create({
137
+ roomId: roomEU.id,
138
+ text,
139
+ })
139
140
  .then(async (m) => {
140
141
  message = m;
141
142
  validateMessage(message, text);
142
143
  const event = await created;
143
144
 
144
145
  validateMessageEvent(event, message, actorEU);
145
- }));
146
+ })
147
+ );
146
148
  });
147
149
 
148
- it('posts a file to a room by specifying the file\'s url and validates the event', () => {
150
+ it("posts a file to a room by specifying the file's url and validates the event", () => {
149
151
  const created = new Promise((resolve) => {
150
152
  webex.messages.on('created', (event) => {
151
153
  debug('message created event called');
@@ -153,24 +155,26 @@ describe('plugin-messages', function () {
153
155
  });
154
156
  });
155
157
 
156
- return webex.messages.listen()
157
- .then(() => webex.messages.create({
158
- roomId: room.id,
159
- files: [KNOWN_HOSTED_IMAGE_URL]
160
- })
158
+ return webex.messages.listen().then(() =>
159
+ webex.messages
160
+ .create({
161
+ roomId: room.id,
162
+ files: [KNOWN_HOSTED_IMAGE_URL],
163
+ })
161
164
  .then(async (message) => {
162
165
  validateMessage(message);
163
166
  const event = await created;
164
167
 
165
168
  validateMessageEvent(event, message, actor);
166
- }));
169
+ })
170
+ );
167
171
  });
168
172
 
169
173
  let blob, buffer;
170
174
  const text = 'A File';
171
175
 
172
- browserOnly(before)(() => fh.fetch('sample-image-small-one.png')
173
- .then((file) => {
176
+ browserOnly(before)(() =>
177
+ fh.fetch('sample-image-small-one.png').then((file) => {
174
178
  blob = file;
175
179
 
176
180
  return new Promise((resolve) => {
@@ -183,46 +187,58 @@ describe('plugin-messages', function () {
183
187
  };
184
188
  fileReader.readAsArrayBuffer(blob);
185
189
  });
186
- }));
190
+ })
191
+ );
187
192
 
188
- nodeOnly(before)(() => fh.fetchWithoutMagic('sample-image-small-one.png')
189
- .then((file) => {
193
+ nodeOnly(before)(() =>
194
+ fh.fetchWithoutMagic('sample-image-small-one.png').then((file) => {
190
195
  buffer = file;
191
- }));
192
-
193
- browserOnly(it)('posts a file to a room by directly supplying its blob and validates the event', () => {
194
- const created = new Promise((resolve) => {
195
- webex.messages.on('created', (event) => {
196
- debug('message created event called');
197
- resolve(event);
196
+ })
197
+ );
198
+
199
+ browserOnly(it)(
200
+ 'posts a file to a room by directly supplying its blob and validates the event',
201
+ () => {
202
+ const created = new Promise((resolve) => {
203
+ webex.messages.on('created', (event) => {
204
+ debug('message created event called');
205
+ resolve(event);
206
+ });
198
207
  });
199
- });
200
208
 
201
- return webex.messages.listen()
202
- .then(() => webex.messages.create({
203
- roomId: room.id,
204
- files: [blob],
205
- text
206
- })
207
- .then(async (message) => {
208
- validateMessage(message);
209
- const event = await created;
209
+ return webex.messages.listen().then(() =>
210
+ webex.messages
211
+ .create({
212
+ roomId: room.id,
213
+ files: [blob],
214
+ text,
215
+ })
216
+ .then(async (message) => {
217
+ validateMessage(message);
218
+ const event = await created;
210
219
 
211
- validateMessageEvent(event, message, actor);
212
- }));
213
- });
220
+ validateMessageEvent(event, message, actor);
221
+ })
222
+ );
223
+ }
224
+ );
214
225
 
215
226
  // Disabling it gating pipelines because it failes a lot and we get
216
227
  // mostly adequate coverage via blob upload
217
- flaky(it, process.env.SKIP_FLAKY_TESTS)('posts a file to a room by directly supplying its buffer and validates the event', () => webex.messages.create({
218
- roomId: room.id,
219
- files: [buffer]
220
- })
221
- .then((message) => {
222
- validateMessage(message, '', 1);
223
- }));
228
+ flaky(it, process.env.SKIP_FLAKY_TESTS)(
229
+ 'posts a file to a room by directly supplying its buffer and validates the event',
230
+ () =>
231
+ webex.messages
232
+ .create({
233
+ roomId: room.id,
234
+ files: [buffer],
235
+ })
236
+ .then((message) => {
237
+ validateMessage(message, '', 1);
238
+ })
239
+ );
224
240
 
225
- it('posts a file with a message to a room by specifying the file\'s url and validates the event', () => {
241
+ it("posts a file with a message to a room by specifying the file's url and validates the event", () => {
226
242
  const created = new Promise((resolve) => {
227
243
  webex.messages.on('created', (event) => {
228
244
  debug('message created event called');
@@ -230,12 +246,13 @@ describe('plugin-messages', function () {
230
246
  });
231
247
  });
232
248
 
233
- return webex.messages.listen()
234
- .then(() => webex.messages.create({
235
- roomId: room.id,
236
- files: [KNOWN_HOSTED_IMAGE_URL],
237
- text
238
- })
249
+ return webex.messages.listen().then(() =>
250
+ webex.messages
251
+ .create({
252
+ roomId: room.id,
253
+ files: [KNOWN_HOSTED_IMAGE_URL],
254
+ text,
255
+ })
239
256
  .then(async (message) => {
240
257
  validateMessage(message);
241
258
  let event = await created;
@@ -257,7 +274,8 @@ describe('plugin-messages', function () {
257
274
  }
258
275
 
259
276
  validateMessageEvent(event, message, actor);
260
- }));
277
+ })
278
+ );
261
279
  });
262
280
 
263
281
  it('posts a message to a card to a room validates the event', () => {
@@ -275,23 +293,24 @@ describe('plugin-messages', function () {
275
293
  body: [
276
294
  {
277
295
  type: 'TextBlock',
278
- text: 'Here is an image'
296
+ text: 'Here is an image',
279
297
  },
280
298
  {
281
299
  type: 'Image',
282
300
  url: KNOWN_HOSTED_IMAGE_URL,
283
- size: 'small'
284
- }
285
- ]
286
- }
301
+ size: 'small',
302
+ },
303
+ ],
304
+ },
287
305
  };
288
306
 
289
- return webex.messages.listen()
290
- .then(() => webex.messages.create({
291
- roomId: room.id,
292
- text,
293
- attachments: [attachment]
294
- })
307
+ return webex.messages.listen().then(() =>
308
+ webex.messages
309
+ .create({
310
+ roomId: room.id,
311
+ text,
312
+ attachments: [attachment],
313
+ })
295
314
  .then(async (message) => {
296
315
  // // Assert that the message shape is valid and contains attachment data.
297
316
  validateMessage(message, text, 0, attachment);
@@ -314,7 +333,8 @@ describe('plugin-messages', function () {
314
333
  }
315
334
 
316
335
  validateMessageEvent(event, message, actor);
317
- }));
336
+ })
337
+ );
318
338
  });
319
339
  });
320
340
 
@@ -322,14 +342,17 @@ describe('plugin-messages', function () {
322
342
  let message;
323
343
  const text = 'This message will be deleted';
324
344
 
325
- beforeEach(() => webex.messages.create({
326
- roomId: room.id,
327
- text
328
- })
329
- .then((m) => {
330
- message = m;
331
- validateMessage(m, text);
332
- }));
345
+ beforeEach(() =>
346
+ webex.messages
347
+ .create({
348
+ roomId: room.id,
349
+ text,
350
+ })
351
+ .then((m) => {
352
+ message = m;
353
+ validateMessage(m, text);
354
+ })
355
+ );
333
356
 
334
357
  it('deletes a single message and validates the message:deleted event', () => {
335
358
  const deleted = new Promise((resolve) => {
@@ -339,8 +362,9 @@ describe('plugin-messages', function () {
339
362
  });
340
363
  });
341
364
 
342
- return webex.messages.listen()
343
- .then(() => webex.messages.remove(message)
365
+ return webex.messages.listen().then(() =>
366
+ webex.messages
367
+ .remove(message)
344
368
  .then((body) => {
345
369
  assert.notOk(body);
346
370
 
@@ -351,7 +375,8 @@ describe('plugin-messages', function () {
351
375
  const event = await deleted;
352
376
 
353
377
  validateMessageEvent(event, message, actor);
354
- }));
378
+ })
379
+ );
355
380
  });
356
381
  });
357
382
 
@@ -365,39 +390,50 @@ describe('plugin-messages', function () {
365
390
  webex.messages.off('created');
366
391
  webex.messages.off('deleted');
367
392
 
368
- return webex.messages.create({
369
- roomId: room.id,
370
- text
371
- })
393
+ return webex.messages
394
+ .create({
395
+ roomId: room.id,
396
+ text,
397
+ })
372
398
  .then((m) => {
373
399
  message = m;
374
400
  validateMessage(message, text);
375
401
  });
376
402
  });
377
403
 
378
- it('returns a single message', () => webex.messages.get(message)
379
- .then((m) => {
404
+ it('returns a single message', () =>
405
+ webex.messages.get(message).then((m) => {
380
406
  assert.isMessage(m);
381
407
  assert.deepEqual(m, message);
382
408
  }));
383
409
  });
384
410
 
385
-
386
411
  describe('#list()', () => {
387
- before(() => webex.rooms.create({
388
- title: 'Room List Test'
389
- })
390
- .then((r) => {
391
- room = r;
392
- }));
393
-
394
- before(() => [1, 2, 3].reduce((promise, value) => promise.then(() => webex.messages.create({
395
- roomId: room.id,
396
- text: `message: ${value}`
397
- })), Promise.resolve()));
398
-
399
- it('returns all messages for a room', () => webex.messages.list({roomId: room.id})
400
- .then((messages) => {
412
+ before(() =>
413
+ webex.rooms
414
+ .create({
415
+ title: 'Room List Test',
416
+ })
417
+ .then((r) => {
418
+ room = r;
419
+ })
420
+ );
421
+
422
+ before(() =>
423
+ [1, 2, 3].reduce(
424
+ (promise, value) =>
425
+ promise.then(() =>
426
+ webex.messages.create({
427
+ roomId: room.id,
428
+ text: `message: ${value}`,
429
+ })
430
+ ),
431
+ Promise.resolve()
432
+ )
433
+ );
434
+
435
+ it('returns all messages for a room', () =>
436
+ webex.messages.list({roomId: room.id}).then((messages) => {
401
437
  assert.isDefined(messages);
402
438
  assert.lengthOf(messages, 3);
403
439
  for (const message of messages) {
@@ -408,7 +444,8 @@ describe('plugin-messages', function () {
408
444
  it('returns a bounded set of messages for a room', () => {
409
445
  const spy = sinon.spy();
410
446
 
411
- return webex.messages.list({roomId: room.id, max: 2})
447
+ return webex.messages
448
+ .list({roomId: room.id, max: 2})
412
449
  .then((messages) => {
413
450
  assert.lengthOf(messages, 2);
414
451
 
@@ -422,7 +459,7 @@ describe('plugin-messages', function () {
422
459
  }
423
460
 
424
461
  return Promise.resolve();
425
- }(messages));
462
+ })(messages);
426
463
  })
427
464
  .then(() => {
428
465
  assert.calledThrice(spy);
@@ -432,12 +469,15 @@ describe('plugin-messages', function () {
432
469
  describe('when a message is threaded', () => {
433
470
  let parentId;
434
471
 
435
- before(() => webex.rooms.create({
436
- title: 'Room List Test'
437
- })
438
- .then((r) => {
439
- room = r;
440
- }));
472
+ before(() =>
473
+ webex.rooms
474
+ .create({
475
+ title: 'Room List Test',
476
+ })
477
+ .then((r) => {
478
+ room = r;
479
+ })
480
+ );
441
481
 
442
482
  before(() => {
443
483
  const createdParent = new Promise((resolve) => {
@@ -447,11 +487,12 @@ describe('plugin-messages', function () {
447
487
  });
448
488
  });
449
489
 
450
- return webex.messages.listen()
451
- .then(() => webex.messages.create({
452
- roomId: room.id,
453
- text: 'This is the parent message'
454
- })
490
+ return webex.messages.listen().then(() =>
491
+ webex.messages
492
+ .create({
493
+ roomId: room.id,
494
+ text: 'This is the parent message',
495
+ })
455
496
  .then(async (message) => {
456
497
  parentId = message.id;
457
498
 
@@ -466,22 +507,24 @@ describe('plugin-messages', function () {
466
507
  });
467
508
  });
468
509
 
469
- return webex.messages.create({
470
- roomId: room.id,
471
- text: 'This is the reply',
472
- parentId
473
- })
510
+ return webex.messages
511
+ .create({
512
+ roomId: room.id,
513
+ text: 'This is the reply',
514
+ parentId,
515
+ })
474
516
  .then(async (message2) => {
475
517
  validateMessage(message2);
476
518
  const event2 = await createdReply;
477
519
 
478
520
  return Promise.resolve(validateMessageEvent(event2, message2, actor));
479
521
  });
480
- }));
522
+ })
523
+ );
481
524
  });
482
525
 
483
- it('returns all messages for a room', () => webex.messages.list({roomId: room.id})
484
- .then((messages) => {
526
+ it('returns all messages for a room', () =>
527
+ webex.messages.list({roomId: room.id}).then((messages) => {
485
528
  assert.isDefined(messages);
486
529
  assert.lengthOf(messages.items, 2);
487
530
  for (const message of messages.items) {
@@ -492,8 +535,8 @@ describe('plugin-messages', function () {
492
535
  }
493
536
  }));
494
537
 
495
- it('returns only the replies for particular message thread', () => webex.messages.list({roomId: room.id, parentId})
496
- .then((messages) => {
538
+ it('returns only the replies for particular message thread', () =>
539
+ webex.messages.list({roomId: room.id, parentId}).then((messages) => {
497
540
  assert.lengthOf(messages.items, 1);
498
541
  const message = messages.items[0];
499
542
 
@@ -505,7 +548,6 @@ describe('plugin-messages', function () {
505
548
  });
506
549
  });
507
550
 
508
-
509
551
  /**
510
552
  * Validate a Message object.
511
553
  * @param {Object} message
@@ -572,30 +614,21 @@ function validateAdaptiveCard(message, attachment) {
572
614
  * @returns {void}
573
615
  */
574
616
  function validateMessageEvent(event, message, actor) {
575
- assert.equal(event.resource, SDK_EVENT.EXTERNAL.RESOURCE.MESSAGES,
576
- 'not a message event');
617
+ assert.equal(event.resource, SDK_EVENT.EXTERNAL.RESOURCE.MESSAGES, 'not a message event');
577
618
  assert.isDefined(event.event, 'message event type not set');
578
619
  assert.isDefined(event.created, 'event listener created date not set');
579
- assert.equal(event.createdBy, actor.id,
580
- 'event listener createdBy not set to our actor');
581
- assert.equal(event.orgId, actor.orgId,
582
- 'event listener orgId not === to our actor\'s');
620
+ assert.equal(event.createdBy, actor.id, 'event listener createdBy not set to our actor');
621
+ assert.equal(event.orgId, actor.orgId, "event listener orgId not === to our actor's");
583
622
  assert.equal(event.ownedBy, 'creator', 'event listener not owned by creator');
584
623
  assert.equal(event.status, 'active', 'event listener status not active');
585
- assert.equal(event.actorId, actor.id,
586
- 'event actorId not equal to our actor\'s id');
624
+ assert.equal(event.actorId, actor.id, "event actorId not equal to our actor's id");
587
625
 
588
626
  // Ensure event data matches data returned from function call
589
- assert.equal(event.data.id, message.id,
590
- 'event/message.id not equal');
591
- assert.equal(event.data.roomId, message.roomId,
592
- 'event/message.roomId not equal');
593
- assert.equal(event.data.personId, message.personId,
594
- 'event/message.personId not equal');
595
- assert.equal(event.data.personEmail, message.personEmail,
596
- 'event/message.personEmail not equal');
597
- assert.equal(event.data.roomType, message.roomType,
598
- 'event/message.roomType not equal');
627
+ assert.equal(event.data.id, message.id, 'event/message.id not equal');
628
+ assert.equal(event.data.roomId, message.roomId, 'event/message.roomId not equal');
629
+ assert.equal(event.data.personId, message.personId, 'event/message.personId not equal');
630
+ assert.equal(event.data.personEmail, message.personEmail, 'event/message.personEmail not equal');
631
+ assert.equal(event.data.roomType, message.roomType, 'event/message.roomType not equal');
599
632
  if (event.event === SDK_EVENT.EXTERNAL.EVENT_TYPE.DELETED) {
600
633
  return;
601
634
  }
@@ -605,14 +638,19 @@ function validateMessageEvent(event, message, actor) {
605
638
  if (message.files) {
606
639
  assert.isArray(event.data.files, 'event.data.files is not array');
607
640
  assert.isArray(message.files, 'message.files is not array');
608
- assert.equal(event.data.files.length, message.files.length,
609
- 'event/message file arrays are different lengths');
641
+ assert.equal(
642
+ event.data.files.length,
643
+ message.files.length,
644
+ 'event/message file arrays are different lengths'
645
+ );
610
646
  for (let i = 0; i < message.files.length; i += 1) {
611
647
  // The gateway returned by the API is apialpha.ciscospark.com
612
648
  // The gateway returned in the event is api.ciscospark.com -- expected?
613
- assert.equal(event.data.files[i].substr(event.data.files[i].lastIndexOf('/') + 1),
649
+ assert.equal(
650
+ event.data.files[i].substr(event.data.files[i].lastIndexOf('/') + 1),
614
651
  message.files[i].substr(message.files[i].lastIndexOf('/') + 1),
615
- 'event/message file urls do not match');
652
+ 'event/message file urls do not match'
653
+ );
616
654
  }
617
655
  }
618
656
  if (message.attachments) {