From 36b621ca5b0894f46d5d6152eb2314c9a3b032d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Thu, 18 Nov 2021 16:15:04 +0100 Subject: [PATCH] Add remaining templates --- .../helpers/email/templateBuilder.js | 4 +- .../helpers/email/templateBuilder.spec.js | 161 ++++++++++++++++-- .../helpers/email/templates/wrongAccount.html | 8 +- 3 files changed, 155 insertions(+), 18 deletions(-) diff --git a/backend/src/middleware/helpers/email/templateBuilder.js b/backend/src/middleware/helpers/email/templateBuilder.js index 5f615f01d..1cbcca8b1 100644 --- a/backend/src/middleware/helpers/email/templateBuilder.js +++ b/backend/src/middleware/helpers/email/templateBuilder.js @@ -41,7 +41,7 @@ export const signupTemplate = ({ email, variables: { nonce, inviteCode = null } } } -export const emailVerificationTemplate = ({ email, nonce, name }) => { +export const emailVerificationTemplate = ({ email, variables: { nonce, name } }) => { const subject = 'Neue E-Mail Adresse | New E-Mail Address' const actionUrl = new URL('/settings/my-email-address/verify', CONFIG.CLIENT_URI) actionUrl.searchParams.set('email', email) @@ -56,7 +56,7 @@ export const emailVerificationTemplate = ({ email, nonce, name }) => { } } -export const resetPasswordTemplate = ({ email, nonce, name }) => { +export const resetPasswordTemplate = ({ email, variables: { nonce, name } }) => { const subject = 'Neues Passwort | Reset Password' const actionUrl = new URL('/password-reset/change-password', CONFIG.CLIENT_URI) actionUrl.searchParams.set('nonce', nonce) diff --git a/backend/src/middleware/helpers/email/templateBuilder.spec.js b/backend/src/middleware/helpers/email/templateBuilder.spec.js index 58fa5addd..60683fab7 100644 --- a/backend/src/middleware/helpers/email/templateBuilder.spec.js +++ b/backend/src/middleware/helpers/email/templateBuilder.spec.js @@ -2,12 +2,13 @@ import CONFIG from '../../../config' import logosWebapp from '../../../config/logos.js' import { signupTemplate, - // resetPasswordTemplate, - // wrongAccountTemplate, - // emailVerificationTemplate, + emailVerificationTemplate, + resetPasswordTemplate, + wrongAccountTemplate, notificationTemplate, } from './templateBuilder' +const englishHint = 'English version below!' const welcomeImageUrl = new URL(logosWebapp.LOGO_WELCOME_PATH, CONFIG.CLIENT_URI) const supportUrl = CONFIG.SUPPORT_URL.toString() let actionUrl, name, settingsUrl @@ -19,6 +20,24 @@ const signupTemplateData = () => ({ inviteCode: 'AAAAAA', }, }) +const emailVerificationTemplateData = () => ({ + email: 'test@example.org', + variables: { + nonce: '12345', + name: 'Mr Example', + }, +}) +const resetPasswordTemplateData = () => ({ + email: 'test@example.org', + variables: { + nonce: '12345', + name: 'Mr Example', + }, +}) +const wrongAccountTemplateData = () => ({ + email: 'test@example.org', + variables: {}, +}) const notificationTemplateData = (locale) => ({ email: 'test@example.org', variables: { @@ -61,29 +80,36 @@ const testEmailData = (emailTemplate, templateBuilder, templateData, texts) => { return emailTemplate } -beforeAll(async () => { - // await cleanDatabase() -}) +// beforeAll(async () => { +// await cleanDatabase() +// }) -afterAll(async () => { - // await cleanDatabase() -}) +// afterAll(async () => { +// await cleanDatabase() +// }) describe('templateBuilder', () => { describe('signupTemplate', () => { describe('multi language', () => { it('e-mail is build with all data', () => { + const subject = `Willkommen, Bienvenue, Welcome to ${CONFIG.APPLICATION_NAME}!` const actionUrl = new URL('/registration', CONFIG.CLIENT_URI).toString() const theSignupTemplateData = signupTemplateData() // locale: en let content = "Thank you for joining our cause – it's awesome to have you on board." const emailTemplate = testEmailData(null, signupTemplate, theSignupTemplateData, [ ...textsStandard, + { + templPropName: 'subject', + isContaining: false, + text: subject, + }, + englishHint, actionUrl, - content, - supportUrl, theSignupTemplateData.variables.nonce, theSignupTemplateData.variables.inviteCode, + content, + supportUrl, ]) // locale: de content = 'Danke, dass Du dich angemeldet hast – wir freuen uns, Dich dabei zu haben.' @@ -95,6 +121,117 @@ describe('templateBuilder', () => { }) }) + describe('emailVerificationTemplate', () => { + describe('multi language', () => { + it('e-mail is build with all data', () => { + const subject = 'Neue E-Mail Adresse | New E-Mail Address' + const actionUrl = new URL('/settings/my-email-address/verify', CONFIG.CLIENT_URI).toString() + const theEmailVerificationTemplateData = emailVerificationTemplateData() + // locale: en + let content = 'So, you want to change your e-mail? No problem!' + const emailTemplate = testEmailData( + null, + emailVerificationTemplate, + theEmailVerificationTemplateData, + [ + ...textsStandard, + { + templPropName: 'subject', + isContaining: false, + text: subject, + }, + englishHint, + actionUrl, + theEmailVerificationTemplateData.variables.nonce, + theEmailVerificationTemplateData.variables.name, + content, + supportUrl, + ], + ) + // locale: de + content = 'Du möchtest also deine E-Mail ändern? Kein Problem!' + testEmailData(emailTemplate, emailVerificationTemplate, theEmailVerificationTemplateData, [ + // ...textsStandard, // tested at locale: en + content, + ]) + }) + }) + }) + + describe('resetPasswordTemplate', () => { + describe('multi language', () => { + it('e-mail is build with all data', () => { + const subject = 'Neues Passwort | Reset Password' + const actionUrl = new URL('/password-reset/change-password', CONFIG.CLIENT_URI).toString() + const theResetPasswordTemplateData = resetPasswordTemplateData() + // locale: en + let content = 'So, you forgot your password? No problem!' + const emailTemplate = testEmailData( + null, + resetPasswordTemplate, + theResetPasswordTemplateData, + [ + ...textsStandard, + { + templPropName: 'subject', + isContaining: false, + text: subject, + }, + englishHint, + actionUrl, + theResetPasswordTemplateData.variables.nonce, + theResetPasswordTemplateData.variables.name, + content, + supportUrl, + ], + ) + // locale: de + content = 'Du hast also dein Passwort vergessen? Kein Problem!' + testEmailData(emailTemplate, resetPasswordTemplate, theResetPasswordTemplateData, [ + // ...textsStandard, // tested at locale: en + content, + ]) + }) + }) + }) + + describe('wrongAccountTemplate', () => { + describe('multi language', () => { + it('e-mail is build with all data', () => { + const subject = 'Falsche Mailadresse? | Wrong E-mail?' + const actionUrl = new URL('/password-reset/request', CONFIG.CLIENT_URI).toString() + const theWrongAccountTemplateData = wrongAccountTemplateData() + // locale: en + let content = + "You requested a password reset but unfortunately we couldn't find an account associated with your e-mail address." + const emailTemplate = testEmailData( + null, + wrongAccountTemplate, + theWrongAccountTemplateData, + [ + ...textsStandard, + { + templPropName: 'subject', + isContaining: false, + text: subject, + }, + englishHint, + actionUrl, + content, + supportUrl, + ], + ) + // locale: de + content = + 'Du hast bei uns ein neues Passwort angefordert – leider haben wir aber keinen Account mit Deiner E-Mailadresse gefunden.' + testEmailData(emailTemplate, wrongAccountTemplate, theWrongAccountTemplateData, [ + // ...textsStandard, // tested at locale: en + content, + ]) + }) + }) + }) + // describe('XXX', () => { // it('e-mail is build with all data', async () => { // XXX({ @@ -107,7 +244,7 @@ describe('templateBuilder', () => { describe('notificationTemplate', () => { beforeEach(() => { actionUrl = new URL('/notifications', CONFIG.CLIENT_URI).toString() - name = 'Mr Example' + name = notificationTemplateData('en').variables.notification.to.name settingsUrl = new URL('/settings/notifications', CONFIG.CLIENT_URI) }) diff --git a/backend/src/middleware/helpers/email/templates/wrongAccount.html b/backend/src/middleware/helpers/email/templates/wrongAccount.html index 8f17e3335..e8f71e9ea 100644 --- a/backend/src/middleware/helpers/email/templates/wrongAccount.html +++ b/backend/src/middleware/helpers/email/templates/wrongAccount.html @@ -24,8 +24,8 @@

Hallo!

-

Du hast bei uns ein neues Passwort angefordert – leider haben wir aber keinen - Account mit Deiner E-Mailadresse gefunden. Kann es sein, dass Du mit einer anderen Adresse bei uns +

Du hast bei uns ein neues Passwort angefordert – leider haben wir aber keinen Account mit Deiner E-Mailadresse gefunden. + Kann es sein, dass Du mit einer anderen Adresse bei uns angemeldet bist?

@@ -122,8 +122,8 @@

Hello!

-

You requested a password reset but unfortunately we couldn't find an account - associated with your e-mail address. Did you maybe use another one when you signed up?

+

You requested a password reset but unfortunately we couldn't find an account associated with your e-mail address. + Did you maybe use another one when you signed up?