@webex/internal-plugin-board 3.12.0 → 3.13.0-next.10

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.
@@ -227,16 +227,29 @@ describe('plugin-board', () => {
227
227
  });
228
228
 
229
229
  describe('#createChannel()', () => {
230
+ const clusterBoardServiceUrl = 'https://board-a.wbx2.com/board/api/v1';
230
231
  const channelRequestBody = {
231
232
  aclUrlLink: channel.aclUrlLink,
232
233
  kmsMessage: channel.kmsMessage,
233
234
  };
234
235
 
235
236
  beforeAll(() => {
236
- webex.request.resetHistory();
237
237
  webex.request.returns(Promise.resolve({statusCode: 200, body: channelRes}));
238
+ });
238
239
 
239
-
240
+ beforeEach(() => {
241
+ webex.request.resetHistory();
242
+ webex.internal.services = {
243
+ getClusterId: sinon.stub().returns('urn:TEAM:us-east-2_a:acl-write'),
244
+ getServiceFromClusterId: sinon.stub().returns({
245
+ name: 'board',
246
+ url: clusterBoardServiceUrl,
247
+ }),
248
+ };
249
+ });
250
+
251
+ afterEach(() => {
252
+ delete webex.internal.services;
240
253
  });
241
254
 
242
255
  afterAll(() => {
@@ -252,6 +265,7 @@ describe('plugin-board', () => {
252
265
  it('supports creating ambiguous channels for PMR support', () => {
253
266
  return webex.internal.board.createChannel()
254
267
  .then(() => {
268
+ assert.notCalled(webex.internal.services.getClusterId);
255
269
  assert.calledWith(
256
270
  webex.request,
257
271
  sinon.match({
@@ -271,7 +285,55 @@ describe('plugin-board', () => {
271
285
  })
272
286
  });
273
287
 
274
- it('requests POST to channels service', () => {
288
+ it('resolves the board host from the conversation ACL cluster', () => {
289
+ return webex.internal.board.createChannel(conversation)
290
+ .then(() => {
291
+ assert.calledWith(webex.internal.services.getClusterId, conversation.aclUrl);
292
+ assert.calledWith(webex.internal.services.getServiceFromClusterId, {
293
+ clusterId: 'urn:TEAM:us-east-2_a:board',
294
+ });
295
+ assert.calledWith(
296
+ webex.request,
297
+ sinon.match({
298
+ method: 'POST',
299
+ uri: `${clusterBoardServiceUrl}/channels`,
300
+ body: channelRequestBody,
301
+ }),
302
+ );
303
+ });
304
+ });
305
+
306
+ it('does not target the home board cluster when a cluster host resolves', () => {
307
+ return webex.internal.board.createChannel(conversation)
308
+ .then(() => {
309
+ const [requestOptions] = webex.request.args[0];
310
+
311
+ assert.notProperty(requestOptions, 'api');
312
+ assert.notProperty(requestOptions, 'resource');
313
+ });
314
+ });
315
+
316
+ it('falls back to the home board service when the cluster cannot be resolved', () => {
317
+ webex.internal.services.getClusterId.returns(undefined);
318
+
319
+ return webex.internal.board.createChannel(conversation)
320
+ .then(() => {
321
+ assert.notCalled(webex.internal.services.getServiceFromClusterId);
322
+ assert.calledWith(
323
+ webex.request,
324
+ sinon.match({
325
+ method: 'POST',
326
+ api: 'board',
327
+ resource: '/channels',
328
+ body: channelRequestBody,
329
+ }),
330
+ );
331
+ });
332
+ });
333
+
334
+ it('falls back to the home board service when no board host exists for the cluster', () => {
335
+ webex.internal.services.getServiceFromClusterId.returns(undefined);
336
+
275
337
  return webex.internal.board.createChannel(conversation)
276
338
  .then(() => {
277
339
  assert.calledWith(
@@ -568,6 +630,108 @@ describe('plugin-board', () => {
568
630
  assert.isRejected(webex.internal.board.getChannels(), '`conversation` is required'));
569
631
  });
570
632
 
633
+ describe('#getChannels()', () => {
634
+ const clusterBoardServiceUrl = 'https://board-a.wbx2.com/board/api/v1';
635
+
636
+ beforeEach(() => {
637
+ webex.request.resetHistory();
638
+ webex.internal.services = {
639
+ getClusterId: sinon.stub().returns('urn:TEAM:us-east-2_a:acl-write'),
640
+ getServiceFromClusterId: sinon.stub().returns({
641
+ name: 'board',
642
+ url: clusterBoardServiceUrl,
643
+ }),
644
+ };
645
+ });
646
+
647
+ afterEach(() => {
648
+ delete webex.internal.services;
649
+ });
650
+
651
+ it('resolves the board host from the conversation ACL cluster', () =>
652
+ webex.internal.board.getChannels(conversation).then(() => {
653
+ assert.calledWith(webex.internal.services.getClusterId, conversation.aclUrl);
654
+ assert.calledWith(webex.internal.services.getServiceFromClusterId, {
655
+ clusterId: 'urn:TEAM:us-east-2_a:board',
656
+ });
657
+ assert.calledWith(
658
+ webex.request,
659
+ sinon.match({
660
+ uri: `${clusterBoardServiceUrl}/channels`,
661
+ qs: {aclUrlLink: conversation.aclUrl},
662
+ })
663
+ );
664
+ }));
665
+
666
+ it('does not target the home board cluster when a cluster host resolves', () =>
667
+ webex.internal.board.getChannels(conversation).then(() => {
668
+ const [requestOptions] = webex.request.args[0];
669
+
670
+ assert.notProperty(requestOptions, 'api');
671
+ assert.notProperty(requestOptions, 'resource');
672
+ }));
673
+
674
+ it('forwards channelsLimit and type as query params', () =>
675
+ webex.internal.board
676
+ .getChannels(conversation, {channelsLimit: 25, type: 'annotated'})
677
+ .then(() => {
678
+ assert.calledWith(
679
+ webex.request,
680
+ sinon.match({
681
+ uri: `${clusterBoardServiceUrl}/channels`,
682
+ qs: {
683
+ aclUrlLink: conversation.aclUrl,
684
+ channelsLimit: 25,
685
+ type: 'annotated',
686
+ },
687
+ })
688
+ );
689
+ }));
690
+
691
+ it('falls back to the home board service when the conversation has no aclUrl', () =>
692
+ webex.internal.board.getChannels({id: 'no-acl'}).then(() => {
693
+ assert.notCalled(webex.internal.services.getClusterId);
694
+ assert.calledWith(
695
+ webex.request,
696
+ sinon.match({
697
+ api: 'board',
698
+ resource: '/channels',
699
+ })
700
+ );
701
+ }));
702
+
703
+ it('falls back to the home board service when the cluster cannot be resolved', () => {
704
+ webex.internal.services.getClusterId.returns(undefined);
705
+
706
+ return webex.internal.board.getChannels(conversation).then(() => {
707
+ assert.notCalled(webex.internal.services.getServiceFromClusterId);
708
+ assert.calledWith(
709
+ webex.request,
710
+ sinon.match({
711
+ api: 'board',
712
+ resource: '/channels',
713
+ qs: {aclUrlLink: conversation.aclUrl},
714
+ })
715
+ );
716
+ });
717
+ });
718
+
719
+ it('falls back to the home board service when no board host exists for the cluster', () => {
720
+ webex.internal.services.getServiceFromClusterId.returns(undefined);
721
+
722
+ return webex.internal.board.getChannels(conversation).then(() => {
723
+ assert.calledWith(
724
+ webex.request,
725
+ sinon.match({
726
+ api: 'board',
727
+ resource: '/channels',
728
+ qs: {aclUrlLink: conversation.aclUrl},
729
+ })
730
+ );
731
+ });
732
+ });
733
+ });
734
+
571
735
  describe('#getContents()', () => {
572
736
  beforeEach(() => {
573
737
  sinon.stub(webex.internal.board, 'decryptContents').returns(['foo']);