import { describe, it, expect, vi } from 'vitest'; import express from 'express'; import request from 'supertest'; import { registerCommonRequestMiddleware, registerServerStatusRoutes } from './core-routes.js'; describe('core-routes', () => { it('should call gracefulShutdown with exitProcess: true on /api/system/shutdown', async () => { const app = express(); let shutdownOpts = null; const dependencies = { gracefulShutdown: vi.fn(async (opts) => { shutdownOpts = opts; }), getHealthSnapshot: () => ({ status: 'ok' }), openchamberVersion: '1.0.0', runtimeName: 'test', express, }; registerServerStatusRoutes(app, dependencies); await request(app).post('/api/system/shutdown'); expect(dependencies.gracefulShutdown).toHaveBeenCalled(); expect(shutdownOpts).toEqual({ exitProcess: true }); }); it('should parse JSON bodies for snippet config routes', async () => { const app = express(); registerCommonRequestMiddleware(app, { express }); app.post('/api/config/snippets/example', (req, res) => { res.json({ body: req.body }); }); const response = await request(app) .post('/api/config/snippets/example') .send({ content: 'Snippet body' }) .expect(200); expect(response.body).toEqual({ body: { content: 'Snippet body' } }); }); });