From fa4c42e8540634c31af6f6d844aafd90740c1eba Mon Sep 17 00:00:00 2001 From: Priya Date: Thu, 5 Dec 2024 00:31:34 +0530 Subject: [PATCH] feat(plugin-cc): added types and add ut for cc file --- .../plugin-cc/src/services/task/types.ts | 23 ++++++++++++++++++- .../@webex/plugin-cc/test/unit/spec/cc.ts | 21 ++++++++++++++--- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/packages/@webex/plugin-cc/src/services/task/types.ts b/packages/@webex/plugin-cc/src/services/task/types.ts index bec6a65acf0..ce205a8667d 100644 --- a/packages/@webex/plugin-cc/src/services/task/types.ts +++ b/packages/@webex/plugin-cc/src/services/task/types.ts @@ -142,7 +142,7 @@ type Interaction = { }; /** - * + * Task payload type */ export type TaskData = { mediaResourceId: string; @@ -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; @@ -282,6 +294,9 @@ export type declinePayload = { mediaResourceId: string; }; +/** + * Parameters to be passed for wrapup task + */ export type WrapupPayLoad = { wrapUpReason: string; auxCodeId: string; @@ -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 diff --git a/packages/@webex/plugin-cc/test/unit/spec/cc.ts b/packages/@webex/plugin-cc/test/unit/spec/cc.ts index f735895fa4e..73d68cf8748 100644 --- a/packages/@webex/plugin-cc/test/unit/spec/cc.ts +++ b/packages/@webex/plugin-cc/test/unit/spec/cc.ts @@ -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', () => ({ @@ -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({ @@ -101,7 +104,7 @@ describe('webex.cc', () => { contact: mockContact }; - const mockTaskManager = { + mockTaskManager = { contact: mockContact, call: undefined, taskCollection: {}, @@ -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); @@ -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', () => { @@ -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); });