This commit is contained in:
@@ -18,7 +18,7 @@ export const registerServerStatusRoutes = (app, dependencies) => {
|
||||
|
||||
app.post('/api/system/shutdown', (_req, res) => {
|
||||
res.json({ ok: true });
|
||||
gracefulShutdown({ exitProcess: false }).catch((error) => {
|
||||
gracefulShutdown({ exitProcess: true }).catch((error) => {
|
||||
console.error('Shutdown request failed:', error?.message || error);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import express from 'express';
|
||||
import request from 'supertest';
|
||||
import { 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',
|
||||
};
|
||||
|
||||
registerServerStatusRoutes(app, dependencies);
|
||||
|
||||
await request(app).post('/api/system/shutdown');
|
||||
|
||||
expect(dependencies.gracefulShutdown).toHaveBeenCalled();
|
||||
expect(shutdownOpts).toEqual({ exitProcess: true });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user