1
0
Fork 0
mirror of synced 2024-06-28 02:50:50 +12:00

Fixing some test cases that were affected by file system refactor.

This commit is contained in:
mike12345567 2021-03-23 18:04:53 +00:00
parent 19b5b41953
commit e715423544
4 changed files with 19 additions and 12 deletions

View file

@ -1,6 +1,8 @@
const { checkBuilderEndpoint } = require("./utilities/TestFunctions") const { checkBuilderEndpoint } = require("./utilities/TestFunctions")
const setup = require("./utilities") const setup = require("./utilities")
jest.mock("../../../utilities/fileSystem/utilities")
describe("/backups", () => { describe("/backups", () => {
let request = setup.getRequest() let request = setup.getRequest()
let config = setup.getConfig() let config = setup.getConfig()
@ -14,7 +16,7 @@ describe("/backups", () => {
describe("exportAppDump", () => { describe("exportAppDump", () => {
it("should be able to export app", async () => { it("should be able to export app", async () => {
const res = await request const res = await request
.get(`/api/backups/export?appId=${config.getAppId()}`) .get(`/api/backups/export?appId=${config.getAppId()}&appname=test`)
.set(config.defaultHeaders()) .set(config.defaultHeaders())
.expect(200) .expect(200)
expect(res.text).toBeDefined() expect(res.text).toBeDefined()

View file

@ -9,6 +9,7 @@ const env = require("./environment")
const eventEmitter = require("./events") const eventEmitter = require("./events")
const automations = require("./automations/index") const automations = require("./automations/index")
const Sentry = require("@sentry/node") const Sentry = require("@sentry/node")
const fileSystem = require("./utilities/fileSystem")
const app = new Koa() const app = new Koa()
@ -65,6 +66,7 @@ module.exports = server.listen(env.PORT || 0, async () => {
console.log(`Budibase running on ${JSON.stringify(server.address())}`) console.log(`Budibase running on ${JSON.stringify(server.address())}`)
env._set("PORT", server.address().port) env._set("PORT", server.address().port)
eventEmitter.emitPort(env.PORT) eventEmitter.emitPort(env.PORT)
fileSystem.init()
await automations.init() await automations.init()
}) })

View file

@ -71,12 +71,6 @@ describe("Authorization middleware", () => {
beforeEach(() => { beforeEach(() => {
config = new TestConfiguration() config = new TestConfiguration()
})
it("passes the middleware for local webhooks", async () => {
config.setRequestUrl("https://something/webhooks/trigger")
await config.executeMiddleware()
expect(config.next).toHaveBeenCalled()
}) })
describe("external web hook call", () => { describe("external web hook call", () => {

View file

@ -16,6 +16,7 @@ const { downloadLibraries, newAppPublicPath } = require("./newApp")
const download = require("download") const download = require("download")
const env = require("../../environment") const env = require("../../environment")
const { homedir } = require("os") const { homedir } = require("os")
const fetch = require("node-fetch")
const DEFAULT_AUTOMATION_BUCKET = const DEFAULT_AUTOMATION_BUCKET =
"https://prod-budi-automations.s3-eu-west-1.amazonaws.com" "https://prod-budi-automations.s3-eu-west-1.amazonaws.com"
@ -29,6 +30,16 @@ const DEFAULT_AUTOMATION_DIRECTORY = ".budibase-automations"
* be done through an object store instead. * be done through an object store instead.
*/ */
/**
* Upon first startup of instance there may not be everything we need in tmp directory, set it up.
*/
exports.init = () => {
const tempDir = budibaseTempDir()
if (!fs.existsSync(tempDir)) {
fs.mkdirSync(tempDir)
}
}
/** /**
* Checks if the system is currently in development mode and if it is makes sure * Checks if the system is currently in development mode and if it is makes sure
* everything required to function is ready. * everything required to function is ready.
@ -167,15 +178,13 @@ exports.automationInit = async () => {
} }
exports.getExternalAutomationStep = async (name, version, bundleName) => { exports.getExternalAutomationStep = async (name, version, bundleName) => {
const directory = env.AUTOMATION_DIRECTORY || join(homedir(), DEFAULT_AUTOMATION_DIRECTORY) const directory =
env.AUTOMATION_DIRECTORY || join(homedir(), DEFAULT_AUTOMATION_DIRECTORY)
const bucket = env.AUTOMATION_BUCKET || DEFAULT_AUTOMATION_BUCKET const bucket = env.AUTOMATION_BUCKET || DEFAULT_AUTOMATION_BUCKET
try { try {
return require(join(directory, bundleName)) return require(join(directory, bundleName))
} catch (err) { } catch (err) {
await download( await download(`${bucket}/${name}/${version}/${bundleName}`, directory)
`${bucket}/${name}/${version}/${bundleName}`,
directory
)
return require(join(directory, bundleName)) return require(join(directory, bundleName))
} }
} }