2026-04-21 22:02:01 +02:00
|
|
|
import { describe, it, expect, vi } from 'vitest';
|
|
|
|
|
import express from 'express';
|
|
|
|
|
import request from 'supertest';
|
2026-05-21 20:00:35 +03:00
|
|
|
import { registerCommonRequestMiddleware, registerServerStatusRoutes } from './core-routes.js';
|
2026-04-21 22:02:01 +02:00
|
|
|
|
|
|
|
|
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',
|
2026-05-21 20:00:35 +03:00
|
|
|
express,
|
2026-04-21 22:02:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
registerServerStatusRoutes(app, dependencies);
|
|
|
|
|
|
|
|
|
|
await request(app).post('/api/system/shutdown');
|
|
|
|
|
|
|
|
|
|
expect(dependencies.gracefulShutdown).toHaveBeenCalled();
|
|
|
|
|
expect(shutdownOpts).toEqual({ exitProcess: true });
|
|
|
|
|
});
|
2026-05-21 20:00:35 +03:00
|
|
|
|
|
|
|
|
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' } });
|
|
|
|
|
});
|
2026-04-21 22:02:01 +02:00
|
|
|
});
|