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

View File

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