mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Test 'sendContributionConfirmedEmail'
This commit is contained in:
parent
c87ffd5b8a
commit
727e5ca1f6
@ -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 CONFIG from '@/config'
|
||||||
import {
|
import {
|
||||||
sendAddedContributionMessageEmail,
|
sendAddedContributionMessageEmail,
|
||||||
sendAccountActivationEmail,
|
sendAccountActivationEmail,
|
||||||
sendAccountMultiRegistrationEmail,
|
sendAccountMultiRegistrationEmail,
|
||||||
|
sendContributionConfirmedEmail,
|
||||||
} from './sendEmailVariants'
|
} from './sendEmailVariants'
|
||||||
import { sendEmailTranslated } from './sendEmailTranslated'
|
import { sendEmailTranslated } from './sendEmailTranslated'
|
||||||
|
|
||||||
CONFIG.EMAIL = true
|
let con: any
|
||||||
CONFIG.EMAIL_SMTP_URL = 'EMAIL_SMTP_URL'
|
let testEnv: any
|
||||||
CONFIG.EMAIL_SMTP_PORT = '1234'
|
|
||||||
CONFIG.EMAIL_USERNAME = 'user'
|
beforeAll(async () => {
|
||||||
CONFIG.EMAIL_PASSWORD = 'pwd'
|
testEnv = await testEnvironment(logger, localization)
|
||||||
|
con = testEnv.con
|
||||||
|
// await cleanDB()
|
||||||
|
})
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
// await cleanDB()
|
||||||
|
await con.close()
|
||||||
|
})
|
||||||
|
|
||||||
jest.mock('./sendEmailTranslated', () => {
|
jest.mock('./sendEmailTranslated', () => {
|
||||||
const originalModule = jest.requireActual('./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 <peter@lustig.de>',
|
||||||
|
},
|
||||||
|
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 <peter@lustig.de>',
|
||||||
|
from: 'Gradido (nicht antworten) <info@gradido.net>',
|
||||||
|
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('<!DOCTYPE html>')
|
||||||
|
expect(result.originalMessage.html).toContain('<html lang="en">')
|
||||||
|
expect(result.originalMessage.html).toContain(
|
||||||
|
'<title>Gradido: Your common good contribution was confirmed</title>',
|
||||||
|
)
|
||||||
|
expect(result.originalMessage.html).toContain(
|
||||||
|
'>Gradido: Your common good contribution was confirmed</h1>',
|
||||||
|
)
|
||||||
|
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:<span> </span><a href="http://localhost/overview">http://localhost/overview</a>',
|
||||||
|
)
|
||||||
|
expect(result.originalMessage.html).toContain('Please do not reply to this email!')
|
||||||
|
expect(result.originalMessage.html).toContain('Kind regards,<br><span>your Gradido team')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -36,13 +36,14 @@ import {
|
|||||||
} from '@/seeds/graphql/queries'
|
} from '@/seeds/graphql/queries'
|
||||||
import { GraphQLError } from 'graphql'
|
import { GraphQLError } from 'graphql'
|
||||||
import { User } from '@entity/User'
|
import { User } from '@entity/User'
|
||||||
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
|
import {
|
||||||
import { sendAccountActivationEmail } from '@/emails/sendEmailVariants'
|
// sendAccountActivationEmail,
|
||||||
|
sendContributionConfirmedEmail,
|
||||||
|
} from '@/emails/sendEmailVariants'
|
||||||
import Decimal from 'decimal.js-light'
|
import Decimal from 'decimal.js-light'
|
||||||
import { Contribution } from '@entity/Contribution'
|
import { Contribution } from '@entity/Contribution'
|
||||||
import { Transaction as DbTransaction } from '@entity/Transaction'
|
import { Transaction as DbTransaction } from '@entity/Transaction'
|
||||||
import { ContributionLink as DbContributionLink } from '@entity/ContributionLink'
|
import { ContributionLink as DbContributionLink } from '@entity/ContributionLink'
|
||||||
import { sendContributionConfirmedEmail } from '@/mailer/sendContributionConfirmedEmail'
|
|
||||||
import { EventProtocol } from '@entity/EventProtocol'
|
import { EventProtocol } from '@entity/EventProtocol'
|
||||||
import { EventProtocolType } from '@/event/EventProtocolType'
|
import { EventProtocolType } from '@/event/EventProtocolType'
|
||||||
|
|
||||||
@ -53,15 +54,10 @@ jest.mock('@/emails/sendEmailVariants', () => {
|
|||||||
__esModule: true,
|
__esModule: true,
|
||||||
...originalModule,
|
...originalModule,
|
||||||
// TODO: test the call of …
|
// TODO: test the call of …
|
||||||
sendAccountActivationEmail: jest.fn((a) => originalModule.sendAccountActivationEmail(a)),
|
// sendAccountActivationEmail: jest.fn((a) => originalModule.sendAccountActivationEmail(a)),
|
||||||
}
|
sendContributionConfirmedEmail: jest.fn((a) =>
|
||||||
})
|
originalModule.sendContributionConfirmedEmail(a),
|
||||||
|
),
|
||||||
// mock account activation email to avoid console spam
|
|
||||||
jest.mock('@/mailer/sendContributionConfirmedEmail', () => {
|
|
||||||
return {
|
|
||||||
__esModule: true,
|
|
||||||
sendContributionConfirmedEmail: jest.fn(),
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -1718,17 +1714,16 @@ describe('AdminResolver', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('calls sendContributionConfirmedEmail', async () => {
|
it('calls sendContributionConfirmedEmail', async () => {
|
||||||
expect(sendContributionConfirmedEmail).toBeCalledWith(
|
expect(sendContributionConfirmedEmail).toBeCalledWith({
|
||||||
expect.objectContaining({
|
firstName: 'Bibi',
|
||||||
contributionMemo: 'Herzlich Willkommen bei Gradido liebe Bibi!',
|
lastName: 'Bloxberg',
|
||||||
overviewURL: 'http://localhost/overview',
|
email: 'bibi@bloxberg.de',
|
||||||
recipientEmail: 'bibi@bloxberg.de',
|
language: 'de',
|
||||||
recipientFirstName: 'Bibi',
|
senderFirstName: 'Peter',
|
||||||
recipientLastName: 'Bloxberg',
|
senderLastName: 'Lustig',
|
||||||
senderFirstName: 'Peter',
|
contributionMemo: 'Herzlich Willkommen bei Gradido liebe Bibi!',
|
||||||
senderLastName: 'Lustig',
|
contributionAmount: expect.decimalEqual(450),
|
||||||
}),
|
})
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('stores the send confirmation email event in the database', async () => {
|
it('stores the send confirmation email event in the database', async () => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user