import { describe, expect, it } from 'vitest';
import { RateLimiter } from '../application/rate-limiter.js';

describe('RateLimiter', () => {
  it('rejects requests above the limit with retry-after', () => {
    const limiter = new RateLimiter(1000, 2);
    expect(limiter.hit('k', 0).allowed).toBe(true);
    expect(limiter.hit('k', 100).allowed).toBe(true);
    const blocked = limiter.hit('k', 200);
    expect(blocked.allowed).toBe(false);
    expect(blocked.retryAfterSeconds).toBeGreaterThan(0);
  });

  it('resets after window expires', () => {
    const limiter = new RateLimiter(1000, 1);
    expect(limiter.hit('k', 0).allowed).toBe(true);
    expect(limiter.hit('k', 100).allowed).toBe(false);
    expect(limiter.hit('k', 1500).allowed).toBe(true);
  });
});
