try to test send verification email

This commit is contained in:
Moriz Wahl 2022-01-04 19:18:05 +01:00
parent b7186209f1
commit 055a9c9d80
2 changed files with 32 additions and 6 deletions

View File

@ -1,4 +1,4 @@
import { sendEMail } from './sendEMail'
import sendEmail from './sendEMail'
import { createTransport } from 'nodemailer'
import CONFIG from '../config'
@ -32,7 +32,7 @@ describe('sendEMail', () => {
// eslint-disable-next-line no-console
console.log = consoleLogMock
beforeEach(async () => {
result = await sendEMail({
result = await sendEmail.sendEMail({
from: 'sender@mail.org',
to: 'receiver@mail.org',
subject: 'Subject',
@ -57,7 +57,7 @@ describe('sendEMail', () => {
describe('config email is true', () => {
beforeEach(async () => {
CONFIG.EMAIL = true
result = await sendEMail({
result = await sendEmail.sendEMail({
from: 'sender@mail.org',
to: 'receiver@mail.org',
subject: 'Subject',
@ -83,3 +83,29 @@ describe('sendEMail', () => {
})
})
})
describe('sendAccountActivationEmail', () => {
const spy = jest.spyOn(sendEmail, 'sendEMail')
beforeEach(async () => {
jest.clearAllMocks()
await sendEmail.sendAccountActivationEmail(
'activationLink',
'Petet',
'Lustig',
'peter@lustig.de',
)
})
it.skip('calls sendEMail', () => {
expect(spy).toBeCalledWith(
expect.objectContaining({
from: `Gradido (nicht antworten) <${CONFIG.EMAIL_SENDER}>`,
to: `Peter Lustig <peter@lustig.de'>`,
subject: 'Gradido: E-Mail Überprüfung',
text:
expect.stringContaining('Hallo Peter Lustig') &&
expect.stringContaining('activationLink'),
}),
)
})
})

View File

@ -2,7 +2,7 @@ import { createTransport } from 'nodemailer'
import CONFIG from '../config'
const sendEMail = async (emailDef: {
export const sendEMail = async (emailDef: {
from: string
to: string
subject: string
@ -30,7 +30,7 @@ const sendEMail = async (emailDef: {
return true
}
const sendAccountActivationEmail = (
export const sendAccountActivationEmail = (
activationLink: string,
firstName: string,
lastName: string,
@ -53,4 +53,4 @@ const sendAccountActivationEmail = (
})
}
export { sendAccountActivationEmail, sendEMail }
export default { sendAccountActivationEmail, sendEMail }