Skip to content

Commit

Permalink
feat(plugin-cc): added types and add ut for cc file
Browse files Browse the repository at this point in the history
  • Loading branch information
Kesari3008 committed Dec 4, 2024
1 parent 4c6a2bc commit fa4c42e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
23 changes: 22 additions & 1 deletion packages/@webex/plugin-cc/src/services/task/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ type Interaction = {
};

/**
*
* Task payload type
*/
export type TaskData = {
mediaResourceId: string;
Expand Down Expand Up @@ -248,19 +248,31 @@ export type VTeamSuccess = Msg<{
agentSessionId: string;
}>;

/**
* Parameters to be passed for pause recording task
*/
export type HoldResumePayload = {
mediaResourceId: string;
};

/**
* Parameters to be passed for resume recording task
*/
export type ResumeRecordingPayload = {
autoResumed: boolean;
};

/**
* Parameters to be passed for transfer task
*/
export type TransferPayLoad = {
to: string;
destinationType: DestinationType;
};

/**
* Parameters to be passed for consult task
*/
export type ConsultPayload = {
to: string | undefined;
destinationType: string;
Expand All @@ -282,6 +294,9 @@ export type declinePayload = {
mediaResourceId: string;
};

/**
* Parameters to be passed for wrapup task
*/
export type WrapupPayLoad = {
wrapUpReason: string;
auxCodeId: string;
Expand All @@ -304,8 +319,14 @@ export type ContactCleanupData = {
};
};

/**
* Response type for the task public methods
*/
export type TaskResponse = AgentContact | Error | void;

/**
* Represents an interface for managing task related operations.
*/
export interface ITask {
/**
* Event data received in the CC events
Expand Down
21 changes: 18 additions & 3 deletions packages/@webex/plugin-cc/test/unit/spec/cc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {CC_FILE} from '../../../src/constants';
import '../../../__mocks__/workerMock';
import {Profile} from '../../../src/services/config/types';
import TaskManager from '../../../src/services/task/TaskManager';
import { TASK_EVENTS } from '../../../src/services/task/types';


jest.mock('../../../src/logger-proxy', () => ({
Expand All @@ -41,8 +42,10 @@ global.URL.createObjectURL = jest.fn(() => 'blob:http://localhost:3000/12345');

describe('webex.cc', () => {
let webex;
let mockWebSocketManager;
let mockContact;
let mockTaskManager;
let mockWebSocketManager;


beforeEach(() => {
webex = MockWebex({
Expand Down Expand Up @@ -101,7 +104,7 @@ describe('webex.cc', () => {
contact: mockContact
};

const mockTaskManager = {
mockTaskManager = {
contact: mockContact,
call: undefined,
taskCollection: {},
Expand All @@ -114,7 +117,8 @@ describe('webex.cc', () => {
getActiveTasks: jest.fn(),
on: jest.fn(),
off: jest.fn(),
emit: jest.fn()
emit: jest.fn(),
unregisterIncomingCallEvent: jest.fn()
}

jest.spyOn(Services, 'getInstance').mockReturnValue(mockServicesInstance);
Expand All @@ -128,12 +132,21 @@ describe('webex.cc', () => {
});

it('should initialize services and logger proxy on READY event', () => {
const mockTask = {};
const onSpy = jest.spyOn(mockTaskManager, 'on');
const emitSpy = jest.spyOn(webex.cc.eventEmitter, 'emit');
const incomingCallCb = onSpy.mock.calls[0][1];
webex.once('READY', () => {
expect(Services.getInstance).toHaveBeenCalled();
expect(LoggerProxy.initialize).toHaveBeenCalledWith(webex.logger);
});

webex.emit('READY');
expect(onSpy).toHaveBeenCalledWith(TASK_EVENTS.TASK_INCOMING, incomingCallCb);

incomingCallCb(mockTask);

expect(emitSpy).toHaveBeenCalledWith(TASK_EVENTS.TASK_INCOMING, mockTask);
});

describe('cc.getDeviceId', () => {
Expand Down Expand Up @@ -458,6 +471,8 @@ describe('webex.cc', () => {
const result = await webex.cc.stationLogout(data);

expect(stationLogoutMock).toHaveBeenCalledWith({data: data});
expect(mockTaskManager.unregisterIncomingCallEvent).toHaveBeenCalledWith();
expect(mockTaskManager.off).toHaveBeenCalledWith(TASK_EVENTS.TASK_INCOMING, expect.any(Function));
expect(result).toEqual(response);
});

Expand Down

0 comments on commit fa4c42e

Please sign in to comment.