/** * Server — Generated Tests * * AUTO-GENERATED by Phoenix VCS * Tests module structure, server health, and Phoenix traceability. */ import { describe, it, expect, afterAll } from 'vitest'; import { startServer } from '../server.js'; import * as connectionHandling from '../connection-handling.js'; import * as rooms from '../rooms.js'; describe('Server modules', () => { describe('Connection Handling', () => { it('exports Phoenix traceability metadata', () => { expect(connectionHandling._phoenix).toBeDefined(); expect(connectionHandling._phoenix.name).toBe('Connection Handling'); expect(connectionHandling._phoenix.risk_tier).toBeTruthy(); }); it('has exported functions', () => { const exports = Object.keys(connectionHandling).filter(k => k !== '_phoenix'); expect(exports.length).toBeGreaterThan(0); }); }); describe('Rooms', () => { it('exports Phoenix traceability metadata', () => { expect(rooms._phoenix).toBeDefined(); expect(rooms._phoenix.name).toBe('Rooms'); expect(rooms._phoenix.risk_tier).toBeTruthy(); }); it('has exported functions', () => { const exports = Object.keys(rooms).filter(k => k !== '_phoenix'); expect(exports.length).toBeGreaterThan(0); }); }); }); describe('Server server', () => { const instance = startServer(0); // random port afterAll(() => new Promise(resolve => instance.server.close(() => resolve()))); it('GET /health returns 200', async () => { await instance.ready; const res = await fetch(`http://localhost:${instance.port}/health`); expect(res.status).toBe(200); const body = await res.json() as Record; expect(body.status).toBe('ok'); expect(body.service).toBe('Server'); }); it('GET /metrics returns request counts', async () => { await instance.ready; const res = await fetch(`http://localhost:${instance.port}/metrics`); expect(res.status).toBe(200); const body = await res.json() as Record; expect(typeof body.requests_total).toBe('number'); }); it('GET /modules lists all registered modules', async () => { await instance.ready; const res = await fetch(`http://localhost:${instance.port}/modules`); expect(res.status).toBe(200); const body = await res.json() as Array>; expect(body.length).toBe(2); }); it('GET /unknown returns 404', async () => { await instance.ready; const res = await fetch(`http://localhost:${instance.port}/unknown`); expect(res.status).toBe(404); }); });