import { expect, tap } from '@git.zone/tstest/tapbundle'; import { DcRouter } from '../ts/index.js'; import { TypedRequest } from '@api.global/typedrequest'; import * as interfaces from '../ts_interfaces/index.js'; let testDcRouter: DcRouter; let adminIdentity: interfaces.data.IIdentity; tap.test('should start DCRouter with OpsServer', async () => { testDcRouter = new DcRouter({ // Minimal config for testing cacheConfig: { enabled: false }, }); await testDcRouter.start(); expect(testDcRouter.opsServer).toBeInstanceOf(Object); }); tap.test('should login as admin', async () => { const loginRequest = new TypedRequest( 'http://localhost:3000/typedrequest', 'adminLoginWithUsernameAndPassword' ); const response = await loginRequest.fire({ username: 'admin', password: 'admin', }); expect(response).toHaveProperty('identity'); adminIdentity = response.identity; }); tap.test('should respond to health status request', async () => { const healthRequest = new TypedRequest( 'http://localhost:3000/typedrequest', 'getHealthStatus' ); const response = await healthRequest.fire({ identity: adminIdentity, detailed: false, }); expect(response).toHaveProperty('health'); expect(response.health.healthy).toBeTrue(); expect(response.health.services).toHaveProperty('OpsServer'); }); tap.test('should respond to server statistics request', async () => { const statsRequest = new TypedRequest( 'http://localhost:3000/typedrequest', 'getServerStatistics' ); const response = await statsRequest.fire({ identity: adminIdentity, includeHistory: false, }); expect(response).toHaveProperty('stats'); expect(response.stats).toHaveProperty('uptime'); expect(response.stats).toHaveProperty('cpuUsage'); expect(response.stats).toHaveProperty('memoryUsage'); }); tap.test('should respond to configuration request', async () => { const configRequest = new TypedRequest( 'http://localhost:3000/typedrequest', 'getConfiguration' ); const response = await configRequest.fire({ identity: adminIdentity, }); expect(response).toHaveProperty('config'); expect(response.config).toHaveProperty('system'); expect(response.config).toHaveProperty('smartProxy'); expect(response.config).toHaveProperty('email'); expect(response.config).toHaveProperty('dns'); expect(response.config).toHaveProperty('tls'); expect(response.config).toHaveProperty('cache'); expect(response.config).toHaveProperty('radius'); expect(response.config).toHaveProperty('remoteIngress'); }); tap.test('should handle log retrieval request', async () => { const logsRequest = new TypedRequest( 'http://localhost:3000/typedrequest', 'getRecentLogs' ); const response = await logsRequest.fire({ identity: adminIdentity, limit: 10, }); expect(response).toHaveProperty('logs'); expect(response).toHaveProperty('total'); expect(response).toHaveProperty('hasMore'); expect(response.logs).toBeArray(); }); tap.test('should reject unauthenticated requests', async () => { const healthRequest = new TypedRequest( 'http://localhost:3000/typedrequest', 'getHealthStatus' ); try { await healthRequest.fire({} as any); expect(true).toBeFalse(); // Should not reach here } catch (error) { expect(error).toBeTruthy(); } }); tap.test('should stop DCRouter', async () => { await testDcRouter.stop(); }); export default tap.start();