import { describe, it, expect } from "vitest";
import { bindDevSeedConsent } from "@/di/bind-dev-seed";

describe("bindDevSeedConsent", () => {
  it("returns a consentFactory function", () => {
    const { consentFactory } = bindDevSeedConsent();
    expect(typeof consentFactory).toBe("function");
  });

  it("factory produces a working IConsent (grant → isGranted round-trip)", async () => {
    const { consentFactory } = bindDevSeedConsent();
    const consent = await consentFactory("user_1");

    expect(consent.isGranted("analytics")).toBe(false);
    await consent.grant("analytics");
    expect(consent.isGranted("analytics")).toBe(true);
    await consent.withdraw("analytics");
    expect(consent.isGranted("analytics")).toBe(false);
  });

  it("each factory call returns an independent instance", async () => {
    const { consentFactory } = bindDevSeedConsent();
    const c1 = await consentFactory("u1");
    const c2 = await consentFactory("u2");

    await c1.grant("marketing");
    expect(c1.isGranted("marketing")).toBe(true);
    expect(c2.isGranted("marketing")).toBe(false);
  });
});
