mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
fix test for logging, test logging, silence logger in test
This commit is contained in:
parent
700f8ada07
commit
9e2f04b309
@ -1,13 +1,34 @@
|
||||
import { sendEMail } from './sendEMail'
|
||||
import { sendEMail, logger } from './sendEMail'
|
||||
import { createTransport } from 'nodemailer'
|
||||
import CONFIG from '@/config'
|
||||
|
||||
import { getLogger } from '@/server/logger'
|
||||
|
||||
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('@/server/logger', () => {
|
||||
const originalModule = jest.requireActual('@/server/logger')
|
||||
return {
|
||||
__esModule: true,
|
||||
...originalModule,
|
||||
getLogger: jest.fn(() => {
|
||||
return {
|
||||
addContext: jest.fn(),
|
||||
trace: jest.fn(),
|
||||
debug: jest.fn(),
|
||||
warn: jest.fn(),
|
||||
info: jest.fn(),
|
||||
error: jest.fn(),
|
||||
fatal: jest.fn(),
|
||||
}
|
||||
}),
|
||||
}
|
||||
})
|
||||
|
||||
jest.mock('nodemailer', () => {
|
||||
return {
|
||||
__esModule: true,
|
||||
@ -25,12 +46,13 @@ jest.mock('nodemailer', () => {
|
||||
|
||||
describe('sendEMail', () => {
|
||||
let result: boolean
|
||||
describe('logger', () => {
|
||||
it('initializes the logger', () => {
|
||||
expect(getLogger).toBeCalledWith('backend.mailer.sendEMail')
|
||||
})
|
||||
})
|
||||
|
||||
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({
|
||||
to: 'receiver@mail.org',
|
||||
@ -39,13 +61,8 @@ describe('sendEMail', () => {
|
||||
})
|
||||
})
|
||||
|
||||
afterAll(() => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log = consoleLog
|
||||
})
|
||||
|
||||
it('logs warining to console', () => {
|
||||
expect(consoleLogMock).toBeCalledWith('Emails are disabled via config')
|
||||
it('logs warining', () => {
|
||||
expect(logger.info).toBeCalledWith('Emails are disabled via config...')
|
||||
})
|
||||
|
||||
it('returns false', () => {
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import log4js from '@/server/logger'
|
||||
import { getLogger } from '@/server/logger'
|
||||
import { createTransport } from 'nodemailer'
|
||||
|
||||
import CONFIG from '@/config'
|
||||
|
||||
const logger = log4js.getLogger('backend.mailer.sendEMail')
|
||||
export const logger = getLogger('backend.mailer.sendEMail')
|
||||
|
||||
export const sendEMail = async (emailDef: {
|
||||
to: string
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user