mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
feat: Test Send Email
This commit is contained in:
parent
0e203a313f
commit
3ef4d94aae
85
backend/src/util/sendEMail.test.ts
Normal file
85
backend/src/util/sendEMail.test.ts
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
import { sendEMail } from './sendEMail'
|
||||||
|
import { createTransport } from 'nodemailer'
|
||||||
|
import CONFIG from '../config'
|
||||||
|
|
||||||
|
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', () => {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
const consoleLog = console.log
|
||||||
|
const consoleLogMock = jest.fn()
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log = consoleLogMock
|
||||||
|
beforeEach(async () => {
|
||||||
|
result = await sendEMail({
|
||||||
|
from: 'sender@mail.org',
|
||||||
|
to: 'receiver@mail.org',
|
||||||
|
subject: 'Subject',
|
||||||
|
text: 'Text text text',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log = consoleLog
|
||||||
|
})
|
||||||
|
|
||||||
|
it('logs warining to console', () => {
|
||||||
|
expect(consoleLogMock).toBeCalledWith('Emails are disabled via config')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns false', () => {
|
||||||
|
expect(result).toBeFalsy()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('config email is true', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
CONFIG.EMAIL = true
|
||||||
|
result = await sendEMail({
|
||||||
|
from: 'sender@mail.org',
|
||||||
|
to: 'receiver@mail.org',
|
||||||
|
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('returns true', () => {
|
||||||
|
expect(result).toBeTruthy()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
Loading…
x
Reference in New Issue
Block a user