Improve Role tests
This commit is contained in:
parent
e431533b5d
commit
d55172a9fb
|
@ -33,13 +33,21 @@ export default class AppApi {
|
|||
|
||||
async canRender(): Promise<[Response, boolean]> {
|
||||
const response = await this.api.get("/routing/client")
|
||||
expect(response).toHaveStatusCode(200)
|
||||
const json = await response.json()
|
||||
const publishedAppRenders = Object.keys(json.routes).length > 0
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(publishedAppRenders).toBe(true)
|
||||
return [response, publishedAppRenders]
|
||||
}
|
||||
|
||||
async failRender(): Promise<[Response, responseMessage]> {
|
||||
const response = await this.api.get("/routing/client")
|
||||
const json = await response.json()
|
||||
expect(response).toHaveStatusCode(404)
|
||||
return [response, json]
|
||||
}
|
||||
|
||||
|
||||
async getAppPackage(appId: string): Promise<[Response, AppPackageResponse]> {
|
||||
const response = await this.api.get(`/applications/${appId}/appPackage`)
|
||||
const json = await response.json()
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import generator from "../../generator"
|
||||
import { Application } from "@budibase/server/api/controllers/public/mapping/types"
|
||||
import { Template } from "@budibase/types"
|
||||
import { App } from "@budibase/types"
|
||||
|
||||
const generate = (
|
||||
export const generateApp = (
|
||||
overrides: Partial<Application> = {}
|
||||
): Partial<Application> => ({
|
||||
name: generator.word() + generator.hash(),
|
||||
|
@ -9,4 +11,15 @@ const generate = (
|
|||
...overrides,
|
||||
})
|
||||
|
||||
export default generate
|
||||
// Applications type doesn't work here, save to add useTemplate parameter?
|
||||
export const appFromTemplate = (): any => {
|
||||
return ({
|
||||
name: generator.word(),
|
||||
url: `/${generator.word()}`,
|
||||
useTemplate: "true",
|
||||
templateName: "Near Miss Register",
|
||||
templateKey: "app/near-miss-register",
|
||||
templateFile: undefined,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import TestConfiguration from "../../../config/internal-api/TestConfiguration"
|
|||
import { Application } from "@budibase/server/api/controllers/public/mapping/types"
|
||||
import { db } from "@budibase/backend-core"
|
||||
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient"
|
||||
import generateApp from "../../../config/internal-api/fixtures/applications"
|
||||
import { generateApp, appFromTemplate } from "../../../config/internal-api/fixtures/applications"
|
||||
import generator from "../../../config/generator"
|
||||
import generateScreen from "../../../config/internal-api/fixtures/screens"
|
||||
|
||||
|
@ -18,16 +18,7 @@ describe("Internal API - Application creation, update, publish and delete", () =
|
|||
await config.afterAll()
|
||||
})
|
||||
|
||||
async function createAppFromTemplate() {
|
||||
return config.applications.create({
|
||||
name: generator.word(),
|
||||
url: `/${generator.word()}`,
|
||||
useTemplate: "true",
|
||||
templateName: "Near Miss Register",
|
||||
templateKey: "app/near-miss-register",
|
||||
templateFile: undefined,
|
||||
})
|
||||
}
|
||||
|
||||
it("Get applications without applications", async () => {
|
||||
await config.applications.fetchEmptyAppList()
|
||||
})
|
||||
|
@ -59,8 +50,7 @@ describe("Internal API - Application creation, update, publish and delete", () =
|
|||
|
||||
it("Publish app", async () => {
|
||||
// create the app
|
||||
const appName = generator.word()
|
||||
const app = await createAppFromTemplate()
|
||||
const app = await config.applications.create(appFromTemplate())
|
||||
config.applications.api.appId = app.appId
|
||||
|
||||
// check preview renders
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import TestConfiguration from "../../../config/internal-api/TestConfiguration"
|
||||
import { App } from "@budibase/types"
|
||||
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient"
|
||||
import generateApp from "../../../config/internal-api/fixtures/applications"
|
||||
import { generateApp, appFromTemplate } from "../../../config/internal-api/fixtures/applications"
|
||||
import { Screen } from "@budibase/types"
|
||||
import generateScreen from "../../../config/internal-api/fixtures/screens"
|
||||
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import TestConfiguration from "../../../config/internal-api/TestConfiguration"
|
||||
import { Application } from "@budibase/server/api/controllers/public/mapping/types"
|
||||
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient"
|
||||
import generateApp from "../../../config/internal-api/fixtures/applications"
|
||||
import { generateApp, appFromTemplate } from "../../../config/internal-api/fixtures/applications"
|
||||
import { generateUser } from "../../../config/internal-api/fixtures/userManagement"
|
||||
import { User } from "@budibase/types"
|
||||
import { generateNewColumnForTable, generateTable } from "../../../config/internal-api/fixtures/table"
|
||||
import generateScreen from "../../../config/internal-api/fixtures/screens"
|
||||
import { db } from "@budibase/backend-core"
|
||||
|
||||
describe("Internal API - App Specific Roles & Permissions", () => {
|
||||
const api = new InternalAPIClient()
|
||||
|
@ -26,7 +27,7 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|||
expect(appUser[0].admin?.global).toEqual(false)
|
||||
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
|
||||
|
||||
const app = await config.applications.create(generateApp())
|
||||
const app = await config.applications.create(appFromTemplate())
|
||||
config.applications.api.appId = app.appId
|
||||
|
||||
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
||||
|
@ -50,7 +51,10 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|||
expect(adminUser[0].admin?.global).toEqual(true)
|
||||
const [createUserResponse, createUserJson] = await config.users.addMultiple(adminUser)
|
||||
|
||||
const app = await config.applications.create(generateApp())
|
||||
//const app = await config.applications.create(generateApp())
|
||||
//config.applications.api.appId = app.appId
|
||||
|
||||
const app = await config.applications.create(appFromTemplate())
|
||||
config.applications.api.appId = app.appId
|
||||
|
||||
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
||||
|
@ -66,6 +70,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|||
expect(changedUserInfoJson.roles[<string>app.appId]).toBeDefined()
|
||||
expect(changedUserInfoJson.roles[<string>app.appId]).toEqual("ADMIN")
|
||||
|
||||
// publish app
|
||||
await config.applications.publish(<string>app.url)
|
||||
// check published app renders
|
||||
config.applications.api.appId = db.getProdAppID(app.appId!)
|
||||
await config.applications.canRender()
|
||||
|
||||
})
|
||||
|
||||
it("Add POWER user to app", async () => {
|
||||
|
@ -190,7 +200,9 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|||
true
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("Screen Access for App specific roles", () => {
|
||||
it("Check Screen access for BASIC Role", async () => {
|
||||
const appUser = generateUser()
|
||||
expect(appUser[0].builder?.global).toEqual(false)
|
||||
|
@ -265,9 +277,7 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|||
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
describe.skip("App Access for custom roles", () => {
|
||||
describe.skip("Screen Access for custom roles", () => {
|
||||
it("Custom role access for level 1 permissions", async () => { })
|
||||
it("Custom role access for level 2 permissions", async () => { })
|
||||
it("Custom role access for level 3 permissions", async () => { })
|
||||
|
@ -275,4 +285,4 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|||
it("Custom role access for level 5 permissions", async () => { })
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue