release: WRNexusJS 0.4.0
This commit is contained in:
@@ -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",
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user