Write a failing test.
This commit is contained in:
parent
ca4884e9cc
commit
13563d18dc
|
@ -16,7 +16,13 @@ import * as setup from "./utilities"
|
|||
import { AppStatus } from "../../../db/utils"
|
||||
import { events, utils, context } from "@budibase/backend-core"
|
||||
import env from "../../../environment"
|
||||
import type { App } from "@budibase/types"
|
||||
import {
|
||||
PermissionLevel,
|
||||
type App,
|
||||
INTERNAL_TABLE_SOURCE_ID,
|
||||
TableSourceType,
|
||||
FieldType,
|
||||
} from "@budibase/types"
|
||||
import tk from "timekeeper"
|
||||
|
||||
describe("/applications", () => {
|
||||
|
@ -256,10 +262,48 @@ describe("/applications", () => {
|
|||
admin: { global: false },
|
||||
})
|
||||
|
||||
const table = await config.api.table.save({
|
||||
name: "table",
|
||||
type: "table",
|
||||
sourceId: INTERNAL_TABLE_SOURCE_ID,
|
||||
sourceType: TableSourceType.INTERNAL,
|
||||
schema: {
|
||||
name: {
|
||||
type: FieldType.STRING,
|
||||
name: "name",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
await config.withUser(user, async () => {
|
||||
const apps = await config.api.application.fetch()
|
||||
expect(apps).toHaveLength(0)
|
||||
})
|
||||
|
||||
const role = await config.api.roles.save({
|
||||
name: "Test",
|
||||
inherits: "PUBLIC",
|
||||
permissionId: "read_only",
|
||||
version: "name",
|
||||
})
|
||||
|
||||
await config.api.user.update({
|
||||
...user,
|
||||
roles: {
|
||||
[config.getAppId()]: role._id!,
|
||||
},
|
||||
})
|
||||
|
||||
await config.api.permission.add({
|
||||
resourceId: table._id!,
|
||||
roleId: role._id!,
|
||||
level: PermissionLevel.READ,
|
||||
})
|
||||
|
||||
await config.withUser(user, async () => {
|
||||
const apps = await config.api.application.fetch()
|
||||
expect(apps).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -11,6 +11,7 @@ import { BackupAPI } from "./backup"
|
|||
import { AttachmentAPI } from "./attachment"
|
||||
import { UserAPI } from "./user"
|
||||
import { QueryAPI } from "./query"
|
||||
import { RoleAPI } from "./role"
|
||||
|
||||
export default class API {
|
||||
table: TableAPI
|
||||
|
@ -25,6 +26,7 @@ export default class API {
|
|||
attachment: AttachmentAPI
|
||||
user: UserAPI
|
||||
query: QueryAPI
|
||||
roles: RoleAPI
|
||||
|
||||
constructor(config: TestConfiguration) {
|
||||
this.table = new TableAPI(config)
|
||||
|
@ -39,5 +41,6 @@ export default class API {
|
|||
this.attachment = new AttachmentAPI(config)
|
||||
this.user = new UserAPI(config)
|
||||
this.query = new QueryAPI(config)
|
||||
this.roles = new RoleAPI(config)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
import {
|
||||
AccessibleRolesResponse,
|
||||
FetchRolesResponse,
|
||||
FindRoleResponse,
|
||||
SaveRoleRequest,
|
||||
SaveRoleResponse,
|
||||
} from "@budibase/types"
|
||||
import { Expectations, TestAPI } from "./base"
|
||||
|
||||
export class RoleAPI extends TestAPI {
|
||||
fetch = async (expectations?: Expectations) => {
|
||||
return await this._get<FetchRolesResponse>(`/api/roles`, {
|
||||
expectations,
|
||||
})
|
||||
}
|
||||
|
||||
find = async (roleId: string, expectations?: Expectations) => {
|
||||
return await this._get<FindRoleResponse>(`/api/roles/${roleId}`, {
|
||||
expectations,
|
||||
})
|
||||
}
|
||||
|
||||
save = async (body: SaveRoleRequest, expectations?: Expectations) => {
|
||||
return await this._post<SaveRoleResponse>(`/api/roles`, {
|
||||
body,
|
||||
expectations,
|
||||
})
|
||||
}
|
||||
|
||||
destroy = async (roleId: string, expectations?: Expectations) => {
|
||||
return await this._delete(`/api/roles/${roleId}`, {
|
||||
expectations,
|
||||
})
|
||||
}
|
||||
|
||||
accesssible = async (expectations?: Expectations) => {
|
||||
return await this._get<AccessibleRolesResponse>(`/api/roles/accessible`, {
|
||||
expectations,
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue