import { ClientIpThrottlerGuard } from './client-ip-throttler.guard'; describe('ClientIpThrottlerGuard.getTracker', () => { // getTracker is protected and needs none of the guard's dependencies. const guard = Object.create( ClientIpThrottlerGuard.prototype, ) as ClientIpThrottlerGuard & { getTracker(req: Record): Promise; }; it('tracks IPv6 clients by their /64 prefix', async () => { await expect(guard.getTracker({ ip: '2001:db8:1:2::9' })).resolves.toBe( '2001:db8:1:2::/64', ); }); it('tracks IPv4 clients by address', async () => { await expect(guard.getTracker({ ip: '203.0.113.7' })).resolves.toBe( '203.0.113.7', ); }); it('falls back to a stable key when req.ip is missing', async () => { await expect(guard.getTracker({})).resolves.toBe('unknown'); }); });