import { describe, expect, it } from "vitest"; import { effectiveRoles } from "./auth.js"; describe("effectiveRoles", () => { it("CFO по умолчанию CFO и может переключаться", () => { expect(effectiveRoles(["cfo"])).toEqual({ roles: ["cfo"], canSwitch: true, acting: "cfo" }); expect(effectiveRoles(["cfo"], "employee")).toEqual({ roles: [], canSwitch: true, acting: "employee" }); expect(effectiveRoles(["cfo"], "accountant").roles).toEqual(["accountant"]); }); it("admin по умолчанию employee и может стать кем угодно", () => { expect(effectiveRoles(["admin"])).toEqual({ roles: [], canSwitch: true, acting: "employee" }); expect(effectiveRoles(["admin"], "cfo").roles).toEqual(["cfo"]); expect(effectiveRoles(["admin"], "bogus").acting).toBe("employee"); }); it("бухгалтер и сотрудник переключаться не могут", () => { expect(effectiveRoles(["accountant"], "cfo")).toEqual({ roles: ["accountant"], canSwitch: false, acting: "accountant" }); expect(effectiveRoles([], "cfo")).toEqual({ roles: [], canSwitch: false, acting: "employee" }); }); });