Test 'sendAccountActivationEmail'

This commit is contained in:
Wolfgang Huß 2022-11-17 15:27:07 +01:00
parent aa97f08460
commit 0fdb3e4401
2 changed files with 88 additions and 19 deletions

View File

@ -1,5 +1,5 @@
import CONFIG from '@/config'
import { sendAccountMultiRegistrationEmail } from './sendEmailVariants'
import { sendAccountActivationEmail, sendAccountMultiRegistrationEmail } from './sendEmailVariants'
import { sendEmailTranslated } from './sendEmailTranslated'
CONFIG.EMAIL = true
@ -19,6 +19,75 @@ jest.mock('./sendEmailTranslated', () => {
describe('sendEmailVariants', () => {
let result: Record<string, unknown> | null
describe('sendAccountActivationEmail', () => {
beforeAll(async () => {
result = await sendAccountActivationEmail({
firstName: 'Peter',
lastName: 'Lustig',
email: 'peter@lustig.de',
language: 'en',
activationLink: 'http://localhost/checkEmail/6627633878930542284',
timeDurationObject: { hours: 24, minutes: 0 },
})
})
describe('calls "sendEmailTranslated"', () => {
it('with expected parameters', () => {
expect(sendEmailTranslated).toBeCalledWith({
receiver: {
to: 'Peter Lustig <peter@lustig.de>',
},
template: 'sendAccountActivation',
locals: {
firstName: 'Peter',
lastName: 'Lustig',
locale: 'en',
activationLink: 'http://localhost/checkEmail/6627633878930542284',
timeDurationObject: { hours: 24, minutes: 0 },
resendLink: CONFIG.EMAIL_LINK_FORGOTPASSWORD,
},
})
})
it('has expected result', () => {
expect(result).toMatchObject({
envelope: {
from: 'info@gradido.net',
to: ['peter@lustig.de'],
},
message: expect.any(String),
originalMessage: expect.objectContaining({
to: 'Peter Lustig <peter@lustig.de>',
from: 'Gradido (nicht antworten) <info@gradido.net>',
attachments: [],
subject: 'Gradido: Email Verification',
html:
expect.stringContaining('<title>Gradido: Email Verification</title>') &&
expect.stringContaining('>Gradido: Email Verification</h1>') &&
expect.stringContaining(
'Your email address has just been registered with Gradido.',
) &&
expect.stringContaining(
'Please click on this link to complete the registration and activate your Gradido account:',
) &&
expect.stringContaining(
'<a href="http://localhost/checkEmail/6627633878930542284">http://localhost/checkEmail/6627633878930542284</a>',
) &&
expect.stringContaining('or copy the link above into your browser window.') &&
expect.stringContaining(
'The link has a validity of {hours} hours and {minutes} minutes. If the validity of the link has already expired, you can have a new link sent to you here by entering your email address:',
) &&
expect.stringContaining(
`<a href="${CONFIG.EMAIL_LINK_FORGOTPASSWORD}">${CONFIG.EMAIL_LINK_FORGOTPASSWORD}</a>`,
) &&
expect.stringContaining('Sincerely yours,<br><span>your Gradido team'),
text: expect.stringContaining('GRADIDO: EMAIL VERIFICATION'),
}),
})
})
})
})
describe('sendAccountMultiRegistrationEmail', () => {
beforeAll(async () => {
result = await sendAccountMultiRegistrationEmail({

View File

@ -1,24 +1,6 @@
import CONFIG from '@/config'
import { sendEmailTranslated } from './sendEmailTranslated'
export const sendAccountMultiRegistrationEmail = (data: {
firstName: string
lastName: string
email: string
language: string
}): Promise<Record<string, unknown> | null> => {
return sendEmailTranslated({
receiver: { to: `${data.firstName} ${data.lastName} <${data.email}>` },
template: 'accountMultiRegistration',
locals: {
firstName: data.firstName,
lastName: data.lastName,
locale: data.language,
resendLink: CONFIG.EMAIL_LINK_FORGOTPASSWORD,
},
})
}
export const sendAccountActivationEmail = (data: {
firstName: string
lastName: string
@ -40,3 +22,21 @@ export const sendAccountActivationEmail = (data: {
},
})
}
export const sendAccountMultiRegistrationEmail = (data: {
firstName: string
lastName: string
email: string
language: string
}): Promise<Record<string, unknown> | null> => {
return sendEmailTranslated({
receiver: { to: `${data.firstName} ${data.lastName} <${data.email}>` },
template: 'accountMultiRegistration',
locals: {
firstName: data.firstName,
lastName: data.lastName,
locale: data.language,
resendLink: CONFIG.EMAIL_LINK_FORGOTPASSWORD,
},
})
}