2026-08-10 17:12:10 -03:00
|
|
|
import { describe, expect, it } from "vitest";
|
2026-09-16 22:30:32 -03:00
|
|
|
import { hasUserRole, isAdminUser } from "@/lib/auth/user-utils";
|
2026-08-10 17:12:10 -03:00
|
|
|
|
|
|
|
|
describe("isAdminUser", () => {
|
|
|
|
|
it("returns true when Admin appears in roles", () => {
|
|
|
|
|
expect(isAdminUser("Admin")).toBe(true);
|
|
|
|
|
expect(isAdminUser("Dispatcher,Admin")).toBe(true);
|
|
|
|
|
expect(isAdminUser(" admin ")).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("returns false for non-admin roles", () => {
|
|
|
|
|
expect(isAdminUser("Dispatcher")).toBe(false);
|
|
|
|
|
expect(isAdminUser(undefined)).toBe(false);
|
|
|
|
|
});
|
|
|
|
|
});
|
2026-09-16 22:30:32 -03:00
|
|
|
|
|
|
|
|
describe("hasUserRole", () => {
|
|
|
|
|
it("finds a role regardless of its position", () => {
|
|
|
|
|
expect(hasUserRole("Dispatcher,Scheduler", "Scheduler")).toBe(true);
|
|
|
|
|
expect(hasUserRole("Dispatcher", "Scheduler")).toBe(false);
|
|
|
|
|
});
|
|
|
|
|
});
|