test(tooling): add vitest baseline policy and order tests

This commit is contained in:
zetaloop
2026-02-22 14:51:21 +08:00
parent 6517018a9c
commit f8c4c87c61
5 changed files with 976 additions and 4 deletions
+31
View File
@@ -0,0 +1,31 @@
import { describe, expect, it } from "vitest"
import { allow, deny, requireAuth } from "@/lib/policy/assert"
describe("policy decision helpers", () => {
it("returns ok for allow", () => {
expect(allow()).toEqual({ ok: true })
})
it("returns reason code for deny", () => {
expect(deny("ROLE_FORBIDDEN", "forbidden")).toEqual({
ok: false,
reasonCode: "ROLE_FORBIDDEN",
message: "forbidden",
})
})
it("requires auth actor", () => {
expect(requireAuth(undefined)).toEqual({
ok: false,
reasonCode: "AUTH_REQUIRED",
message: "请先登录",
})
expect(
requireAuth({
userId: "u1",
role: "consumer",
}),
).toEqual({ ok: true })
})
})