added get allowed levels (not working yet)

This commit is contained in:
Mateus Badan de Pieri 2023-04-14 10:29:52 +01:00
parent 9bf580e761
commit fa83c5d7a1
1 changed files with 33 additions and 6 deletions

View File

@ -5,6 +5,7 @@ import {
PermissionLevel, PermissionLevel,
PermissionType, PermissionType,
levelToNumber, levelToNumber,
getAllowedLevels,
} from "../permissions" } from "../permissions"
describe("levelToNumber", () => { describe("levelToNumber", () => {
@ -28,12 +29,38 @@ describe("levelToNumber", () => {
expect(levelToNumber("unknown" as PermissionLevel)).toBe(-1) expect(levelToNumber("unknown" as PermissionLevel)).toBe(-1)
}) })
}) })
describe("getBuiltinPermissionByID", () => { describe("getAllowedLevels", () => {
it("should return the correct permission object", () => { it('should return ["execute"] for EXECUTE', () => {
const id = "123" expect(getAllowedLevels(PermissionLevel.EXECUTE)).toEqual([
const permission = { _id: id, name: "Test Permission" } PermissionLevel.EXECUTE,
expect(getBuiltinPermissionByID(id)).toEqual(permission) ])
expect(getBuiltinPermissionByID("456")).toBeUndefined() })
it('should return ["execute", "read"] for READ', () => {
expect(getAllowedLevels(PermissionLevel.READ)).toEqual([
PermissionLevel.EXECUTE,
PermissionLevel.READ,
])
})
it('should return ["execute", "read", "write"] for WRITE', () => {
expect(getAllowedLevels(PermissionLevel.WRITE)).toEqual([
PermissionLevel.EXECUTE,
PermissionLevel.READ,
PermissionLevel.WRITE,
])
})
it('should return ["execute", "read", "write"] for ADMIN', () => {
expect(getAllowedLevels(PermissionLevel.ADMIN)).toEqual([
PermissionLevel.EXECUTE,
PermissionLevel.READ,
PermissionLevel.WRITE,
])
})
it("should return [] for an unknown permission level", () => {
expect(getAllowedLevels("unknown" as PermissionLevel)).toEqual([])
}) })
}) })