Test e-mail templates, remain files, first step

This commit is contained in:
Wolfgang Huß 2021-11-18 08:53:31 +01:00
parent 6f4acaef61
commit ce5161f937
8 changed files with 15 additions and 17 deletions

View File

@ -19,7 +19,7 @@ const defaultParams = {
}
const englishHint = 'English version below!'
export const signupTemplate = ({ email, nonce, inviteCode = null }) => {
export const signupTemplate = ({ email, variables: { nonce, inviteCode = null } }) => {
const subject = `Willkommen, Bienvenue, Welcome to ${CONFIG.APPLICATION_NAME}!`
// dev format example: http://localhost:3000/registration?method=invite-mail&email=wolle.huss%40pjannto.com&nonce=64853
const actionUrl = new URL('/registration', CONFIG.CLIENT_URI)
@ -84,7 +84,7 @@ export const wrongAccountTemplate = ({ email }) => {
}
}
export const notificationTemplate = ({ email, notification }) => {
export const notificationTemplate = ({ email, variables: { notification } }) => {
const actionUrl = new URL('/notifications', CONFIG.CLIENT_URI)
const settingsUrl = new URL('/settings/notifications', CONFIG.CLIENT_URI)
const renderParams = { ...defaultParams, name: notification.to.name, settingsUrl, actionUrl }

View File

@ -25,8 +25,7 @@
<h1
style="margin: 0 0 10px 0; font-family: Lato, sans-serif; font-size: 25px; line-height: 30px; color: #333333; font-weight: normal;">
Hallo {{ name }},</h1>
<p style="margin: 0;">Du hast mindestens eine Benachrichtigung erhalten. Klick auf diesen Button,
um sie anzusehen:</p>
<p style="margin: 0;">Du hast mindestens eine Benachrichtigung erhalten. Klick auf diesen Button, um sie anzusehen:</p>
</td>
</tr>
<tr>

View File

@ -11,9 +11,9 @@ const sendSignupMail = async (resolve, root, args, context, resolveInfo) => {
const response = await resolve(root, args, context, resolveInfo)
const { email, nonce } = response
if (inviteCode) {
await sendMail(signupTemplate({ email, nonce, inviteCode }))
await sendMail(signupTemplate({ email, variables: { nonce, inviteCode } }))
} else {
await sendMail(signupTemplate({ email, nonce }))
await sendMail(signupTemplate({ email, variables: { nonce } }))
}
delete response.nonce
return response

View File

@ -41,7 +41,6 @@ const publishNotifications = async (context, promises) => {
notifications.forEach((notificationAdded, index) => {
pubsub.publish(NOTIFICATION_ADDED, { notificationAdded })
if (notificationAdded.to.sendNotificationEmails) {
// Wolle await
sendMail(
notificationTemplate({
email: notificationsEmailAddresses[index].email,

View File

@ -195,7 +195,7 @@ describe('slugifyMiddleware', () => {
variables = {
...variables,
name: 'I am a user',
nonce: '123456',
nonce: '12345',
password: 'yo',
email: '123@example.org',
termsAndConditionsAgreedVersion: '0.0.1',
@ -206,7 +206,7 @@ describe('slugifyMiddleware', () => {
beforeEach(async () => {
await Factory.build('emailAddress', {
email: '123@example.org',
nonce: '123456',
nonce: '12345',
verifiedAt: null,
})
})

View File

@ -118,7 +118,7 @@ describe('passwordReset', () => {
describe('resetPassword', () => {
const setup = async (options = {}) => {
const { email = 'user@example.org', issuedAt = new Date(), nonce = 'abcdef' } = options
const { email = 'user@example.org', issuedAt = new Date(), nonce = 'abcde' } = options
await createPasswordReset({ driver, email, issuedAt, nonce })
}
@ -148,7 +148,7 @@ describe('resetPassword', () => {
describe('invalid email', () => {
it('resolves to false', async () => {
await setup()
variables = { ...variables, email: 'non-existent@example.org', nonce: 'abcdef' }
variables = { ...variables, email: 'non-existent@example.org', nonce: 'abcde' }
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
data: { resetPassword: false },
})
@ -177,7 +177,7 @@ describe('resetPassword', () => {
beforeEach(() => {
variables = {
...variables,
nonce: 'abcdef',
nonce: 'abcde',
}
})

View File

@ -179,7 +179,7 @@ describe('SignupVerification', () => {
beforeEach(async () => {
variables = {
...variables,
nonce: '123456',
nonce: '12345',
name: 'John Doe',
password: '123',
email: 'john@example.org',
@ -207,7 +207,7 @@ describe('SignupVerification', () => {
describe('sending a valid nonce', () => {
beforeEach(() => {
variables = { ...variables, nonce: '123456' }
variables = { ...variables, nonce: '12345' }
})
it('rejects', async () => {
@ -222,7 +222,7 @@ describe('SignupVerification', () => {
beforeEach(async () => {
const args = {
email: 'john@example.org',
nonce: '123456',
nonce: '12345',
}
await neode.model('EmailAddress').create(args)
})

View File

@ -40,7 +40,7 @@ describe('ChangePassword ', () => {
describe('given email and nonce', () => {
beforeEach(() => {
propsData.email = 'mail@example.org'
propsData.nonce = '123456'
propsData.nonce = '12345'
})
describe('submitting new password', () => {
@ -57,7 +57,7 @@ describe('ChangePassword ', () => {
it('delivers new password to backend', () => {
const expected = expect.objectContaining({
variables: { nonce: '123456', email: 'mail@example.org', password: 'supersecret' },
variables: { nonce: '12345', email: 'mail@example.org', password: 'supersecret' },
})
expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expected)
})