From 110ae15fb3635ef0130929b580991c0ab3e5d4da Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 5 Mar 2021 11:24:15 +0000 Subject: [PATCH] Some more quick modifications to test re-factor before PR. --- .../src/api/routes/tests/automation.spec.js | 3 +- .../server/src/api/routes/tests/testUtils.js | 1 - .../api/routes/tests/utilities/controllers.js | 2 +- .../src/api/routes/tests/utilities/index.js | 2 + .../server/src/api/routes/tests/view.spec.js | 103 +++++++++--------- 5 files changed, 54 insertions(+), 57 deletions(-) delete mode 100644 packages/server/src/api/routes/tests/testUtils.js diff --git a/packages/server/src/api/routes/tests/automation.spec.js b/packages/server/src/api/routes/tests/automation.spec.js index 8038ea8481..c737f1da6b 100644 --- a/packages/server/src/api/routes/tests/automation.spec.js +++ b/packages/server/src/api/routes/tests/automation.spec.js @@ -5,8 +5,7 @@ const { clearAllAutomations, } = require("./utilities/TestFunctions") const { basicAutomation } = require("./utilities/structures") - -const { delay } = require("./testUtils") +const { delay } = require("./utilities") const MAX_RETRIES = 4 diff --git a/packages/server/src/api/routes/tests/testUtils.js b/packages/server/src/api/routes/tests/testUtils.js deleted file mode 100644 index 0e66b47c3d..0000000000 --- a/packages/server/src/api/routes/tests/testUtils.js +++ /dev/null @@ -1 +0,0 @@ -module.exports.delay = ms => new Promise(resolve => setTimeout(resolve, ms)) diff --git a/packages/server/src/api/routes/tests/utilities/controllers.js b/packages/server/src/api/routes/tests/utilities/controllers.js index d1e23d4527..541495bec8 100644 --- a/packages/server/src/api/routes/tests/utilities/controllers.js +++ b/packages/server/src/api/routes/tests/utilities/controllers.js @@ -8,5 +8,5 @@ module.exports = { user: require("../../../controllers/user"), automation: require("../../../controllers/automation"), datasource: require("../../../controllers/datasource"), - query: require("../../../controllers/query") + query: require("../../../controllers/query"), } diff --git a/packages/server/src/api/routes/tests/utilities/index.js b/packages/server/src/api/routes/tests/utilities/index.js index 6e7825b599..7786dc2bcc 100644 --- a/packages/server/src/api/routes/tests/utilities/index.js +++ b/packages/server/src/api/routes/tests/utilities/index.js @@ -1,3 +1,5 @@ const TEST_CLIENT_ID = "test-client-id" exports.TEST_CLIENT_ID = TEST_CLIENT_ID + +exports.delay = ms => new Promise(resolve => setTimeout(resolve, ms)) diff --git a/packages/server/src/api/routes/tests/view.spec.js b/packages/server/src/api/routes/tests/view.spec.js index 50abb1b855..39549daa98 100644 --- a/packages/server/src/api/routes/tests/view.spec.js +++ b/packages/server/src/api/routes/tests/view.spec.js @@ -1,30 +1,27 @@ -const TestConfig = require("./utilities/TestConfiguration"); +const TestConfig = require("./utilities/TestConfiguration") describe("/views", () => { - let request; - let app; - let config; - let appId; - let table; + let request + let config + let table beforeAll(async () => { - config = new TestConfig(); - request = config.request; - }); + config = new TestConfig() + request = config.request + }) beforeEach(async () => { - app = await config.init(); - appId = app.instance._id; - }); + await config.init() + }) afterAll(() => { - config.end(); - }); + config.end() + }) describe("create", () => { beforeEach(async () => { - table = await config.createTable(); - }); + table = await config.createTable() + }) it("returns a success message when the view is successfully created", async () => { const res = await request @@ -37,12 +34,12 @@ describe("/views", () => { }) .set(config.defaultHeaders()) .expect("Content-Type", /json/) - .expect(200); + .expect(200) expect(res.res.statusMessage).toEqual( "View TestView saved successfully." - ); - }); + ) + }) it("updates the table row with the new view metadata", async () => { const res = await request @@ -55,12 +52,12 @@ describe("/views", () => { }) .set(config.defaultHeaders()) .expect("Content-Type", /json/) - .expect(200); + .expect(200) expect(res.res.statusMessage).toEqual( "View TestView saved successfully." - ); - const updatedTable = await config.getTable(table._id); + ) + const updatedTable = await config.getTable(table._id) expect(updatedTable.views).toEqual({ TestView: { field: "Price", @@ -91,14 +88,14 @@ describe("/views", () => { }, }, }, - }); - }); - }); + }) + }) + }) describe("fetch", () => { beforeEach(async () => { - table = await config.createTable(); - }); + table = await config.createTable() + }) it("returns only custom views", async () => { await config.createView({ @@ -106,21 +103,21 @@ describe("/views", () => { field: "Price", calculation: "stats", tableId: table._id, - }); + }) const res = await request .get(`/api/views`) .set(config.defaultHeaders()) .expect("Content-Type", /json/) - .expect(200); - expect(res.body.length).toBe(1); - expect(res.body.find(({ name }) => name === "TestView")).toBeDefined(); - }); - }); + .expect(200) + expect(res.body.length).toBe(1) + expect(res.body.find(({ name }) => name === "TestView")).toBeDefined() + }) + }) describe("query", () => { beforeEach(async () => { - table = await config.createTable(); - }); + table = await config.createTable() + }) it("returns data for the created view", async () => { await config.createView({ @@ -128,27 +125,27 @@ describe("/views", () => { field: "Price", calculation: "stats", tableId: table._id, - }); + }) await config.createRow({ tableId: table._id, Price: 1000, - }); + }) await config.createRow({ tableId: table._id, Price: 2000, - }); + }) await config.createRow({ tableId: table._id, Price: 4000, - }); + }) const res = await request .get(`/api/views/TestView?calculation=stats`) .set(config.defaultHeaders()) .expect("Content-Type", /json/) - .expect(200); - expect(res.body.length).toBe(1); - expect(res.body).toMatchSnapshot(); - }); + .expect(200) + expect(res.body.length).toBe(1) + expect(res.body).toMatchSnapshot() + }) it("returns data for the created view using a group by", async () => { await config.createView({ @@ -157,30 +154,30 @@ describe("/views", () => { field: "Price", groupBy: "Category", tableId: table._id, - }); + }) await config.createRow({ tableId: table._id, Price: 1000, Category: "One", - }); + }) await config.createRow({ tableId: table._id, Price: 2000, Category: "One", - }); + }) await config.createRow({ tableId: table._id, Price: 4000, Category: "Two", - }); + }) const res = await request .get(`/api/views/TestView?calculation=stats&group=Category`) .set(config.defaultHeaders()) .expect("Content-Type", /json/) - .expect(200); + .expect(200) - expect(res.body.length).toBe(2); - expect(res.body).toMatchSnapshot(); - }); - }); -}); + expect(res.body.length).toBe(2) + expect(res.body).toMatchSnapshot() + }) + }) +})