acc_invoices: роль admin и переключатель роли CFO/accountant/employee; Keycloak: фирменный стиль KH Build
All checks were successful
ci / test (push) Successful in 55s
ci / deploy (push) Successful in 3m13s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-04 14:36:45 +03:00
parent d79ebfda10
commit b878aa72bb
9 changed files with 126 additions and 15 deletions

View File

@@ -0,0 +1,19 @@
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" });
});
});