mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
sendAccountActivationEmail in separate file
This commit is contained in:
parent
b95eb902e9
commit
c6863d6e64
@ -652,7 +652,6 @@ export class TransactionResolver {
|
||||
// send notification email
|
||||
// TODO: translate
|
||||
await sendEMail({
|
||||
from: `Gradido (nicht antworten) <${CONFIG.EMAIL_SENDER}>`,
|
||||
to: `${recipiantUser.firstName} ${recipiantUser.lastName} <${recipiantUser.email}>`,
|
||||
subject: 'Gradido Überweisung',
|
||||
text: `Hallo ${recipiantUser.firstName} ${recipiantUser.lastName}
|
||||
|
||||
@ -12,9 +12,9 @@ import { LoginUserBackup } from '@entity/LoginUserBackup'
|
||||
import { LoginEmailOptIn } from '@entity/LoginEmailOptIn'
|
||||
import { User } from '@entity/User'
|
||||
import CONFIG from '../../config'
|
||||
import { sendAccountActivationEmail } from '../../util/sendEMail'
|
||||
import { sendAccountActivationEmail } from '../../mailer/sendAccountActivationEmail'
|
||||
|
||||
jest.mock('../../util/sendEMail', () => {
|
||||
jest.mock('../../mailer/sendAccountActivationEmail', () => {
|
||||
return {
|
||||
__esModule: true,
|
||||
sendAccountActivationEmail: jest.fn(),
|
||||
|
||||
@ -20,7 +20,8 @@ import { UserRepository } from '../../typeorm/repository/User'
|
||||
import { LoginUser } from '@entity/LoginUser'
|
||||
import { LoginUserBackup } from '@entity/LoginUserBackup'
|
||||
import { LoginEmailOptIn } from '@entity/LoginEmailOptIn'
|
||||
import { sendAccountActivationEmail, sendEMail } from '../../mailer/sendEMail'
|
||||
import { sendEMail } from '../../mailer/sendEMail'
|
||||
import { sendAccountActivationEmail } from '../../mailer/sendAccountActivationEmail'
|
||||
import { LoginElopageBuysRepository } from '../../typeorm/repository/LoginElopageBuys'
|
||||
import { signIn } from '../../apis/KlicktippController'
|
||||
import { RIGHTS } from '../../auth/RIGHTS'
|
||||
@ -522,7 +523,6 @@ export class UserResolver {
|
||||
)
|
||||
|
||||
const emailSent = await sendEMail({
|
||||
from: `Gradido (nicht antworten) <${CONFIG.EMAIL_SENDER}>`,
|
||||
to: `${loginUser.firstName} ${loginUser.lastName} <${email}>`,
|
||||
subject: 'Gradido: Reset Password',
|
||||
text: `Hallo ${loginUser.firstName} ${loginUser.lastName},
|
||||
|
||||
24
backend/src/mailer/sendAccountActivationEmail.test.ts
Normal file
24
backend/src/mailer/sendAccountActivationEmail.test.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { sendAccountActivationEmail } from './sendAccountActivationEmail'
|
||||
import { sendEMail } from './sendEMail'
|
||||
|
||||
jest.mock('./sendEMail', () => {
|
||||
return {
|
||||
__esModule: true,
|
||||
sendEMail: jest.fn(),
|
||||
}
|
||||
})
|
||||
|
||||
describe('sendAccountActivationEmail', () => {
|
||||
beforeEach(async () => {
|
||||
await sendAccountActivationEmail('activationLink', 'Peter', 'Lustig', 'peter@lustig.de')
|
||||
})
|
||||
|
||||
it('calls sendEMail', () => {
|
||||
expect(sendEMail).toBeCalledWith({
|
||||
to: `Peter Lustig <peter@lustig.de>`,
|
||||
subject: 'Gradido: E-Mail Überprüfung',
|
||||
text:
|
||||
expect.stringContaining('Hallo Peter Lustig') && expect.stringContaining('activationLink'),
|
||||
})
|
||||
})
|
||||
})
|
||||
23
backend/src/mailer/sendAccountActivationEmail.ts
Normal file
23
backend/src/mailer/sendAccountActivationEmail.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { sendEMail } from './sendEMail'
|
||||
|
||||
export const sendAccountActivationEmail = (
|
||||
activationLink: string,
|
||||
firstName: string,
|
||||
lastName: string,
|
||||
email: string,
|
||||
): Promise<boolean> => {
|
||||
return sendEMail({
|
||||
to: `${firstName} ${lastName} <${email}>`,
|
||||
subject: 'Gradido: E-Mail Überprüfung',
|
||||
text: `Hallo ${firstName} ${lastName},
|
||||
|
||||
Deine EMail wurde soeben bei Gradido registriert.
|
||||
|
||||
Klicke bitte auf diesen Link, um die Registrierung abzuschließen und dein Gradido-Konto zu aktivieren:
|
||||
${activationLink}
|
||||
oder kopiere den obigen Link in dein Browserfenster.
|
||||
|
||||
Mit freundlichen Grüßen,
|
||||
dein Gradido-Team`,
|
||||
})
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
import sendEmail from './sendEMail'
|
||||
import { sendEMail } from './sendEMail'
|
||||
import { createTransport } from 'nodemailer'
|
||||
import CONFIG from '../config'
|
||||
|
||||
@ -32,8 +32,7 @@ describe('sendEMail', () => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log = consoleLogMock
|
||||
beforeEach(async () => {
|
||||
result = await sendEmail.sendEMail({
|
||||
from: 'sender@mail.org',
|
||||
result = await sendEMail({
|
||||
to: 'receiver@mail.org',
|
||||
subject: 'Subject',
|
||||
text: 'Text text text',
|
||||
@ -57,8 +56,7 @@ describe('sendEMail', () => {
|
||||
describe('config email is true', () => {
|
||||
beforeEach(async () => {
|
||||
CONFIG.EMAIL = true
|
||||
result = await sendEmail.sendEMail({
|
||||
from: 'sender@mail.org',
|
||||
result = await sendEMail({
|
||||
to: 'receiver@mail.org',
|
||||
subject: 'Subject',
|
||||
text: 'Text text text',
|
||||
@ -83,29 +81,3 @@ 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'),
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@ -3,7 +3,6 @@ import { createTransport } from 'nodemailer'
|
||||
import CONFIG from '../config'
|
||||
|
||||
export const sendEMail = async (emailDef: {
|
||||
from: string
|
||||
to: string
|
||||
subject: string
|
||||
text: string
|
||||
@ -23,34 +22,12 @@ export const sendEMail = async (emailDef: {
|
||||
pass: CONFIG.EMAIL_PASSWORD,
|
||||
},
|
||||
})
|
||||
const info = await transporter.sendMail(emailDef)
|
||||
const info = await transporter.sendMail({
|
||||
...emailDef,
|
||||
from: `Gradido (nicht antworten) <${CONFIG.EMAIL_SENDER}>`,
|
||||
})
|
||||
if (!info.messageId) {
|
||||
throw new Error('error sending notification email, but transaction succeed')
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
export const sendAccountActivationEmail = (
|
||||
activationLink: string,
|
||||
firstName: string,
|
||||
lastName: string,
|
||||
email: string,
|
||||
): Promise<boolean> => {
|
||||
return sendEMail({
|
||||
from: `Gradido (nicht antworten) <${CONFIG.EMAIL_SENDER}>`,
|
||||
to: `${firstName} ${lastName} <${email}>`,
|
||||
subject: 'Gradido: E-Mail Überprüfung',
|
||||
text: `Hallo ${firstName} ${lastName},
|
||||
|
||||
Deine EMail wurde soeben bei Gradido registriert.
|
||||
|
||||
Klicke bitte auf diesen Link, um die Registrierung abzuschließen und dein Gradido-Konto zu aktivieren:
|
||||
${activationLink}
|
||||
oder kopiere den obigen Link in dein Browserfenster.
|
||||
|
||||
Mit freundlichen Grüßen,
|
||||
dein Gradido-Team`,
|
||||
})
|
||||
}
|
||||
|
||||
export default { sendAccountActivationEmail, sendEMail }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user