From fa83c5d7a1dd77e34d967d764f7c07987b3e54a4 Mon Sep 17 00:00:00 2001 From: Mateus Badan de Pieri Date: Fri, 14 Apr 2023 10:29:52 +0100 Subject: [PATCH] added get allowed levels (not working yet) --- .../src/security/tests/permissions.spec.ts | 39 ++++++++++++++++--- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/packages/backend-core/src/security/tests/permissions.spec.ts b/packages/backend-core/src/security/tests/permissions.spec.ts index e77394d947..264e521f8b 100644 --- a/packages/backend-core/src/security/tests/permissions.spec.ts +++ b/packages/backend-core/src/security/tests/permissions.spec.ts @@ -5,6 +5,7 @@ import { PermissionLevel, PermissionType, levelToNumber, + getAllowedLevels, } from "../permissions" describe("levelToNumber", () => { @@ -28,12 +29,38 @@ describe("levelToNumber", () => { expect(levelToNumber("unknown" as PermissionLevel)).toBe(-1) }) }) -describe("getBuiltinPermissionByID", () => { - it("should return the correct permission object", () => { - const id = "123" - const permission = { _id: id, name: "Test Permission" } - expect(getBuiltinPermissionByID(id)).toEqual(permission) - expect(getBuiltinPermissionByID("456")).toBeUndefined() +describe("getAllowedLevels", () => { + it('should return ["execute"] for EXECUTE', () => { + expect(getAllowedLevels(PermissionLevel.EXECUTE)).toEqual([ + PermissionLevel.EXECUTE, + ]) + }) + + 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([]) }) })