Backend modules from tastefully 8bd93d15: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email. solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal from tastefully 8bd93d15. Copied as tracked files only. Literal secrets replaced with environment placeholders: - services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY, MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default) - services-system: JUMIO_TOKEN, JUMIO_SECRET (optional) - services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed - core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default removed, ipgeolocation key read from IPGEOLOCATION_API_KEY - services-system EkycAppConfig: commented Jumio credentials removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
117 lines
3.7 KiB
TypeScript
117 lines
3.7 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { sidebarFromAclMenu } from "./aclSidebar";
|
|
import type { AdminModule } from "./types";
|
|
|
|
describe("sidebarFromAclMenu", () => {
|
|
it("returns no entries for a null/undefined tree", () => {
|
|
expect(sidebarFromAclMenu(null)).toEqual([]);
|
|
expect(sidebarFromAclMenu(undefined)).toEqual([]);
|
|
});
|
|
|
|
it("turns top-level M nodes under the R root into links using their url/iconName", () => {
|
|
const root: AdminModule = {
|
|
name: "root",
|
|
type: "R",
|
|
children: [
|
|
{ name: "Dashboard", type: "M", url: "/", iconName: "LayoutDashboard" },
|
|
{ name: "Members", type: "M", url: "/members", iconName: "Users" },
|
|
],
|
|
};
|
|
expect(sidebarFromAclMenu(root)).toEqual([
|
|
{ name: "Dashboard", url: "/", iconName: "LayoutDashboard", children: [] },
|
|
{ name: "Members", url: "/members", iconName: "Users", children: [] },
|
|
]);
|
|
});
|
|
|
|
it("nests M children of an M node", () => {
|
|
const root: AdminModule = {
|
|
name: "root",
|
|
type: "R",
|
|
children: [
|
|
{
|
|
name: "Reports",
|
|
type: "M",
|
|
url: "/reports",
|
|
iconName: "FileText",
|
|
children: [
|
|
{ name: "Sales", type: "M", url: "/reports/sales" },
|
|
{ name: "Commissions", type: "M", url: "/reports/commissions" },
|
|
],
|
|
},
|
|
],
|
|
};
|
|
const [reports] = sidebarFromAclMenu(root);
|
|
expect(reports.children.map((c) => c.name)).toEqual(["Sales", "Commissions"]);
|
|
});
|
|
|
|
it("does not render an A (action) node, or its subtree, as a link", () => {
|
|
const root: AdminModule = {
|
|
name: "root",
|
|
type: "R",
|
|
children: [
|
|
{ name: "Members", type: "M", url: "/members" },
|
|
{
|
|
name: "Export Members",
|
|
type: "A",
|
|
children: [{ name: "Should Not Appear", type: "M", url: "/members/export-detail" }],
|
|
},
|
|
],
|
|
};
|
|
const names = sidebarFromAclMenu(root).map((n) => n.name);
|
|
expect(names).toEqual(["Members"]);
|
|
expect(names).not.toContain("Export Members");
|
|
expect(names).not.toContain("Should Not Appear");
|
|
});
|
|
|
|
it("turns a url-less M node with linkable descendants into a group link (children nested, not hoisted)", () => {
|
|
const root: AdminModule = {
|
|
name: "root",
|
|
type: "R",
|
|
children: [
|
|
{
|
|
name: "Group",
|
|
type: "M",
|
|
iconName: "Shield",
|
|
children: [{ name: "Leaf", type: "M", url: "/leaf", iconName: "Circle" }],
|
|
},
|
|
],
|
|
};
|
|
const result = sidebarFromAclMenu(root);
|
|
expect(result).toEqual([
|
|
{
|
|
name: "Group",
|
|
url: "",
|
|
iconName: "Shield",
|
|
children: [{ name: "Leaf", url: "/leaf", iconName: "Circle", children: [] }],
|
|
},
|
|
]);
|
|
// Not hoisted: "Leaf" must not appear at the top level alongside "Group".
|
|
expect(result.map((n) => n.name)).toEqual(["Group"]);
|
|
});
|
|
|
|
it("yields nothing for a url-less M node with no linkable descendants (empty group)", () => {
|
|
const root: AdminModule = {
|
|
name: "root",
|
|
type: "R",
|
|
children: [
|
|
{
|
|
name: "EmptyGroup",
|
|
type: "M",
|
|
children: [{ name: "Hidden Action", type: "A", children: [{ name: "Nested", type: "M", url: "/nested" }] }],
|
|
},
|
|
],
|
|
};
|
|
expect(sidebarFromAclMenu(root)).toEqual([]);
|
|
});
|
|
|
|
it("a module absent from the tree is simply absent from the result (not a link)", () => {
|
|
const root: AdminModule = {
|
|
name: "root",
|
|
type: "R",
|
|
children: [{ name: "Members", type: "M", url: "/members" }],
|
|
};
|
|
const names = sidebarFromAclMenu(root).map((n) => n.name);
|
|
expect(names).not.toContain("Settings");
|
|
});
|
|
});
|