release: WRNexusJS 0.4.0

This commit is contained in:
2026-07-27 12:42:18 +05:30
parent 8b728a3e5d
commit 30e5721e84
250 changed files with 10065 additions and 3923 deletions
+15
View File
@@ -9,6 +9,7 @@ import {
any,
all,
attr,
decision,
type Policy,
} from "../src/index.ts";
@@ -78,3 +79,17 @@ test("guards: authorize / requireRole / requirePermission", async () => {
(await authorize((c) => (c.user as User)?.id === "u1")(ctx({ id: "u1" }), ok)).status,
).toBe(200);
});
test("explainable decisions only include denial reasons when denied", async () => {
const policy = decision("owner", (subject: User) => subject.id === "u1");
expect(await policy({ id: "u1" })).toEqual({
allowed: true,
reason: undefined,
policy: "owner",
});
expect(await policy({ id: "u2" })).toEqual({
allowed: false,
reason: "Policy denied access",
policy: "owner",
});
});