NobGit
public anord read

Ledger

Why work hard when you can work easier?

Languages

Repository composition by tracked source files.

TypeScript
TypeScript 86% CSS 10% SQL 3% Shell 1% HTML 0%
Create file Wiki Documentation
Clone
https://nobgit.com/orgs/anord/ledger.git
ssh://[email protected]:2222/orgs/anord/ledger.git
rbac.test.ts
import { describe, expect, it } from "vitest";
import { canReadVisibility } from "@ledger/shared";

describe("RBAC visibility", () => {
  const viewer = {
    id: "user-1",
    email: "[email protected]",
    displayName: "Viewer",
    role: "viewer" as const,
    groupIds: []
  };

  it("allows public pages for anonymous users", () => {
    expect(canReadVisibility(null, "public")).toBe(true);
  });

  it("blocks internal pages for anonymous users", () => {
    expect(canReadVisibility(null, "internal")).toBe(false);
  });

  it("allows restricted pages only when group and role match", () => {
    expect(canReadVisibility(viewer, "restricted", ["viewer"], ["group-1"])).toBe(false);
    expect(
      canReadVisibility({ ...viewer, groupIds: ["group-1"] }, "restricted", ["viewer"], ["group-1"])
    ).toBe(true);
  });
});