import { describe, expect, it } from "vitest";
import { resolveClientCreateAccess } from "./clientCreateAccess";

describe("client create access", () => {
  it("allows privileged roles to create clients without developer request approval", () => {
    expect(
      resolveClientCreateAccess({
        role: "super_admin",
      }),
    ).toBe("can_create");
  });

  it("requires a developer request for basic users without approval", () => {
    expect(
      resolveClientCreateAccess({
        role: "user",
        accessStatus: { status: "none" },
      }),
    ).toBe("request_required");
  });

  it("treats unresolved roles as request required instead of allowing creation", () => {
    expect(
      resolveClientCreateAccess({
        role: "",
        accessStatus: undefined,
      }),
    ).toBe("request_required");
  });

  it("shows pending state while a developer request is under review", () => {
    expect(
      resolveClientCreateAccess({
        role: "user",
        accessStatus: { status: "pending", pendingPages: ["client_create"] },
      }),
    ).toBe("pending");
  });

  it("allows client creation after developer request approval", () => {
    expect(
      resolveClientCreateAccess({
        role: "user",
        accessStatus: {
          status: "approved",
          approvedPages: ["client_create"],
        },
      }),
    ).toBe("can_create");
  });

  it("routes cancelled or rejected requests back to requestable state", () => {
    expect(
      resolveClientCreateAccess({
        role: "user",
        accessStatus: { status: "cancelled" },
      }),
    ).toBe("request_required");

    expect(
      resolveClientCreateAccess({
        role: "user",
        accessStatus: { status: "rejected" },
      }),
    ).toBe("request_required");
  });
});
