From 1a878c3e08e5b5a9872a59bbd1dce6dfdc0f9259 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 23 Mar 2021 18:04:53 +0000 Subject: [PATCH] Fixing some test cases that were affected by file system refactor. --- .../src/api/routes/tests/backup.spec.js | 4 +++- packages/server/src/app.js | 2 ++ .../src/middleware/tests/authorized.spec.js | 6 ------ .../server/src/utilities/fileSystem/index.js | 19 ++++++++++++++----- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/packages/server/src/api/routes/tests/backup.spec.js b/packages/server/src/api/routes/tests/backup.spec.js index d603990294..4e586bfd08 100644 --- a/packages/server/src/api/routes/tests/backup.spec.js +++ b/packages/server/src/api/routes/tests/backup.spec.js @@ -1,6 +1,8 @@ const { checkBuilderEndpoint } = require("./utilities/TestFunctions") const setup = require("./utilities") +jest.mock("../../../utilities/fileSystem/utilities") + describe("/backups", () => { let request = setup.getRequest() let config = setup.getConfig() @@ -14,7 +16,7 @@ describe("/backups", () => { describe("exportAppDump", () => { it("should be able to export app", async () => { const res = await request - .get(`/api/backups/export?appId=${config.getAppId()}`) + .get(`/api/backups/export?appId=${config.getAppId()}&appname=test`) .set(config.defaultHeaders()) .expect(200) expect(res.text).toBeDefined() diff --git a/packages/server/src/app.js b/packages/server/src/app.js index 8bbea00474..e5e9b77084 100644 --- a/packages/server/src/app.js +++ b/packages/server/src/app.js @@ -9,6 +9,7 @@ const env = require("./environment") const eventEmitter = require("./events") const automations = require("./automations/index") const Sentry = require("@sentry/node") +const fileSystem = require("./utilities/fileSystem") 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())}`) env._set("PORT", server.address().port) eventEmitter.emitPort(env.PORT) + fileSystem.init() await automations.init() }) diff --git a/packages/server/src/middleware/tests/authorized.spec.js b/packages/server/src/middleware/tests/authorized.spec.js index d3e5e52d2d..7669821da2 100644 --- a/packages/server/src/middleware/tests/authorized.spec.js +++ b/packages/server/src/middleware/tests/authorized.spec.js @@ -71,12 +71,6 @@ describe("Authorization middleware", () => { beforeEach(() => { 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", () => { diff --git a/packages/server/src/utilities/fileSystem/index.js b/packages/server/src/utilities/fileSystem/index.js index b19b89f710..a64a24a9fc 100644 --- a/packages/server/src/utilities/fileSystem/index.js +++ b/packages/server/src/utilities/fileSystem/index.js @@ -16,6 +16,7 @@ const { downloadLibraries, newAppPublicPath } = require("./newApp") const download = require("download") const env = require("../../environment") const { homedir } = require("os") +const fetch = require("node-fetch") const DEFAULT_AUTOMATION_BUCKET = "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. */ +/** + * 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 * everything required to function is ready. @@ -167,15 +178,13 @@ exports.automationInit = async () => { } 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 try { return require(join(directory, bundleName)) } catch (err) { - await download( - `${bucket}/${name}/${version}/${bundleName}`, - directory - ) + await download(`${bucket}/${name}/${version}/${bundleName}`, directory) return require(join(directory, bundleName)) } }