// Avoid pulling in the real config (which would require env vars). The // websocket module only reads config.ws.{port,token}, so a small stub is enough. jest.mock('../config', () => ({ ws: { port: 0, token: 'test-token' }, logLevel: 'error', })); const { proxyRequest, isAgentConnected, AgentNotConnectedError } = require('../services/websocket'); describe('websocket service', () => { describe('isAgentConnected', () => { it('returns false when no agent is connected', () => { expect(isAgentConnected()).toBe(false); }); }); describe('proxyRequest', () => { it('rejects with AgentNotConnectedError when no agent is connected', async () => { await expect(proxyRequest({ method: 'GET', url: 'http://x' })).rejects.toBeInstanceOf( AgentNotConnectedError ); await expect(proxyRequest({ method: 'GET', url: 'http://x' })).rejects.toMatchObject({ code: 'AGENT_NOT_CONNECTED', }); }); }); });