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", () => { describe("fetch", () => {
it("should list custom roles, plus 2 default roles", async () => { it("should list custom roles, plus 2 default roles", async () => {
const createRes = await request const customRole = await config.createRole()
.post(`/api/roles`)
.send(basicRole())
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200)
const customRole = createRes.body
const res = await request const res = await request
.get(`/api/roles`) .get(`/api/roles`)
@ -68,24 +61,31 @@ describe("/roles", () => {
BUILTIN_PERMISSION_IDS.READ_ONLY 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", () => { describe("destroy", () => {
it("should delete custom roles", async () => { it("should delete custom roles", async () => {
const createRes = await request const customRole = await config.createRole({
.post(`/api/roles`) name: "user",
.send({ name: "user", permissionId: BUILTIN_PERMISSION_IDS.READ_ONLY }) permissionId: BUILTIN_PERMISSION_IDS.READ_ONLY
.set(config.defaultHeaders()) })
.expect("Content-Type", /json/)
.expect(200)
const customRole = createRes.body
await request await request
.delete(`/api/roles/${customRole._id}/${customRole._rev}`) .delete(`/api/roles/${customRole._id}/${customRole._rev}`)
.set(config.defaultHeaders()) .set(config.defaultHeaders())
.expect(200) .expect(200)
await request await request
.get(`/api/roles/${customRole._id}`) .get(`/api/roles/${customRole._id}`)
.set(config.defaultHeaders()) .set(config.defaultHeaders())

View File

@ -14,6 +14,9 @@ const {
} = require("./structures") } = require("./structures")
const controllers = require("./controllers") const controllers = require("./controllers")
const supertest = require("supertest") const supertest = require("supertest")
const fs = require("fs")
const { budibaseAppsDir } = require("../../../../utilities/budibaseDir")
const { join } = require("path")
const EMAIL = "babs@babs.com" const EMAIL = "babs@babs.com"
const PASSWORD = "babs_password" const PASSWORD = "babs_password"
@ -25,6 +28,7 @@ class TestConfiguration {
// we need the request for logging in, involves cookies, hard to fake // we need the request for logging in, involves cookies, hard to fake
this.request = supertest(this.server) this.request = supertest(this.server)
this.appId = null this.appId = null
this.allApps = []
} }
getRequest() { getRequest() {
@ -58,6 +62,13 @@ class TestConfiguration {
end() { end() {
this.server.close() 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() { defaultHeaders() {
@ -98,6 +109,7 @@ class TestConfiguration {
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
this.allApps.push(this.app)
return this.app return this.app
} }

View File

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