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
1c7ea650cd
commit
4baed0b10c
@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
@ -12,7 +12,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 { DISPLAY_NAME } from './lib/product-config.js';
|
||||
import { DISPLAY_NAME, PRODUCT_ID } from './lib/product-config.js';
|
||||
import type { JwtPayload } from './lib/request-context.js';
|
||||
|
||||
const jwtSecret = new TextEncoder().encode(config.JWT_SECRET);
|
||||
@ -59,5 +59,14 @@ await registerApiPlugin(workspaceRoutes);
|
||||
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