Improve Role tests

This commit is contained in:
Pedro Silva 2022-12-14 23:15:02 +00:00
parent e431533b5d
commit d55172a9fb
5 changed files with 45 additions and 24 deletions

View File

@ -33,13 +33,21 @@ export default class AppApi {
async canRender(): Promise<[Response, boolean]> { async canRender(): Promise<[Response, boolean]> {
const response = await this.api.get("/routing/client") const response = await this.api.get("/routing/client")
expect(response).toHaveStatusCode(200)
const json = await response.json() const json = await response.json()
const publishedAppRenders = Object.keys(json.routes).length > 0 const publishedAppRenders = Object.keys(json.routes).length > 0
expect(response).toHaveStatusCode(200)
expect(publishedAppRenders).toBe(true) expect(publishedAppRenders).toBe(true)
return [response, publishedAppRenders] 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]> { async getAppPackage(appId: string): Promise<[Response, AppPackageResponse]> {
const response = await this.api.get(`/applications/${appId}/appPackage`) const response = await this.api.get(`/applications/${appId}/appPackage`)
const json = await response.json() const json = await response.json()

View File

@ -1,7 +1,9 @@
import generator from "../../generator" import generator from "../../generator"
import { Application } from "@budibase/server/api/controllers/public/mapping/types" 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> = {} overrides: Partial<Application> = {}
): Partial<Application> => ({ ): Partial<Application> => ({
name: generator.word() + generator.hash(), name: generator.word() + generator.hash(),
@ -9,4 +11,15 @@ const generate = (
...overrides, ...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,
})
}

View File

@ -2,7 +2,7 @@ import TestConfiguration from "../../../config/internal-api/TestConfiguration"
import { Application } from "@budibase/server/api/controllers/public/mapping/types" import { Application } from "@budibase/server/api/controllers/public/mapping/types"
import { db } from "@budibase/backend-core" import { db } from "@budibase/backend-core"
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" 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 generator from "../../../config/generator"
import generateScreen from "../../../config/internal-api/fixtures/screens" import generateScreen from "../../../config/internal-api/fixtures/screens"
@ -18,16 +18,7 @@ describe("Internal API - Application creation, update, publish and delete", () =
await config.afterAll() 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 () => { it("Get applications without applications", async () => {
await config.applications.fetchEmptyAppList() await config.applications.fetchEmptyAppList()
}) })
@ -59,8 +50,7 @@ describe("Internal API - Application creation, update, publish and delete", () =
it("Publish app", async () => { it("Publish app", async () => {
// create the app // create the app
const appName = generator.word() const app = await config.applications.create(appFromTemplate())
const app = await createAppFromTemplate()
config.applications.api.appId = app.appId config.applications.api.appId = app.appId
// check preview renders // check preview renders

View File

@ -1,7 +1,7 @@
import TestConfiguration from "../../../config/internal-api/TestConfiguration" import TestConfiguration from "../../../config/internal-api/TestConfiguration"
import { App } from "@budibase/types" import { App } from "@budibase/types"
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" 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 { Screen } from "@budibase/types"
import generateScreen from "../../../config/internal-api/fixtures/screens" import generateScreen from "../../../config/internal-api/fixtures/screens"

View File

@ -1,11 +1,12 @@
import TestConfiguration from "../../../config/internal-api/TestConfiguration" import TestConfiguration from "../../../config/internal-api/TestConfiguration"
import { Application } from "@budibase/server/api/controllers/public/mapping/types" import { Application } from "@budibase/server/api/controllers/public/mapping/types"
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" 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 { generateUser } from "../../../config/internal-api/fixtures/userManagement"
import { User } from "@budibase/types" import { User } from "@budibase/types"
import { generateNewColumnForTable, generateTable } from "../../../config/internal-api/fixtures/table" import { generateNewColumnForTable, generateTable } from "../../../config/internal-api/fixtures/table"
import generateScreen from "../../../config/internal-api/fixtures/screens" import generateScreen from "../../../config/internal-api/fixtures/screens"
import { db } from "@budibase/backend-core"
describe("Internal API - App Specific Roles & Permissions", () => { describe("Internal API - App Specific Roles & Permissions", () => {
const api = new InternalAPIClient() const api = new InternalAPIClient()
@ -26,7 +27,7 @@ describe("Internal API - App Specific Roles & Permissions", () => {
expect(appUser[0].admin?.global).toEqual(false) expect(appUser[0].admin?.global).toEqual(false)
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser) 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 config.applications.api.appId = app.appId
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) 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) expect(adminUser[0].admin?.global).toEqual(true)
const [createUserResponse, createUserJson] = await config.users.addMultiple(adminUser) 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 config.applications.api.appId = app.appId
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) 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]).toBeDefined()
expect(changedUserInfoJson.roles[<string>app.appId]).toEqual("ADMIN") 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 () => { it("Add POWER user to app", async () => {
@ -190,7 +200,9 @@ describe("Internal API - App Specific Roles & Permissions", () => {
true true
) )
}) })
})
describe("Screen Access for App specific roles", () => {
it("Check Screen access for BASIC Role", async () => { it("Check Screen access for BASIC Role", async () => {
const appUser = generateUser() const appUser = generateUser()
expect(appUser[0].builder?.global).toEqual(false) expect(appUser[0].builder?.global).toEqual(false)
@ -265,9 +277,7 @@ describe("Internal API - App Specific Roles & Permissions", () => {
}) })
}) })
describe.skip("Screen Access for custom roles", () => {
describe.skip("App Access for custom roles", () => {
it("Custom role access for level 1 permissions", async () => { }) it("Custom role access for level 1 permissions", async () => { })
it("Custom role access for level 2 permissions", async () => { }) it("Custom role access for level 2 permissions", async () => { })
it("Custom role access for level 3 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 () => { }) it("Custom role access for level 5 permissions", async () => { })
}) })
}) })