import { describe, expect, it } from "vitest";
import {
  ROLE_RP_ADMIN,
  ROLE_SUPER_ADMIN,
  ROLE_TENANT_ADMIN,
  ROLE_USER,
  isSuperAdminRole,
  normalizeAdminRole,
} from "./roles";

describe("admin role helpers", () => {
  it.each([
    ["super_admin", ROLE_SUPER_ADMIN],
    ["superadmin", ROLE_SUPER_ADMIN],
    ["super-admin", ROLE_SUPER_ADMIN],
    ["  SUPER-ADMIN  ", ROLE_SUPER_ADMIN],
    ["tenant_admin", ROLE_TENANT_ADMIN],
    ["tenantadmin", ROLE_TENANT_ADMIN],
    ["tenant-admin", ROLE_TENANT_ADMIN],
    ["admin", ROLE_TENANT_ADMIN],
    ["rp_admin", ROLE_RP_ADMIN],
    ["rpadmin", ROLE_RP_ADMIN],
    ["rp-admin", ROLE_RP_ADMIN],
    ["tenant_member", ROLE_USER],
    ["member", ROLE_USER],
    ["custom", ROLE_USER],
    ["", ROLE_USER],
  ])("normalizes %s to %s", (input, expected) => {
    expect(normalizeAdminRole(input)).toBe(expected);
  });

  it("detects super admin aliases", () => {
    expect(isSuperAdminRole("super-admin")).toBe(true);
    expect(isSuperAdminRole("admin")).toBe(false);
    expect(isSuperAdminRole(undefined)).toBe(false);
  });
});
