From efacbe861ad79a04d62e8694d2ef72135e28d5d6 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Thu, 6 May 2021 10:54:01 +0100 Subject: [PATCH] unit tests --- .../src/api/routes/tests/configs.spec.js | 38 +++++++++++++++++++ .../tests/utilities/TestConfiguration.js | 27 +++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 packages/worker/src/api/routes/tests/configs.spec.js diff --git a/packages/worker/src/api/routes/tests/configs.spec.js b/packages/worker/src/api/routes/tests/configs.spec.js new file mode 100644 index 0000000000..0b01c5b261 --- /dev/null +++ b/packages/worker/src/api/routes/tests/configs.spec.js @@ -0,0 +1,38 @@ +const setup = require("./utilities") + +// mock the email system +const sendMailMock = jest.fn() +jest.mock("nodemailer") +const nodemailer = require("nodemailer") +nodemailer.createTransport.mockReturnValue({ + verify: jest.fn() +}) + +describe("/api/admin/configs/checklist", () => { + let request = setup.getRequest() + let config = setup.getConfig() + + beforeAll(async () => { + await config.init() + }) + + afterAll(setup.afterAll) + + it("should return the correct checklist status based on the state of the budibase installation", async () => { + // initially configure settings + await config.saveAdminUser() + await config.saveSmtpConfig() + + const res = await request + .get(`/api/admin/configs/checklist`) + .set(config.defaultHeaders()) + .expect("Content-Type", /json/) + .expect(200) + + const checklist = res.body + + expect(checklist.apps).toBe(0) + expect(checklist.smtp).toBe(true) + expect(checklist.adminUser).toBe(true) + }) +}) \ No newline at end of file diff --git a/packages/worker/src/api/routes/tests/utilities/TestConfiguration.js b/packages/worker/src/api/routes/tests/utilities/TestConfiguration.js index 0f97b50c82..a262f6a2e2 100644 --- a/packages/worker/src/api/routes/tests/utilities/TestConfiguration.js +++ b/packages/worker/src/api/routes/tests/utilities/TestConfiguration.js @@ -105,6 +105,22 @@ class TestConfiguration { ) } + async saveOAuthConfig() { + await this.deleteConfig(Configs.GOOGLE) + await this._req( + { + type: Configs.GOOGLE, + config: { + callbackURL: "http://somecallbackurl", + clientID: "clientId", + clientSecret: "clientSecret", + }, + }, + null, + controllers.config.save + ) + } + async saveSmtpConfig() { await this.deleteConfig(Configs.SMTP) await this._req( @@ -141,6 +157,17 @@ class TestConfiguration { controllers.config.save ) } + + async saveAdminUser() { + await this._req( + { + email: "testuser@test.com", + password: "test@test.com" + }, + null, + controllers.users.adminUser + ) + } } module.exports = TestConfiguration