diff --git a/backend/src/emails/sendEmailVariants.test.ts b/backend/src/emails/sendEmailVariants.test.ts index 38e901828..1d562ebe9 100644 --- a/backend/src/emails/sendEmailVariants.test.ts +++ b/backend/src/emails/sendEmailVariants.test.ts @@ -1,16 +1,30 @@ +/* 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 { sendAddedContributionMessageEmail, sendAccountActivationEmail, sendAccountMultiRegistrationEmail, + sendContributionConfirmedEmail, } 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') @@ -243,4 +257,76 @@ describe('sendEmailVariants', () => { }) }) }) + + 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 (nicht antworten) ', + 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: http://localhost/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/graphql/resolver/AdminResolver.test.ts b/backend/src/graphql/resolver/AdminResolver.test.ts index 2ff7b0437..d5b4cade5 100644 --- a/backend/src/graphql/resolver/AdminResolver.test.ts +++ b/backend/src/graphql/resolver/AdminResolver.test.ts @@ -36,13 +36,14 @@ 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 '@/emails/sendEmailVariants' +import { + // sendAccountActivationEmail, + sendContributionConfirmedEmail, +} 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' @@ -53,15 +54,10 @@ jest.mock('@/emails/sendEmailVariants', () => { __esModule: true, ...originalModule, // TODO: test the call of … - sendAccountActivationEmail: jest.fn((a) => originalModule.sendAccountActivationEmail(a)), - } -}) - -// mock account activation email to avoid console spam -jest.mock('@/mailer/sendContributionConfirmedEmail', () => { - return { - __esModule: true, - sendContributionConfirmedEmail: jest.fn(), + // sendAccountActivationEmail: jest.fn((a) => originalModule.sendAccountActivationEmail(a)), + sendContributionConfirmedEmail: jest.fn((a) => + originalModule.sendContributionConfirmedEmail(a), + ), } }) @@ -1718,17 +1714,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 () => {