Files
template/web/tests/utils/authorization-guards/authorization-guard.test.ts
T
2026-06-19 23:55:45 -07:00

42 lines
1.1 KiB
TypeScript

import { type RouteLocationNormalized } from "vue-router"
import authorizationGuard from "@/utils/authorization-guards/authorization-guard"
describe("web/src/utils/authorization-guards/authorization-guard.ts", () => {
describe("authorizationGuard", () => {
test("when there are no guards, returns true", async () => {
const to = {
meta: {},
} as unknown as RouteLocationNormalized
const result = await authorizationGuard(to)
expect(result).toBe(true)
})
test("when all guards return true, returns true", async () => {
const to = {
meta: {
guards: [() => true, () => true, () => true],
},
} as unknown as RouteLocationNormalized
const result = await authorizationGuard(to)
expect(result).toBe(true)
})
test("when any guard returns false, returns false", async () => {
const to = {
meta: {
guards: [() => true, () => false, () => true],
},
} as unknown as RouteLocationNormalized
const result = await authorizationGuard(to)
expect(result).toBe(false)
})
})
})