Fixing an issue with tmp directory filling up with different test apps.
This commit is contained in:
parent
5d340d4559
commit
40b9743c3c
|
@ -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())
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@ exports.afterAll = () => {
|
|||
if (config) {
|
||||
config.end()
|
||||
}
|
||||
// clear app files
|
||||
|
||||
request = null
|
||||
config = null
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue