Skip to content

Commit

Permalink
feat(cc-sdk): merged-with-ravi-pr
Browse files Browse the repository at this point in the history
  • Loading branch information
adhmenon committed Nov 11, 2024
1 parent 8821963 commit 994fe63
Showing 1 changed file with 33 additions and 24 deletions.
57 changes: 33 additions & 24 deletions packages/@webex/plugin-cc/test/unit/spec/services/agent/index.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,43 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { AqmReqs } from '../../../../../src/services/core/aqm-reqs';
import routingAgent from '../../../../../src/services/agent';
import { WebSocketManager } from '../../../../../src/services/core/WebSocket/WebSocketManager';
import { Signal } from '../../../../../src/services/core/Signal';
import {AqmReqs} from '../../../../../src/services/core/aqm-reqs';
import * as Utils from '../../../../../src/services/core/Utils';

jest.mock('../../../../../src/services/core/HttpRequest');
jest.mock('../../../../../src/services/core/WebSocket/WebSocketManager');
jest.mock('../../../../../src/services/core/Utils', () => ({
createErrDetailsObject: jest.fn(),
getRoutingHost: jest.fn(),
}));

global.URL.createObjectURL = jest.fn(() => 'blob:http://localhost:3000/12345');

class MockWebSocketManager extends WebSocketManager {
constructor() {
super({ webex: {} as any });
const { send, signal } = Signal.create.withData<string>();
(this as any).onMessage = signal;
(this as any).onMessageSend = send;
}
}
jest.mock('../../../../../src/services/core/aqm-reqs', () => ({
AqmReqs: jest.fn().mockImplementation(() => ({
reqEmpty: jest.fn().mockImplementation((fn) => fn),
req: jest.fn().mockImplementation((fn) => fn),
evt: jest.fn().mockImplementation((fn) => fn),
})),
}));

describe('AQM routing agent', () => {
let fakeAqm: AqmReqs;
let agent: any;
let fakeAqm: jest.Mocked<AqmReqs>;
let agent: ReturnType<typeof routingAgent>;

beforeEach(() => {
const mockWebSocketManager = new MockWebSocketManager();
jest.clearAllMocks();

const getroutingSpy = jest
.spyOn(Utils, 'getRoutingHost')
.mockReturnValue('https://mock-routing-host.com');

fakeAqm = new AqmReqs(mockWebSocketManager);
agent = routingAgent(fakeAqm) as any;
fakeAqm = new AqmReqs() as jest.Mocked<AqmReqs>;
fakeAqm.reqEmpty = jest.fn().mockImplementation((fn) => fn);
fakeAqm.req = jest.fn().mockImplementation((fn) => fn);
fakeAqm.evt = jest.fn().mockImplementation((fn) => fn);

agent = routingAgent(fakeAqm);
});

it('logout', async () => {
const req = agent.logout({ data: { logoutReason: 'User requested logout' } }).catch((e: any) => e);
const reqSpy = jest.spyOn(fakeAqm, 'reqEmpty');
reqSpy.mockRejectedValue(new Error('dasd'));
const req = await agent.logout({data: {logoutReason: 'User requested logout'}});
expect(req).toBeDefined();
expect(reqSpy).toHaveBeenCalled();
});
Expand All @@ -43,13 +50,15 @@ describe('AQM routing agent', () => {
});

it('stationLogin', async () => {
const req = agent.stationLogin({ data: {} as any }).catch((e: any) => e);
const reqSpy = jest.spyOn(fakeAqm, 'req');
const req = await agent.stationLogin({data: {} as any});
expect(req).toBeDefined();
expect(reqSpy).toHaveBeenCalled();
});

it('stateChange', async () => {
const req = agent.stateChange({ data: {} as any }).catch((e: any) => e);
const reqSpy = jest.spyOn(fakeAqm, 'evt');
const req = await agent.stateChange({data: {} as any});
expect(req).toBeDefined();
expect(reqSpy).toHaveBeenCalled();
});
Expand Down

0 comments on commit 994fe63

Please sign in to comment.