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: "rp_admin",
      }),
    ).toBe("can_create");
  });

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

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

  it("shows pending state while a developer request is under review", () => {
    expect(
      resolveClientCreateAccess({
        role: "tenant_member",
        requestStatus: "pending",
      }),
    ).toBe("pending");
  });

  it("allows client creation after developer request approval", () => {
    expect(
      resolveClientCreateAccess({
        role: "user",
        requestStatus: "approved",
      }),
    ).toBe("can_create");
  });

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

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