2022-02-01 10:05:14 +13:00
|
|
|
jest.mock("nodemailer")
|
2022-11-12 04:43:41 +13:00
|
|
|
import { TestConfiguration, mocks } from "../../../../tests"
|
2022-04-07 03:57:56 +12:00
|
|
|
const sendMailMock = mocks.email.mock()
|
2022-08-26 06:41:47 +12:00
|
|
|
import { EmailTemplatePurpose } from "../../../../constants"
|
2021-04-24 01:58:06 +12:00
|
|
|
|
2021-08-05 20:59:08 +12:00
|
|
|
describe("/api/global/email", () => {
|
2022-08-26 06:41:47 +12:00
|
|
|
const config = new TestConfiguration()
|
2021-04-24 01:58:06 +12:00
|
|
|
|
2021-04-24 05:54:12 +12:00
|
|
|
beforeAll(async () => {
|
2022-04-07 03:57:56 +12:00
|
|
|
await config.beforeAll()
|
2021-04-24 05:54:12 +12:00
|
|
|
})
|
|
|
|
|
2022-04-07 03:57:56 +12:00
|
|
|
afterAll(async () => {
|
|
|
|
await config.afterAll()
|
|
|
|
})
|
2021-04-24 01:58:06 +12:00
|
|
|
|
|
|
|
it("should be able to send an email (with mocking)", async () => {
|
|
|
|
// initially configure settings
|
|
|
|
await config.saveSmtpConfig()
|
|
|
|
await config.saveSettingsConfig()
|
2022-08-26 06:41:47 +12:00
|
|
|
|
2022-11-12 04:43:41 +13:00
|
|
|
const res = await config.api.emails.sendEmail(
|
|
|
|
EmailTemplatePurpose.INVITATION
|
|
|
|
)
|
2022-08-26 06:41:47 +12:00
|
|
|
|
2021-04-24 05:54:12 +12:00
|
|
|
expect(res.body.message).toBeDefined()
|
|
|
|
expect(sendMailMock).toHaveBeenCalled()
|
|
|
|
const emailCall = sendMailMock.mock.calls[0][0]
|
|
|
|
expect(emailCall.subject).toBe("Hello!")
|
2021-12-07 06:58:43 +13:00
|
|
|
expect(emailCall.html).not.toContain("Invalid binding")
|
2021-04-24 01:58:06 +12:00
|
|
|
})
|
2021-12-07 06:58:43 +13:00
|
|
|
})
|