From 420cb36ca7247930bbb0d01a15702291bf95e3b1 Mon Sep 17 00:00:00 2001 From: adrinr Date: Fri, 3 Feb 2023 19:02:40 +0000 Subject: [PATCH] Replace beforeeach for before alls --- .../query/import/tests/index.spec.js | 2 +- .../src/api/routes/tests/analytics.spec.js | 5 ++++- .../src/api/routes/tests/apikeys.spec.js | 2 +- .../server/src/api/routes/tests/auth.spec.js | 2 +- .../src/api/routes/tests/component.spec.js | 2 +- .../server/src/api/routes/tests/dev.spec.js | 2 +- .../src/api/routes/tests/integration.spec.js | 2 +- .../src/api/routes/tests/layout.spec.js | 2 +- .../src/api/routes/tests/metadata.spec.js | 2 +- .../server/src/api/routes/tests/misc.spec.js | 2 +- .../src/api/routes/tests/query.seq.spec.js | 20 +++++++++++++++++-- .../server/src/api/routes/tests/role.spec.js | 7 ++++++- .../src/api/routes/tests/routing.spec.js | 2 +- .../src/api/routes/tests/static.spec.js | 2 +- .../server/src/api/routes/tests/table.spec.js | 2 +- .../src/api/routes/tests/templates.spec.js | 2 +- .../server/src/api/routes/tests/view.spec.js | 5 ++++- .../src/api/routes/tests/webhook.spec.js | 8 ++++++-- .../src/automations/tests/automation.spec.js | 2 +- .../server/src/automations/tests/bash.spec.js | 2 +- .../src/automations/tests/discord.spec.js | 2 +- .../automations/tests/executeQuery.spec.js | 3 +-- .../automations/tests/executeScript.spec.js | 2 +- .../automations/tests/outgoingWebhook.spec.js | 2 +- .../automations/tests/sendSmtpEmail.spec.js | 2 +- .../src/automations/tests/serverLog.spec.js | 2 +- .../src/automations/tests/updateRow.spec.js | 2 +- .../src/automations/tests/zapier.spec.js | 2 +- .../server/src/db/tests/linkTests.spec.js | 2 +- .../functions/tests/appUrls.spec.js | 2 +- .../functions/tests/syncQuotas.spec.js | 2 +- .../tests/userEmailViewCasing.spec.js | 2 +- 32 files changed, 65 insertions(+), 35 deletions(-) diff --git a/packages/server/src/api/controllers/query/import/tests/index.spec.js b/packages/server/src/api/controllers/query/import/tests/index.spec.js index adcb31f8e7..60030ae7f3 100644 --- a/packages/server/src/api/controllers/query/import/tests/index.spec.js +++ b/packages/server/src/api/controllers/query/import/tests/index.spec.js @@ -41,7 +41,7 @@ const datasets = { describe("Rest Importer", () => { const config = new TestConfig(false) - beforeEach(async () => { + beforeAll(async () => { await config.init() }) diff --git a/packages/server/src/api/routes/tests/analytics.spec.js b/packages/server/src/api/routes/tests/analytics.spec.js index f8b3a6763f..ac7cd978c8 100644 --- a/packages/server/src/api/routes/tests/analytics.spec.js +++ b/packages/server/src/api/routes/tests/analytics.spec.js @@ -10,8 +10,11 @@ describe("/static", () => { afterAll(setup.afterAll) - beforeEach(async () => { + beforeAll(async () => { app = await config.init() + }) + + beforeEach(()=>{ jest.clearAllMocks() }) diff --git a/packages/server/src/api/routes/tests/apikeys.spec.js b/packages/server/src/api/routes/tests/apikeys.spec.js index 24402a8794..4a52ea84b4 100644 --- a/packages/server/src/api/routes/tests/apikeys.spec.js +++ b/packages/server/src/api/routes/tests/apikeys.spec.js @@ -7,7 +7,7 @@ describe("/api/keys", () => { afterAll(setup.afterAll) - beforeEach(async () => { + beforeAll(async () => { await config.init() }) diff --git a/packages/server/src/api/routes/tests/auth.spec.js b/packages/server/src/api/routes/tests/auth.spec.js index 06a1f52ad8..9418d44046 100644 --- a/packages/server/src/api/routes/tests/auth.spec.js +++ b/packages/server/src/api/routes/tests/auth.spec.js @@ -7,7 +7,7 @@ describe("/authenticate", () => { afterAll(setup.afterAll) - beforeEach(async () => { + beforeAll(async () => { await config.init() }) diff --git a/packages/server/src/api/routes/tests/component.spec.js b/packages/server/src/api/routes/tests/component.spec.js index 14ec58cf38..160a1ca160 100644 --- a/packages/server/src/api/routes/tests/component.spec.js +++ b/packages/server/src/api/routes/tests/component.spec.js @@ -7,7 +7,7 @@ describe("/component", () => { afterAll(setup.afterAll) - beforeEach(async () => { + beforeAll(async () => { await config.init() }) diff --git a/packages/server/src/api/routes/tests/dev.spec.js b/packages/server/src/api/routes/tests/dev.spec.js index db6bad11f4..111f3dbd5b 100644 --- a/packages/server/src/api/routes/tests/dev.spec.js +++ b/packages/server/src/api/routes/tests/dev.spec.js @@ -8,7 +8,7 @@ describe("/dev", () => { afterAll(setup.afterAll) - beforeEach(async () => { + beforeAll(async () => { await config.init() jest.clearAllMocks() }) diff --git a/packages/server/src/api/routes/tests/integration.spec.js b/packages/server/src/api/routes/tests/integration.spec.js index 528d0d3417..dde780681b 100644 --- a/packages/server/src/api/routes/tests/integration.spec.js +++ b/packages/server/src/api/routes/tests/integration.spec.js @@ -7,7 +7,7 @@ describe("/integrations", () => { afterAll(setup.afterAll) - beforeEach(async () => { + beforeAll(async () => { await config.init() }) diff --git a/packages/server/src/api/routes/tests/layout.spec.js b/packages/server/src/api/routes/tests/layout.spec.js index c149a0fec5..ebd6ab7278 100644 --- a/packages/server/src/api/routes/tests/layout.spec.js +++ b/packages/server/src/api/routes/tests/layout.spec.js @@ -10,7 +10,7 @@ describe("/layouts", () => { afterAll(setup.afterAll) - beforeEach(async () => { + beforeAll(async () => { await config.init() layout = await config.createLayout() jest.clearAllMocks() diff --git a/packages/server/src/api/routes/tests/metadata.spec.js b/packages/server/src/api/routes/tests/metadata.spec.js index 8ef8e3d45b..bb28951ee3 100644 --- a/packages/server/src/api/routes/tests/metadata.spec.js +++ b/packages/server/src/api/routes/tests/metadata.spec.js @@ -9,7 +9,7 @@ describe("/metadata", () => { afterAll(setup.afterAll) - beforeEach(async () => { + beforeAll(async () => { await config.init() automation = await config.createAutomation() }) diff --git a/packages/server/src/api/routes/tests/misc.spec.js b/packages/server/src/api/routes/tests/misc.spec.js index 2451953df1..6dd82df496 100644 --- a/packages/server/src/api/routes/tests/misc.spec.js +++ b/packages/server/src/api/routes/tests/misc.spec.js @@ -7,7 +7,7 @@ describe("run misc tests", () => { afterAll(setup.afterAll) - beforeEach(async () => { + beforeAll(async () => { await config.init() }) diff --git a/packages/server/src/api/routes/tests/query.seq.spec.js b/packages/server/src/api/routes/tests/query.seq.spec.js index 6db6ea69cf..699d95fea2 100644 --- a/packages/server/src/api/routes/tests/query.seq.spec.js +++ b/packages/server/src/api/routes/tests/query.seq.spec.js @@ -30,11 +30,15 @@ describe("/queries", () => { afterAll(setup.afterAll) - beforeEach(async () => { - config.modeSelf() + const setupTest = async()=>{ + await config.init() datasource = await config.createDatasource() query = await config.createQuery() + } + + beforeAll(async () => { + await setupTest() }) async function createInvalidIntegration() { @@ -105,6 +109,10 @@ describe("/queries", () => { }) describe("fetch", () => { + beforeEach(async() => { + await setupTest() + }) + it("returns all the queries from the server", async () => { const res = await request .get(`/api/queries`) @@ -182,6 +190,10 @@ describe("/queries", () => { }) describe("destroy", () => { + beforeEach(async() => { + await setupTest() + }) + it("deletes a query and returns a success message", async () => { await request .delete(`/api/queries/${query._id}/${query._rev}`) @@ -243,6 +255,10 @@ describe("/queries", () => { }) describe("execute", () => { + beforeEach(async() => { + await setupTest() + }) + it("should be able to execute the query", async () => { const res = await request .post(`/api/queries/${query._id}`) diff --git a/packages/server/src/api/routes/tests/role.spec.js b/packages/server/src/api/routes/tests/role.spec.js index 8402a7b13c..f42ffe4846 100644 --- a/packages/server/src/api/routes/tests/role.spec.js +++ b/packages/server/src/api/routes/tests/role.spec.js @@ -10,7 +10,7 @@ describe("/roles", () => { afterAll(setup.afterAll) - beforeEach(async () => { + beforeAll(async () => { await config.init() }) @@ -60,6 +60,11 @@ describe("/roles", () => { }) describe("fetch", () => { + beforeAll(async () => { + // Recreate the app + await config.init() + }) + it("should list custom roles, plus 2 default roles", async () => { const customRole = await config.createRole() diff --git a/packages/server/src/api/routes/tests/routing.spec.js b/packages/server/src/api/routes/tests/routing.spec.js index 48762dbf06..ff6d7aba1d 100644 --- a/packages/server/src/api/routes/tests/routing.spec.js +++ b/packages/server/src/api/routes/tests/routing.spec.js @@ -16,7 +16,7 @@ describe("/routing", () => { afterAll(setup.afterAll) - beforeEach(async () => { + beforeAll(async () => { await config.init() screen = basicScreen() screen.routing.route = route diff --git a/packages/server/src/api/routes/tests/static.spec.js b/packages/server/src/api/routes/tests/static.spec.js index 6e0ffd2319..a0532f12fb 100644 --- a/packages/server/src/api/routes/tests/static.spec.js +++ b/packages/server/src/api/routes/tests/static.spec.js @@ -8,7 +8,7 @@ describe("/static", () => { afterAll(setup.afterAll) - beforeEach(async () => { + beforeAll(async () => { config.modeSelf() app = await config.init() }) diff --git a/packages/server/src/api/routes/tests/table.spec.js b/packages/server/src/api/routes/tests/table.spec.js index 521b64e0c0..d28f2232ee 100644 --- a/packages/server/src/api/routes/tests/table.spec.js +++ b/packages/server/src/api/routes/tests/table.spec.js @@ -10,7 +10,7 @@ describe("/tables", () => { afterAll(setup.afterAll) - beforeEach(async () => { + beforeAll(async () => { const app = await config.init() appId = app.appId }) diff --git a/packages/server/src/api/routes/tests/templates.spec.js b/packages/server/src/api/routes/tests/templates.spec.js index 30e337e855..3cb22fd2d3 100644 --- a/packages/server/src/api/routes/tests/templates.spec.js +++ b/packages/server/src/api/routes/tests/templates.spec.js @@ -6,7 +6,7 @@ describe("/templates", () => { afterAll(setup.afterAll) - beforeEach(async () => { + beforeAll(async () => { await config.init() }) diff --git a/packages/server/src/api/routes/tests/view.spec.js b/packages/server/src/api/routes/tests/view.spec.js index bd5177b905..522987ab29 100644 --- a/packages/server/src/api/routes/tests/view.spec.js +++ b/packages/server/src/api/routes/tests/view.spec.js @@ -28,8 +28,11 @@ describe("/views", () => { afterAll(setup.afterAll) - beforeEach(async () => { + beforeAll(async () => { await config.init() + }) + + beforeEach(async() => { table = await config.createTable(priceTable()) }) diff --git a/packages/server/src/api/routes/tests/webhook.spec.js b/packages/server/src/api/routes/tests/webhook.spec.js index 2c619e7906..988d0e3748 100644 --- a/packages/server/src/api/routes/tests/webhook.spec.js +++ b/packages/server/src/api/routes/tests/webhook.spec.js @@ -9,7 +9,7 @@ describe("/webhooks", () => { afterAll(setup.afterAll) - beforeEach(async () => { + const setupTest = async () => { config.modeSelf() await config.init() const autoConfig = basicAutomation() @@ -19,7 +19,9 @@ describe("/webhooks", () => { } await config.createAutomation(autoConfig) webhook = await config.createWebhook() - }) + } + + beforeAll(setupTest) describe("create", () => { it("should create a webhook successfully", async () => { @@ -85,6 +87,8 @@ describe("/webhooks", () => { }) describe("build schema", () => { + beforeAll(setupTest) + it("should allow building a schema", async () => { const res = await request .post(`/api/webhooks/schema/${config.getAppId()}/${webhook._id}`) diff --git a/packages/server/src/automations/tests/automation.spec.js b/packages/server/src/automations/tests/automation.spec.js index 59ee531e9b..b63d1f4b5b 100644 --- a/packages/server/src/automations/tests/automation.spec.js +++ b/packages/server/src/automations/tests/automation.spec.js @@ -21,7 +21,7 @@ const setup = require("./utilities") describe("Run through some parts of the automations system", () => { let config = setup.getConfig() - beforeEach(async () => { + beforeAll(async () => { await automation.init() await config.init() }) diff --git a/packages/server/src/automations/tests/bash.spec.js b/packages/server/src/automations/tests/bash.spec.js index cf358a089d..a8695c7460 100644 --- a/packages/server/src/automations/tests/bash.spec.js +++ b/packages/server/src/automations/tests/bash.spec.js @@ -3,7 +3,7 @@ const setup = require("./utilities") describe("test the bash action", () => { let config = setup.getConfig() - beforeEach(async () => { + beforeAll(async () => { await config.init() }) afterAll(setup.afterAll) diff --git a/packages/server/src/automations/tests/discord.spec.js b/packages/server/src/automations/tests/discord.spec.js index cb51748a04..d91c46094a 100644 --- a/packages/server/src/automations/tests/discord.spec.js +++ b/packages/server/src/automations/tests/discord.spec.js @@ -7,7 +7,7 @@ describe("test the outgoing webhook action", () => { let inputs let config = setup.getConfig() - beforeEach(async () => { + beforeAll(async () => { await config.init() inputs = { username: "joe_bloggs", diff --git a/packages/server/src/automations/tests/executeQuery.spec.js b/packages/server/src/automations/tests/executeQuery.spec.js index 2136baa99e..ae2ca1dfd8 100644 --- a/packages/server/src/automations/tests/executeQuery.spec.js +++ b/packages/server/src/automations/tests/executeQuery.spec.js @@ -1,10 +1,9 @@ const setup = require("./utilities") describe("test the execute query action", () => { - let datasource let config = setup.getConfig() - beforeEach(async () => { + beforeAll(async () => { await config.init() await config.createDatasource() diff --git a/packages/server/src/automations/tests/executeScript.spec.js b/packages/server/src/automations/tests/executeScript.spec.js index d0febe4078..b9aedb8e31 100644 --- a/packages/server/src/automations/tests/executeScript.spec.js +++ b/packages/server/src/automations/tests/executeScript.spec.js @@ -3,7 +3,7 @@ const setup = require("./utilities") describe("test the execute script action", () => { let config = setup.getConfig() - beforeEach(async () => { + beforeAll(async () => { await config.init() }) afterAll(setup.afterAll) diff --git a/packages/server/src/automations/tests/outgoingWebhook.spec.js b/packages/server/src/automations/tests/outgoingWebhook.spec.js index 9f82fb7604..c31ed850e7 100644 --- a/packages/server/src/automations/tests/outgoingWebhook.spec.js +++ b/packages/server/src/automations/tests/outgoingWebhook.spec.js @@ -7,7 +7,7 @@ describe("test the outgoing webhook action", () => { let inputs let config = setup.getConfig() - beforeEach(async () => { + beforeAll(async () => { await config.init() inputs = { requestMethod: "POST", diff --git a/packages/server/src/automations/tests/sendSmtpEmail.spec.js b/packages/server/src/automations/tests/sendSmtpEmail.spec.js index fcafc329c0..998a1f54b2 100644 --- a/packages/server/src/automations/tests/sendSmtpEmail.spec.js +++ b/packages/server/src/automations/tests/sendSmtpEmail.spec.js @@ -36,7 +36,7 @@ const setup = require("./utilities") describe("test the outgoing webhook action", () => { let inputs let config = setup.getConfig() - beforeEach(async () => { + beforeAll(async () => { await config.init() }) diff --git a/packages/server/src/automations/tests/serverLog.spec.js b/packages/server/src/automations/tests/serverLog.spec.js index 550910723a..8b5ce2e64f 100644 --- a/packages/server/src/automations/tests/serverLog.spec.js +++ b/packages/server/src/automations/tests/serverLog.spec.js @@ -3,7 +3,7 @@ const setup = require("./utilities") describe("test the server log action", () => { let config = setup.getConfig() - beforeEach(async () => { + beforeAll(async () => { await config.init() inputs = { text: "log message", diff --git a/packages/server/src/automations/tests/updateRow.spec.js b/packages/server/src/automations/tests/updateRow.spec.js index 36b3b1748f..77383d80e9 100644 --- a/packages/server/src/automations/tests/updateRow.spec.js +++ b/packages/server/src/automations/tests/updateRow.spec.js @@ -4,7 +4,7 @@ describe("test the update row action", () => { let table, row, inputs let config = setup.getConfig() - beforeEach(async () => { + beforeAll(async () => { await config.init() table = await config.createTable() row = await config.createRow() diff --git a/packages/server/src/automations/tests/zapier.spec.js b/packages/server/src/automations/tests/zapier.spec.js index e1fc785152..9d94a4c17f 100644 --- a/packages/server/src/automations/tests/zapier.spec.js +++ b/packages/server/src/automations/tests/zapier.spec.js @@ -7,7 +7,7 @@ describe("test the outgoing webhook action", () => { let inputs let config = setup.getConfig() - beforeEach(async () => { + beforeAll(async () => { await config.init() inputs = { value1: "test", diff --git a/packages/server/src/db/tests/linkTests.spec.js b/packages/server/src/db/tests/linkTests.spec.js index 0684255ea1..b7764dacb7 100644 --- a/packages/server/src/db/tests/linkTests.spec.js +++ b/packages/server/src/db/tests/linkTests.spec.js @@ -9,7 +9,7 @@ describe("test link functionality", () => { describe("getLinkedTable", () => { let table - beforeEach(async () => { + beforeAll(async () => { const app = await config.init() appId = app.appId table = await config.createTable() diff --git a/packages/server/src/migrations/functions/tests/appUrls.spec.js b/packages/server/src/migrations/functions/tests/appUrls.spec.js index dafe67712f..f60dff855c 100644 --- a/packages/server/src/migrations/functions/tests/appUrls.spec.js +++ b/packages/server/src/migrations/functions/tests/appUrls.spec.js @@ -6,7 +6,7 @@ const migration = require("../appUrls") describe("run", () => { let config = new TestConfig(false) - beforeEach(async () => { + beforeAll(async () => { await config.init() }) diff --git a/packages/server/src/migrations/functions/tests/syncQuotas.spec.js b/packages/server/src/migrations/functions/tests/syncQuotas.spec.js index cdffeea8bd..71f6554b84 100644 --- a/packages/server/src/migrations/functions/tests/syncQuotas.spec.js +++ b/packages/server/src/migrations/functions/tests/syncQuotas.spec.js @@ -11,7 +11,7 @@ const migration = require("../syncQuotas") describe("run", () => { let config = new TestConfig(false) - beforeEach(async () => { + beforeAll(async () => { await config.init() }) diff --git a/packages/server/src/migrations/functions/tests/userEmailViewCasing.spec.js b/packages/server/src/migrations/functions/tests/userEmailViewCasing.spec.js index e6e6725f07..c0066b1c71 100644 --- a/packages/server/src/migrations/functions/tests/userEmailViewCasing.spec.js +++ b/packages/server/src/migrations/functions/tests/userEmailViewCasing.spec.js @@ -19,7 +19,7 @@ const migration = require("../userEmailViewCasing") describe("run", () => { let config = new TestConfig(false) - beforeEach(async () => { + beforeAll(async () => { await config.init() })