From 584f7c240399e03aaae84e1965a92aa6b6da90e6 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 19 May 2021 16:39:17 +0100 Subject: [PATCH] Fixing worker test cases. --- .../worker/src/api/routes/tests/auth.spec.js | 2 +- .../src/api/routes/tests/configs.spec.js | 2 +- .../worker/src/api/routes/tests/users.spec.js | 2 +- .../tests/utilities/TestConfiguration.js | 31 +++++++++++-------- packages/worker/src/utilities/email.js | 4 ++- 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/packages/worker/src/api/routes/tests/auth.spec.js b/packages/worker/src/api/routes/tests/auth.spec.js index df90210433..8b9b699839 100644 --- a/packages/worker/src/api/routes/tests/auth.spec.js +++ b/packages/worker/src/api/routes/tests/auth.spec.js @@ -30,7 +30,7 @@ describe("/api/admin/auth", () => { expect(sendMailMock).toHaveBeenCalled() const emailCall = sendMailMock.mock.calls[0][0] // after this URL there should be a code - const parts = emailCall.html.split("http://localhost:10000/reset?code=") + const parts = emailCall.html.split("http://localhost:10000/builder/auth/reset?code=") code = parts[1].split("\"")[0] expect(code).toBeDefined() }) diff --git a/packages/worker/src/api/routes/tests/configs.spec.js b/packages/worker/src/api/routes/tests/configs.spec.js index 0b01c5b261..13ba2bd3bc 100644 --- a/packages/worker/src/api/routes/tests/configs.spec.js +++ b/packages/worker/src/api/routes/tests/configs.spec.js @@ -13,7 +13,7 @@ describe("/api/admin/configs/checklist", () => { let config = setup.getConfig() beforeAll(async () => { - await config.init() + await config.init(false) }) afterAll(setup.afterAll) diff --git a/packages/worker/src/api/routes/tests/users.spec.js b/packages/worker/src/api/routes/tests/users.spec.js index 0a4812ea09..bf5b67ab1a 100644 --- a/packages/worker/src/api/routes/tests/users.spec.js +++ b/packages/worker/src/api/routes/tests/users.spec.js @@ -30,7 +30,7 @@ describe("/api/admin/users", () => { expect(sendMailMock).toHaveBeenCalled() const emailCall = sendMailMock.mock.calls[0][0] // after this URL there should be a code - const parts = emailCall.html.split("http://localhost:10000/invite?code=") + const parts = emailCall.html.split("http://localhost:10000/builder/invite?code=") code = parts[1].split("\"")[0] expect(code).toBeDefined() }) diff --git a/packages/worker/src/api/routes/tests/utilities/TestConfiguration.js b/packages/worker/src/api/routes/tests/utilities/TestConfiguration.js index 7e9d56aa66..746a26c800 100644 --- a/packages/worker/src/api/routes/tests/utilities/TestConfiguration.js +++ b/packages/worker/src/api/routes/tests/utilities/TestConfiguration.js @@ -38,20 +38,25 @@ class TestConfiguration { return request.body } - async init() { - // create a test user - await this._req( - { - email: "test@test.com", - password: "test", - _id: "us_uuid1", - builder: { - global: true, + async init(createUser = true) { + if (createUser) { + // create a test user + await this._req( + { + email: "test@test.com", + password: "test", + _id: "us_uuid1", + builder: { + global: true, + }, + admin: { + global: true, + }, }, - }, - null, - controllers.users.save - ) + null, + controllers.users.save + ) + } } async end() { diff --git a/packages/worker/src/utilities/email.js b/packages/worker/src/utilities/email.js index 179f662a96..e6e1db2184 100644 --- a/packages/worker/src/utilities/email.js +++ b/packages/worker/src/utilities/email.js @@ -155,10 +155,12 @@ exports.sendEmail = async ( const context = await getSettingsTemplateContext(purpose, code) const message = { from: from || config.from, - subject: await processString(subject || config.subject, context), to: email, html: await buildEmail(purpose, email, context, { user, contents }), } + if (subject || config.subject) { + message.subject = await processString(subject || config.subject, context) + } const response = await transport.sendMail(message) if (TEST_MODE) { console.log("Test email URL: " + nodemailer.getTestMessageUrl(response))