diff --git a/packages/server/src/tests/utilities/TestConfiguration.ts b/packages/server/src/tests/utilities/TestConfiguration.ts index c8b917f626..5522af347e 100644 --- a/packages/server/src/tests/utilities/TestConfiguration.ts +++ b/packages/server/src/tests/utilities/TestConfiguration.ts @@ -50,6 +50,7 @@ import { SearchFilters, UserRoles, Automation, + PermissionLevel, } from "@budibase/types" import { BUILTIN_ROLE_IDS } from "@budibase/backend-core/src/security/roles" @@ -620,7 +621,11 @@ class TestConfiguration { return this._req(config, null, controllers.role.save) } - async addPermission(roleId: string, resourceId: string, level = "read") { + async addPermission( + roleId: string, + resourceId: string, + level = PermissionLevel.READ + ) { return this._req( null, { diff --git a/packages/server/src/tests/utilities/api/index.ts b/packages/server/src/tests/utilities/api/index.ts index a6002a72d8..40995b62f2 100644 --- a/packages/server/src/tests/utilities/api/index.ts +++ b/packages/server/src/tests/utilities/api/index.ts @@ -1,4 +1,5 @@ import TestConfiguration from "../TestConfiguration" +import { PermissionAPI } from "./permission" import { RowAPI } from "./row" import { TableAPI } from "./table" import { ViewV2API } from "./viewV2" @@ -7,10 +8,12 @@ export default class API { table: TableAPI viewV2: ViewV2API row: RowAPI + permission: PermissionAPI constructor(config: TestConfiguration) { this.table = new TableAPI(config) this.viewV2 = new ViewV2API(config) this.row = new RowAPI(config) + this.permission = new PermissionAPI(config) } } diff --git a/packages/server/src/tests/utilities/api/permission.ts b/packages/server/src/tests/utilities/api/permission.ts new file mode 100644 index 0000000000..b06df11df8 --- /dev/null +++ b/packages/server/src/tests/utilities/api/permission.ts @@ -0,0 +1,25 @@ +import { AnyDocument, PermissionLevel } from "@budibase/types" +import TestConfiguration from "../TestConfiguration" +import { TestAPI } from "./base" + +export class PermissionAPI extends TestAPI { + constructor(config: TestConfiguration) { + super(config) + } + + create = async ( + { + roleId, + resourceId, + level, + }: { roleId: string; resourceId: string; level: PermissionLevel }, + { expectStatus } = { expectStatus: 200 } + ): Promise => { + const res = await this.request + .post(`/api/permission/${roleId}/${resourceId}/${level}`) + .set(this.config.defaultHeaders()) + .expect("Content-Type", /json/) + .expect(expectStatus) + return res.body + } +}