/* @vitest-environment node */

import { describe, it, expect } from "vitest";
import { ROLES, isAdminLike, canManageUsers } from "./roles.js";

describe("lib/frontend/auth/roles", () => {
	describe("isAdminLike", () => {
		it("returns true for admin, superadmin, dev", () => {
			expect(isAdminLike(ROLES.ADMIN)).toBe(true);
			expect(isAdminLike(ROLES.SUPERADMIN)).toBe(true);
			expect(isAdminLike(ROLES.DEV)).toBe(true);
		});

		it("returns false for branch and unknown roles", () => {
			expect(isAdminLike(ROLES.BRANCH)).toBe(false);
			expect(isAdminLike("user")).toBe(false);
			expect(isAdminLike(null)).toBe(false);
			expect(isAdminLike(undefined)).toBe(false);
		});
	});

	describe("canManageUsers", () => {
		it("returns true for superadmin and dev", () => {
			expect(canManageUsers(ROLES.SUPERADMIN)).toBe(true);
			expect(canManageUsers(ROLES.DEV)).toBe(true);
		});

		it("returns false for admin, branch and unknown roles", () => {
			expect(canManageUsers(ROLES.ADMIN)).toBe(false);
			expect(canManageUsers(ROLES.BRANCH)).toBe(false);
			expect(canManageUsers("user")).toBe(false);
			expect(canManageUsers(null)).toBe(false);
			expect(canManageUsers(undefined)).toBe(false);
		});
	});
});
