Add remaining templates

This commit is contained in:
Wolfgang Huß 2021-11-18 16:15:04 +01:00
parent 8e1fda5e90
commit 36b621ca5b
3 changed files with 155 additions and 18 deletions

View File

@ -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)

View File

@ -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)
})

View File

@ -24,8 +24,8 @@
<h1
style="margin: 0 0 10px 0; font-family: Lato, sans-serif; font-size: 25px; line-height: 30px; color: #333333; font-weight: normal;">
Hallo!</h1>
<p style="margin: 0;">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
<p style="margin: 0;">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?</p>
</td>
</tr>
@ -122,8 +122,8 @@
<h1
style="margin: 0 0 10px 0; font-family: Lato, sans-serif; font-size: 25px; line-height: 30px; color: #333333; font-weight: normal;">
Hello!</h1>
<p style="margin: 0;">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?</p>
<p style="margin: 0;">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?</p>
</td>
</tr>
<tr>