test(tooling): add vitest baseline policy and order tests
This commit is contained in:
@@ -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 })
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user