/** * Tests unitaires pour lib/metrics.ts */ import { normalizePath } from '@/lib/metrics'; describe('Metrics - normalizePath', () => { it('should replace UUIDs with :id', () => { const path = '/api/users/123e4567-e89b-12d3-a456-426614174000'; const normalized = normalizePath(path); expect(normalized).toBe('/api/users/:id'); }); it('should replace numeric IDs with :id', () => { const path = '/api/tickets/12345'; const normalized = normalizePath(path); expect(normalized).toBe('/api/tickets/:id'); }); it('should replace ticket codes with :code', () => { const path = '/api/game/ticket/TTP2025ABC'; const normalized = normalizePath(path); expect(normalized).toBe('/api/game/ticket/:code'); }); it('should handle multiple replacements', () => { const path = '/api/users/123e4567-e89b-12d3-a456-426614174000/tickets/12345'; const normalized = normalizePath(path); expect(normalized).toBe('/api/users/:id/tickets/:id'); }); it('should not modify paths without IDs', () => { const path = '/api/auth/login'; const normalized = normalizePath(path); expect(normalized).toBe('/api/auth/login'); }); it('should handle root path', () => { const path = '/'; const normalized = normalizePath(path); expect(normalized).toBe('/'); }); it('should handle paths with query strings', () => { const path = '/api/users/123'; const normalized = normalizePath(path); expect(normalized).toBe('/api/users/:id'); }); }); describe('Metrics - recordHttpRequest', () => { // Note: These tests would require mocking prom-client // In a real scenario, we would mock the Counter and Histogram it('should be a function', async () => { const { recordHttpRequest } = await import('@/lib/metrics'); expect(typeof recordHttpRequest).toBe('function'); }); }); describe('Metrics - getRegistry', () => { it('should return a registry', async () => { const { getRegistry } = await import('@/lib/metrics'); const registry = getRegistry(); expect(registry).toBeDefined(); }); it('should return the same registry instance', async () => { const { getRegistry } = await import('@/lib/metrics'); const registry1 = getRegistry(); const registry2 = getRegistry(); expect(registry1).toBe(registry2); }); });