Skip to content

Commit

Permalink
fix(plugin-meetings): added unit test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Parimala032 committed Oct 2, 2024
1 parent c7bee57 commit a414ad5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 22 deletions.
4 changes: 1 addition & 3 deletions docs/samples/browser-plugin-meetings/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function register() {
unregisterElm.disabled = true;
registrationStatusElm.innerText = 'Registering...';

webex.meetings.register(isGuest)
webex.meetings.register()
.then(() => {
console.log('Authentication#register() :: successfully registered');
toggleUnifiedMeetings.removeAttribute('disabled');
Expand Down Expand Up @@ -226,7 +226,6 @@ function unregister() {
});
}

let isGuest = false;
async function getGuestAccessToken() {

await axios({
Expand All @@ -238,7 +237,6 @@ async function getGuestAccessToken() {
}).then(function (response) {
console.log("guest token response", response.data.body.token);
tokenElm.value = response.data.body.token
isGuest = true;
}).catch((e) =>{
console.error("Error fetching guest", e)
})
Expand Down
35 changes: 16 additions & 19 deletions packages/@webex/plugin-meetings/src/meetings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,8 @@ export default class Meetings extends WebexPlugin {
* @returns {Promise}
* @public
* @memberof Meetings
* @param {boolean} isGuest
*/
public register(isGuest) {
public register() {
// @ts-ignore
if (!this.webex.canAuthorize) {
LoggerProxy.logger.error(
Expand All @@ -546,16 +545,8 @@ export default class Meetings extends WebexPlugin {
return Promise.resolve();
}

const promises = [];
// Only call fetchUserPreferredWebexSite() if not a guest
if (!isGuest) {
promises.push(this.fetchUserPreferredWebexSite());
} else {
LoggerProxy.logger.info(
'Meetings:index#register --> INFO, Skipping fetchUserPreferredWebexSite() because user is a guest'
);
}
promises.push(
return Promise.all([
this.fetchUserPreferredWebexSite(),
this.getGeoHint(),
this.startReachability().catch((error) => {
LoggerProxy.logger.error(`Meetings:index#register --> GDM error, ${error.message}`);
Expand All @@ -572,10 +563,8 @@ export default class Meetings extends WebexPlugin {
)
// @ts-ignore
.then(() => this.webex.internal.mercury.connect()),
MeetingsUtil.checkH264Support.call(this)
);

return Promise.all(promises)
MeetingsUtil.checkH264Support.call(this),
])
.then(() => {
this.listenForEvents();
Trigger.trigger(
Expand Down Expand Up @@ -772,10 +761,18 @@ export default class Meetings extends WebexPlugin {
* @memberof Meetings
*/
fetchUserPreferredWebexSite() {
return this.request.getMeetingPreferences().then((res) => {
if (res) {
this.preferredWebexSite = MeetingsUtil.parseDefaultSiteFromMeetingPreferences(res);
// @ts-ignore
return this.webex.people._getMe().then((me) => {
const Guest = me.type === 'appuser';
if (!Guest) {
return this.request.getMeetingPreferences().then((res) => {
if (res) {
this.preferredWebexSite = MeetingsUtil.parseDefaultSiteFromMeetingPreferences(res);
}
});
}

return Promise.resolve();
});
}

Expand Down
20 changes: 20 additions & 0 deletions packages/@webex/plugin-meetings/test/unit/spec/meetings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ describe('plugin-meetings', () => {

Object.assign(webex, {
logger,
people: {
_getMe: sinon.stub().resolves({
type: 'validuser',
}),
}
});

Object.assign(webex.meetings, {
Expand Down Expand Up @@ -1276,6 +1281,21 @@ describe('plugin-meetings', () => {
assert.equal(webex.meetings.preferredWebexSite, 'go.webex.com');
});

const setup = ({me = {type: 'validuser'}} = {}) => {
Object.assign(webex.people,{
_getMe: sinon.stub().returns(Promise.resolve(me)),
})
}

it('should not call request.getMeetingPreferences if user is a guest', async () => {
setup({me: {type: 'appuser'}});

await webex.meetings.fetchUserPreferredWebexSite();

assert.equal(webex.meetings.preferredWebexSite, '');
assert.notCalled(webex.internal.services.getMeetingPreferences);
});

it('should not fail if UserPreferred info is not fetched ', async () => {
Object.assign(webex.internal, {
services: {
Expand Down

0 comments on commit a414ad5

Please sign in to comment.