Fixing an issue with tmp directory filling up with different test apps.

This commit is contained in:
mike12345567 2021-03-11 12:09:47 +00:00
parent 8f82b069d2
commit 2617127bd6
3 changed files with 32 additions and 18 deletions

View File

@ -34,14 +34,7 @@ describe("/roles", () => {
describe("fetch", () => {
it("should list custom roles, plus 2 default roles", async () => {
const createRes = await request
.post(`/api/roles`)
.send(basicRole())
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200)
const customRole = createRes.body
const customRole = await config.createRole()
const res = await request
.get(`/api/roles`)
@ -68,24 +61,31 @@ describe("/roles", () => {
BUILTIN_PERMISSION_IDS.READ_ONLY
)
})
it("should be able to get the role with a permission added", async () => {
const table = await config.createTable()
await config.addPermission(BUILTIN_ROLE_IDS.POWER, table._id)
const res = await request
.get(`/api/roles`)
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200)
expect(res.body.length).toBeGreaterThan(0)
const power = res.body.find(role => role._id === BUILTIN_ROLE_IDS.POWER)
expect(power.permissions[table._id]).toEqual("read")
})
})
describe("destroy", () => {
it("should delete custom roles", async () => {
const createRes = await request
.post(`/api/roles`)
.send({ name: "user", permissionId: BUILTIN_PERMISSION_IDS.READ_ONLY })
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200)
const customRole = createRes.body
const customRole = await config.createRole({
name: "user",
permissionId: BUILTIN_PERMISSION_IDS.READ_ONLY
})
await request
.delete(`/api/roles/${customRole._id}/${customRole._rev}`)
.set(config.defaultHeaders())
.expect(200)
await request
.get(`/api/roles/${customRole._id}`)
.set(config.defaultHeaders())

View File

@ -14,6 +14,9 @@ const {
} = require("./structures")
const controllers = require("./controllers")
const supertest = require("supertest")
const fs = require("fs")
const { budibaseAppsDir } = require("../../../../utilities/budibaseDir")
const { join } = require("path")
const EMAIL = "babs@babs.com"
const PASSWORD = "babs_password"
@ -25,6 +28,7 @@ class TestConfiguration {
// we need the request for logging in, involves cookies, hard to fake
this.request = supertest(this.server)
this.appId = null
this.allApps = []
}
getRequest() {
@ -58,6 +62,13 @@ class TestConfiguration {
end() {
this.server.close()
const appDir = budibaseAppsDir()
const files = fs.readdirSync(appDir)
for (let file of files) {
if (this.allApps.some(app => file.includes(app._id))) {
fs.rmdirSync(join(appDir, file), { recursive: true })
}
}
}
defaultHeaders() {
@ -98,6 +109,7 @@ class TestConfiguration {
async createApp(appName) {
this.app = await this._req({ name: appName }, null, controllers.app.create)
this.appId = this.app._id
this.allApps.push(this.app)
return this.app
}

View File

@ -14,6 +14,8 @@ exports.afterAll = () => {
if (config) {
config.end()
}
// clear app files
request = null
config = null
}