import { getToolkitSocketUrl } from '../src/socket/toolkitSocketClient'; const originalToolkitSocketUrl = process.env.TOOLKIT_SOCKET_URL; const originalLocation = Object.getOwnPropertyDescriptor( globalThis, 'location', ); function setTestLocation(hostname: string, protocol = 'http:') { Object.defineProperty(globalThis, 'location', { configurable: true, value: { hostname, protocol, }, }); } function restoreTestLocation() { if (originalLocation == null) { Reflect.deleteProperty(globalThis, 'location'); return; } Object.defineProperty(globalThis, 'location', originalLocation); } describe('toolkit socket client configuration', () => { afterEach(() => { if (originalToolkitSocketUrl == null) { delete process.env.TOOLKIT_SOCKET_URL; } else { process.env.TOOLKIT_SOCKET_URL = originalToolkitSocketUrl; } restoreTestLocation(); }); it('uses explicit toolkit socket URL configuration first', () => { process.env.TOOLKIT_SOCKET_URL = 'http://socket.example.test:5174'; setTestLocation('bone-kingdom.tabitha.tealthrone'); expect(getToolkitSocketUrl()).toBe('http://socket.example.test:5174'); }); it('uses local socket defaults for localhost development', () => { delete process.env.TOOLKIT_SOCKET_URL; setTestLocation('localhost'); expect(getToolkitSocketUrl()).toBe('http://127.0.0.1:5174'); }); it('derives the deployed socket URL from the current browser host', () => { delete process.env.TOOLKIT_SOCKET_URL; setTestLocation('bone-kingdom.tabitha.tealthrone'); expect(getToolkitSocketUrl()).toBe( 'http://bone-kingdom.tabitha.tealthrone:5174', ); }); });