Updating routing test cases.

This commit is contained in:
mike12345567 2021-03-08 14:49:19 +00:00
parent 94135aa714
commit a3257d37e6
4 changed files with 107 additions and 0 deletions

View File

@ -0,0 +1,85 @@
const setup = require("./utilities")
const { basicScreen } = require("./utilities/structures")
const { checkBuilderEndpoint } = require("./utilities/TestFunctions")
const { BUILTIN_ROLE_IDS } = require("../../../utilities/security/roles")
describe("/routing", () => {
let request = setup.getRequest()
let config = setup.getConfig()
let screen, screen2
afterAll(setup.afterAll)
beforeEach(async () => {
await config.init()
screen = await config.createScreen(basicScreen())
screen2 = basicScreen()
screen2.routing.roleId = BUILTIN_ROLE_IDS.POWER
screen2 = await config.createScreen(screen2)
})
describe("fetch", () => {
it("returns the correct routing for basic user", async () => {
const res = await request
.get(`/api/routing/client`)
.set(await config.roleHeaders("basic@test.com", BUILTIN_ROLE_IDS.BASIC))
.expect("Content-Type", /json/)
.expect(200)
expect(res.body.routes).toBeDefined()
expect(res.body.routes["/"]).toEqual({
subpaths: {
["/"]: {
screenId: screen._id,
roleId: screen.routing.roleId
}
}
})
})
it("returns the correct routing for power user", async () => {
const res = await request
.get(`/api/routing/client`)
.set(await config.roleHeaders("basic@test.com", BUILTIN_ROLE_IDS.POWER))
.expect("Content-Type", /json/)
.expect(200)
expect(res.body.routes).toBeDefined()
expect(res.body.routes["/"]).toEqual({
subpaths: {
["/"]: {
screenId: screen2._id,
roleId: screen2.routing.roleId
}
}
})
})
})
describe("fetch all", () => {
it("should fetch all routes for builder", async () => {
const res = await request
.get(`/api/routing`)
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200)
expect(res.body.routes).toBeDefined()
expect(res.body.routes["/"]).toEqual({
subpaths: {
["/"]: {
screens: {
[screen2.routing.roleId]: screen2._id,
[screen.routing.roleId]: screen._id,
}
}
}
})
})
it("make sure it is a builder only endpoint", async () => {
await checkBuilderEndpoint({
config,
method: "GET",
url: `/api/routing`,
})
})
})
})

View File

@ -8,6 +8,7 @@ const {
basicAutomation, basicAutomation,
basicDatasource, basicDatasource,
basicQuery, basicQuery,
basicScreen,
} = require("./structures") } = require("./structures")
const controllers = require("./controllers") const controllers = require("./controllers")
const supertest = require("supertest") const supertest = require("supertest")
@ -83,6 +84,15 @@ class TestConfiguration {
return headers return headers
} }
async roleHeaders(email = EMAIL, roleId) {
try {
await this.createUser(email, PASSWORD, roleId)
} catch (err) {
// allow errors here
}
return this.login(email, PASSWORD)
}
async createApp(appName) { async createApp(appName) {
this.app = await this._req({ name: appName }, null, controllers.app.create) this.app = await this._req({ name: appName }, null, controllers.app.create)
this.appId = this.app._id this.appId = this.app._id
@ -208,6 +218,11 @@ class TestConfiguration {
return this._req(config, null, controllers.query.save) return this._req(config, null, controllers.query.save)
} }
async createScreen(config = null) {
config = config || basicScreen()
return this._req(config, null, controllers.screen.save)
}
async createUser( async createUser(
email = EMAIL, email = EMAIL,
password = PASSWORD, password = PASSWORD,
@ -241,6 +256,7 @@ class TestConfiguration {
return { return {
Accept: "application/json", Accept: "application/json",
Cookie: result.headers["set-cookie"], Cookie: result.headers["set-cookie"],
"x-budibase-app-id": this.appId,
} }
} }
} }

View File

@ -9,4 +9,5 @@ module.exports = {
automation: require("../../../controllers/automation"), automation: require("../../../controllers/automation"),
datasource: require("../../../controllers/datasource"), datasource: require("../../../controllers/datasource"),
query: require("../../../controllers/query"), query: require("../../../controllers/query"),
screen: require("../../../controllers/screen"),
} }

View File

@ -2,6 +2,7 @@ const { BUILTIN_ROLE_IDS } = require("../../../../utilities/security/roles")
const { const {
BUILTIN_PERMISSION_IDS, BUILTIN_PERMISSION_IDS,
} = require("../../../../utilities/security/permissions") } = require("../../../../utilities/security/permissions")
const { createHomeScreen } = require("../../../../constants/screens")
exports.basicTable = () => { exports.basicTable = () => {
return { return {
@ -85,3 +86,7 @@ exports.basicUser = role => {
roleId: role, roleId: role,
} }
} }
exports.basicScreen = () => {
return createHomeScreen()
}