import { describe, it, expect } from "vitest";
import { NoopRateLimit } from "@/rate-limit/noop-rate-limit";
import type { IRateLimit } from "@/rate-limit/rate-limit.interface";

describe("NoopRateLimit", () => {
  it("satisfies IRateLimit", () => {
    const rl: IRateLimit = new NoopRateLimit();
    expect(rl).toBeDefined();
  });

  it("consume always resolves allowed with Infinity remaining", async () => {
    const rl = new NoopRateLimit();
    const result = await rl.consume("signin", "user-1");
    expect(result.allowed).toBe(true);
    expect(result.remaining).toBe(Infinity);
  });

  it("consume always resolves resetAt as epoch", async () => {
    const rl = new NoopRateLimit();
    const result = await rl.consume("signin", "user-1", 5);
    expect(result.resetAt).toEqual(new Date(0));
  });

  it("reset is a no-op and resolves", async () => {
    const rl = new NoopRateLimit();
    await expect(rl.reset("signin", "user-1")).resolves.toBeUndefined();
  });

  it("consume remains allowed after many calls", async () => {
    const rl = new NoopRateLimit();
    for (let i = 0; i < 100; i++) {
      const result = await rl.consume("signin", "user-1");
      expect(result.allowed).toBe(true);
    }
  });
});
