import assert from 'node:assert/strict'; import { test } from 'node:test'; import Fastify from 'fastify'; import healthRoutes from '../src/routes/health'; test('health checks the database and reports a failure without leaking connection details', async () => { const app = Fastify(); let available = true; app.decorate('db', { execute: async () => { if (!available) throw new Error('postgres://secret@database'); return { rows: [{ result: 1 }] }; } } as any); try { await app.register(healthRoutes); const healthy = await app.inject('/health'); assert.equal(healthy.statusCode, 200); assert.equal(healthy.json().status, 'ok'); assert.equal(healthy.headers['cache-control'], 'no-store'); available = false; const unhealthy = await app.inject('/health'); assert.equal(unhealthy.statusCode, 503); assert.deepEqual(unhealthy.json(), { status: 'unavailable' }); } finally { await app.close(); } }); test('version endpoint reports image metadata without a database or authentication', async () => { const previousVersion = process.env.FEDEO_VERSION; const previousRevision = process.env.FEDEO_REVISION; process.env.FEDEO_VERSION = '1.2.3'; process.env.FEDEO_REVISION = 'a'.repeat(40); const app = Fastify(); try { await app.register(healthRoutes); const response = await app.inject({ method: 'GET', url: '/version' }); assert.equal(response.statusCode, 200); assert.equal(response.headers['cache-control'], 'no-store'); assert.deepEqual(response.json(), { product: 'FEDEO', version: '1.2.3', revision: 'a'.repeat(40) }); } finally { await app.close(); if (previousVersion === undefined) delete process.env.FEDEO_VERSION; else process.env.FEDEO_VERSION = previousVersion; if (previousRevision === undefined) delete process.env.FEDEO_REVISION; else process.env.FEDEO_REVISION = previousRevision; } });