Small amount more user refactoring, removing use of couchTestUtils.

This commit is contained in:
mike12345567 2021-03-04 17:06:33 +00:00
parent ed0ee4fe60
commit 10d5da6aab
2 changed files with 29 additions and 32 deletions

View File

@ -1,8 +1,6 @@
const {
testPermissionsForEndpoint,
} = require("./couchTestUtils")
const { BUILTIN_ROLE_IDS } = require("../../../utilities/security/roles")
const TestConfig = require("./utilities/TestConfiguration")
const { checkPermissionsEndpoint } = require("./utilities/TestFunctions")
const { cloneDeep } = require("lodash/fp")
const baseBody = {
@ -13,9 +11,6 @@ const baseBody = {
describe("/users", () => {
let request
let server
let app
let appId
let config
beforeAll(async () => {
@ -24,8 +19,7 @@ describe("/users", () => {
})
beforeEach(async () => {
app = await config.init()
appId = app.instance._id
await config.init()
})
afterAll(() => {
@ -49,11 +43,11 @@ describe("/users", () => {
it("should apply authorization to endpoint", async () => {
await config.createUser("brenda@brenda.com", "brendas_password")
await testPermissionsForEndpoint({
await checkPermissionsEndpoint({
config,
request,
method: "GET",
url: `/api/users`,
appId: appId,
passRole: BUILTIN_ROLE_IDS.ADMIN,
failRole: BUILTIN_ROLE_IDS.PUBLIC,
})
@ -66,7 +60,7 @@ describe("/users", () => {
body.email = "bill@budibase.com"
const res = await request
.post(`/api/users`)
.set(defaultHeaders(appId))
.set(config.defaultHeaders())
.send(body)
.expect(200)
.expect("Content-Type", /json/)
@ -78,12 +72,11 @@ describe("/users", () => {
it("should apply authorization to endpoint", async () => {
const body = cloneDeep(baseBody)
body.email = "brandNewUser@user.com"
await testPermissionsForEndpoint({
request,
await checkPermissionsEndpoint({
config,
method: "POST",
body,
url: `/api/users`,
appId: appId,
passRole: BUILTIN_ROLE_IDS.ADMIN,
failRole: BUILTIN_ROLE_IDS.PUBLIC,
})

View File

@ -54,24 +54,28 @@ exports.checkBuilderEndpoint = async ({ config, method, url, body }) => {
.expect(403)
}
/**
* Raw DB insert utility.
*/
exports.insertDocument = async (databaseId, document) => {
const { id, ...documentFields } = document
return await new CouchDB(databaseId).put({ _id: id, ...documentFields })
}
exports.checkPermissionsEndpoint = async ({
config,
method,
url,
body,
passRole,
failRole,
}) => {
const password = "PASSWORD"
await config.createUser("passUser@budibase.com", password, passRole)
const passHeader = await config.login("passUser@budibase.com", password)
/**
* Raw DB delete utility.
*/
exports.destroyDocument = async (databaseId, documentId) => {
return await new CouchDB(databaseId).destroy(documentId)
}
await exports
.createRequest(config.request, method, url, body)
.set(passHeader)
.expect(200)
/**
* Raw DB get utility.
*/
exports.getDocument = async (databaseId, documentId) => {
return await new CouchDB(databaseId).get(documentId)
await config.createUser("failUser@budibase.com", password, failRole)
const failHeader = await config.login("failUser@budibase.com", password)
await exports
.createRequest(config.request, method, url, body)
.set(failHeader)
.expect(403)
}