import { describe, it, expect } from "vitest";
import { createDedup } from "./dedup.js";

describe("createDedup", () => {
  it("first markSeen returns false (not seen before)", () => {
    const d = createDedup(10);
    expect(d.markSeen("a")).toBe(false);
  });

  it("second markSeen for same id returns true", () => {
    const d = createDedup(10);
    d.markSeen("a");
    expect(d.markSeen("a")).toBe(true);
  });

  it("FIFO eviction past capacity", () => {
    const d = createDedup(3);
    d.markSeen("a");
    d.markSeen("b");
    d.markSeen("c");
    d.markSeen("d");
    expect(d.markSeen("a")).toBe(false);
    expect(d.markSeen("d")).toBe(true);
  });

  it("undefined messageId always returns false (not deduped)", () => {
    const d = createDedup(10);
    expect(d.markSeen(undefined)).toBe(false);
    expect(d.markSeen(undefined)).toBe(false);
  });
});
