From a6bde49ad3a7cda31c0bbec8e125b76ebca99365 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 10 Mar 2021 12:56:30 +0000 Subject: [PATCH] Updating application tests to run a lot deeper, which required updating some other tests to account for creation of empty screens and layouts. --- .../server/src/api/controllers/application.js | 6 ++- .../src/api/routes/tests/application.spec.js | 39 +++++++++++++++++++ .../src/api/routes/tests/automation.spec.js | 2 +- .../src/api/routes/tests/routing.spec.js | 29 +++++++------- .../src/api/routes/tests/screen.spec.js | 4 +- .../tests/utilities/TestConfiguration.js | 2 +- 6 files changed, 61 insertions(+), 21 deletions(-) diff --git a/packages/server/src/api/controllers/application.js b/packages/server/src/api/controllers/application.js index e899a2dca9..cba3e6455a 100644 --- a/packages/server/src/api/controllers/application.js +++ b/packages/server/src/api/controllers/application.js @@ -104,9 +104,10 @@ async function createInstance(template) { await createRoutingView(appId) // replicate the template data to the instance DB + // this is currently very hard to test, downloading and importing template files + /* istanbul ignore next */ if (template) { let dbDumpReadStream - if (template.fileImportPath) { dbDumpReadStream = fs.createReadStream(template.fileImportPath) } else { @@ -181,8 +182,9 @@ exports.create = async function(ctx) { const instanceDb = new CouchDB(appId) await instanceDb.put(newApplication) + const newAppFolder = await createEmptyAppPackage(ctx, newApplication) + /* istanbul ignore next */ if (env.NODE_ENV !== "jest") { - const newAppFolder = await createEmptyAppPackage(ctx, newApplication) await downloadExtractComponentLibraries(newAppFolder) } diff --git a/packages/server/src/api/routes/tests/application.spec.js b/packages/server/src/api/routes/tests/application.spec.js index c146cc63fb..12fcf6f8ea 100644 --- a/packages/server/src/api/routes/tests/application.spec.js +++ b/packages/server/src/api/routes/tests/application.spec.js @@ -58,4 +58,43 @@ describe("/applications", () => { }) }) + describe("fetchAppDefinition", () => { + it("should be able to get an apps definition", async () => { + const res = await request + .get(`/api/applications/${config.getAppId()}/definition`) + .set(config.defaultHeaders()) + .expect('Content-Type', /json/) + .expect(200) + // should have empty packages + expect(res.body.screens.length).toEqual(2) + expect(res.body.layouts.length).toEqual(2) + }) + }) + + describe("fetchAppPackage", () => { + it("should be able to fetch the app package", async () => { + const res = await request + .get(`/api/applications/${config.getAppId()}/appPackage`) + .set(config.defaultHeaders()) + .expect('Content-Type', /json/) + .expect(200) + expect(res.body.application).toBeDefined() + expect(res.body.screens.length).toEqual(2) + expect(res.body.layouts.length).toEqual(2) + }) + }) + + describe("update", () => { + it("should be able to fetch the app package", async () => { + const res = await request + .put(`/api/applications/${config.getAppId()}`) + .send({ + name: "TEST_APP" + }) + .set(config.defaultHeaders()) + .expect('Content-Type', /json/) + .expect(200) + expect(res.body.rev).toBeDefined() + }) + }) }) diff --git a/packages/server/src/api/routes/tests/automation.spec.js b/packages/server/src/api/routes/tests/automation.spec.js index 588de641b7..9d11219506 100644 --- a/packages/server/src/api/routes/tests/automation.spec.js +++ b/packages/server/src/api/routes/tests/automation.spec.js @@ -73,7 +73,7 @@ describe("/automations", () => { .expect('Content-Type', /json/) .expect(200) - expect(Object.keys(res.body.action).length).toEqual(Object.keys(ACTION_DEFINITIONS).length) + expect(Object.keys(res.body.action).length).toBeGreaterThanOrEqual(Object.keys(ACTION_DEFINITIONS).length) expect(Object.keys(res.body.trigger).length).toEqual(Object.keys(TRIGGER_DEFINITIONS).length) expect(Object.keys(res.body.logic).length).toEqual(Object.keys(LOGIC_DEFINITIONS).length) }) diff --git a/packages/server/src/api/routes/tests/routing.spec.js b/packages/server/src/api/routes/tests/routing.spec.js index 3b7523f586..70d1632bf3 100644 --- a/packages/server/src/api/routes/tests/routing.spec.js +++ b/packages/server/src/api/routes/tests/routing.spec.js @@ -3,6 +3,8 @@ const { basicScreen } = require("./utilities/structures") const { checkBuilderEndpoint } = require("./utilities/TestFunctions") const { BUILTIN_ROLE_IDS } = require("../../../utilities/security/roles") +const route = "/test" + describe("/routing", () => { let request = setup.getRequest() let config = setup.getConfig() @@ -12,9 +14,12 @@ describe("/routing", () => { beforeEach(async () => { await config.init() - screen = await config.createScreen(basicScreen()) + screen = basicScreen() + screen.routing.route = route + screen = await config.createScreen(screen) screen2 = basicScreen() screen2.routing.roleId = BUILTIN_ROLE_IDS.POWER + screen2.routing.route = route screen2 = await config.createScreen(screen2) }) @@ -26,9 +31,9 @@ describe("/routing", () => { .expect("Content-Type", /json/) .expect(200) expect(res.body.routes).toBeDefined() - expect(res.body.routes["/"]).toEqual({ + expect(res.body.routes[route]).toEqual({ subpaths: { - ["/"]: { + [route]: { screenId: screen._id, roleId: screen.routing.roleId } @@ -43,9 +48,9 @@ describe("/routing", () => { .expect("Content-Type", /json/) .expect(200) expect(res.body.routes).toBeDefined() - expect(res.body.routes["/"]).toEqual({ + expect(res.body.routes[route]).toEqual({ subpaths: { - ["/"]: { + [route]: { screenId: screen2._id, roleId: screen2.routing.roleId } @@ -62,16 +67,10 @@ describe("/routing", () => { .expect("Content-Type", /json/) .expect(200) expect(res.body.routes).toBeDefined() - expect(res.body.routes["/"]).toEqual({ - subpaths: { - ["/"]: { - screens: { - [screen2.routing.roleId]: screen2._id, - [screen.routing.roleId]: screen._id, - } - } - } - }) + expect(res.body.routes[route].subpaths[route]).toBeDefined() + const subpath = res.body.routes[route].subpaths[route] + expect(subpath.screens[screen2.routing.roleId]).toEqual(screen2._id) + expect(subpath.screens[screen.routing.roleId]).toEqual(screen._id) }) it("make sure it is a builder only endpoint", async () => { diff --git a/packages/server/src/api/routes/tests/screen.spec.js b/packages/server/src/api/routes/tests/screen.spec.js index 0c2799eca2..ae30afd29c 100644 --- a/packages/server/src/api/routes/tests/screen.spec.js +++ b/packages/server/src/api/routes/tests/screen.spec.js @@ -21,8 +21,8 @@ describe("/screens", () => { .set(config.defaultHeaders()) .expect("Content-Type", /json/) .expect(200) - expect(res.body.length).toEqual(1) - expect(res.body[0]._id).toEqual(screen._id) + expect(res.body.length).toEqual(3) + expect(res.body.some(s => s._id === screen._id)).toEqual(true) }) it("should apply authorization to endpoint", async () => { diff --git a/packages/server/src/api/routes/tests/utilities/TestConfiguration.js b/packages/server/src/api/routes/tests/utilities/TestConfiguration.js index 31989894ee..5e50bd033c 100644 --- a/packages/server/src/api/routes/tests/utilities/TestConfiguration.js +++ b/packages/server/src/api/routes/tests/utilities/TestConfiguration.js @@ -241,7 +241,7 @@ class TestConfiguration { async createUser( email = EMAIL, password = PASSWORD, - roleId = BUILTIN_ROLE_IDS.POWER, + roleId = BUILTIN_ROLE_IDS.POWER ) { return this._req( {