30 lines
677 B
TypeScript
30 lines
677 B
TypeScript
import { allow, deny, requireAuth } from "@/lib/decision"
|
|
import { describe, expect, it } from "vitest"
|
|
|
|
describe("policy decision helpers", () => {
|
|
it("returns ok for allow", () => {
|
|
expect(allow()).toEqual({ ok: true })
|
|
})
|
|
|
|
it("returns error for deny", () => {
|
|
expect(deny(403, "forbidden")).toEqual({
|
|
ok: false,
|
|
error: { code: 403, msg: "forbidden" },
|
|
})
|
|
})
|
|
|
|
it("requires auth actor", () => {
|
|
expect(requireAuth(undefined)).toEqual({
|
|
ok: false,
|
|
error: { code: 401, msg: "请先登录" },
|
|
})
|
|
|
|
expect(
|
|
requireAuth({
|
|
userId: "1001",
|
|
role: "consumer",
|
|
}),
|
|
).toEqual({ ok: true })
|
|
})
|
|
})
|