Skip to content

Commit

Permalink
fix: rebased code and fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rsarika committed Nov 11, 2024
1 parent 35b6e15 commit 1be5059
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 116 deletions.
6 changes: 3 additions & 3 deletions packages/@webex/plugin-cc/src/cc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {WebexPlugin} from '@webex/webex-core';
import AgentConfig from './features/Agentconfig';
import {SetStateResponse} from './features/types';
import {
SetStateResponse,
CCPluginConfig,
IContactCenter,
WebexSDK,
Expand Down Expand Up @@ -195,15 +195,15 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter
* @throws Error
*/

public async setAgentStatus(data: StateChange): Promise<SetStateResponse> {
public async setAgentState(data: StateChange): Promise<SetStateResponse> {
try {
const agentStatusPromise = await this.services.agent.stateChange({data});

this.$webex.logger.log(`file: ${CC_FILE}: SET AGENT STATUS API SUCCESS`);

return Promise.resolve(agentStatusPromise);
} catch (error) {
return Promise.reject(error);
throw getErrorDetails(error, 'setAgentState');
}
}
}
61 changes: 0 additions & 61 deletions packages/@webex/plugin-cc/src/features/Agent.ts

This file was deleted.

13 changes: 0 additions & 13 deletions packages/@webex/plugin-cc/src/features/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {WebexSDK} from '../types';
import * as Agent from '../services/agent/types';

type Enum<T extends Record<string, unknown>> = T[keyof T];

Expand Down Expand Up @@ -34,15 +33,3 @@ export type AgentConfigRequest = {
*/
orgId: string;
};

/**
* Represents the response from setAgentStatus.
*
* @public
*/
export type SetStateResponse = {
data?: Agent.StateChangeSuccess;
error?: string;
};

export type StationLoginResponse = Agent.StationLoginSuccess | Error;
1 change: 1 addition & 0 deletions packages/@webex/plugin-cc/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,4 @@ export type RequestBody =
export type StationLoginResponse = Agent.StationLoginSuccess | Error;
export type StationLogoutResponse = Agent.LogoutSuccess | Error;
export type StationReLoginResponse = Agent.ReloginSuccess | Error;
export type SetStateResponse = Agent.StateChangeSuccess | Error;
81 changes: 42 additions & 39 deletions packages/@webex/plugin-cc/test/unit/spec/cc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ describe('webex.cc', () => {
stationLogin: jest.fn(),
logout: jest.fn(),
reload: jest.fn(),
stateChange: jest.fn(),
},
};
(Services.getInstance as jest.Mock).mockReturnValue(mockServicesInstance);
Expand Down Expand Up @@ -312,90 +313,92 @@ describe('webex.cc', () => {

describe('setAgentStatus', () => {
it('should set agent status successfully when status is Available', async () => {

const expectedPayload = {
const expectedPayload = {
state: 'Available',
auxCodeId: '0',
agentId: '123',
lastStateChangeReason: 'Agent is available',
};

const setAgentStatusMock = jest
.spyOn(webex.cc.agent, 'setAgentStatus')
.spyOn(webex.cc.services.agent, 'stateChange')
.mockResolvedValue(expectedPayload);

const result = await webex.cc.setAgentStatus(expectedPayload);
const result = await webex.cc.setAgentState(expectedPayload);

expect(setAgentStatusMock).toHaveBeenCalledWith(expectedPayload);
expect(setAgentStatusMock).toHaveBeenCalledWith({data: expectedPayload});
expect(result).toEqual(expectedPayload);
expect(webex.logger.log).toHaveBeenCalledWith('file: cc: SET AGENT STATUS API SUCCESS');
});

it('should handle error during setAgentStatus when status is Available', async () => {

const expectedPayload = {
state: 'Available',
auxCodeId: '0',
agentId: '123',
lastStateChangeReason: 'Agent is available',
};

const error = new Error('Set status failed');
jest.spyOn(webex.cc.agent, 'setAgentStatus').mockRejectedValue(error);

await expect(webex.cc.setAgentStatus(expectedPayload)).rejects.toThrow(error);
expect(webex.logger.error).toHaveBeenCalledWith('SET AGENT STATUS FAILED', error);
});

it('should set agent status successfully when status is Meeting', async () => {

const expectedPayload = {
const expectedPayload = {
state: 'Meeting',
auxCodeId: '12345',
agentId: '123',
lastStateChangeReason: 'Agent is in meeting',
};

const setAgentStatusMock = jest
.spyOn(webex.cc.agent, 'setAgentStatus')
.spyOn(webex.cc.services.agent, 'stateChange')
.mockResolvedValue(expectedPayload);

const result = await webex.cc.setAgentStatus(expectedPayload);
const result = await webex.cc.setAgentState(expectedPayload);

expect(setAgentStatusMock).toHaveBeenCalledWith(expectedPayload);
expect(setAgentStatusMock).toHaveBeenCalledWith({data: expectedPayload});
expect(result).toEqual(expectedPayload);
expect(webex.logger.log).toHaveBeenCalledWith('file: cc: SET AGENT STATUS API SUCCESS');
});

it('should handle error during setAgentStatus when status is Meeting', async () => {

const expectedPayload = {
const expectedPayload = {
state: 'Meeting',
auxCodeId: '12345',
agentId: '123',
lastStateChangeReason: 'Agent is in meeting',
};

const error = new Error('Set status failed');
jest.spyOn(webex.cc.agent, 'setAgentStatus').mockRejectedValue(error);
const error = {
details: {
trackingId: '1234',
data: {
reason: 'missing status',
},
},
};
jest.spyOn(webex.cc.services.agent, 'stateChange').mockRejectedValue(error);

await expect(webex.cc.setAgentStatus(expectedPayload)).rejects.toThrow(error);
expect(webex.logger.error).toHaveBeenCalledWith('SET AGENT STATUS FAILED', error);
await expect(webex.cc.setAgentState(expectedPayload)).rejects.toThrow(
error.details.data.reason
);
expect(LoggerProxy.logger.error).toHaveBeenCalledWith(
`setAgentState failed with trackingId: ${error.details.trackingId}`
);
});

it('should handle invalid status', async () => {

const invalidPayload = {
const invalidPayload = {
state: 'invalid',
auxCodeId: '12345',
agentId: '123',
lastStateChangeReason: 'invalid',
};
const error = new Error('Invalid status');
jest.spyOn(webex.cc.agent, 'setAgentStatus').mockRejectedValue(error);
const error = {
details: {
trackingId: '1234',
data: {
reason: 'Invalid status',
},
},
};
jest.spyOn(webex.cc.services.agent, 'stateChange').mockRejectedValue(error);

await expect(webex.cc.setAgentStatus(invalidPayload)).rejects.toThrow(error);
expect(webex.logger.error).toHaveBeenCalledWith('SET AGENT STATUS FAILED', error);
await expect(webex.cc.setAgentState(invalidPayload)).rejects.toThrow(
error.details.data.reason
);
expect(LoggerProxy.logger.error).toHaveBeenCalledWith(
`setAgentState failed with trackingId: ${error.details.trackingId}`
);
});
});
});
});
45 changes: 45 additions & 0 deletions packages/@webex/plugin-cc/test/unit/spec/features/AgentConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ describe('AgentConfig', () => {
name: 'testName',
workTypeCode: WORK_TYPE_CODE.IDLE_CODE,
},
{
active: true,
defaultCode: true,
description: 'Agent is available to receive calls',
id: '0',
isSystemCode: false,
name: 'Available',
workTypeCode: 'IDLE_CODE',
},
],
};

Expand Down Expand Up @@ -221,6 +230,15 @@ describe('AgentConfig', () => {
name: 'testName',
workTypeCode: WORK_TYPE_CODE.IDLE_CODE,
},
{
active: true,
defaultCode: true,
description: 'Agent is available to receive calls',
id: '0',
isSystemCode: false,
name: 'Available',
workTypeCode: 'IDLE_CODE',
},
],
};

Expand Down Expand Up @@ -297,6 +315,15 @@ describe('AgentConfig', () => {
name: 'testName',
workTypeCode: WORK_TYPE_CODE.IDLE_CODE,
},
{
active: true,
defaultCode: true,
description: 'Agent is available to receive calls',
id: '0',
isSystemCode: false,
name: 'Available',
workTypeCode: 'IDLE_CODE',
},
],
};

Expand Down Expand Up @@ -373,6 +400,15 @@ describe('AgentConfig', () => {
name: 'testName',
workTypeCode: WORK_TYPE_CODE.IDLE_CODE,
},
{
active: true,
defaultCode: true,
description: 'Agent is available to receive calls',
id: '0',
isSystemCode: false,
name: 'Available',
workTypeCode: 'IDLE_CODE',
},
],
};

Expand Down Expand Up @@ -449,6 +485,15 @@ describe('AgentConfig', () => {
name: 'testName',
workTypeCode: WORK_TYPE_CODE.IDLE_CODE,
},
{
active: true,
defaultCode: true,
description: 'Agent is available to receive calls',
id: '0',
isSystemCode: false,
name: 'Available',
workTypeCode: 'IDLE_CODE',
},
],
};

Expand Down

0 comments on commit 1be5059

Please sign in to comment.