From c4683a37430c00ff2b7b18b11befb21fc3a70d5a Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 14 Sep 2020 14:32:20 +0100 Subject: [PATCH] Updating some test cases which were failing silently and changing how environment want handled. --- packages/server/src/api/routes/tests/accesslevel.spec.js | 4 ++-- packages/server/src/api/routes/tests/couchTestUtils.js | 9 +++------ packages/server/src/api/routes/tests/model.spec.js | 4 ++++ packages/server/src/environment.js | 1 + packages/server/src/workflows/index.js | 3 ++- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/server/src/api/routes/tests/accesslevel.spec.js b/packages/server/src/api/routes/tests/accesslevel.spec.js index 81ab6a78ad..b2878e92ed 100644 --- a/packages/server/src/api/routes/tests/accesslevel.spec.js +++ b/packages/server/src/api/routes/tests/accesslevel.spec.js @@ -37,7 +37,7 @@ describe("/accesslevels", () => { beforeEach(async () => { instanceId = (await createInstance(request, appId))._id model = await createModel(request, appId, instanceId) - view = await createView(request, appId, instanceId) + view = await createView(request, appId, instanceId, model._id) }) describe("create", () => { @@ -111,7 +111,7 @@ describe("/accesslevels", () => { await request .get(`/api/accesslevels/${customLevel._id}`) .set(defaultHeaders(appId, instanceId)) - .expect(404) + .expect(404) }) }) diff --git a/packages/server/src/api/routes/tests/couchTestUtils.js b/packages/server/src/api/routes/tests/couchTestUtils.js index ddeab96ade..13be04cf87 100644 --- a/packages/server/src/api/routes/tests/couchTestUtils.js +++ b/packages/server/src/api/routes/tests/couchTestUtils.js @@ -67,9 +67,10 @@ exports.createModel = async (request, appId, instanceId, model) => { return res.body } -exports.createView = async (request, appId, instanceId, view) => { +exports.createView = async (request, appId, instanceId, modelId, view) => { view = view || { map: "function(doc) { emit(doc[doc.key], doc._id); } ", + modelId: modelId, } const res = await request @@ -262,11 +263,7 @@ exports.builderEndpointShouldBlockNormalUsers = async ({ appId, instanceId, }) => { - const headers = await createUserWithAdminPermissions( - request, - appId, - instanceId - ) + const headers = await createUserWithAdminPermissions(request, appId, instanceId) await createRequest(request, method, url, body) .set(headers) diff --git a/packages/server/src/api/routes/tests/model.spec.js b/packages/server/src/api/routes/tests/model.spec.js index 49f6be41ad..23214b95c3 100644 --- a/packages/server/src/api/routes/tests/model.spec.js +++ b/packages/server/src/api/routes/tests/model.spec.js @@ -120,6 +120,10 @@ describe("/models", () => { testModel = await createModel(request, app._id, instance._id, testModel) }); + afterEach(() => { + delete testModel._rev + }); + it("returns all the models for that instance in the response body", done => { request .get(`/api/models`) diff --git a/packages/server/src/environment.js b/packages/server/src/environment.js index 9bab1ed1a0..b3043fbfe0 100644 --- a/packages/server/src/environment.js +++ b/packages/server/src/environment.js @@ -7,4 +7,5 @@ module.exports = { COUCH_DB_URL: process.env.COUCH_DB_URL, SALT_ROUNDS: process.env.SALT_ROUNDS, LOGGER: process.env.LOGGER, + BUDIBASE_ENVIRONMENT: process.env.BUDIBASE_ENVIRONMENT, } diff --git a/packages/server/src/workflows/index.js b/packages/server/src/workflows/index.js index 545fc3382d..81708e8b12 100644 --- a/packages/server/src/workflows/index.js +++ b/packages/server/src/workflows/index.js @@ -1,4 +1,5 @@ const triggers = require("./triggers") +const environment = require("../environment") const workerFarm = require("worker-farm") const singleThread = require("./thread") @@ -21,7 +22,7 @@ function runWorker(job) { */ module.exports.init = function() { triggers.workflowQueue.process(async job => { - if (process.env.BUDIBASE_ENVIRONMENT === "PRODUCTION") { + if (environment.BUDIBASE_ENVIRONMENT === "PRODUCTION") { await runWorker(job) } else { await singleThread(job)