import { describe, it, expect, beforeEach } from "vitest";
import { RecordingConsent } from "@repo/core-testing/instrumentation";
import { isGrantedHandler } from "@/handlers/is-granted.handler";

describe("isGrantedHandler", () => {
  let consent: RecordingConsent;

  beforeEach(() => {
    consent = new RecordingConsent();
  });

  it("returns { granted: false } before any grant", () => {
    expect(isGrantedHandler(consent, { category: "analytics" })).toEqual({
      granted: false,
    });
  });

  it("returns { granted: true } after grant", async () => {
    await consent.grant("analytics");
    expect(isGrantedHandler(consent, { category: "analytics" })).toEqual({
      granted: true,
    });
  });

  it("returns { granted: false } after withdraw", async () => {
    await consent.grant("analytics");
    await consent.withdraw("analytics");
    expect(isGrantedHandler(consent, { category: "analytics" })).toEqual({
      granted: false,
    });
  });
});
