diff --git a/DOCKER_MORE_CLOSELY.md b/CONTRIBUTING.md similarity index 65% rename from DOCKER_MORE_CLOSELY.md rename to CONTRIBUTING.md index f2aae81c7..3ebcdb73a 100644 --- a/DOCKER_MORE_CLOSELY.md +++ b/CONTRIBUTING.md @@ -1,10 +1,28 @@ -# Docker More Closely +# Contributing -## Apple M1 Platform +If you contribute to our project, please consider the following points. + +## Localization + +### Quotation Marks + +The following characters are different from the programming quotation mark: + +`"` or `\"` + +Please copy and paste the following quotes for the languages: + +- de: „Dies ist ein Beispielsatz.“ +- en: “This is a sample sentence.” + - See + +## Docker – More Closely + +### Apple M1 Platform ***Attention:** For using Docker commands in Apple M1 environments!* -### Enviroment Variable For Apple M1 Platform +#### Environment Variable For Apple M1 Platform To set the Docker platform environment variable in your terminal tab, run: @@ -13,7 +31,7 @@ To set the Docker platform environment variable in your terminal tab, run: $ export DOCKER_DEFAULT_PLATFORM=linux/amd64 ``` -### Docker Compose Override File For Apple M1 Platform +#### Docker Compose Override File For Apple M1 Platform For Docker compose `up` or `build` commands, you can use our Apple M1 override file that specifies the M1 platform: @@ -27,7 +45,7 @@ $ docker compose -f docker-compose.yml -f docker-compose.override.yml -f docker- $ docker compose -f docker-compose.yml -f docker-compose.apple-m1.override.yml up ``` -## Analysing Docker Builds +### Analyzing Docker Builds To analyze a Docker build, there is a wonderful tool called [dive](https://github.com/wagoodman/dive). Please sponsor if you're using it! diff --git a/backend/package.json b/backend/package.json index 519f9e6c0..c6b3dabc2 100644 --- a/backend/package.json +++ b/backend/package.json @@ -8,7 +8,7 @@ "license": "Apache-2.0", "private": false, "scripts": { - "build": "tsc --build", + "build": "tsc --build && mkdir -p build/src/emails/templates/ && cp -r src/emails/templates/* build/src/emails/templates/ && mkdir -p build/src/locales/ && cp -r src/locales/*.json build/src/locales/", "clean": "tsc --build --clean", "start": "cross-env TZ=UTC TS_NODE_BASEURL=./build node -r tsconfig-paths/register build/src/index.js", "dev": "cross-env TZ=UTC nodemon -w src --ext ts --exec ts-node -r tsconfig-paths/register src/index.ts", diff --git a/backend/src/emails/accountMultiRegistration/subject.pug b/backend/src/emails/accountMultiRegistration/subject.pug deleted file mode 100644 index 322f07c78..000000000 --- a/backend/src/emails/accountMultiRegistration/subject.pug +++ /dev/null @@ -1 +0,0 @@ -= t('emails.accountMultiRegistration.subject') \ No newline at end of file diff --git a/backend/src/emails/sendEmailTranslated.test.ts b/backend/src/emails/sendEmailTranslated.test.ts index 28327f779..eb4b26b92 100644 --- a/backend/src/emails/sendEmailTranslated.test.ts +++ b/backend/src/emails/sendEmailTranslated.test.ts @@ -89,7 +89,7 @@ describe('sendEmailTranslated', () => { originalMessage: expect.objectContaining({ to: 'receiver@mail.org', cc: 'support@gradido.net', - from: 'Gradido (nicht antworten) ', + from: 'Gradido (do not answer) ', attachments: [], subject: 'Gradido: Try To Register Again With Your Email', html: expect.stringContaining('Gradido: Try To Register Again With Your Email'), @@ -107,4 +107,41 @@ describe('sendEmailTranslated', () => { expect(i18n.__).toBeCalled() }) }) + + describe('with email EMAIL_TEST_MODUS true', () => { + beforeEach(async () => { + jest.clearAllMocks() + CONFIG.EMAIL = true + CONFIG.EMAIL_TEST_MODUS = true + result = await sendEmailTranslated({ + receiver: { + to: 'receiver@mail.org', + cc: 'support@gradido.net', + }, + template: 'accountMultiRegistration', + locals: { + locale: 'en', + }, + }) + }) + + it('call of "sendEmailTranslated" with faked "to"', () => { + expect(result).toMatchObject({ + envelope: { + from: CONFIG.EMAIL_SENDER, + to: [CONFIG.EMAIL_TEST_RECEIVER, 'support@gradido.net'], + }, + message: expect.any(String), + originalMessage: expect.objectContaining({ + to: CONFIG.EMAIL_TEST_RECEIVER, + cc: 'support@gradido.net', + from: `Gradido (do not answer) <${CONFIG.EMAIL_SENDER}>`, + attachments: [], + subject: 'Gradido: Try To Register Again With Your Email', + html: expect.stringContaining('Gradido: Try To Register Again With Your Email'), + text: expect.stringContaining('GRADIDO: TRY TO REGISTER AGAIN WITH YOUR EMAIL'), + }), + }) + }) + }) }) diff --git a/backend/src/emails/sendEmailTranslated.ts b/backend/src/emails/sendEmailTranslated.ts index 3fe4177f4..69008c00e 100644 --- a/backend/src/emails/sendEmailTranslated.ts +++ b/backend/src/emails/sendEmailTranslated.ts @@ -1,18 +1,17 @@ +import CONFIG from '@/config' import { backendLogger as logger } from '@/server/logger' import path from 'path' import { createTransport } from 'nodemailer' import Email from 'email-templates' import i18n from 'i18n' -import CONFIG from '@/config' - export const sendEmailTranslated = async (params: { receiver: { to: string cc?: string } template: string - locals: Record + locals: Record }): Promise | null> => { let resultSend: Record | null = null @@ -32,8 +31,7 @@ export const sendEmailTranslated = async (params: { logger.info(`Emails are disabled via config...`) return null } - // because 'CONFIG.EMAIL_TEST_MODUS' can be boolean 'true' or string '`false`' - if (CONFIG.EMAIL_TEST_MODUS === true) { + if (CONFIG.EMAIL_TEST_MODUS) { logger.info( `Testmodus=ON: change receiver from ${params.receiver.to} to ${CONFIG.EMAIL_TEST_RECEIVER}`, ) @@ -50,12 +48,12 @@ export const sendEmailTranslated = async (params: { }, }) - i18n.setLocale(params.locals.locale) // for email + i18n.setLocale(params.locals.locale as string) // for email // TESTING: see 'README.md' const email = new Email({ message: { - from: `Gradido (nicht antworten) <${CONFIG.EMAIL_SENDER}>`, + from: `Gradido (${i18n.__('emails.general.doNotAnswer')}) <${CONFIG.EMAIL_SENDER}>`, }, transport, preview: false, @@ -65,7 +63,7 @@ export const sendEmailTranslated = async (params: { // ATTENTION: await is needed, because otherwise on send the email gets send in the language of the current user, because below the language gets reset await email .send({ - template: path.join(__dirname, params.template), + template: path.join(__dirname, 'templates', params.template), message: params.receiver, locals: params.locals, // the 'locale' in here seems not to be used by 'email-template', because it doesn't work if the language isn't set before by 'i18n.setLocale' }) diff --git a/backend/src/emails/sendEmailVariants.test.ts b/backend/src/emails/sendEmailVariants.test.ts index 4ac8221a7..262b91be2 100644 --- a/backend/src/emails/sendEmailVariants.test.ts +++ b/backend/src/emails/sendEmailVariants.test.ts @@ -1,12 +1,34 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +import Decimal from 'decimal.js-light' +import { testEnvironment } from '@test/helpers' +import { logger, i18n as localization } from '@test/testSetup' import CONFIG from '@/config' -import { sendAccountMultiRegistrationEmail } from './sendEmailVariants' +import { + sendAddedContributionMessageEmail, + sendAccountActivationEmail, + sendAccountMultiRegistrationEmail, + sendContributionConfirmedEmail, + sendContributionRejectedEmail, + sendResetPasswordEmail, + sendTransactionLinkRedeemedEmail, + sendTransactionReceivedEmail, +} from './sendEmailVariants' import { sendEmailTranslated } from './sendEmailTranslated' -CONFIG.EMAIL = true -CONFIG.EMAIL_SMTP_URL = 'EMAIL_SMTP_URL' -CONFIG.EMAIL_SMTP_PORT = '1234' -CONFIG.EMAIL_USERNAME = 'user' -CONFIG.EMAIL_PASSWORD = 'pwd' +let con: any +let testEnv: any + +beforeAll(async () => { + testEnv = await testEnvironment(logger, localization) + con = testEnv.con + // await cleanDB() +}) + +afterAll(async () => { + // await cleanDB() + await con.close() +}) jest.mock('./sendEmailTranslated', () => { const originalModule = jest.requireActual('./sendEmailTranslated') @@ -17,7 +39,154 @@ jest.mock('./sendEmailTranslated', () => { }) describe('sendEmailVariants', () => { - let result: Record | null + // eslint-disable-next-line @typescript-eslint/no-explicit-any + let result: any + + describe('sendAddedContributionMessageEmail', () => { + beforeAll(async () => { + result = await sendAddedContributionMessageEmail({ + firstName: 'Peter', + lastName: 'Lustig', + email: 'peter@lustig.de', + language: 'en', + senderFirstName: 'Bibi', + senderLastName: 'Bloxberg', + contributionMemo: 'My contribution.', + }) + }) + + describe('calls "sendEmailTranslated"', () => { + it('with expected parameters', () => { + expect(sendEmailTranslated).toBeCalledWith({ + receiver: { + to: 'Peter Lustig ', + }, + template: 'addedContributionMessage', + locals: { + firstName: 'Peter', + lastName: 'Lustig', + locale: 'en', + senderFirstName: 'Bibi', + senderLastName: 'Bloxberg', + contributionMemo: 'My contribution.', + overviewURL: CONFIG.EMAIL_LINK_OVERVIEW, + }, + }) + }) + + 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 ', + from: 'Gradido (do not answer) ', + attachments: [], + subject: 'Gradido: Message about your common good contribution', + html: expect.any(String), + text: expect.stringContaining('GRADIDO: MESSAGE ABOUT YOUR COMMON GOOD CONTRIBUTION'), + }), + }) + expect(result.originalMessage.html).toContain('') + expect(result.originalMessage.html).toContain('') + expect(result.originalMessage.html).toContain( + 'Gradido: Message about your common good contribution', + ) + expect(result.originalMessage.html).toContain( + '>Gradido: Message about your common good contribution', + ) + expect(result.originalMessage.html).toContain('Hello Peter Lustig') + expect(result.originalMessage.html).toContain( + 'you have received a message from Bibi Bloxberg regarding your common good contribution “My contribution.”.', + ) + expect(result.originalMessage.html).toContain( + 'To view and reply to the message, go to the “Community” menu in your Gradido account and click on the “My contributions to the common good” tab!', + ) + expect(result.originalMessage.html).toContain( + `Link to your account: ${CONFIG.EMAIL_LINK_OVERVIEW}`, + ) + expect(result.originalMessage.html).toContain('Please do not reply to this email!') + expect(result.originalMessage.html).toContain('Kind regards,
your Gradido team') + }) + }) + }) + + describe('sendAccountActivationEmail', () => { + beforeAll(async () => { + result = await sendAccountActivationEmail({ + firstName: 'Peter', + lastName: 'Lustig', + email: 'peter@lustig.de', + language: 'en', + activationLink: 'http://localhost/checkEmail/6627633878930542284', + timeDurationObject: { hours: 23, minutes: 30 }, + }) + }) + + describe('calls "sendEmailTranslated"', () => { + it('with expected parameters', () => { + expect(sendEmailTranslated).toBeCalledWith({ + receiver: { + to: 'Peter Lustig ', + }, + template: 'accountActivation', + locals: { + firstName: 'Peter', + lastName: 'Lustig', + locale: 'en', + activationLink: 'http://localhost/checkEmail/6627633878930542284', + timeDurationObject: { hours: 23, minutes: 30 }, + 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 ', + from: 'Gradido (do not answer) ', + attachments: [], + subject: 'Gradido: Email Verification', + html: expect.any(String), + text: expect.stringContaining('GRADIDO: EMAIL VERIFICATION'), + }), + }) + expect(result.originalMessage.html).toContain('') + expect(result.originalMessage.html).toContain('') + expect(result.originalMessage.html).toContain('Gradido: Email Verification') + expect(result.originalMessage.html).toContain('>Gradido: Email Verification') + expect(result.originalMessage.html).toContain('Hello Peter Lustig') + expect(result.originalMessage.html).toContain( + 'Your email address has just been registered with Gradido.', + ) + expect(result.originalMessage.html).toContain( + 'Please click on this link to complete the registration and activate your Gradido account:', + ) + expect(result.originalMessage.html).toContain( + 'http://localhost/checkEmail/6627633878930542284', + ) + expect(result.originalMessage.html).toContain( + 'or copy the link above into your browser window.', + ) + expect(result.originalMessage.html).toContain( + 'The link has a validity of 23 hours and 30 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(result.originalMessage.html).toContain( + `${CONFIG.EMAIL_LINK_FORGOTPASSWORD}`, + ) + expect(result.originalMessage.html).toContain('Kind regards,
your Gradido team') + }) + }) + }) describe('sendAccountMultiRegistrationEmail', () => { beforeAll(async () => { @@ -54,34 +223,401 @@ describe('sendEmailVariants', () => { message: expect.any(String), originalMessage: expect.objectContaining({ to: 'Peter Lustig ', - from: 'Gradido (nicht antworten) ', + from: 'Gradido (do not answer) ', attachments: [], subject: 'Gradido: Try To Register Again With Your Email', - html: - expect.stringContaining( - 'Gradido: Try To Register Again With Your Email', - ) && - expect.stringContaining('>Gradido: Try To Register Again With Your Email') && - expect.stringContaining( - 'Your email address has just been used again to register an account with Gradido.', - ) && - expect.stringContaining( - 'However, an account already exists for your email address.', - ) && - expect.stringContaining( - 'Please click on the following link if you have forgotten your password:', - ) && - expect.stringContaining( - `${CONFIG.EMAIL_LINK_FORGOTPASSWORD}`, - ) && - expect.stringContaining('or copy the link above into your browser window.') && - expect.stringContaining( - 'If you are not the one who tried to register again, please contact our support:', - ) && - expect.stringContaining('Sincerely yours,
your Gradido team'), + html: expect.any(String), text: expect.stringContaining('GRADIDO: TRY TO REGISTER AGAIN WITH YOUR EMAIL'), }), }) + expect(result.originalMessage.html).toContain('') + expect(result.originalMessage.html).toContain('') + expect(result.originalMessage.html).toContain( + 'Gradido: Try To Register Again With Your Email', + ) + expect(result.originalMessage.html).toContain( + '>Gradido: Try To Register Again With Your Email', + ) + expect(result.originalMessage.html).toContain('Hello Peter Lustig') + expect(result.originalMessage.html).toContain( + 'Your email address has just been used again to register an account with Gradido.', + ) + expect(result.originalMessage.html).toContain( + 'However, an account already exists for your email address.', + ) + expect(result.originalMessage.html).toContain( + 'Please click on the following link if you have forgotten your password:', + ) + expect(result.originalMessage.html).toContain( + `${CONFIG.EMAIL_LINK_FORGOTPASSWORD}`, + ) + expect(result.originalMessage.html).toContain( + 'or copy the link above into your browser window.', + ) + expect(result.originalMessage.html).toContain( + 'If you are not the one who tried to register again, please contact our support:', + ) + expect(result.originalMessage.html).toContain('Kind regards,
your Gradido team') + }) + }) + }) + + describe('sendContributionConfirmedEmail', () => { + beforeAll(async () => { + result = await sendContributionConfirmedEmail({ + firstName: 'Peter', + lastName: 'Lustig', + email: 'peter@lustig.de', + language: 'en', + senderFirstName: 'Bibi', + senderLastName: 'Bloxberg', + contributionMemo: 'My contribution.', + contributionAmount: new Decimal(23.54), + }) + }) + + describe('calls "sendEmailTranslated"', () => { + it('with expected parameters', () => { + expect(sendEmailTranslated).toBeCalledWith({ + receiver: { + to: 'Peter Lustig ', + }, + template: 'contributionConfirmed', + locals: { + firstName: 'Peter', + lastName: 'Lustig', + locale: 'en', + senderFirstName: 'Bibi', + senderLastName: 'Bloxberg', + contributionMemo: 'My contribution.', + contributionAmount: '23.54', + overviewURL: CONFIG.EMAIL_LINK_OVERVIEW, + }, + }) + }) + + 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 ', + from: 'Gradido (do not answer) ', + attachments: [], + subject: 'Gradido: Your common good contribution was confirmed', + html: expect.any(String), + text: expect.stringContaining('GRADIDO: YOUR COMMON GOOD CONTRIBUTION WAS CONFIRMED'), + }), + }) + expect(result.originalMessage.html).toContain('') + expect(result.originalMessage.html).toContain('') + expect(result.originalMessage.html).toContain( + 'Gradido: Your common good contribution was confirmed', + ) + expect(result.originalMessage.html).toContain( + '>Gradido: Your common good contribution was confirmed', + ) + expect(result.originalMessage.html).toContain('Hello Peter Lustig') + expect(result.originalMessage.html).toContain( + 'Your public good contribution “My contribution.” has just been confirmed by Bibi Bloxberg and credited to your Gradido account.', + ) + expect(result.originalMessage.html).toContain('Amount: 23.54 GDD') + expect(result.originalMessage.html).toContain( + `Link to your account: ${CONFIG.EMAIL_LINK_OVERVIEW}`, + ) + expect(result.originalMessage.html).toContain('Please do not reply to this email!') + expect(result.originalMessage.html).toContain('Kind regards,
your Gradido team') + }) + }) + }) + + describe('sendContributionRejectedEmail', () => { + beforeAll(async () => { + result = await sendContributionRejectedEmail({ + firstName: 'Peter', + lastName: 'Lustig', + email: 'peter@lustig.de', + language: 'en', + senderFirstName: 'Bibi', + senderLastName: 'Bloxberg', + contributionMemo: 'My contribution.', + }) + }) + + describe('calls "sendEmailTranslated"', () => { + it('with expected parameters', () => { + expect(sendEmailTranslated).toBeCalledWith({ + receiver: { + to: 'Peter Lustig ', + }, + template: 'contributionRejected', + locals: { + firstName: 'Peter', + lastName: 'Lustig', + locale: 'en', + senderFirstName: 'Bibi', + senderLastName: 'Bloxberg', + contributionMemo: 'My contribution.', + overviewURL: CONFIG.EMAIL_LINK_OVERVIEW, + }, + }) + }) + + 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 ', + from: 'Gradido (do not answer) ', + attachments: [], + subject: 'Gradido: Your common good contribution was rejected', + html: expect.any(String), + text: expect.stringContaining('GRADIDO: YOUR COMMON GOOD CONTRIBUTION WAS REJECTED'), + }), + }) + expect(result.originalMessage.html).toContain('') + expect(result.originalMessage.html).toContain('') + expect(result.originalMessage.html).toContain( + 'Gradido: Your common good contribution was rejected', + ) + expect(result.originalMessage.html).toContain( + '>Gradido: Your common good contribution was rejected', + ) + expect(result.originalMessage.html).toContain('Hello Peter Lustig') + expect(result.originalMessage.html).toContain( + 'Your public good contribution “My contribution.” was rejected by Bibi Bloxberg.', + ) + expect(result.originalMessage.html).toContain( + 'To see your common good contributions and related messages, go to the “Community” menu in your Gradido account and click on the “My contributions to the common good” tab!', + ) + expect(result.originalMessage.html).toContain( + `Link to your account: ${CONFIG.EMAIL_LINK_OVERVIEW}`, + ) + expect(result.originalMessage.html).toContain('Please do not reply to this email!') + expect(result.originalMessage.html).toContain('Kind regards,
your Gradido team') + }) + }) + }) + + describe('sendResetPasswordEmail', () => { + beforeAll(async () => { + result = await sendResetPasswordEmail({ + firstName: 'Peter', + lastName: 'Lustig', + email: 'peter@lustig.de', + language: 'en', + resetLink: 'http://localhost/reset-password/3762660021544901417', + timeDurationObject: { hours: 23, minutes: 30 }, + }) + }) + + describe('calls "sendEmailTranslated"', () => { + it('with expected parameters', () => { + expect(sendEmailTranslated).toBeCalledWith({ + receiver: { + to: 'Peter Lustig ', + }, + template: 'resetPassword', + locals: { + firstName: 'Peter', + lastName: 'Lustig', + locale: 'en', + resetLink: 'http://localhost/reset-password/3762660021544901417', + timeDurationObject: { hours: 23, minutes: 30 }, + 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 ', + from: 'Gradido (do not answer) ', + attachments: [], + subject: 'Gradido: Reset password', + html: expect.any(String), + text: expect.stringContaining('GRADIDO: RESET PASSWORD'), + }), + }) + expect(result.originalMessage.html).toContain('') + expect(result.originalMessage.html).toContain('') + expect(result.originalMessage.html).toContain('Gradido: Reset password') + expect(result.originalMessage.html).toContain('>Gradido: Reset password') + expect(result.originalMessage.html).toContain('Hello Peter Lustig') + expect(result.originalMessage.html).toContain( + 'You, or someone else, requested a password reset for this account.', + ) + expect(result.originalMessage.html).toContain('If it was you, please click on the link:') + expect(result.originalMessage.html).toContain( + 'http://localhost/reset-password/3762660021544901417', + ) + expect(result.originalMessage.html).toContain( + 'or copy the link above into your browser window.', + ) + expect(result.originalMessage.html).toContain( + 'The link has a validity of 23 hours and 30 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(result.originalMessage.html).toContain( + `${CONFIG.EMAIL_LINK_FORGOTPASSWORD}`, + ) + expect(result.originalMessage.html).toContain('Kind regards,
your Gradido team') + }) + }) + }) + + describe('sendTransactionLinkRedeemedEmail', () => { + beforeAll(async () => { + result = await sendTransactionLinkRedeemedEmail({ + firstName: 'Peter', + lastName: 'Lustig', + email: 'peter@lustig.de', + language: 'en', + senderFirstName: 'Bibi', + senderLastName: 'Bloxberg', + senderEmail: 'bibi@bloxberg.de', + transactionMemo: 'You deserve it! 🙏🏼', + transactionAmount: new Decimal(17.65), + }) + }) + + describe('calls "sendEmailTranslated"', () => { + it('with expected parameters', () => { + expect(sendEmailTranslated).toBeCalledWith({ + receiver: { + to: 'Peter Lustig ', + }, + template: 'transactionLinkRedeemed', + locals: { + firstName: 'Peter', + lastName: 'Lustig', + locale: 'en', + senderFirstName: 'Bibi', + senderLastName: 'Bloxberg', + senderEmail: 'bibi@bloxberg.de', + transactionMemo: 'You deserve it! 🙏🏼', + transactionAmount: '17.65', + overviewURL: CONFIG.EMAIL_LINK_OVERVIEW, + }, + }) + }) + + 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 ', + from: 'Gradido (do not answer) ', + attachments: [], + subject: 'Gradido: Your Gradido link has been redeemed', + html: expect.any(String), + text: expect.stringContaining('GRADIDO: YOUR GRADIDO LINK HAS BEEN REDEEMED'), + }), + }) + expect(result.originalMessage.html).toContain('') + expect(result.originalMessage.html).toContain('') + expect(result.originalMessage.html).toContain( + 'Gradido: Your Gradido link has been redeemed', + ) + expect(result.originalMessage.html).toContain( + '>Gradido: Your Gradido link has been redeemed', + ) + expect(result.originalMessage.html).toContain('Hello Peter Lustig') + expect(result.originalMessage.html).toContain( + 'Bibi Bloxberg (bibi@bloxberg.de) has just redeemed your link.', + ) + expect(result.originalMessage.html).toContain('Amount: 17.65 GDD') + expect(result.originalMessage.html).toContain('Memo: You deserve it! 🙏🏼') + expect(result.originalMessage.html).toContain( + `You can find transaction details in your Gradido account: ${CONFIG.EMAIL_LINK_OVERVIEW}`, + ) + expect(result.originalMessage.html).toContain('Please do not reply to this email!') + expect(result.originalMessage.html).toContain('Kind regards,
your Gradido team') + }) + }) + }) + + describe('sendTransactionReceivedEmail', () => { + beforeAll(async () => { + result = await sendTransactionReceivedEmail({ + firstName: 'Peter', + lastName: 'Lustig', + email: 'peter@lustig.de', + language: 'en', + senderFirstName: 'Bibi', + senderLastName: 'Bloxberg', + senderEmail: 'bibi@bloxberg.de', + transactionAmount: new Decimal(37.4), + }) + }) + + describe('calls "sendEmailTranslated"', () => { + it('with expected parameters', () => { + expect(sendEmailTranslated).toBeCalledWith({ + receiver: { + to: 'Peter Lustig ', + }, + template: 'transactionReceived', + locals: { + firstName: 'Peter', + lastName: 'Lustig', + locale: 'en', + senderFirstName: 'Bibi', + senderLastName: 'Bloxberg', + senderEmail: 'bibi@bloxberg.de', + transactionAmount: '37.40', + overviewURL: CONFIG.EMAIL_LINK_OVERVIEW, + }, + }) + }) + + 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 ', + from: 'Gradido (do not answer) ', + attachments: [], + subject: 'Gradido: You have received Gradidos', + html: expect.any(String), + text: expect.stringContaining('GRADIDO: YOU HAVE RECEIVED GRADIDOS'), + }), + }) + expect(result.originalMessage.html).toContain('') + expect(result.originalMessage.html).toContain('') + expect(result.originalMessage.html).toContain( + 'Gradido: You have received Gradidos', + ) + expect(result.originalMessage.html).toContain('>Gradido: You have received Gradidos') + expect(result.originalMessage.html).toContain('Hello Peter Lustig') + expect(result.originalMessage.html).toContain( + 'You have just received 37.40 GDD from Bibi Bloxberg (bibi@bloxberg.de).', + ) + expect(result.originalMessage.html).toContain( + `You can find transaction details in your Gradido account: ${CONFIG.EMAIL_LINK_OVERVIEW}`, + ) + expect(result.originalMessage.html).toContain('Please do not reply to this email!') + expect(result.originalMessage.html).toContain('Kind regards,
your Gradido team') }) }) }) diff --git a/backend/src/emails/sendEmailVariants.ts b/backend/src/emails/sendEmailVariants.ts index fb142f206..356f95e39 100644 --- a/backend/src/emails/sendEmailVariants.ts +++ b/backend/src/emails/sendEmailVariants.ts @@ -1,6 +1,56 @@ +import Decimal from 'decimal.js-light' import CONFIG from '@/config' +import { decimalSeparatorByLanguage } from '@/util/utilities' import { sendEmailTranslated } from './sendEmailTranslated' +export const sendAddedContributionMessageEmail = (data: { + firstName: string + lastName: string + email: string + language: string + senderFirstName: string + senderLastName: string + contributionMemo: string +}): Promise | null> => { + return sendEmailTranslated({ + receiver: { + to: `${data.firstName} ${data.lastName} <${data.email}>`, + }, + template: 'addedContributionMessage', + locals: { + firstName: data.firstName, + lastName: data.lastName, + locale: data.language, + senderFirstName: data.senderFirstName, + senderLastName: data.senderLastName, + contributionMemo: data.contributionMemo, + overviewURL: CONFIG.EMAIL_LINK_OVERVIEW, + }, + }) +} + +export const sendAccountActivationEmail = (data: { + firstName: string + lastName: string + email: string + language: string + activationLink: string + timeDurationObject: Record +}): Promise | null> => { + return sendEmailTranslated({ + receiver: { to: `${data.firstName} ${data.lastName} <${data.email}>` }, + template: 'accountActivation', + locals: { + firstName: data.firstName, + lastName: data.lastName, + locale: data.language, + activationLink: data.activationLink, + timeDurationObject: data.timeDurationObject, + resendLink: CONFIG.EMAIL_LINK_FORGOTPASSWORD, + }, + }) +} + export const sendAccountMultiRegistrationEmail = (data: { firstName: string lastName: string @@ -11,10 +61,136 @@ export const sendAccountMultiRegistrationEmail = (data: { receiver: { to: `${data.firstName} ${data.lastName} <${data.email}>` }, template: 'accountMultiRegistration', locals: { - locale: data.language, firstName: data.firstName, lastName: data.lastName, + locale: data.language, resendLink: CONFIG.EMAIL_LINK_FORGOTPASSWORD, }, }) } + +export const sendContributionConfirmedEmail = (data: { + firstName: string + lastName: string + email: string + language: string + senderFirstName: string + senderLastName: string + contributionMemo: string + contributionAmount: Decimal +}): Promise | null> => { + return sendEmailTranslated({ + receiver: { to: `${data.firstName} ${data.lastName} <${data.email}>` }, + template: 'contributionConfirmed', + locals: { + firstName: data.firstName, + lastName: data.lastName, + locale: data.language, + senderFirstName: data.senderFirstName, + senderLastName: data.senderLastName, + contributionMemo: data.contributionMemo, + contributionAmount: decimalSeparatorByLanguage(data.contributionAmount, data.language), + overviewURL: CONFIG.EMAIL_LINK_OVERVIEW, + }, + }) +} + +export const sendContributionRejectedEmail = (data: { + firstName: string + lastName: string + email: string + language: string + senderFirstName: string + senderLastName: string + contributionMemo: string +}): Promise | null> => { + return sendEmailTranslated({ + receiver: { to: `${data.firstName} ${data.lastName} <${data.email}>` }, + template: 'contributionRejected', + locals: { + firstName: data.firstName, + lastName: data.lastName, + locale: data.language, + senderFirstName: data.senderFirstName, + senderLastName: data.senderLastName, + contributionMemo: data.contributionMemo, + overviewURL: CONFIG.EMAIL_LINK_OVERVIEW, + }, + }) +} + +export const sendResetPasswordEmail = (data: { + firstName: string + lastName: string + email: string + language: string + resetLink: string + timeDurationObject: Record +}): Promise | null> => { + return sendEmailTranslated({ + receiver: { to: `${data.firstName} ${data.lastName} <${data.email}>` }, + template: 'resetPassword', + locals: { + firstName: data.firstName, + lastName: data.lastName, + locale: data.language, + resetLink: data.resetLink, + timeDurationObject: data.timeDurationObject, + resendLink: CONFIG.EMAIL_LINK_FORGOTPASSWORD, + }, + }) +} + +export const sendTransactionLinkRedeemedEmail = (data: { + firstName: string + lastName: string + email: string + language: string + senderFirstName: string + senderLastName: string + senderEmail: string + transactionMemo: string + transactionAmount: Decimal +}): Promise | null> => { + return sendEmailTranslated({ + receiver: { to: `${data.firstName} ${data.lastName} <${data.email}>` }, + template: 'transactionLinkRedeemed', + locals: { + firstName: data.firstName, + lastName: data.lastName, + locale: data.language, + senderFirstName: data.senderFirstName, + senderLastName: data.senderLastName, + senderEmail: data.senderEmail, + transactionMemo: data.transactionMemo, + transactionAmount: decimalSeparatorByLanguage(data.transactionAmount, data.language), + overviewURL: CONFIG.EMAIL_LINK_OVERVIEW, + }, + }) +} + +export const sendTransactionReceivedEmail = (data: { + firstName: string + lastName: string + email: string + language: string + senderFirstName: string + senderLastName: string + senderEmail: string + transactionAmount: Decimal +}): Promise | null> => { + return sendEmailTranslated({ + receiver: { to: `${data.firstName} ${data.lastName} <${data.email}>` }, + template: 'transactionReceived', + locals: { + firstName: data.firstName, + lastName: data.lastName, + locale: data.language, + senderFirstName: data.senderFirstName, + senderLastName: data.senderLastName, + senderEmail: data.senderEmail, + transactionAmount: decimalSeparatorByLanguage(data.transactionAmount, data.language), + overviewURL: CONFIG.EMAIL_LINK_OVERVIEW, + }, + }) +} diff --git a/backend/src/emails/templates/accountActivation/html.pug b/backend/src/emails/templates/accountActivation/html.pug new file mode 100644 index 000000000..f283e941e --- /dev/null +++ b/backend/src/emails/templates/accountActivation/html.pug @@ -0,0 +1,20 @@ +doctype html +html(lang=locale) + head + title= t('emails.accountActivation.subject') + body + h1(style='margin-bottom: 24px;')= t('emails.accountActivation.subject') + #container.col + p(style='margin-bottom: 24px;')= t('emails.general.helloName', { firstName, lastName }) + p= t('emails.accountActivation.emailRegistered') + p= t('emails.accountActivation.pleaseClickLink') + br + a(href=activationLink) #{activationLink} + br + span= t('emails.general.orCopyLink') + p= t('emails.accountActivation.duration', { hours: timeDurationObject.hours, minutes: timeDurationObject.minutes }) + br + a(href=resendLink) #{resendLink} + p(style='margin-top: 24px;')= t('emails.general.sincerelyYours') + br + span= t('emails.general.yourGradidoTeam') diff --git a/backend/src/emails/templates/accountActivation/subject.pug b/backend/src/emails/templates/accountActivation/subject.pug new file mode 100644 index 000000000..81749a38e --- /dev/null +++ b/backend/src/emails/templates/accountActivation/subject.pug @@ -0,0 +1 @@ += t('emails.accountActivation.subject') diff --git a/backend/src/emails/accountMultiRegistration/html.pug b/backend/src/emails/templates/accountMultiRegistration/html.pug similarity index 73% rename from backend/src/emails/accountMultiRegistration/html.pug rename to backend/src/emails/templates/accountMultiRegistration/html.pug index 4c8a94d28..b3764403b 100644 --- a/backend/src/emails/accountMultiRegistration/html.pug +++ b/backend/src/emails/templates/accountMultiRegistration/html.pug @@ -5,7 +5,7 @@ html(lang=locale) body h1(style='margin-bottom: 24px;')= t('emails.accountMultiRegistration.subject') #container.col - p(style='margin-bottom: 24px;')= t('emails.accountMultiRegistration.helloName', { firstName, lastName }) + p(style='margin-bottom: 24px;')= t('emails.general.helloName', { firstName, lastName }) p= t('emails.accountMultiRegistration.emailReused') br span= t('emails.accountMultiRegistration.emailExists') @@ -17,6 +17,6 @@ html(lang=locale) p= t('emails.accountMultiRegistration.ifYouAreNotTheOne') br a(href='https://gradido.net/de/contact/') https://gradido.net/de/contact/ - p(style='margin-top: 24px;')= t('emails.accountMultiRegistration.sincerelyYours') + p(style='margin-top: 24px;')= t('emails.general.sincerelyYours') br - span= t('emails.accountMultiRegistration.yourGradidoTeam') + span= t('emails.general.yourGradidoTeam') diff --git a/backend/src/emails/templates/accountMultiRegistration/subject.pug b/backend/src/emails/templates/accountMultiRegistration/subject.pug new file mode 100644 index 000000000..fb130f0e4 --- /dev/null +++ b/backend/src/emails/templates/accountMultiRegistration/subject.pug @@ -0,0 +1 @@ += t('emails.accountMultiRegistration.subject') diff --git a/backend/src/emails/templates/addedContributionMessage/html.pug b/backend/src/emails/templates/addedContributionMessage/html.pug new file mode 100644 index 000000000..5e5d0975c --- /dev/null +++ b/backend/src/emails/templates/addedContributionMessage/html.pug @@ -0,0 +1,17 @@ +doctype html +html(lang=locale) + head + title= t('emails.addedContributionMessage.subject') + body + h1(style='margin-bottom: 24px;')= t('emails.addedContributionMessage.subject') + #container.col + p(style='margin-bottom: 24px;')= t('emails.general.helloName', { firstName, lastName }) + p= t('emails.addedContributionMessage.commonGoodContributionMessage', { senderFirstName, senderLastName, contributionMemo }) + p= t('emails.addedContributionMessage.toSeeAndAnswerMessage') + p= t('emails.general.linkToYourAccount') + span= " " + a(href=overviewURL) #{overviewURL} + p= t('emails.general.pleaseDoNotReply') + p(style='margin-top: 24px;')= t('emails.general.sincerelyYours') + br + span= t('emails.general.yourGradidoTeam') diff --git a/backend/src/emails/templates/addedContributionMessage/subject.pug b/backend/src/emails/templates/addedContributionMessage/subject.pug new file mode 100644 index 000000000..4ac85fa23 --- /dev/null +++ b/backend/src/emails/templates/addedContributionMessage/subject.pug @@ -0,0 +1 @@ += t('emails.addedContributionMessage.subject') diff --git a/backend/src/emails/templates/contributionConfirmed/html.pug b/backend/src/emails/templates/contributionConfirmed/html.pug new file mode 100644 index 000000000..32626b147 --- /dev/null +++ b/backend/src/emails/templates/contributionConfirmed/html.pug @@ -0,0 +1,17 @@ +doctype html +html(lang=locale) + head + title= t('emails.contributionConfirmed.subject') + body + h1(style='margin-bottom: 24px;')= t('emails.contributionConfirmed.subject') + #container.col + p(style='margin-bottom: 24px;')= t('emails.general.helloName', { firstName, lastName }) + p= t('emails.contributionConfirmed.commonGoodContributionConfirmed', { senderFirstName, senderLastName, contributionMemo }) + p= t('emails.general.amountGDD', { amountGDD: contributionAmount }) + p= t('emails.general.linkToYourAccount') + span= " " + a(href=overviewURL) #{overviewURL} + p= t('emails.general.pleaseDoNotReply') + p(style='margin-top: 24px;')= t('emails.general.sincerelyYours') + br + span= t('emails.general.yourGradidoTeam') diff --git a/backend/src/emails/templates/contributionConfirmed/subject.pug b/backend/src/emails/templates/contributionConfirmed/subject.pug new file mode 100644 index 000000000..c5bd41421 --- /dev/null +++ b/backend/src/emails/templates/contributionConfirmed/subject.pug @@ -0,0 +1 @@ += t('emails.contributionConfirmed.subject') diff --git a/backend/src/emails/templates/contributionRejected/html.pug b/backend/src/emails/templates/contributionRejected/html.pug new file mode 100644 index 000000000..07c014f92 --- /dev/null +++ b/backend/src/emails/templates/contributionRejected/html.pug @@ -0,0 +1,17 @@ +doctype html +html(lang=locale) + head + title= t('emails.contributionRejected.subject') + body + h1(style='margin-bottom: 24px;')= t('emails.contributionRejected.subject') + #container.col + p(style='margin-bottom: 24px;')= t('emails.general.helloName', { firstName, lastName }) + p= t('emails.contributionRejected.commonGoodContributionRejected', { senderFirstName, senderLastName, contributionMemo }) + p= t('emails.contributionRejected.toSeeContributionsAndMessages') + p= t('emails.general.linkToYourAccount') + span= " " + a(href=overviewURL) #{overviewURL} + p= t('emails.general.pleaseDoNotReply') + p(style='margin-top: 24px;')= t('emails.general.sincerelyYours') + br + span= t('emails.general.yourGradidoTeam') diff --git a/backend/src/emails/templates/contributionRejected/subject.pug b/backend/src/emails/templates/contributionRejected/subject.pug new file mode 100644 index 000000000..40a7622b8 --- /dev/null +++ b/backend/src/emails/templates/contributionRejected/subject.pug @@ -0,0 +1 @@ += t('emails.contributionRejected.subject') diff --git a/backend/src/emails/templates/resetPassword/html.pug b/backend/src/emails/templates/resetPassword/html.pug new file mode 100644 index 000000000..a3ced9a75 --- /dev/null +++ b/backend/src/emails/templates/resetPassword/html.pug @@ -0,0 +1,20 @@ +doctype html +html(lang=locale) + head + title= t('emails.resetPassword.subject') + body + h1(style='margin-bottom: 24px;')= t('emails.resetPassword.subject') + #container.col + p(style='margin-bottom: 24px;')= t('emails.general.helloName', { firstName, lastName }) + p= t('emails.resetPassword.youOrSomeoneResetPassword') + p= t('emails.resetPassword.pleaseClickLink') + br + a(href=resetLink) #{resetLink} + br + span= t('emails.general.orCopyLink') + p= t('emails.resetPassword.duration', { hours: timeDurationObject.hours, minutes: timeDurationObject.minutes }) + br + a(href=resendLink) #{resendLink} + p(style='margin-top: 24px;')= t('emails.general.sincerelyYours') + br + span= t('emails.general.yourGradidoTeam') diff --git a/backend/src/emails/templates/resetPassword/subject.pug b/backend/src/emails/templates/resetPassword/subject.pug new file mode 100644 index 000000000..21f277316 --- /dev/null +++ b/backend/src/emails/templates/resetPassword/subject.pug @@ -0,0 +1 @@ += t('emails.resetPassword.subject') diff --git a/backend/src/emails/templates/transactionLinkRedeemed/html.pug b/backend/src/emails/templates/transactionLinkRedeemed/html.pug new file mode 100644 index 000000000..321d070b4 --- /dev/null +++ b/backend/src/emails/templates/transactionLinkRedeemed/html.pug @@ -0,0 +1,19 @@ +doctype html +html(lang=locale) + head + title= t('emails.transactionLinkRedeemed.subject') + body + h1(style='margin-bottom: 24px;')= t('emails.transactionLinkRedeemed.subject') + #container.col + p(style='margin-bottom: 24px;')= t('emails.general.helloName', { firstName, lastName }) + p= t('emails.transactionLinkRedeemed.hasRedeemedYourLink', { senderFirstName, senderLastName, senderEmail }) + p= t('emails.general.amountGDD', { amountGDD: transactionAmount }) + br + span= t('emails.transactionLinkRedeemed.memo', { transactionMemo }) + p= t('emails.general.detailsYouFindOnLinkToYourAccount') + span= " " + a(href=overviewURL) #{overviewURL} + p= t('emails.general.pleaseDoNotReply') + p(style='margin-top: 24px;')= t('emails.general.sincerelyYours') + br + span= t('emails.general.yourGradidoTeam') diff --git a/backend/src/emails/templates/transactionLinkRedeemed/subject.pug b/backend/src/emails/templates/transactionLinkRedeemed/subject.pug new file mode 100644 index 000000000..6f4f74f04 --- /dev/null +++ b/backend/src/emails/templates/transactionLinkRedeemed/subject.pug @@ -0,0 +1 @@ += t('emails.transactionLinkRedeemed.subject') diff --git a/backend/src/emails/templates/transactionReceived/html.pug b/backend/src/emails/templates/transactionReceived/html.pug new file mode 100644 index 000000000..eaf57f975 --- /dev/null +++ b/backend/src/emails/templates/transactionReceived/html.pug @@ -0,0 +1,16 @@ +doctype html +html(lang=locale) + head + title= t('emails.transactionReceived.subject') + body + h1(style='margin-bottom: 24px;')= t('emails.transactionReceived.subject') + #container.col + p(style='margin-bottom: 24px;')= t('emails.general.helloName', { firstName, lastName }) + p= t('emails.transactionReceived.haveReceivedAmountGDDFrom', { transactionAmount, senderFirstName, senderLastName, senderEmail }) + p= t('emails.general.detailsYouFindOnLinkToYourAccount') + span= " " + a(href=overviewURL) #{overviewURL} + p= t('emails.general.pleaseDoNotReply') + p(style='margin-top: 24px;')= t('emails.general.sincerelyYours') + br + span= t('emails.general.yourGradidoTeam') diff --git a/backend/src/emails/templates/transactionReceived/subject.pug b/backend/src/emails/templates/transactionReceived/subject.pug new file mode 100644 index 000000000..630752b02 --- /dev/null +++ b/backend/src/emails/templates/transactionReceived/subject.pug @@ -0,0 +1 @@ += t('emails.transactionReceived.subject') diff --git a/backend/src/graphql/resolver/AdminResolver.test.ts b/backend/src/graphql/resolver/AdminResolver.test.ts index 4a55bd0ad..b83a9876f 100644 --- a/backend/src/graphql/resolver/AdminResolver.test.ts +++ b/backend/src/graphql/resolver/AdminResolver.test.ts @@ -3,6 +3,7 @@ import { objectValuesToArray } from '@/util/utilities' import { testEnvironment, resetToken, cleanDB, contributionDateFormatter } from '@test/helpers' +import { logger, i18n as localization } from '@test/testSetup' import { userFactory } from '@/seeds/factory/user' import { creationFactory } from '@/seeds/factory/creation' import { creations } from '@/seeds/creation/index' @@ -35,30 +36,31 @@ import { } from '@/seeds/graphql/queries' import { GraphQLError } from 'graphql' import { User } from '@entity/User' -/* eslint-disable-next-line @typescript-eslint/no-unused-vars */ -import { sendAccountActivationEmail } from '@/mailer/sendAccountActivationEmail' +import { + // sendAccountActivationEmail, + sendContributionConfirmedEmail, + // sendContributionRejectedEmail, +} from '@/emails/sendEmailVariants' import Decimal from 'decimal.js-light' import { Contribution } from '@entity/Contribution' import { Transaction as DbTransaction } from '@entity/Transaction' import { ContributionLink as DbContributionLink } from '@entity/ContributionLink' -import { sendContributionConfirmedEmail } from '@/mailer/sendContributionConfirmedEmail' import { EventProtocol } from '@entity/EventProtocol' import { EventProtocolType } from '@/event/EventProtocolType' -import { logger } from '@test/testSetup' // mock account activation email to avoid console spam -jest.mock('@/mailer/sendAccountActivationEmail', () => { +jest.mock('@/emails/sendEmailVariants', () => { + const originalModule = jest.requireActual('@/emails/sendEmailVariants') return { __esModule: true, - sendAccountActivationEmail: jest.fn(), - } -}) - -// mock account activation email to avoid console spam -jest.mock('@/mailer/sendContributionConfirmedEmail', () => { - return { - __esModule: true, - sendContributionConfirmedEmail: jest.fn(), + ...originalModule, + // TODO: test the call of … + // sendAccountActivationEmail: jest.fn((a) => originalModule.sendAccountActivationEmail(a)), + sendContributionConfirmedEmail: jest.fn((a) => + originalModule.sendContributionConfirmedEmail(a), + ), + // TODO: test the call of … + // sendContributionRejectedEmail: jest.fn((a) => originalModule.sendContributionRejectedEmail(a)), } }) @@ -66,7 +68,7 @@ let mutate: any, query: any, con: any let testEnv: any beforeAll(async () => { - testEnv = await testEnvironment() + testEnv = await testEnvironment(logger, localization) mutate = testEnv.mutate query = testEnv.query con = testEnv.con @@ -1737,17 +1739,16 @@ describe('AdminResolver', () => { }) it('calls sendContributionConfirmedEmail', async () => { - expect(sendContributionConfirmedEmail).toBeCalledWith( - expect.objectContaining({ - contributionMemo: 'Herzlich Willkommen bei Gradido liebe Bibi!', - overviewURL: 'http://localhost/overview', - recipientEmail: 'bibi@bloxberg.de', - recipientFirstName: 'Bibi', - recipientLastName: 'Bloxberg', - senderFirstName: 'Peter', - senderLastName: 'Lustig', - }), - ) + expect(sendContributionConfirmedEmail).toBeCalledWith({ + firstName: 'Bibi', + lastName: 'Bloxberg', + email: 'bibi@bloxberg.de', + language: 'de', + senderFirstName: 'Peter', + senderLastName: 'Lustig', + contributionMemo: 'Herzlich Willkommen bei Gradido liebe Bibi!', + contributionAmount: expect.decimalEqual(450), + }) }) it('stores the send confirmation email event in the database', async () => { diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 9ff4824e5..d084799e7 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -39,8 +39,14 @@ import { Decay } from '@model/Decay' import Paginated from '@arg/Paginated' import TransactionLinkFilters from '@arg/TransactionLinkFilters' import { Order } from '@enum/Order' -import { findUserByEmail, activationLink, printTimeDuration } from './UserResolver' -import { sendAccountActivationEmail } from '@/mailer/sendAccountActivationEmail' +import { getTimeDurationObject } from '@/util/time' +import { findUserByEmail, activationLink } from './UserResolver' +import { + sendAddedContributionMessageEmail, + sendAccountActivationEmail, + sendContributionConfirmedEmail, + sendContributionRejectedEmail, +} from '@/emails/sendEmailVariants' import { transactionLinkCode as contributionLinkCode } from './TransactionLinkResolver' import CONFIG from '@/config' import { @@ -63,9 +69,6 @@ import { ContributionMessage as DbContributionMessage } from '@entity/Contributi import ContributionMessageArgs from '@arg/ContributionMessageArgs' import { ContributionMessageType } from '@enum/MessageType' import { ContributionMessage } from '@model/ContributionMessage' -import { sendContributionConfirmedEmail } from '@/mailer/sendContributionConfirmedEmail' -import { sendContributionRejectedEmail } from '@/mailer/sendContributionRejectedEmail' -import { sendAddedContributionMessageEmail } from '@/mailer/sendAddedContributionMessageEmail' import { eventProtocol } from '@/event/EventProtocolEmitter' import { Event, @@ -492,14 +495,13 @@ export class AdminResolver { event.setEventAdminContributionDelete(eventAdminContributionDelete), ) sendContributionRejectedEmail({ + firstName: user.firstName, + lastName: user.lastName, + email: user.emailContact.email, + language: user.language, senderFirstName: moderator.firstName, senderLastName: moderator.lastName, - recipientEmail: user.emailContact.email, - recipientFirstName: user.firstName, - recipientLastName: user.lastName, contributionMemo: contribution.memo, - contributionAmount: contribution.amount, - overviewURL: CONFIG.EMAIL_LINK_OVERVIEW, }) return !!res @@ -587,14 +589,14 @@ export class AdminResolver { await queryRunner.commitTransaction() logger.info('creation commited successfuly.') sendContributionConfirmedEmail({ + firstName: user.firstName, + lastName: user.lastName, + email: user.emailContact.email, + language: user.language, senderFirstName: moderatorUser.firstName, senderLastName: moderatorUser.lastName, - recipientFirstName: user.firstName, - recipientLastName: user.lastName, - recipientEmail: user.emailContact.email, contributionMemo: contribution.memo, contributionAmount: contribution.amount, - overviewURL: CONFIG.EMAIL_LINK_OVERVIEW, }) } catch (e) { await queryRunner.rollbackTransaction() @@ -655,17 +657,18 @@ export class AdminResolver { } const emailContact = user.emailContact if (emailContact.deletedAt) { - logger.error(`The emailContact: ${email} of htis User is deleted.`) - throw new Error(`The emailContact: ${email} of htis User is deleted.`) + logger.error(`The emailContact: ${email} of this User is deleted.`) + throw new Error(`The emailContact: ${email} of this User is deleted.`) } // eslint-disable-next-line @typescript-eslint/no-unused-vars const emailSent = await sendAccountActivationEmail({ - link: activationLink(emailContact.emailVerificationCode), firstName: user.firstName, lastName: user.lastName, email, - duration: printTimeDuration(CONFIG.EMAIL_CODE_VALID_TIME), + language: user.language, + activationLink: activationLink(emailContact.emailVerificationCode), + timeDurationObject: getTimeDurationObject(CONFIG.EMAIL_CODE_VALID_TIME), }) // In case EMails are disabled log the activation link for the user @@ -900,15 +903,13 @@ export class AdminResolver { } await sendAddedContributionMessageEmail({ + firstName: contribution.user.firstName, + lastName: contribution.user.lastName, + email: contribution.user.emailContact.email, + language: contribution.user.language, senderFirstName: user.firstName, senderLastName: user.lastName, - recipientFirstName: contribution.user.firstName, - recipientLastName: contribution.user.lastName, - recipientEmail: contribution.user.emailContact.email, - senderEmail: user.emailContact.email, contributionMemo: contribution.memo, - message, - overviewURL: CONFIG.EMAIL_LINK_OVERVIEW, }) await queryRunner.commitTransaction() } catch (e) { diff --git a/backend/src/graphql/resolver/ContributionMessageResolver.test.ts b/backend/src/graphql/resolver/ContributionMessageResolver.test.ts index 612c2d20b..436830c2c 100644 --- a/backend/src/graphql/resolver/ContributionMessageResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionMessageResolver.test.ts @@ -2,6 +2,7 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import { cleanDB, resetToken, testEnvironment } from '@test/helpers' +import { logger, i18n as localization } from '@test/testSetup' import { GraphQLError } from 'graphql' import { adminCreateContributionMessage, @@ -13,12 +14,16 @@ import { listContributionMessages } from '@/seeds/graphql/queries' import { userFactory } from '@/seeds/factory/user' import { bibiBloxberg } from '@/seeds/users/bibi-bloxberg' import { peterLustig } from '@/seeds/users/peter-lustig' -import { sendAddedContributionMessageEmail } from '@/mailer/sendAddedContributionMessageEmail' +import { sendAddedContributionMessageEmail } from '@/emails/sendEmailVariants' -jest.mock('@/mailer/sendAddedContributionMessageEmail', () => { +jest.mock('@/emails/sendEmailVariants', () => { + const originalModule = jest.requireActual('@/emails/sendEmailVariants') return { __esModule: true, - sendAddedContributionMessageEmail: jest.fn(), + ...originalModule, + sendAddedContributionMessageEmail: jest.fn((a) => + originalModule.sendAddedContributionMessageEmail(a), + ), } }) @@ -27,7 +32,7 @@ let testEnv: any let result: any beforeAll(async () => { - testEnv = await testEnvironment() + testEnv = await testEnvironment(logger, localization) mutate = testEnv.mutate con = testEnv.con await cleanDB() @@ -162,15 +167,13 @@ describe('ContributionMessageResolver', () => { it('calls sendAddedContributionMessageEmail', async () => { expect(sendAddedContributionMessageEmail).toBeCalledWith({ + firstName: 'Bibi', + lastName: 'Bloxberg', + email: 'bibi@bloxberg.de', + language: 'de', senderFirstName: 'Peter', senderLastName: 'Lustig', - recipientFirstName: 'Bibi', - recipientLastName: 'Bloxberg', - recipientEmail: 'bibi@bloxberg.de', - senderEmail: 'peter@lustig.de', contributionMemo: 'Test env contribution', - message: 'Admin Test', - overviewURL: 'http://localhost/overview', }) }) }) diff --git a/backend/src/graphql/resolver/TransactionResolver.ts b/backend/src/graphql/resolver/TransactionResolver.ts index f2edda2c1..eb8cda2c5 100644 --- a/backend/src/graphql/resolver/TransactionResolver.ts +++ b/backend/src/graphql/resolver/TransactionResolver.ts @@ -2,14 +2,11 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ import { backendLogger as logger } from '@/server/logger' -import CONFIG from '@/config' import { Context, getUser } from '@/server/context' import { Resolver, Query, Args, Authorized, Ctx, Mutation } from 'type-graphql' import { getCustomRepository, getConnection, In } from '@dbTools/typeorm' -import { sendTransactionReceivedEmail } from '@/mailer/sendTransactionReceivedEmail' - import { Transaction } from '@model/Transaction' import { TransactionList } from '@model/TransactionList' @@ -36,7 +33,10 @@ import Decimal from 'decimal.js-light' import { BalanceResolver } from './BalanceResolver' import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from './const/const' import { findUserByEmail } from './UserResolver' -import { sendTransactionLinkRedeemedEmail } from '@/mailer/sendTransactionLinkRedeemed' +import { + sendTransactionLinkRedeemedEmail, + sendTransactionReceivedEmail, +} from '@/emails/sendEmailVariants' import { Event, EventTransactionReceive, EventTransactionSend } from '@/event/Event' import { eventProtocol } from '@/event/EventProtocolEmitter' @@ -159,29 +159,27 @@ export const executeTransaction = async ( await queryRunner.release() } logger.debug(`prepare Email for transaction received...`) - // send notification email - // TODO: translate await sendTransactionReceivedEmail({ + firstName: recipient.firstName, + lastName: recipient.lastName, + email: recipient.emailContact.email, + language: recipient.language, senderFirstName: sender.firstName, senderLastName: sender.lastName, - recipientFirstName: recipient.firstName, - recipientLastName: recipient.lastName, - email: recipient.emailContact.email, senderEmail: sender.emailContact.email, - amount, - overviewURL: CONFIG.EMAIL_LINK_OVERVIEW, + transactionAmount: amount, }) if (transactionLink) { await sendTransactionLinkRedeemedEmail({ + firstName: sender.firstName, + lastName: sender.lastName, + email: sender.emailContact.email, + language: sender.language, senderFirstName: recipient.firstName, senderLastName: recipient.lastName, - recipientFirstName: sender.firstName, - recipientLastName: sender.lastName, - email: sender.emailContact.email, senderEmail: recipient.emailContact.email, - amount, - memo, - overviewURL: CONFIG.EMAIL_LINK_OVERVIEW, + transactionAmount: amount, + transactionMemo: memo, }) } logger.info(`finished executeTransaction successfully`) diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index d8472fba9..ee88e58cc 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -2,6 +2,8 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import { testEnvironment, headerPushMock, resetToken, cleanDB } from '@test/helpers' +import { logger, i18n as localization } from '@test/testSetup' +import { printTimeDuration } from '@/util/time' import { userFactory } from '@/seeds/factory/user' import { bibiBloxberg } from '@/seeds/users/bibi-bloxberg' import { @@ -18,18 +20,18 @@ import { verifyLogin, queryOptIn, searchAdminUsers } from '@/seeds/graphql/queri import { GraphQLError } from 'graphql' import { User } from '@entity/User' import CONFIG from '@/config' -import { sendAccountActivationEmail } from '@/mailer/sendAccountActivationEmail' -import { sendAccountMultiRegistrationEmail } from '@/emails/sendEmailVariants' -import { sendResetPasswordEmail } from '@/mailer/sendResetPasswordEmail' -import { printTimeDuration, activationLink } from './UserResolver' +import { + sendAccountActivationEmail, + sendAccountMultiRegistrationEmail, + sendResetPasswordEmail, +} from '@/emails/sendEmailVariants' +import { activationLink } from './UserResolver' import { contributionLinkFactory } from '@/seeds/factory/contributionLink' import { transactionLinkFactory } from '@/seeds/factory/transactionLink' import { ContributionLink } from '@model/ContributionLink' import { TransactionLink } from '@entity/TransactionLink' - import { EventProtocolType } from '@/event/EventProtocolType' import { EventProtocol } from '@entity/EventProtocol' -import { logger, i18n as localization } from '@test/testSetup' import { validate as validateUUID, version as versionUUID } from 'uuid' import { peterLustig } from '@/seeds/users/peter-lustig' import { UserContact } from '@entity/UserContact' @@ -42,24 +44,16 @@ import { SecretKeyCryptographyCreateKey } from '@/password/EncryptorUtils' // import { klicktippSignIn } from '@/apis/KlicktippController' -jest.mock('@/mailer/sendAccountActivationEmail', () => { - return { - __esModule: true, - sendAccountActivationEmail: jest.fn(), - } -}) - jest.mock('@/emails/sendEmailVariants', () => { + const originalModule = jest.requireActual('@/emails/sendEmailVariants') return { __esModule: true, - sendAccountMultiRegistrationEmail: jest.fn(), - } -}) - -jest.mock('@/mailer/sendResetPasswordEmail', () => { - return { - __esModule: true, - sendResetPasswordEmail: jest.fn(), + ...originalModule, + sendAccountActivationEmail: jest.fn((a) => originalModule.sendAccountActivationEmail(a)), + sendAccountMultiRegistrationEmail: jest.fn((a) => + originalModule.sendAccountMultiRegistrationEmail(a), + ), + sendResetPasswordEmail: jest.fn((a) => originalModule.sendResetPasswordEmail(a)), } }) @@ -184,11 +178,15 @@ describe('UserResolver', () => { emailVerificationCode, ).replace(/{code}/g, '') expect(sendAccountActivationEmail).toBeCalledWith({ - link: activationLink, firstName: 'Peter', lastName: 'Lustig', email: 'peter@lustig.de', - duration: expect.any(String), + language: 'de', + activationLink, + timeDurationObject: expect.objectContaining({ + hours: expect.any(Number), + minutes: expect.any(Number), + }), }) }) @@ -853,11 +851,15 @@ describe('UserResolver', () => { it('sends reset password email', () => { expect(sendResetPasswordEmail).toBeCalledWith({ - link: activationLink(emailContact.emailVerificationCode), firstName: 'Bibi', lastName: 'Bloxberg', email: 'bibi@bloxberg.de', - duration: expect.any(String), + language: 'de', + resetLink: activationLink(emailContact.emailVerificationCode), + timeDurationObject: expect.objectContaining({ + hours: expect.any(Number), + minutes: expect.any(Number), + }), }) }) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 752c585fd..6bdddb7b7 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -9,6 +9,7 @@ import { User } from '@model/User' import { User as DbUser } from '@entity/User' import { UserContact as DbUserContact } from '@entity/UserContact' import { communityDbUser } from '@/util/communityUser' +import { getTimeDurationObject, printTimeDuration } from '@/util/time' import { TransactionLink as dbTransactionLink } from '@entity/TransactionLink' import { ContributionLink as dbContributionLink } from '@entity/ContributionLink' import { encode } from '@/auth/JWT' @@ -17,9 +18,11 @@ import UnsecureLoginArgs from '@arg/UnsecureLoginArgs' import UpdateUserInfosArgs from '@arg/UpdateUserInfosArgs' import { klicktippNewsletterStateMiddleware } from '@/middleware/klicktippMiddleware' import { OptInType } from '@enum/OptInType' -import { sendResetPasswordEmail as sendResetPasswordEmailMailer } from '@/mailer/sendResetPasswordEmail' -import { sendAccountActivationEmail } from '@/mailer/sendAccountActivationEmail' -import { sendAccountMultiRegistrationEmail } from '@/emails/sendEmailVariants' +import { + sendAccountActivationEmail, + sendAccountMultiRegistrationEmail, + sendResetPasswordEmail, +} from '@/emails/sendEmailVariants' import { klicktippSignIn } from '@/apis/KlicktippController' import { RIGHTS } from '@/auth/RIGHTS' import { hasElopageBuys } from '@/util/hasElopageBuys' @@ -507,11 +510,12 @@ export class UserResolver { // eslint-disable-next-line @typescript-eslint/no-unused-vars const emailSent = await sendAccountActivationEmail({ - link: activationLink, firstName, lastName, email, - duration: printTimeDuration(CONFIG.EMAIL_CODE_VALID_TIME), + language, + activationLink, + timeDurationObject: getTimeDurationObject(CONFIG.EMAIL_CODE_VALID_TIME), }) logger.info(`sendAccountActivationEmail of ${firstName}.${lastName} to ${email}`) eventSendConfirmEmail.userId = dbUser.id @@ -570,12 +574,13 @@ export class UserResolver { // optInCode = await checkOptInCode(optInCode, user, OptInType.EMAIL_OPT_IN_RESET_PASSWORD) logger.info(`optInCode for ${email}=${dbUserContact}`) // eslint-disable-next-line @typescript-eslint/no-unused-vars - const emailSent = await sendResetPasswordEmailMailer({ - link: activationLink(dbUserContact.emailVerificationCode), + const emailSent = await sendResetPasswordEmail({ firstName: user.firstName, lastName: user.lastName, email, - duration: printTimeDuration(CONFIG.EMAIL_CODE_VALID_TIME), + language: user.language, + resetLink: activationLink(dbUserContact.emailVerificationCode), + timeDurationObject: getTimeDurationObject(CONFIG.EMAIL_CODE_VALID_TIME), }) /* uncomment this, when you need the activation link on the console */ @@ -913,20 +918,3 @@ const canResendOptIn = (optIn: LoginEmailOptIn): boolean => { const canEmailResend = (updatedAt: Date): boolean => { return !isTimeExpired(updatedAt, CONFIG.EMAIL_CODE_REQUEST_TIME) } - -const getTimeDurationObject = (time: number): { hours?: number; minutes: number } => { - if (time > 60) { - return { - hours: Math.floor(time / 60), - minutes: time % 60, - } - } - return { minutes: time } -} - -export const printTimeDuration = (duration: number): string => { - const time = getTimeDurationObject(duration) - const result = time.minutes > 0 ? `${time.minutes} minutes` : '' - if (time.hours) return `${time.hours} hours` + (result !== '' ? ` and ${result}` : '') - return result -} diff --git a/backend/src/locales/de.json b/backend/src/locales/de.json index 6c270f148..8aff6caa4 100644 --- a/backend/src/locales/de.json +++ b/backend/src/locales/de.json @@ -1,15 +1,61 @@ { "emails": { + "addedContributionMessage": { + "commonGoodContributionMessage": "du hast zu deinem Gemeinwohl-Beitrag „{contributionMemo}“ eine Nachricht von {senderFirstName} {senderLastName} erhalten.", + "subject": "Gradido: Nachricht zu deinem Gemeinwohl-Beitrag", + "toSeeAndAnswerMessage": "Um die Nachricht zu sehen und darauf zu antworten, gehe in deinem Gradido-Konto ins Menü „Gemeinschaft“ auf den Tab „Meine Beiträge zum Gemeinwohl“!" + }, + "accountActivation": { + "duration": "Der Link hat eine Gültigkeit von {hours} Stunden und {minutes} Minuten. Sollte die Gültigkeit des Links bereits abgelaufen sein, kannst du dir hier einen neuen Link schicken lassen, in dem du deine E-Mail-Adresse eingibst:", + "emailRegistered": "deine E-Mail-Adresse wurde soeben bei Gradido registriert.", + "pleaseClickLink": "Klicke bitte auf diesen Link, um die Registrierung abzuschließen und dein Gradido-Konto zu aktivieren:", + "subject": "Gradido: E-Mail Überprüfung" + }, "accountMultiRegistration": { "emailExists": "Es existiert jedoch zu deiner E-Mail-Adresse schon ein Konto.", - "emailReused": "Deine E-Mail-Adresse wurde soeben erneut benutzt, um bei Gradido ein Konto zu registrieren.", - "helloName": "Hallo {firstName} {lastName}", + "emailReused": "deine E-Mail-Adresse wurde soeben erneut benutzt, um bei Gradido ein Konto zu registrieren.", "ifYouAreNotTheOne": "Wenn du nicht derjenige bist, der sich versucht hat erneut zu registrieren, wende dich bitte an unseren support:", "onForgottenPasswordClickLink": "Klicke bitte auf den folgenden Link, falls du dein Passwort vergessen haben solltest:", "onForgottenPasswordCopyLink": "oder kopiere den obigen Link in dein Browserfenster.", - "sincerelyYours": "Mit freundlichen Grüßen,", - "subject": "Gradido: Erneuter Registrierungsversuch mit deiner E-Mail", + "subject": "Gradido: Erneuter Registrierungsversuch mit deiner E-Mail" + }, + "contributionConfirmed": { + "commonGoodContributionConfirmed": "dein Gemeinwohl-Beitrag „{contributionMemo}“ wurde soeben von {senderFirstName} {senderLastName} bestätigt und in deinem Gradido-Konto gutgeschrieben.", + "subject": "Gradido: Dein Gemeinwohl-Beitrag wurde bestätigt" + }, + "contributionRejected": { + "commonGoodContributionRejected": "dein Gemeinwohl-Beitrag „{contributionMemo}“ wurde von {senderFirstName} {senderLastName} abgelehnt.", + "subject": "Gradido: Dein Gemeinwohl-Beitrag wurde abgelehnt", + "toSeeContributionsAndMessages": "Um deine Gemeinwohl-Beiträge und dazugehörige Nachrichten zu sehen, gehe in deinem Gradido-Konto ins Menü „Gemeinschaft“ auf den Tab „Meine Beiträge zum Gemeinwohl“!" + }, + "general": { + "amountGDD": "Betrag: {amountGDD} GDD", + "detailsYouFindOnLinkToYourAccount": "Details zur Transaktion findest du in deinem Gradido-Konto:", + "doNotAnswer": "nicht antworten", + "helloName": "Hallo {firstName} {lastName},", + "linkToYourAccount": "Link zu deinem Konto:", + "orCopyLink": "oder kopiere den obigen Link in dein Browserfenster.", + "pleaseDoNotReply": "Bitte antworte nicht auf diese E-Mail!", + "sincerelyYours": "Liebe Grüße", "yourGradidoTeam": "dein Gradido-Team" + }, + "resetPassword": { + "duration": "Der Link hat eine Gültigkeit von {hours} Stunden und {minutes} Minuten. Sollte die Gültigkeit des Links bereits abgelaufen sein, kannst du dir hier einen neuen Link schicken lassen, in dem du deine E-Mail-Adresse eingibst:", + "pleaseClickLink": "Wenn du es warst, klicke bitte auf den Link:", + "subject": "Gradido: Passwort zurücksetzen", + "youOrSomeoneResetPassword": "du, oder jemand anderes, hast für dieses Konto ein Zurücksetzen des Passworts angefordert." + }, + "transactionLinkRedeemed": { + "hasRedeemedYourLink": "{senderFirstName} {senderLastName} ({senderEmail}) hat soeben deinen Link eingelöst.", + "memo": "Memo: {transactionMemo}", + "subject": "Gradido: Dein Gradido-Link wurde eingelöst" + }, + "transactionReceived": { + "haveReceivedAmountGDDFrom": "du hast soeben {transactionAmount} GDD von {senderFirstName} {senderLastName} ({senderEmail}) erhalten.", + "subject": "Gradido: Du hast Gradidos erhalten" } + }, + "general": { + "decimalSeparator": "," } -} \ No newline at end of file +} diff --git a/backend/src/locales/en.json b/backend/src/locales/en.json index 7655aae6a..99217840e 100644 --- a/backend/src/locales/en.json +++ b/backend/src/locales/en.json @@ -1,15 +1,61 @@ { - "emails": { - "accountMultiRegistration": { + "emails": { + "addedContributionMessage": { + "commonGoodContributionMessage": "you have received a message from {senderFirstName} {senderLastName} regarding your common good contribution “{contributionMemo}”.", + "subject": "Gradido: Message about your common good contribution", + "toSeeAndAnswerMessage": "To view and reply to the message, go to the “Community” menu in your Gradido account and click on the “My contributions to the common good” tab!" + }, + "accountActivation": { + "duration": "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:", + "emailRegistered": "Your email address has just been registered with Gradido.", + "pleaseClickLink": "Please click on this link to complete the registration and activate your Gradido account:", + "subject": "Gradido: Email Verification" + }, + "accountMultiRegistration": { "emailExists": "However, an account already exists for your email address.", "emailReused": "Your email address has just been used again to register an account with Gradido.", - "helloName": "Hello {firstName} {lastName}", "ifYouAreNotTheOne": "If you are not the one who tried to register again, please contact our support:", "onForgottenPasswordClickLink": "Please click on the following link if you have forgotten your password:", "onForgottenPasswordCopyLink": "or copy the link above into your browser window.", - "sincerelyYours": "Sincerely yours,", - "subject": "Gradido: Try To Register Again With Your Email", + "subject": "Gradido: Try To Register Again With Your Email" + }, + "contributionConfirmed": { + "commonGoodContributionConfirmed": "Your public good contribution “{contributionMemo}” has just been confirmed by {senderFirstName} {senderLastName} and credited to your Gradido account.", + "subject": "Gradido: Your common good contribution was confirmed" + }, + "contributionRejected": { + "commonGoodContributionRejected": "Your public good contribution “{contributionMemo}” was rejected by {senderFirstName} {senderLastName}.", + "subject": "Gradido: Your common good contribution was rejected", + "toSeeContributionsAndMessages": "To see your common good contributions and related messages, go to the “Community” menu in your Gradido account and click on the “My contributions to the common good” tab!" + }, + "general": { + "amountGDD": "Amount: {amountGDD} GDD", + "detailsYouFindOnLinkToYourAccount": "You can find transaction details in your Gradido account:", + "doNotAnswer": "do not answer", + "helloName": "Hello {firstName} {lastName}", + "linkToYourAccount": "Link to your account:", + "orCopyLink": "or copy the link above into your browser window.", + "pleaseDoNotReply": "Please do not reply to this email!", + "sincerelyYours": "Kind regards,", "yourGradidoTeam": "your Gradido team" - } - } -} \ No newline at end of file + }, + "resetPassword": { + "duration": "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:", + "pleaseClickLink": "If it was you, please click on the link:", + "subject": "Gradido: Reset password", + "youOrSomeoneResetPassword": "You, or someone else, requested a password reset for this account." + }, + "transactionLinkRedeemed": { + "hasRedeemedYourLink": "{senderFirstName} {senderLastName} ({senderEmail}) has just redeemed your link.", + "memo": "Memo: {transactionMemo}", + "subject": "Gradido: Your Gradido link has been redeemed" + }, + "transactionReceived": { + "haveReceivedAmountGDDFrom": "You have just received {transactionAmount} GDD from {senderFirstName} {senderLastName} ({senderEmail}).", + "subject": "Gradido: You have received Gradidos" + } + }, + "general": { + "decimalSeparator": "." + } +} diff --git a/backend/src/mailer/sendAccountActivationEmail.test.ts b/backend/src/mailer/sendAccountActivationEmail.test.ts deleted file mode 100644 index 08ddae166..000000000 --- a/backend/src/mailer/sendAccountActivationEmail.test.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { sendAccountActivationEmail } from './sendAccountActivationEmail' -import { sendEMail } from './sendEMail' - -jest.mock('./sendEMail', () => { - return { - __esModule: true, - sendEMail: jest.fn(), - } -}) - -describe('sendAccountActivationEmail', () => { - beforeEach(async () => { - await sendAccountActivationEmail({ - link: 'activationLink', - firstName: 'Peter', - lastName: 'Lustig', - email: 'peter@lustig.de', - duration: '23 hours and 30 minutes', - }) - }) - - it('calls sendEMail', () => { - expect(sendEMail).toBeCalledWith({ - to: `Peter Lustig `, - subject: 'Gradido: E-Mail Überprüfung', - text: - expect.stringContaining('Hallo Peter Lustig') && - expect.stringContaining('activationLink') && - expect.stringContaining('23 Stunden und 30 Minuten'), - }) - }) -}) diff --git a/backend/src/mailer/sendAccountActivationEmail.ts b/backend/src/mailer/sendAccountActivationEmail.ts deleted file mode 100644 index 335f80a82..000000000 --- a/backend/src/mailer/sendAccountActivationEmail.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { sendEMail } from './sendEMail' -import { accountActivation } from './text/accountActivation' -import CONFIG from '@/config' - -export const sendAccountActivationEmail = (data: { - link: string - firstName: string - lastName: string - email: string - duration: string -}): Promise => { - return sendEMail({ - to: `${data.firstName} ${data.lastName} <${data.email}>`, - subject: accountActivation.de.subject, - text: accountActivation.de.text({ ...data, resendLink: CONFIG.EMAIL_LINK_FORGOTPASSWORD }), - }) -} diff --git a/backend/src/mailer/sendAddedContributionMessageEmail.test.ts b/backend/src/mailer/sendAddedContributionMessageEmail.test.ts deleted file mode 100644 index 9a2ec1aa1..000000000 --- a/backend/src/mailer/sendAddedContributionMessageEmail.test.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { sendAddedContributionMessageEmail } from './sendAddedContributionMessageEmail' -import { sendEMail } from './sendEMail' - -jest.mock('./sendEMail', () => { - return { - __esModule: true, - sendEMail: jest.fn(), - } -}) - -describe('sendAddedContributionMessageEmail', () => { - beforeEach(async () => { - await sendAddedContributionMessageEmail({ - senderFirstName: 'Peter', - senderLastName: 'Lustig', - recipientFirstName: 'Bibi', - recipientLastName: 'Bloxberg', - recipientEmail: 'bibi@bloxberg.de', - senderEmail: 'peter@lustig.de', - contributionMemo: 'Vielen herzlichen Dank für den neuen Hexenbesen!', - message: 'Was für ein Besen ist es geworden?', - overviewURL: 'http://localhost/overview', - }) - }) - - it('calls sendEMail', () => { - expect(sendEMail).toBeCalledWith({ - to: `Bibi Bloxberg `, - subject: 'Nachricht zu deinem Gemeinwohl-Beitrag', - text: - expect.stringContaining('Hallo Bibi Bloxberg') && - expect.stringContaining('Peter Lustig') && - expect.stringContaining( - 'du hast zu deinem Gemeinwohl-Beitrag "Vielen herzlichen Dank für den neuen Hexenbesen!" eine Nachricht von Peter Lustig erhalten.', - ) && - expect.stringContaining('Was für ein Besen ist es geworden?') && - expect.stringContaining('http://localhost/overview'), - }) - }) -}) diff --git a/backend/src/mailer/sendAddedContributionMessageEmail.ts b/backend/src/mailer/sendAddedContributionMessageEmail.ts deleted file mode 100644 index 14d5f6d31..000000000 --- a/backend/src/mailer/sendAddedContributionMessageEmail.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { backendLogger as logger } from '@/server/logger' -import { sendEMail } from './sendEMail' -import { contributionMessageReceived } from './text/contributionMessageReceived' - -export const sendAddedContributionMessageEmail = (data: { - senderFirstName: string - senderLastName: string - recipientFirstName: string - recipientLastName: string - recipientEmail: string - senderEmail: string - contributionMemo: string - message: string - overviewURL: string -}): Promise => { - logger.info( - `sendEmail(): to=${data.recipientFirstName} ${data.recipientLastName} <${data.recipientEmail}>, - subject=${contributionMessageReceived.de.subject}, - text=${contributionMessageReceived.de.text(data)}`, - ) - return sendEMail({ - to: `${data.recipientFirstName} ${data.recipientLastName} <${data.recipientEmail}>`, - subject: contributionMessageReceived.de.subject, - text: contributionMessageReceived.de.text(data), - }) -} diff --git a/backend/src/mailer/sendContributionConfirmedEmail.test.ts b/backend/src/mailer/sendContributionConfirmedEmail.test.ts deleted file mode 100644 index bd89afa69..000000000 --- a/backend/src/mailer/sendContributionConfirmedEmail.test.ts +++ /dev/null @@ -1,39 +0,0 @@ -import Decimal from 'decimal.js-light' -import { sendContributionConfirmedEmail } from './sendContributionConfirmedEmail' -import { sendEMail } from './sendEMail' - -jest.mock('./sendEMail', () => { - return { - __esModule: true, - sendEMail: jest.fn(), - } -}) - -describe('sendContributionConfirmedEmail', () => { - beforeEach(async () => { - await sendContributionConfirmedEmail({ - senderFirstName: 'Peter', - senderLastName: 'Lustig', - recipientFirstName: 'Bibi', - recipientLastName: 'Bloxberg', - recipientEmail: 'bibi@bloxberg.de', - contributionMemo: 'Vielen herzlichen Dank für den neuen Hexenbesen!', - contributionAmount: new Decimal(200.0), - overviewURL: 'http://localhost/overview', - }) - }) - - it('calls sendEMail', () => { - expect(sendEMail).toBeCalledWith({ - to: 'Bibi Bloxberg ', - subject: 'Dein Gemeinwohl-Beitrag wurde bestätigt', - text: - expect.stringContaining('Hallo Bibi Bloxberg') && - expect.stringContaining( - 'dein Gemeinwohl-Beitrag "Vielen herzlichen Dank für den neuen Hexenbesen!" wurde soeben von Peter Lustig bestätigt und in deinem Gradido-Konto gutgeschrieben.', - ) && - expect.stringContaining('Betrag: 200,00 GDD') && - expect.stringContaining('Link zu deinem Konto: http://localhost/overview'), - }) - }) -}) diff --git a/backend/src/mailer/sendContributionConfirmedEmail.ts b/backend/src/mailer/sendContributionConfirmedEmail.ts deleted file mode 100644 index 439d240eb..000000000 --- a/backend/src/mailer/sendContributionConfirmedEmail.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { backendLogger as logger } from '@/server/logger' -import Decimal from 'decimal.js-light' -import { sendEMail } from './sendEMail' -import { contributionConfirmed } from './text/contributionConfirmed' - -export const sendContributionConfirmedEmail = (data: { - senderFirstName: string - senderLastName: string - recipientFirstName: string - recipientLastName: string - recipientEmail: string - contributionMemo: string - contributionAmount: Decimal - overviewURL: string -}): Promise => { - logger.info( - `sendEmail(): to=${data.recipientFirstName} ${data.recipientLastName} <${data.recipientEmail}>, - subject=${contributionConfirmed.de.subject}, - text=${contributionConfirmed.de.text(data)}`, - ) - return sendEMail({ - to: `${data.recipientFirstName} ${data.recipientLastName} <${data.recipientEmail}>`, - subject: contributionConfirmed.de.subject, - text: contributionConfirmed.de.text(data), - }) -} diff --git a/backend/src/mailer/sendContributionRejectedEmail.test.ts b/backend/src/mailer/sendContributionRejectedEmail.test.ts deleted file mode 100644 index be41ff15f..000000000 --- a/backend/src/mailer/sendContributionRejectedEmail.test.ts +++ /dev/null @@ -1,38 +0,0 @@ -import Decimal from 'decimal.js-light' -import { sendContributionRejectedEmail } from './sendContributionRejectedEmail' -import { sendEMail } from './sendEMail' - -jest.mock('./sendEMail', () => { - return { - __esModule: true, - sendEMail: jest.fn(), - } -}) - -describe('sendContributionConfirmedEmail', () => { - beforeEach(async () => { - await sendContributionRejectedEmail({ - senderFirstName: 'Peter', - senderLastName: 'Lustig', - recipientFirstName: 'Bibi', - recipientLastName: 'Bloxberg', - recipientEmail: 'bibi@bloxberg.de', - contributionMemo: 'Vielen herzlichen Dank für den neuen Hexenbesen!', - contributionAmount: new Decimal(200.0), - overviewURL: 'http://localhost/overview', - }) - }) - - it('calls sendEMail', () => { - expect(sendEMail).toBeCalledWith({ - to: 'Bibi Bloxberg ', - subject: 'Dein Gemeinwohl-Beitrag wurde abgelehnt', - text: - expect.stringContaining('Hallo Bibi Bloxberg') && - expect.stringContaining( - 'dein Gemeinwohl-Beitrag "Vielen herzlichen Dank für den neuen Hexenbesen!" wurde von Peter Lustig abgelehnt.', - ) && - expect.stringContaining('Link zu deinem Konto: http://localhost/overview'), - }) - }) -}) diff --git a/backend/src/mailer/sendContributionRejectedEmail.ts b/backend/src/mailer/sendContributionRejectedEmail.ts deleted file mode 100644 index 9edb5ba2a..000000000 --- a/backend/src/mailer/sendContributionRejectedEmail.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { backendLogger as logger } from '@/server/logger' -import Decimal from 'decimal.js-light' -import { sendEMail } from './sendEMail' -import { contributionRejected } from './text/contributionRejected' - -export const sendContributionRejectedEmail = (data: { - senderFirstName: string - senderLastName: string - recipientFirstName: string - recipientLastName: string - recipientEmail: string - contributionMemo: string - contributionAmount: Decimal - overviewURL: string -}): Promise => { - logger.info( - `sendEmail(): to=${data.recipientFirstName} ${data.recipientLastName} <${data.recipientEmail}>, - subject=${contributionRejected.de.subject}, - text=${contributionRejected.de.text(data)}`, - ) - return sendEMail({ - to: `${data.recipientFirstName} ${data.recipientLastName} <${data.recipientEmail}>`, - subject: contributionRejected.de.subject, - text: contributionRejected.de.text(data), - }) -} diff --git a/backend/src/mailer/sendEMail.test.ts b/backend/src/mailer/sendEMail.test.ts deleted file mode 100644 index e062b71d8..000000000 --- a/backend/src/mailer/sendEMail.test.ts +++ /dev/null @@ -1,113 +0,0 @@ -import { sendEMail } from './sendEMail' -import { createTransport } from 'nodemailer' -import CONFIG from '@/config' - -import { logger } from '@test/testSetup' - -CONFIG.EMAIL = false -CONFIG.EMAIL_SMTP_URL = 'EMAIL_SMTP_URL' -CONFIG.EMAIL_SMTP_PORT = '1234' -CONFIG.EMAIL_USERNAME = 'user' -CONFIG.EMAIL_PASSWORD = 'pwd' - -jest.mock('nodemailer', () => { - return { - __esModule: true, - createTransport: jest.fn(() => { - return { - sendMail: jest.fn(() => { - return { - messageId: 'message', - } - }), - } - }), - } -}) - -describe('sendEMail', () => { - let result: boolean - describe('config email is false', () => { - beforeEach(async () => { - jest.clearAllMocks() - result = await sendEMail({ - to: 'receiver@mail.org', - cc: 'support@gradido.net', - subject: 'Subject', - text: 'Text text text', - }) - }) - - it('logs warning', () => { - expect(logger.info).toBeCalledWith('Emails are disabled via config...') - }) - - it('returns false', () => { - expect(result).toBeFalsy() - }) - }) - - describe('config email is true', () => { - beforeEach(async () => { - jest.clearAllMocks() - CONFIG.EMAIL = true - result = await sendEMail({ - to: 'receiver@mail.org', - cc: 'support@gradido.net', - subject: 'Subject', - text: 'Text text text', - }) - }) - - it('calls the transporter', () => { - expect(createTransport).toBeCalledWith({ - host: 'EMAIL_SMTP_URL', - port: 1234, - secure: false, - requireTLS: true, - auth: { - user: 'user', - pass: 'pwd', - }, - }) - }) - - it('calls sendMail of transporter', () => { - expect((createTransport as jest.Mock).mock.results[0].value.sendMail).toBeCalledWith({ - from: `Gradido (nicht antworten) <${CONFIG.EMAIL_SENDER}>`, - to: 'receiver@mail.org', - cc: 'support@gradido.net', - subject: 'Subject', - text: 'Text text text', - }) - }) - - it('returns true', () => { - expect(result).toBeTruthy() - }) - }) - - describe('with email EMAIL_TEST_MODUS true', () => { - beforeEach(async () => { - jest.clearAllMocks() - CONFIG.EMAIL = true - CONFIG.EMAIL_TEST_MODUS = true - result = await sendEMail({ - to: 'receiver@mail.org', - cc: 'support@gradido.net', - subject: 'Subject', - text: 'Text text text', - }) - }) - - it('calls sendMail of transporter with faked to', () => { - expect((createTransport as jest.Mock).mock.results[0].value.sendMail).toBeCalledWith({ - from: `Gradido (nicht antworten) <${CONFIG.EMAIL_SENDER}>`, - to: CONFIG.EMAIL_TEST_RECEIVER, - cc: 'support@gradido.net', - subject: 'Subject', - text: 'Text text text', - }) - }) - }) -}) diff --git a/backend/src/mailer/sendEMail.ts b/backend/src/mailer/sendEMail.ts deleted file mode 100644 index 00282f232..000000000 --- a/backend/src/mailer/sendEMail.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { backendLogger as logger } from '@/server/logger' -import { createTransport } from 'nodemailer' - -import CONFIG from '@/config' - -export const sendEMail = async (emailDef: { - to: string - cc?: string - subject: string - text: string -}): Promise => { - logger.info( - `send Email: to=${emailDef.to}` + - (emailDef.cc ? `, cc=${emailDef.cc}` : '') + - `, subject=${emailDef.subject}, text=${emailDef.text}`, - ) - - if (!CONFIG.EMAIL) { - logger.info(`Emails are disabled via config...`) - return false - } - if (CONFIG.EMAIL_TEST_MODUS) { - logger.info( - `Testmodus=ON: change receiver from ${emailDef.to} to ${CONFIG.EMAIL_TEST_RECEIVER}`, - ) - emailDef.to = CONFIG.EMAIL_TEST_RECEIVER - } - const transporter = createTransport({ - host: CONFIG.EMAIL_SMTP_URL, - port: Number(CONFIG.EMAIL_SMTP_PORT), - secure: false, // true for 465, false for other ports - requireTLS: true, - auth: { - user: CONFIG.EMAIL_USERNAME, - pass: CONFIG.EMAIL_PASSWORD, - }, - }) - const info = await transporter.sendMail({ - ...emailDef, - from: `Gradido (nicht antworten) <${CONFIG.EMAIL_SENDER}>`, - }) - if (!info.messageId) { - logger.error('error sending notification email, but transaction succeed') - throw new Error('error sending notification email, but transaction succeed') - } - logger.info('send Email successfully.') - return true -} diff --git a/backend/src/mailer/sendResetPasswordEmail.test.ts b/backend/src/mailer/sendResetPasswordEmail.test.ts deleted file mode 100644 index 94f69cf8b..000000000 --- a/backend/src/mailer/sendResetPasswordEmail.test.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { sendResetPasswordEmail } from './sendResetPasswordEmail' -import { sendEMail } from './sendEMail' - -jest.mock('./sendEMail', () => { - return { - __esModule: true, - sendEMail: jest.fn(), - } -}) - -describe('sendResetPasswordEmail', () => { - beforeEach(async () => { - await sendResetPasswordEmail({ - link: 'resetLink', - firstName: 'Peter', - lastName: 'Lustig', - email: 'peter@lustig.de', - duration: '23 hours and 30 minutes', - }) - }) - - it('calls sendEMail', () => { - expect(sendEMail).toBeCalledWith({ - to: `Peter Lustig `, - subject: 'Gradido: Passwort zurücksetzen', - text: - expect.stringContaining('Hallo Peter Lustig') && - expect.stringContaining('resetLink') && - expect.stringContaining('23 Stunden und 30 Minuten'), - }) - }) -}) diff --git a/backend/src/mailer/sendResetPasswordEmail.ts b/backend/src/mailer/sendResetPasswordEmail.ts deleted file mode 100644 index d9770f940..000000000 --- a/backend/src/mailer/sendResetPasswordEmail.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { sendEMail } from './sendEMail' -import { resetPassword } from './text/resetPassword' -import CONFIG from '@/config' - -export const sendResetPasswordEmail = (data: { - link: string - firstName: string - lastName: string - email: string - duration: string -}): Promise => { - return sendEMail({ - to: `${data.firstName} ${data.lastName} <${data.email}>`, - subject: resetPassword.de.subject, - text: resetPassword.de.text({ ...data, resendLink: CONFIG.EMAIL_LINK_FORGOTPASSWORD }), - }) -} diff --git a/backend/src/mailer/sendTransactionLinkRedeemed.test.ts b/backend/src/mailer/sendTransactionLinkRedeemed.test.ts deleted file mode 100644 index b56ff40a1..000000000 --- a/backend/src/mailer/sendTransactionLinkRedeemed.test.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { sendEMail } from './sendEMail' -import Decimal from 'decimal.js-light' -import { sendTransactionLinkRedeemedEmail } from './sendTransactionLinkRedeemed' - -jest.mock('./sendEMail', () => { - return { - __esModule: true, - sendEMail: jest.fn(), - } -}) - -describe('sendTransactionLinkRedeemedEmail', () => { - beforeEach(async () => { - await sendTransactionLinkRedeemedEmail({ - email: 'bibi@bloxberg.de', - senderFirstName: 'Peter', - senderLastName: 'Lustig', - recipientFirstName: 'Bibi', - recipientLastName: 'Bloxberg', - senderEmail: 'peter@lustig.de', - amount: new Decimal(42.0), - memo: 'Vielen Dank dass Du dabei bist', - overviewURL: 'http://localhost/overview', - }) - }) - - it('calls sendEMail', () => { - expect(sendEMail).toBeCalledWith({ - to: `Bibi Bloxberg `, - subject: 'Gradido-Link wurde eingelöst', - text: - expect.stringContaining('Hallo Bibi Bloxberg') && - expect.stringContaining( - 'Peter Lustig (peter@lustig.de) hat soeben deinen Link eingelöst.', - ) && - expect.stringContaining('Betrag: 42,00 GDD,') && - expect.stringContaining('Memo: Vielen Dank dass Du dabei bist') && - expect.stringContaining( - 'Details zur Transaktion findest du in deinem Gradido-Konto: http://localhost/overview', - ) && - expect.stringContaining('Bitte antworte nicht auf diese E-Mail!'), - }) - }) -}) diff --git a/backend/src/mailer/sendTransactionLinkRedeemed.ts b/backend/src/mailer/sendTransactionLinkRedeemed.ts deleted file mode 100644 index a78f3b3c9..000000000 --- a/backend/src/mailer/sendTransactionLinkRedeemed.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { backendLogger as logger } from '@/server/logger' -import Decimal from 'decimal.js-light' -import { sendEMail } from './sendEMail' -import { transactionLinkRedeemed } from './text/transactionLinkRedeemed' - -export const sendTransactionLinkRedeemedEmail = (data: { - email: string - senderFirstName: string - senderLastName: string - recipientFirstName: string - recipientLastName: string - senderEmail: string - amount: Decimal - memo: string - overviewURL: string -}): Promise => { - logger.info( - `sendEmail(): to=${data.recipientFirstName} ${data.recipientLastName}, - <${data.email}>, - subject=${transactionLinkRedeemed.de.subject}, - text=${transactionLinkRedeemed.de.text(data)}`, - ) - return sendEMail({ - to: `${data.recipientFirstName} ${data.recipientLastName} <${data.email}>`, - subject: transactionLinkRedeemed.de.subject, - text: transactionLinkRedeemed.de.text(data), - }) -} diff --git a/backend/src/mailer/sendTransactionReceivedEmail.test.ts b/backend/src/mailer/sendTransactionReceivedEmail.test.ts deleted file mode 100644 index ca813c033..000000000 --- a/backend/src/mailer/sendTransactionReceivedEmail.test.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { sendTransactionReceivedEmail } from './sendTransactionReceivedEmail' -import { sendEMail } from './sendEMail' -import Decimal from 'decimal.js-light' - -jest.mock('./sendEMail', () => { - return { - __esModule: true, - sendEMail: jest.fn(), - } -}) - -describe('sendTransactionReceivedEmail', () => { - beforeEach(async () => { - await sendTransactionReceivedEmail({ - senderFirstName: 'Bibi', - senderLastName: 'Bloxberg', - recipientFirstName: 'Peter', - recipientLastName: 'Lustig', - email: 'peter@lustig.de', - senderEmail: 'bibi@bloxberg.de', - amount: new Decimal(42.0), - overviewURL: 'http://localhost/overview', - }) - }) - - it('calls sendEMail', () => { - expect(sendEMail).toBeCalledWith({ - to: `Peter Lustig `, - subject: 'Du hast Gradidos erhalten', - text: - expect.stringContaining('Hallo Peter Lustig') && - expect.stringContaining('42,00 GDD') && - expect.stringContaining('Bibi Bloxberg') && - expect.stringContaining('(bibi@bloxberg.de)') && - expect.stringContaining('http://localhost/overview'), - }) - }) -}) diff --git a/backend/src/mailer/sendTransactionReceivedEmail.ts b/backend/src/mailer/sendTransactionReceivedEmail.ts deleted file mode 100644 index 5e981659c..000000000 --- a/backend/src/mailer/sendTransactionReceivedEmail.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { backendLogger as logger } from '@/server/logger' -import Decimal from 'decimal.js-light' -import { sendEMail } from './sendEMail' -import { transactionReceived } from './text/transactionReceived' - -export const sendTransactionReceivedEmail = (data: { - senderFirstName: string - senderLastName: string - recipientFirstName: string - recipientLastName: string - email: string - senderEmail: string - amount: Decimal - overviewURL: string -}): Promise => { - logger.info( - `sendEmail(): to=${data.recipientFirstName} ${data.recipientLastName}, - <${data.email}>, - subject=${transactionReceived.de.subject}, - text=${transactionReceived.de.text(data)}`, - ) - return sendEMail({ - to: `${data.recipientFirstName} ${data.recipientLastName} <${data.email}>`, - subject: transactionReceived.de.subject, - text: transactionReceived.de.text(data), - }) -} diff --git a/backend/src/mailer/text/accountActivation.ts b/backend/src/mailer/text/accountActivation.ts deleted file mode 100644 index 2755c4c0a..000000000 --- a/backend/src/mailer/text/accountActivation.ts +++ /dev/null @@ -1,32 +0,0 @@ -export const accountActivation = { - de: { - subject: 'Gradido: E-Mail Überprüfung', - text: (data: { - link: string - firstName: string - lastName: string - email: string - duration: string - resendLink: string - }): string => - `Hallo ${data.firstName} ${data.lastName}, - -Deine E-Mail-Adresse wurde soeben bei Gradido registriert. - -Klicke bitte auf diesen Link, um die Registrierung abzuschließen und dein Gradido-Konto zu aktivieren: -${data.link} -oder kopiere den obigen Link in dein Browserfenster. - -Der Link hat eine Gültigkeit von ${data.duration - .replace('hours', 'Stunden') - .replace('minutes', 'Minuten') - .replace( - ' and ', - ' und ', - )}. Sollte die Gültigkeit des Links bereits abgelaufen sein, kannst du dir hier einen neuen Link schicken lassen, in dem du deine E-Mail-Adresse eingibst: -${data.resendLink} - -Mit freundlichen Grüßen, -dein Gradido-Team`, - }, -} diff --git a/backend/src/mailer/text/accountMultiRegistration.ts b/backend/src/mailer/text/accountMultiRegistration.ts deleted file mode 100644 index c5b55bac5..000000000 --- a/backend/src/mailer/text/accountMultiRegistration.ts +++ /dev/null @@ -1,25 +0,0 @@ -export const accountMultiRegistration = { - de: { - subject: 'Gradido: Erneuter Registrierungsversuch mit deiner E-Mail', - text: (data: { - firstName: string - lastName: string - email: string - resendLink: string - }): string => - `Hallo ${data.firstName} ${data.lastName}, - -Deine E-Mail-Adresse wurde soeben erneut benutzt, um bei Gradido ein Konto zu registrieren. -Es existiert jedoch zu deiner E-Mail-Adresse schon ein Konto. - -Klicke bitte auf den folgenden Link, falls du dein Passwort vergessen haben solltest: -${data.resendLink} -oder kopiere den obigen Link in dein Browserfenster. - -Wenn du nicht derjenige bist, der sich versucht hat erneut zu registrieren, wende dich bitte an unseren support: -https://gradido.net/de/contact/ - -Mit freundlichen Grüßen, -dein Gradido-Team`, - }, -} diff --git a/backend/src/mailer/text/contributionConfirmed.ts b/backend/src/mailer/text/contributionConfirmed.ts deleted file mode 100644 index 106c3a4c5..000000000 --- a/backend/src/mailer/text/contributionConfirmed.ts +++ /dev/null @@ -1,30 +0,0 @@ -import Decimal from 'decimal.js-light' - -export const contributionConfirmed = { - de: { - subject: 'Dein Gemeinwohl-Beitrag wurde bestätigt', - text: (data: { - senderFirstName: string - senderLastName: string - recipientFirstName: string - recipientLastName: string - contributionMemo: string - contributionAmount: Decimal - overviewURL: string - }): string => - `Hallo ${data.recipientFirstName} ${data.recipientLastName}, - -dein Gemeinwohl-Beitrag "${data.contributionMemo}" wurde soeben von ${data.senderFirstName} ${ - data.senderLastName - } bestätigt und in deinem Gradido-Konto gutgeschrieben. - -Betrag: ${data.contributionAmount.toFixed(2).replace('.', ',')} GDD - -Link zu deinem Konto: ${data.overviewURL} - -Bitte antworte nicht auf diese E-Mail! - -Liebe Grüße -dein Gradido-Team`, - }, -} diff --git a/backend/src/mailer/text/contributionMessageReceived.ts b/backend/src/mailer/text/contributionMessageReceived.ts deleted file mode 100644 index 301ebef22..000000000 --- a/backend/src/mailer/text/contributionMessageReceived.ts +++ /dev/null @@ -1,28 +0,0 @@ -export const contributionMessageReceived = { - de: { - subject: 'Nachricht zu deinem Gemeinwohl-Beitrag', - text: (data: { - senderFirstName: string - senderLastName: string - recipientFirstName: string - recipientLastName: string - recipientEmail: string - senderEmail: string - contributionMemo: string - message: string - overviewURL: string - }): string => - `Hallo ${data.recipientFirstName} ${data.recipientLastName}, - -du hast zu deinem Gemeinwohl-Beitrag "${data.contributionMemo}" eine Nachricht von ${data.senderFirstName} ${data.senderLastName} erhalten. - -Um die Nachricht zu sehen und darauf zu antworten, gehe in deinem Gradido-Konto ins Menü "Gemeinschaft" auf den Tab "Meine Beiträge zum Gemeinwohl"! - -Link zu deinem Konto: ${data.overviewURL} - -Bitte antworte nicht auf diese E-Mail! - -Liebe Grüße -dein Gradido-Team`, - }, -} diff --git a/backend/src/mailer/text/contributionRejected.ts b/backend/src/mailer/text/contributionRejected.ts deleted file mode 100644 index ff52c7b5a..000000000 --- a/backend/src/mailer/text/contributionRejected.ts +++ /dev/null @@ -1,28 +0,0 @@ -import Decimal from 'decimal.js-light' - -export const contributionRejected = { - de: { - subject: 'Dein Gemeinwohl-Beitrag wurde abgelehnt', - text: (data: { - senderFirstName: string - senderLastName: string - recipientFirstName: string - recipientLastName: string - contributionMemo: string - contributionAmount: Decimal - overviewURL: string - }): string => - `Hallo ${data.recipientFirstName} ${data.recipientLastName}, - -dein Gemeinwohl-Beitrag "${data.contributionMemo}" wurde von ${data.senderFirstName} ${data.senderLastName} abgelehnt. - -Um deine Gemeinwohl-Beiträge und dazugehörige Nachrichten zu sehen, gehe in deinem Gradido-Konto ins Menü "Gemeinschaft" auf den Tab "Meine Beiträge zum Gemeinwohl"! - -Link zu deinem Konto: ${data.overviewURL} - -Bitte antworte nicht auf diese E-Mail! - -Liebe Grüße -dein Gradido-Team`, - }, -} diff --git a/backend/src/mailer/text/resetPassword.ts b/backend/src/mailer/text/resetPassword.ts deleted file mode 100644 index ff660f76e..000000000 --- a/backend/src/mailer/text/resetPassword.ts +++ /dev/null @@ -1,30 +0,0 @@ -export const resetPassword = { - de: { - subject: 'Gradido: Passwort zurücksetzen', - text: (data: { - link: string - firstName: string - lastName: string - email: string - duration: string - resendLink: string - }): string => - `Hallo ${data.firstName} ${data.lastName}, - -Du oder jemand anderes hat für dieses Konto ein Zurücksetzen des Passworts angefordert. -Wenn du es warst, klicke bitte auf den Link: ${data.link} -oder kopiere den obigen Link in Dein Browserfenster. - -Der Link hat eine Gültigkeit von ${data.duration - .replace('hours', 'Stunden') - .replace('minutes', 'Minuten') - .replace( - ' and ', - ' und ', - )}. Sollte die Gültigkeit des Links bereits abgelaufen sein, kannst du dir hier einen neuen Link schicken lassen, in dem du deine E-Mail-Adresse eingibst: -${data.resendLink} - -Mit freundlichen Grüßen, -dein Gradido-Team`, - }, -} diff --git a/backend/src/mailer/text/transactionLinkRedeemed.ts b/backend/src/mailer/text/transactionLinkRedeemed.ts deleted file mode 100644 index a63e5d275..000000000 --- a/backend/src/mailer/text/transactionLinkRedeemed.ts +++ /dev/null @@ -1,33 +0,0 @@ -import Decimal from 'decimal.js-light' - -export const transactionLinkRedeemed = { - de: { - subject: 'Gradido-Link wurde eingelöst', - text: (data: { - email: string - senderFirstName: string - senderLastName: string - recipientFirstName: string - recipientLastName: string - senderEmail: string - amount: Decimal - memo: string - overviewURL: string - }): string => - `Hallo ${data.recipientFirstName} ${data.recipientLastName}, - -${data.senderFirstName} ${data.senderLastName} (${ - data.senderEmail - }) hat soeben deinen Link eingelöst. - -Betrag: ${data.amount.toFixed(2).replace('.', ',')} GDD, -Memo: ${data.memo} - -Details zur Transaktion findest du in deinem Gradido-Konto: ${data.overviewURL} - -Bitte antworte nicht auf diese E-Mail! - -Liebe Grüße -dein Gradido-Team`, - }, -} diff --git a/backend/src/mailer/text/transactionReceived.ts b/backend/src/mailer/text/transactionReceived.ts deleted file mode 100644 index 67758c0e1..000000000 --- a/backend/src/mailer/text/transactionReceived.ts +++ /dev/null @@ -1,29 +0,0 @@ -import Decimal from 'decimal.js-light' - -export const transactionReceived = { - de: { - subject: 'Du hast Gradidos erhalten', - text: (data: { - senderFirstName: string - senderLastName: string - recipientFirstName: string - recipientLastName: string - email: string - senderEmail: string - amount: Decimal - overviewURL: string - }): string => - `Hallo ${data.recipientFirstName} ${data.recipientLastName}, - -du hast soeben ${data.amount.toFixed(2).replace('.', ',')} GDD von ${data.senderFirstName} ${ - data.senderLastName - } (${data.senderEmail}) erhalten. - -Details zur Transaktion findest du in deinem Gradido-Konto: ${data.overviewURL} - -Bitte antworte nicht auf diese E-Mail! - -Liebe Grüße -dein Gradido-Team`, - }, -} diff --git a/backend/src/util/time.ts b/backend/src/util/time.ts new file mode 100644 index 000000000..d429c8d6b --- /dev/null +++ b/backend/src/util/time.ts @@ -0,0 +1,16 @@ +export const getTimeDurationObject = (time: number): { hours?: number; minutes: number } => { + if (time > 60) { + return { + hours: Math.floor(time / 60), + minutes: time % 60, + } + } + return { minutes: time } +} + +export const printTimeDuration = (duration: number): string => { + const time = getTimeDurationObject(duration) + const result = time.minutes > 0 ? `${time.minutes} minutes` : '' + if (time.hours) return `${time.hours} hours` + (result !== '' ? ` and ${result}` : '') + return result +} diff --git a/backend/src/util/utilities.ts b/backend/src/util/utilities.ts index 9abb31554..fa8e82d9e 100644 --- a/backend/src/util/utilities.ts +++ b/backend/src/util/utilities.ts @@ -1,5 +1,16 @@ +import Decimal from 'decimal.js-light' +import i18n from 'i18n' + export const objectValuesToArray = (obj: { [x: string]: string }): Array => { return Object.keys(obj).map(function (key) { return obj[key] }) } + +export const decimalSeparatorByLanguage = (a: Decimal, language: string): string => { + const rememberLocaleToRestore = i18n.getLocale() + i18n.setLocale(language) + const result = a.toFixed(2).replace('.', i18n.__('general.decimalSeparator')) + i18n.setLocale(rememberLocaleToRestore) + return result +} diff --git a/backend/test/testSetup.ts b/backend/test/testSetup.ts index 06779674d..300a9cbf3 100644 --- a/backend/test/testSetup.ts +++ b/backend/test/testSetup.ts @@ -1,6 +1,10 @@ +import CONFIG from '@/config' import { backendLogger as logger } from '@/server/logger' import { i18n } from '@/server/localization' +CONFIG.EMAIL = true +CONFIG.EMAIL_TEST_MODUS = false + jest.setTimeout(1000000) jest.mock('@/server/logger', () => { diff --git a/docker-compose.yml b/docker-compose.yml index 5f0ab4dde..5eea075c6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -108,7 +108,7 @@ services: #env_file: # - ./frontend/.env volumes: - # : – mirror bidirectional path in local context with path in Docker container + # : – mirror bidirectional path in local context with path in Docker container - ./logs/backend:/logs/backend ########################################################