From 06be5d03722134d4790ccbcd585741ce5c09454a Mon Sep 17 00:00:00 2001 From: mickelr Date: Tue, 26 Nov 2024 15:14:09 +0800 Subject: [PATCH 1/6] feat(ps): add start ps API and displayhint --- .../@webex/plugin-meetings/src/constants.ts | 6 +++ .../src/meeting/in-meeting-actions.ts | 17 +++++++++ .../plugin-meetings/src/meeting/index.ts | 16 ++++++++ .../plugin-meetings/src/webinar/index.ts | 38 +++++++++++++++---- .../unit/spec/meeting/in-meeting-actions.ts | 12 +++++- 5 files changed, 80 insertions(+), 9 deletions(-) diff --git a/packages/@webex/plugin-meetings/src/constants.ts b/packages/@webex/plugin-meetings/src/constants.ts index 6c2a155a86c..5231d3e0184 100644 --- a/packages/@webex/plugin-meetings/src/constants.ts +++ b/packages/@webex/plugin-meetings/src/constants.ts @@ -988,6 +988,12 @@ export const DISPLAY_HINTS = { STAGE_VIEW_INACTIVE: 'STAGE_VIEW_INACTIVE', ENABLE_STAGE_VIEW: 'ENABLE_STAGE_VIEW', DISABLE_STAGE_VIEW: 'DISABLE_STAGE_VIEW', + + // Practice Session + PRACTICE_SESSION_ON: 'PRACTICE_SESSION_ON', + PRACTICE_SESSION_OFF: 'PRACTICE_SESSION_OFF', + SHOW_PRACTICE_SESSION_START: 'SHOW_PRACTICE_SESSION_START', + SHOW_PRACTICE_SESSION_STOP: 'SHOW_PRACTICE_SESSION_STOP', }; export const INTERSTITIAL_DISPLAY_HINTS = [DISPLAY_HINTS.VOIP_IS_ENABLED]; diff --git a/packages/@webex/plugin-meetings/src/meeting/in-meeting-actions.ts b/packages/@webex/plugin-meetings/src/meeting/in-meeting-actions.ts index 3d1810ad539..af58dd15831 100644 --- a/packages/@webex/plugin-meetings/src/meeting/in-meeting-actions.ts +++ b/packages/@webex/plugin-meetings/src/meeting/in-meeting-actions.ts @@ -93,6 +93,10 @@ interface IInMeetingActions { canShowStageView?: boolean; canEnableStageView?: boolean; canDisableStageView?: boolean; + IsPracticeSessionOn?: boolean; + IsPracticeSessionOff?: boolean; + canStartPracticeSession?: boolean; + canStopPracticeSession?: boolean; } /** @@ -266,6 +270,15 @@ export default class InMeetingActions implements IInMeetingActions { canEnableStageView = null; canDisableStageView = null; + + IsPracticeSessionOn = null; + + IsPracticeSessionOff = null; + + canStartPracticeSession = null; + + canStopPracticeSession = null; + /** * Returns all meeting action options * @returns {Object} @@ -354,6 +367,10 @@ export default class InMeetingActions implements IInMeetingActions { canShowStageView: this.canShowStageView, canEnableStageView: this.canEnableStageView, canDisableStageView: this.canDisableStageView, + IsPracticeSessionOn: this.IsPracticeSessionOn, + IsPracticeSessionOff: this.IsPracticeSessionOff, + canStartPracticeSession: this.canStartPracticeSession, + canStopPracticeSession: this.canStopPracticeSession, }); /** diff --git a/packages/@webex/plugin-meetings/src/meeting/index.ts b/packages/@webex/plugin-meetings/src/meeting/index.ts index a1cd18ad353..d5a761cbe98 100644 --- a/packages/@webex/plugin-meetings/src/meeting/index.ts +++ b/packages/@webex/plugin-meetings/src/meeting/index.ts @@ -3904,6 +3904,22 @@ export default class Meeting extends StatelessWebexPlugin { requiredHints: [DISPLAY_HINTS.DISABLE_STAGE_VIEW], displayHints: this.userDisplayHints, }), + IsPracticeSessionOn: ControlsOptionsUtil.hasHints({ + requiredHints: [DISPLAY_HINTS.PRACTICE_SESSION_ON], + displayHints: this.userDisplayHints, + }), + IsPracticeSessionOff: ControlsOptionsUtil.hasHints({ + requiredHints: [DISPLAY_HINTS.PRACTICE_SESSION_OFF], + displayHints: this.userDisplayHints, + }), + canStartPracticeSession: ControlsOptionsUtil.hasHints({ + requiredHints: [DISPLAY_HINTS.SHOW_PRACTICE_SESSION_START], + displayHints: this.userDisplayHints, + }), + canStopPracticeSession: ControlsOptionsUtil.hasHints({ + requiredHints: [DISPLAY_HINTS.SHOW_PRACTICE_SESSION_STOP], + displayHints: this.userDisplayHints, + }), canShareFile: (ControlsOptionsUtil.hasHints({ requiredHints: [DISPLAY_HINTS.SHARE_FILE], diff --git a/packages/@webex/plugin-meetings/src/webinar/index.ts b/packages/@webex/plugin-meetings/src/webinar/index.ts index 709ca7f9cde..1b4fbc460db 100644 --- a/packages/@webex/plugin-meetings/src/webinar/index.ts +++ b/packages/@webex/plugin-meetings/src/webinar/index.ts @@ -3,9 +3,10 @@ */ import {WebexPlugin} from '@webex/webex-core'; import {get} from 'lodash'; -import {MEETINGS, SELF_ROLES} from '../constants'; +import {HTTP_VERBS, MEETINGS, SELF_ROLES} from '../constants'; import WebinarCollection from './collection'; +import LoggerProxy from '../common/logs/logger-proxy'; /** * @class Webinar @@ -59,18 +60,39 @@ const Webinar = WebexPlugin.extend({ * @returns {{isPromoted: boolean, isDemoted: boolean}} Role transition states */ updateRoleChanged(payload) { + const oldRoles = get(payload, 'oldRoles', []); + const newRoles = get(payload, 'newRoles', []); + const isPromoted = - get(payload, 'oldRoles', []).includes(SELF_ROLES.ATTENDEE) && - get(payload, 'newRoles', []).includes(SELF_ROLES.PANELIST); + oldRoles.includes(SELF_ROLES.ATTENDEE) && newRoles.includes(SELF_ROLES.PANELIST); const isDemoted = - get(payload, 'oldRoles', []).includes(SELF_ROLES.PANELIST) && - get(payload, 'newRoles', []).includes(SELF_ROLES.ATTENDEE); - this.set('selfIsPanelist', get(payload, 'newRoles', []).includes(SELF_ROLES.PANELIST)); - this.set('selfIsAttendee', get(payload, 'newRoles', []).includes(SELF_ROLES.ATTENDEE)); - this.updateCanManageWebcast(get(payload, 'newRoles', []).includes(SELF_ROLES.MODERATOR)); + oldRoles.includes(SELF_ROLES.PANELIST) && newRoles.includes(SELF_ROLES.ATTENDEE); + this.set('selfIsPanelist', newRoles.includes(SELF_ROLES.PANELIST)); + this.set('selfIsAttendee', newRoles.includes(SELF_ROLES.ATTENDEE)); + this.updateCanManageWebcast(newRoles.includes(SELF_ROLES.MODERATOR)); return {isPromoted, isDemoted}; }, + + /** + * start practice session for webinar + * @param {boolean} enabled + * @returns {Promise} + */ + startPracticeSession(enabled) { + return this.request({ + method: HTTP_VERBS.PATCH, + uri: `${this.locusUrl}/controls`, + body: { + practiceSession: { + enabled, + }, + }, + }).catch((error) => { + LoggerProxy.logger.error('Meeting:webinar#startPracticeSession failed', error); + throw error; + }); + }, }); export default Webinar; diff --git a/packages/@webex/plugin-meetings/test/unit/spec/meeting/in-meeting-actions.ts b/packages/@webex/plugin-meetings/test/unit/spec/meeting/in-meeting-actions.ts index c64833dd0f6..5c0d1cb4da1 100644 --- a/packages/@webex/plugin-meetings/test/unit/spec/meeting/in-meeting-actions.ts +++ b/packages/@webex/plugin-meetings/test/unit/spec/meeting/in-meeting-actions.ts @@ -88,6 +88,11 @@ describe('plugin-meetings', () => { canShowStageView: null, canEnableStageView: null, canDisableStageView: null, + IsPracticeSessionOn : null, + IsPracticeSessionOff : null, + canStartPracticeSession: null, + canStopPracticeSession: null, + ...expected, }; @@ -181,7 +186,12 @@ describe('plugin-meetings', () => { 'canShowStageView', 'canEnableStageView', 'canDisableStageView', - ].forEach((key) => { + 'IsPracticeSessionOn', + 'IsPracticeSessionOff', + 'canStartPracticeSession', + 'canStopPracticeSession', + + ].forEach((key) => { it(`get and set for ${key} work as expected`, () => { const inMeetingActions = new InMeetingActions(); From 72647b2d167205fbd7b8fa0f8b20a2f3fc4bc952 Mon Sep 17 00:00:00 2001 From: mickelr Date: Tue, 26 Nov 2024 17:07:28 +0800 Subject: [PATCH 2/6] feat(ps): add ut --- .../test/unit/spec/webinar/index.ts | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/packages/@webex/plugin-meetings/test/unit/spec/webinar/index.ts b/packages/@webex/plugin-meetings/test/unit/spec/webinar/index.ts index 8a06824220c..ee38d557feb 100644 --- a/packages/@webex/plugin-meetings/test/unit/spec/webinar/index.ts +++ b/packages/@webex/plugin-meetings/test/unit/spec/webinar/index.ts @@ -122,5 +122,56 @@ describe('plugin-meetings', () => { }); }); + describe('#startPracticeSession', () => { + it('sends a PATCH request to enable the practice session', async () => { + const enabled = true; + + const result = await webinar.startPracticeSession(enabled); + + assert.calledOnce(webex.request); + assert.calledWith(webex.request, { + method: 'PATCH', + uri: `${webinar.locusUrl}/controls`, + body: { + practiceSession: { enabled }, + }, + }); + assert.equal(result, 'REQUEST_RETURN_VALUE', 'should return the resolved value from the request'); + }); + + it('sends a PATCH request to disable the practice session', async () => { + const enabled = false; + + const result = await webinar.startPracticeSession(enabled); + + assert.calledOnce(webex.request); + assert.calledWith(webex.request, { + method: 'PATCH', + uri: `${webinar.locusUrl}/controls`, + body: { + practiceSession: { enabled }, + }, + }); + assert.equal(result, 'REQUEST_RETURN_VALUE', 'should return the resolved value from the request'); + }); + + it('handles API call failures gracefully', async () => { + webex.request.rejects(new Error('API_ERROR')); + const errorLogger = sinon.stub(LoggerProxy.logger, 'error'); + + try { + await webinar.startPracticeSession(true); + assert.fail('startPracticeSession should throw an error'); + } catch (error) { + assert.equal(error.message, 'API_ERROR', 'should throw the correct error'); + assert.calledOnce(errorLogger); + assert.calledWith(errorLogger, 'Meeting:webinar#startPracticeSession failed', sinon.match.instanceOf(Error)); + } + + errorLogger.restore(); + }); + }); + + }) }) From 609ae79abeb7d1249c3378e7651d71f4c12b2bfc Mon Sep 17 00:00:00 2001 From: mickelr Date: Mon, 2 Dec 2024 15:47:43 +0800 Subject: [PATCH 3/6] feat(ps): updatePracticeSessionStatus --- packages/@webex/plugin-meetings/src/meeting/index.ts | 1 + packages/@webex/plugin-meetings/src/webinar/index.ts | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/packages/@webex/plugin-meetings/src/meeting/index.ts b/packages/@webex/plugin-meetings/src/meeting/index.ts index e77b7033138..823e75bac32 100644 --- a/packages/@webex/plugin-meetings/src/meeting/index.ts +++ b/packages/@webex/plugin-meetings/src/meeting/index.ts @@ -2655,6 +2655,7 @@ export default class Meeting extends StatelessWebexPlugin { }); this.locusInfo.on(LOCUSINFO.EVENTS.CONTROLS_PRACTICE_SESSION_STATUS_UPDATED, ({state}) => { + this.webinar.updatePracticeSessionStatus(state); Trigger.trigger( this, {file: 'meeting/index', function: 'setupLocusControlsListener'}, diff --git a/packages/@webex/plugin-meetings/src/webinar/index.ts b/packages/@webex/plugin-meetings/src/webinar/index.ts index 1b4fbc460db..dd2653a4133 100644 --- a/packages/@webex/plugin-meetings/src/webinar/index.ts +++ b/packages/@webex/plugin-meetings/src/webinar/index.ts @@ -23,6 +23,7 @@ const Webinar = WebexPlugin.extend({ canManageWebcast: 'boolean', // appears the ability to manage webcast selfIsPanelist: 'boolean', // self is panelist selfIsAttendee: 'boolean', // self is attendee + practiceSessionEnabled: 'boolean', // practice session enabled }, /** @@ -93,6 +94,15 @@ const Webinar = WebexPlugin.extend({ throw error; }); }, + + /** + * update practice session status + * @param {object} payload + * @returns {void} + */ + updatePracticeSessionStatus(payload) { + this.set('practiceSessionEnabled', payload.enabled); + }, }); export default Webinar; From 8af552d8f2cde788dffe17abbf6aa60195579f08 Mon Sep 17 00:00:00 2001 From: mickelr Date: Mon, 2 Dec 2024 18:15:46 +0800 Subject: [PATCH 4/6] feat(ps): add ut --- .../src/meeting/in-meeting-actions.ts | 12 ++-- .../plugin-meetings/src/meeting/index.ts | 4 +- .../plugin-meetings/src/webinar/index.ts | 6 +- .../unit/spec/meeting/in-meeting-actions.ts | 8 +-- .../test/unit/spec/meeting/index.js | 3 + .../test/unit/spec/webinar/index.ts | 62 +++++++++---------- 6 files changed, 47 insertions(+), 48 deletions(-) diff --git a/packages/@webex/plugin-meetings/src/meeting/in-meeting-actions.ts b/packages/@webex/plugin-meetings/src/meeting/in-meeting-actions.ts index af58dd15831..f803251507c 100644 --- a/packages/@webex/plugin-meetings/src/meeting/in-meeting-actions.ts +++ b/packages/@webex/plugin-meetings/src/meeting/in-meeting-actions.ts @@ -93,8 +93,8 @@ interface IInMeetingActions { canShowStageView?: boolean; canEnableStageView?: boolean; canDisableStageView?: boolean; - IsPracticeSessionOn?: boolean; - IsPracticeSessionOff?: boolean; + isPracticeSessionOn?: boolean; + isPracticeSessionOff?: boolean; canStartPracticeSession?: boolean; canStopPracticeSession?: boolean; } @@ -271,9 +271,9 @@ export default class InMeetingActions implements IInMeetingActions { canDisableStageView = null; - IsPracticeSessionOn = null; + isPracticeSessionOn = null; - IsPracticeSessionOff = null; + isPracticeSessionOff = null; canStartPracticeSession = null; @@ -367,8 +367,8 @@ export default class InMeetingActions implements IInMeetingActions { canShowStageView: this.canShowStageView, canEnableStageView: this.canEnableStageView, canDisableStageView: this.canDisableStageView, - IsPracticeSessionOn: this.IsPracticeSessionOn, - IsPracticeSessionOff: this.IsPracticeSessionOff, + isPracticeSessionOn: this.isPracticeSessionOn, + isPracticeSessionOff: this.isPracticeSessionOff, canStartPracticeSession: this.canStartPracticeSession, canStopPracticeSession: this.canStopPracticeSession, }); diff --git a/packages/@webex/plugin-meetings/src/meeting/index.ts b/packages/@webex/plugin-meetings/src/meeting/index.ts index 823e75bac32..d03bba607b0 100644 --- a/packages/@webex/plugin-meetings/src/meeting/index.ts +++ b/packages/@webex/plugin-meetings/src/meeting/index.ts @@ -3905,11 +3905,11 @@ export default class Meeting extends StatelessWebexPlugin { requiredHints: [DISPLAY_HINTS.DISABLE_STAGE_VIEW], displayHints: this.userDisplayHints, }), - IsPracticeSessionOn: ControlsOptionsUtil.hasHints({ + isPracticeSessionOn: ControlsOptionsUtil.hasHints({ requiredHints: [DISPLAY_HINTS.PRACTICE_SESSION_ON], displayHints: this.userDisplayHints, }), - IsPracticeSessionOff: ControlsOptionsUtil.hasHints({ + isPracticeSessionOff: ControlsOptionsUtil.hasHints({ requiredHints: [DISPLAY_HINTS.PRACTICE_SESSION_OFF], displayHints: this.userDisplayHints, }), diff --git a/packages/@webex/plugin-meetings/src/webinar/index.ts b/packages/@webex/plugin-meetings/src/webinar/index.ts index dd2653a4133..f185161d8b6 100644 --- a/packages/@webex/plugin-meetings/src/webinar/index.ts +++ b/packages/@webex/plugin-meetings/src/webinar/index.ts @@ -76,11 +76,11 @@ const Webinar = WebexPlugin.extend({ }, /** - * start practice session for webinar + * start or stop practice session for webinar * @param {boolean} enabled * @returns {Promise} */ - startPracticeSession(enabled) { + setPracticeSessionState(enabled) { return this.request({ method: HTTP_VERBS.PATCH, uri: `${this.locusUrl}/controls`, @@ -90,7 +90,7 @@ const Webinar = WebexPlugin.extend({ }, }, }).catch((error) => { - LoggerProxy.logger.error('Meeting:webinar#startPracticeSession failed', error); + LoggerProxy.logger.error('Meeting:webinar#setPracticeSessionState failed', error); throw error; }); }, diff --git a/packages/@webex/plugin-meetings/test/unit/spec/meeting/in-meeting-actions.ts b/packages/@webex/plugin-meetings/test/unit/spec/meeting/in-meeting-actions.ts index 5c0d1cb4da1..d6b2dec374b 100644 --- a/packages/@webex/plugin-meetings/test/unit/spec/meeting/in-meeting-actions.ts +++ b/packages/@webex/plugin-meetings/test/unit/spec/meeting/in-meeting-actions.ts @@ -88,8 +88,8 @@ describe('plugin-meetings', () => { canShowStageView: null, canEnableStageView: null, canDisableStageView: null, - IsPracticeSessionOn : null, - IsPracticeSessionOff : null, + isPracticeSessionOn : null, + isPracticeSessionOff : null, canStartPracticeSession: null, canStopPracticeSession: null, @@ -186,8 +186,8 @@ describe('plugin-meetings', () => { 'canShowStageView', 'canEnableStageView', 'canDisableStageView', - 'IsPracticeSessionOn', - 'IsPracticeSessionOff', + 'isPracticeSessionOn', + 'isPracticeSessionOff', 'canStartPracticeSession', 'canStopPracticeSession', diff --git a/packages/@webex/plugin-meetings/test/unit/spec/meeting/index.js b/packages/@webex/plugin-meetings/test/unit/spec/meeting/index.js index a94ea8b5737..870efbd3de9 100644 --- a/packages/@webex/plugin-meetings/test/unit/spec/meeting/index.js +++ b/packages/@webex/plugin-meetings/test/unit/spec/meeting/index.js @@ -8982,6 +8982,8 @@ describe('plugin-meetings', () => { }); it('listens to MEETING_CONTROLS_PRACTICE_SESSION_STATUS_UPDATED', async () => { + meeting.webinar.updatePracticeSessionStatus = sinon.stub(); + const state = {example: 'value'}; await meeting.locusInfo.emitScoped( @@ -8990,6 +8992,7 @@ describe('plugin-meetings', () => { {state} ); + assert.calledOnceWithExactly( meeting.webinar.updatePracticeSessionStatus, state); assert.calledWith( TriggerProxy.trigger, meeting, diff --git a/packages/@webex/plugin-meetings/test/unit/spec/webinar/index.ts b/packages/@webex/plugin-meetings/test/unit/spec/webinar/index.ts index ee38d557feb..d466995c637 100644 --- a/packages/@webex/plugin-meetings/test/unit/spec/webinar/index.ts +++ b/packages/@webex/plugin-meetings/test/unit/spec/webinar/index.ts @@ -122,37 +122,20 @@ describe('plugin-meetings', () => { }); }); - describe('#startPracticeSession', () => { - it('sends a PATCH request to enable the practice session', async () => { - const enabled = true; - - const result = await webinar.startPracticeSession(enabled); - - assert.calledOnce(webex.request); - assert.calledWith(webex.request, { - method: 'PATCH', - uri: `${webinar.locusUrl}/controls`, - body: { - practiceSession: { enabled }, - }, - }); - assert.equal(result, 'REQUEST_RETURN_VALUE', 'should return the resolved value from the request'); - }); - - it('sends a PATCH request to disable the practice session', async () => { - const enabled = false; - - const result = await webinar.startPracticeSession(enabled); - - assert.calledOnce(webex.request); - assert.calledWith(webex.request, { - method: 'PATCH', - uri: `${webinar.locusUrl}/controls`, - body: { - practiceSession: { enabled }, - }, + describe("#setPracticeSessionState", () => { + [true, false].forEach((enabled) => { + it(`sends a PATCH request to ${enabled ? "enable" : "disable"} the practice session`, async () => { + const result = await webinar.setPracticeSessionState(enabled); + assert.calledOnce(webex.request); + assert.calledWith(webex.request, { + method: "PATCH", + uri: `${webinar.locusUrl}/controls`, + body: { + practiceSession: { enabled } + } + }); + assert.equal(result, "REQUEST_RETURN_VALUE", "should return the resolved value from the request"); }); - assert.equal(result, 'REQUEST_RETURN_VALUE', 'should return the resolved value from the request'); }); it('handles API call failures gracefully', async () => { @@ -160,18 +143,31 @@ describe('plugin-meetings', () => { const errorLogger = sinon.stub(LoggerProxy.logger, 'error'); try { - await webinar.startPracticeSession(true); - assert.fail('startPracticeSession should throw an error'); + await webinar.setPracticeSessionState(true); + assert.fail('setPracticeSessionState should throw an error'); } catch (error) { assert.equal(error.message, 'API_ERROR', 'should throw the correct error'); assert.calledOnce(errorLogger); - assert.calledWith(errorLogger, 'Meeting:webinar#startPracticeSession failed', sinon.match.instanceOf(Error)); + assert.calledWith(errorLogger, 'Meeting:webinar#setPracticeSessionState failed', sinon.match.instanceOf(Error)); } errorLogger.restore(); }); }); + describe('#updatePracticeSessionStatus', () => { + it('sets PS state true', () => { + webinar.updatePracticeSessionStatus({enabled: true}); + + assert.equal(webinar.practiceSessionEnabled, true); + }); + it('sets PS state true', () => { + webinar.updatePracticeSessionStatus({enabled: false}); + + assert.equal(webinar.practiceSessionEnabled, false); + }); + }); + }) }) From 38c7b861f39927e4f93c5c60eb30e79000083ca4 Mon Sep 17 00:00:00 2001 From: mickelr Date: Thu, 5 Dec 2024 10:32:05 +0800 Subject: [PATCH 5/6] feat(ps): add roles for invite API --- packages/@webex/plugin-meetings/src/meeting/index.ts | 1 + packages/@webex/plugin-meetings/src/members/util.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/@webex/plugin-meetings/src/meeting/index.ts b/packages/@webex/plugin-meetings/src/meeting/index.ts index d03bba607b0..a8a635c3aca 100644 --- a/packages/@webex/plugin-meetings/src/meeting/index.ts +++ b/packages/@webex/plugin-meetings/src/meeting/index.ts @@ -3506,6 +3506,7 @@ export default class Meeting extends StatelessWebexPlugin { emailAddress: string; email: string; phoneNumber: string; + roles: Array; }, alertIfActive = true ) { diff --git a/packages/@webex/plugin-meetings/src/members/util.ts b/packages/@webex/plugin-meetings/src/members/util.ts index 449d686f22a..930d187b2d7 100644 --- a/packages/@webex/plugin-meetings/src/members/util.ts +++ b/packages/@webex/plugin-meetings/src/members/util.ts @@ -46,6 +46,7 @@ const MembersUtil = { { address: options.invitee.emailAddress || options.invitee.email || options.invitee.phoneNumber, + ...(options.invitee.roles ? {roles: options.invitee.roles} : {}), }, ], alertIfActive: options.alertIfActive, From 025b8233ad32f8937e3627f77f38f6ad5ebea6ae Mon Sep 17 00:00:00 2001 From: mickelr Date: Thu, 5 Dec 2024 13:31:01 +0800 Subject: [PATCH 6/6] feat(ps): add ut for invite api --- .../test/unit/spec/members/utils.js | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/packages/@webex/plugin-meetings/test/unit/spec/members/utils.js b/packages/@webex/plugin-meetings/test/unit/spec/members/utils.js index c5477c8b340..e79aca4e490 100644 --- a/packages/@webex/plugin-meetings/test/unit/spec/members/utils.js +++ b/packages/@webex/plugin-meetings/test/unit/spec/members/utils.js @@ -262,5 +262,100 @@ describe('plugin-meetings', () => { testParams(false); }); }); + + describe('#getAddMemberBody', () => { + it('returns the correct body with email address and roles', () => { + const options = { + invitee: { + emailAddress: 'test@example.com', + roles: ['role1', 'role2'], + }, + alertIfActive: true, + }; + + assert.deepEqual(MembersUtil.getAddMemberBody(options), { + invitees: [ + { + address: 'test@example.com', + roles: ['role1', 'role2'], + }, + ], + alertIfActive: true, + }); + }); + + it('returns the correct body with phone number and no roles', () => { + const options = { + invitee: { + phoneNumber: '1234567890', + }, + alertIfActive: false, + }; + + assert.deepEqual(MembersUtil.getAddMemberBody(options), { + invitees: [ + { + address: '1234567890', + }, + ], + alertIfActive: false, + }); + }); + + it('returns the correct body with fallback to email', () => { + const options = { + invitee: { + email: 'fallback@example.com', + }, + alertIfActive: true, + }; + + assert.deepEqual(MembersUtil.getAddMemberBody(options), { + invitees: [ + { + address: 'fallback@example.com', + }, + ], + alertIfActive: true, + }); + }); + + it('handles missing `alertIfActive` gracefully', () => { + const options = { + invitee: { + emailAddress: 'test@example.com', + roles: ['role1'], + }, + }; + + assert.deepEqual(MembersUtil.getAddMemberBody(options), { + invitees: [ + { + address: 'test@example.com', + roles: ['role1'], + }, + ], + alertIfActive: undefined, + }); + }); + + it('ignores roles if not provided', () => { + const options = { + invitee: { + emailAddress: 'test@example.com', + }, + alertIfActive: false, + }; + + assert.deepEqual(MembersUtil.getAddMemberBody(options), { + invitees: [ + { + address: 'test@example.com', + }, + ], + alertIfActive: false, + }); + }); + }); }); });