feat(backend): add GET /api/diagnostics/config route + test
- Returns sanitized config: productId, serviceName, port, nodeEnv, dbProvider, telemetryEnabled, featureFlagsEnabled - Integration test validates response shape
This commit is contained in:
parent
95c2f9426a
commit
62f94be845
@ -3,6 +3,8 @@ import Fastify from 'fastify';
|
||||
import type { FastifyInstance } from 'fastify';
|
||||
import { getAllFlags } from './lib/feature-flags.js';
|
||||
import { getBufferedEvents, flushEvents } from './lib/telemetry.js';
|
||||
import { config } from './lib/config.js';
|
||||
import { PRODUCT_ID } from './lib/product-config.js';
|
||||
|
||||
let app: FastifyInstance;
|
||||
|
||||
@ -11,6 +13,15 @@ beforeAll(async () => {
|
||||
app.get('/api/diagnostics/flags', async () => getAllFlags());
|
||||
app.get('/api/diagnostics/telemetry', async () => ({ events: getBufferedEvents() }));
|
||||
app.post('/api/diagnostics/telemetry/flush', async () => ({ flushed: flushEvents().length }));
|
||||
app.get('/api/diagnostics/config', async () => ({
|
||||
productId: PRODUCT_ID,
|
||||
serviceName: config.SERVICE_NAME,
|
||||
port: config.PORT,
|
||||
nodeEnv: config.NODE_ENV,
|
||||
dbProvider: config.DB_PROVIDER,
|
||||
telemetryEnabled: config.TELEMETRY_ENABLED,
|
||||
featureFlagsEnabled: config.FEATURE_FLAGS_ENABLED,
|
||||
}));
|
||||
await app.ready();
|
||||
});
|
||||
|
||||
@ -42,4 +53,17 @@ describe('diagnostics routes', () => {
|
||||
expect(body).toHaveProperty('flushed');
|
||||
expect(typeof body.flushed).toBe('number');
|
||||
});
|
||||
|
||||
it('GET /api/diagnostics/config returns sanitized config', async () => {
|
||||
const res = await app.inject({ method: 'GET', url: '/api/diagnostics/config' });
|
||||
expect(res.statusCode).toBe(200);
|
||||
const body = res.json();
|
||||
expect(body).toHaveProperty('productId');
|
||||
expect(body).toHaveProperty('serviceName');
|
||||
expect(body).toHaveProperty('port');
|
||||
expect(body).toHaveProperty('nodeEnv');
|
||||
expect(body).toHaveProperty('dbProvider');
|
||||
expect(typeof body.telemetryEnabled).toBe('boolean');
|
||||
expect(typeof body.featureFlagsEnabled).toBe('boolean');
|
||||
});
|
||||
});
|
||||
|
||||
@ -17,6 +17,7 @@ import { initDatastore } from './lib/datastore.js';
|
||||
import { config } from './lib/config.js';
|
||||
import { getAllFlags } from './lib/feature-flags.js';
|
||||
import { getBufferedEvents, flushEvents } from './lib/telemetry.js';
|
||||
import { PRODUCT_ID } from './lib/product-config.js';
|
||||
|
||||
import { jwtVerify } from 'jose';
|
||||
import type { JwtPayload } from './lib/request-context.js';
|
||||
@ -56,5 +57,14 @@ await app.register(webhookRoutes, { prefix: '/api' });
|
||||
app.get('/api/diagnostics/flags', async () => getAllFlags());
|
||||
app.get('/api/diagnostics/telemetry', async () => ({ events: getBufferedEvents() }));
|
||||
app.post('/api/diagnostics/telemetry/flush', async () => ({ flushed: flushEvents().length }));
|
||||
app.get('/api/diagnostics/config', async () => ({
|
||||
productId: PRODUCT_ID,
|
||||
serviceName: config.SERVICE_NAME,
|
||||
port: config.PORT,
|
||||
nodeEnv: config.NODE_ENV,
|
||||
dbProvider: config.DB_PROVIDER,
|
||||
telemetryEnabled: config.TELEMETRY_ENABLED,
|
||||
featureFlagsEnabled: config.FEATURE_FLAGS_ENABLED,
|
||||
}));
|
||||
|
||||
await startService(app, { port: config.PORT, host: config.HOST });
|
||||
|
||||
Loading…
Reference in New Issue
Block a user