mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 16:19:01 +00:00
36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
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);
|
|
});
|
|
});
|