Browse Source

Fixing worker test cases.

master
mike12345567 5 years ago
parent
commit
12bbe19ed0
  1. 2
      packages/worker/src/api/routes/tests/auth.spec.js
  2. 2
      packages/worker/src/api/routes/tests/configs.spec.js
  3. 2
      packages/worker/src/api/routes/tests/users.spec.js
  4. 31
      packages/worker/src/api/routes/tests/utilities/TestConfiguration.js
  5. 4
      packages/worker/src/utilities/email.js

2
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()
})

2
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)

2
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()
})

31
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() {

4
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))

Loading…
Cancel
Save