import { MetricsService } from './metrics.service'; describe('MetricsService', () => { it('exports bounded API process and HTTP metrics without raw identifiers', () => { const service = new MetricsService(); const startedAt = service.beginRequest(); service.finishRequest(startedAt, 'GET', '/api/admin/tenants/:id', 200); const inboundStartedAt = service.beginCmppInboundStage(); service.finishCmppInboundStage(inboundStartedAt, 'application_lookup', 'success'); const sendStartedAt = service.beginSendWorkerStage(); service.finishSendWorkerStage(sendStartedAt, 'route_lookup', 'success'); service.setSendWorkerSlots(20, 3); service.setSendWorkerQueueJobs('waiting', 12); service.recordSendWorkerResult('completed'); service.setSendWorkerDatabasePool('max', 8); service.setSendWorkerDatabasePool('waiting', 2); const output = service.render(); expect(output).toContain('cmpp_api_process_resident_memory_bytes'); expect(output).toContain('cmpp_api_http_requests_total{method="GET",route="/api/admin/tenants/:id",status="200"} 1'); expect(output).toContain('cmpp_api_http_request_duration_seconds_bucket'); expect(output).toContain('cmpp_api_cmpp_inbound_stage_duration_seconds_count{stage="application_lookup",result="success"} 1'); expect(output).toContain('cmpp_worker_send_stage_duration_seconds_count{stage="route_lookup",result="success"} 1'); expect(output).toContain('cmpp_worker_send_slots{state="configured"} 20'); expect(output).toContain('cmpp_worker_send_slots{state="in_flight"} 3'); expect(output).toContain('cmpp_worker_send_queue_jobs{state="waiting"} 12'); expect(output).toContain('cmpp_worker_send_jobs_total{result="completed"} 1'); expect(output).toContain('cmpp_worker_database_pool_connections{state="max"} 8'); expect(output).toContain('cmpp_worker_database_pool_connections{state="waiting"} 2'); expect(output).not.toContain('phone_number'); expect(output).not.toContain('tenant_id'); expect(output).not.toContain('channel_id'); service.onModuleDestroy(); }); });