mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 12:30:58 +00:00
58 lines
2.0 KiB
TypeScript
58 lines
2.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import type { AuthUser } from "@/auth/types";
|
|
import { FREIGHT_PERMS } from "./permissions";
|
|
import { NO_ACCESS_PATH, resolveLandingPath } from "./landing";
|
|
|
|
const withPermissions = (...keys: string[]): AuthUser => ({
|
|
permissionKeys: keys,
|
|
});
|
|
|
|
const withRole = (roleKey: string): AuthUser => ({ roles: [{ key: roleKey }] });
|
|
|
|
describe("resolveLandingPath", () => {
|
|
it("keeps normal staff on the overview", () => {
|
|
expect(resolveLandingPath(withPermissions(FREIGHT_PERMS.overview.view))).toBe(
|
|
"/dashboard/overview",
|
|
);
|
|
});
|
|
|
|
it("sends super admins to the overview (they pass every check)", () => {
|
|
expect(resolveLandingPath(withRole("super_admin"))).toBe(
|
|
"/dashboard/overview",
|
|
);
|
|
});
|
|
|
|
it("sends IAM-only admins to the user-management dashboard", () => {
|
|
// A pure unit_admin holds `can:*` IAM keys and no edr_freight_app:* key, so
|
|
// the freight sidebar filters down to nothing. Landing them on the overview
|
|
// is what produced the blank page.
|
|
for (const role of ["unit_admin", "admin", "organization_admin"]) {
|
|
expect(resolveLandingPath(withRole(role))).toBe(
|
|
"/user-management/user_management-dashboard",
|
|
);
|
|
}
|
|
});
|
|
|
|
it("lands staff without overview:view on a page they can see", () => {
|
|
const target = resolveLandingPath(
|
|
withPermissions(FREIGHT_PERMS.warehouses.view),
|
|
);
|
|
expect(target).not.toBe("/dashboard/overview");
|
|
expect(target.startsWith("/dashboard/")).toBe(true);
|
|
});
|
|
|
|
it("never returns /user-management for a freight-only staff key", () => {
|
|
// The Staff sidebar item points at /user-management, which redirects by
|
|
// ROLE — returning it here would ping-pong for a user with no IAM role.
|
|
expect(resolveLandingPath(withPermissions(FREIGHT_PERMS.staff.roles.view))).toBe(
|
|
NO_ACCESS_PATH,
|
|
);
|
|
});
|
|
|
|
it("falls back to the no-access page when nothing is granted", () => {
|
|
expect(resolveLandingPath({})).toBe(NO_ACCESS_PATH);
|
|
expect(resolveLandingPath(null)).toBe(NO_ACCESS_PATH);
|
|
});
|
|
});
|