shoc-frontend-new/src/test/lib/auth/user-utils.test.ts

37 lines
1.4 KiB
TypeScript
Raw Normal View History

import { describe, expect, it } from "vitest";
import { canViewAllDispatchersOnDashboard, hasUserRole, isAdminUser } from "@/lib/auth/user-utils";
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);
});
});
describe("hasUserRole", () => {
it("finds a role regardless of its position", () => {
expect(hasUserRole("Dispatcher,Scheduler", "Scheduler")).toBe(true);
expect(hasUserRole("Dispatcher", "Scheduler")).toBe(false);
});
});
describe("canViewAllDispatchersOnDashboard", () => {
it("grants the dashboard picker to Admin and Scheduler", () => {
expect(canViewAllDispatchersOnDashboard("Admin")).toBe(true);
expect(canViewAllDispatchersOnDashboard("Scheduler")).toBe(true);
expect(canViewAllDispatchersOnDashboard("Dispatcher, Scheduler")).toBe(true);
});
it("locks a Dispatcher (and unknown roles) to their own work orders", () => {
expect(canViewAllDispatchersOnDashboard("Dispatcher")).toBe(false);
expect(canViewAllDispatchersOnDashboard("Technician")).toBe(false);
expect(canViewAllDispatchersOnDashboard(undefined)).toBe(false);
});
});