Skip to content

Commit

Permalink
feat(plugin-cc): merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Kesari3008 committed Dec 2, 2024
2 parents 37ec111 + 3fa2938 commit e8dcefd
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 4 deletions.
6 changes: 4 additions & 2 deletions docs/samples/contact-center/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,15 @@ function register() {
});
const loginVoiceOptions = agentProfile.loginVoiceOptions;
agentLogin.innerHTML = '<option value="" selected>Choose Agent Login ...</option>'; // Clear previously selected option on agentLogin.
dialNumber.value = '';
dialNumber.disabled = true;
dialNumber.value = agentProfile.defaultDn ? agentProfile.defaultDn : '';
dialNumber.disabled = agentProfile.defaultDn ? false : true;
if (loginVoiceOptions.length > 0) loginAgentElm.disabled = false;
loginVoiceOptions.forEach((voiceOptions)=> {
const option = document.createElement('option');
option.text = voiceOptions;
option.value = voiceOptions;
agentLogin.add(option);
option.selected = agentProfile.isAgentLoggedIn && voiceOptions === agentProfile.deviceType;
});

if (agentProfile.isAgentLoggedIn) {
Expand Down Expand Up @@ -236,6 +237,7 @@ function logoutAgent() {

setTimeout(() => {
logoutAgentElm.classList.add('hidden');
agentLogin.selectedIndex = 0;
}, 1000);
}
).catch((error) => {
Expand Down
27 changes: 25 additions & 2 deletions packages/@webex/plugin-cc/src/cc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter
private async silentRelogin(): Promise<void> {
try {
const reLoginResponse = await this.services.agent.reload();
const {auxCodeId, agentId, lastStateChangeReason} = reLoginResponse.data;
const {auxCodeId, agentId, lastStateChangeReason, deviceType, dn} = reLoginResponse.data;

if (lastStateChangeReason === 'agent-wss-disconnect') {
LoggerProxy.info(
Expand All @@ -331,7 +331,8 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter
};
await this.setAgentState(stateChangeData);
}
// Updating isAgentLoggedIn as true to indicate to the end user

await this.handleDeviceType(deviceType as LoginOption, dn);
this.agentConfig.isAgentLoggedIn = true;
} catch (error) {
const {reason, error: detailedError} = getErrorDetails(error, 'silentReLogin', CC_FILE);
Expand All @@ -346,4 +347,26 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter
throw detailedError;
}
}

/**
* Handles the device type specific logic
*/
private async handleDeviceType(deviceType: LoginOption, dn: string): Promise<void> {
switch (deviceType) {
case LoginOption.BROWSER:
await this.webCallingService.registerWebCallingLine();
break;
case LoginOption.AGENT_DN:
case LoginOption.EXTENSION:
this.agentConfig.defaultDn = dn;
break;
default:
LoggerProxy.error(`Unsupported device type: ${deviceType}`, {
module: CC_FILE,
method: this.handleDeviceType.name,
});
throw new Error(`Unsupported device type: ${deviceType}`);
}
this.agentConfig.deviceType = deviceType;
}
}
65 changes: 65 additions & 0 deletions packages/@webex/plugin-cc/test/unit/spec/cc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ describe('webex.cc', () => {
data: {
auxCodeId: 'auxCodeId',
agentId: 'agentId',
deviceType: LoginOption.EXTENSION,
dn: '12345',
},
});
const configSpy = jest
Expand Down Expand Up @@ -701,6 +703,8 @@ describe('webex.cc', () => {
auxCodeId: 'auxCodeId',
agentId: 'agentId',
lastStateChangeReason: 'agent-wss-disconnect',
deviceType: LoginOption.BROWSER,
dn: '12345',
},
};

Expand Down Expand Up @@ -729,6 +733,7 @@ describe('webex.cc', () => {
agentId: 'agentId',
});
expect(webex.cc.agentConfig.isAgentLoggedIn).toBe(true);
expect(webex.cc.agentConfig.deviceType).toBe(LoginOption.BROWSER);
});

it('should handle AGENT_NOT_FOUND error silently', async () => {
Expand All @@ -748,5 +753,65 @@ describe('webex.cc', () => {
{module: CC_FILE, method: 'silentRelogin'}
);
});

it('should handle errors during silent relogin', async () => {
const error = new Error('Error while performing silentReLogin');
jest.spyOn(webex.cc.services.agent, 'reload').mockRejectedValue(error);

await expect(webex.cc['silentRelogin']()).rejects.toThrow(error);
});

it('should update agentConfig with deviceType during silent relogin for EXTENSION', async () => {
const mockReLoginResponse = {
data: {
auxCodeId: 'auxCodeId',
agentId: 'agentId',
lastStateChangeReason: 'agent-wss-disconnect',
deviceType: LoginOption.EXTENSION,
dn: '12345',
},
};

// Mock the agentConfig
webex.cc.agentConfig = {
agentId: 'agentId',
agentProfileID: 'test-agent-profile-id',
isAgentLoggedIn: false,
} as Profile;

jest.spyOn(webex.cc.services.agent, 'reload').mockResolvedValue(mockReLoginResponse);

await webex.cc['silentRelogin']();

expect(webex.cc.agentConfig.deviceType).toBe(LoginOption.EXTENSION);
expect(webex.cc.agentConfig.defaultDn).toBe('12345');
});

it('should update agentConfig with deviceType during silent relogin for AGENT_DN', async () => {
const mockReLoginResponse = {
data: {
auxCodeId: 'auxCodeId',
agentId: 'agentId',
lastStateChangeReason: 'agent-wss-disconnect',
deviceType: LoginOption.AGENT_DN,
dn: '67890',
subStatus: 'subStatusValue',
},
};

// Mock the agentConfig
webex.cc.agentConfig = {
agentId: 'agentId',
agentProfileID: 'test-agent-profile-id',
isAgentLoggedIn: false,
} as Profile;

jest.spyOn(webex.cc.services.agent, 'reload').mockResolvedValue(mockReLoginResponse);

await webex.cc['silentRelogin']();

expect(webex.cc.agentConfig.deviceType).toBe(LoginOption.AGENT_DN);
expect(webex.cc.agentConfig.defaultDn).toBe('67890');
});
});
});

0 comments on commit e8dcefd

Please sign in to comment.