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 { createTransport } from 'nodemailer'
|
||||||
import CONFIG from '@/config'
|
import CONFIG from '@/config'
|
||||||
|
|
||||||
|
import { getLogger } from '@/server/logger'
|
||||||
|
|
||||||
CONFIG.EMAIL = false
|
CONFIG.EMAIL = false
|
||||||
CONFIG.EMAIL_SMTP_URL = 'EMAIL_SMTP_URL'
|
CONFIG.EMAIL_SMTP_URL = 'EMAIL_SMTP_URL'
|
||||||
CONFIG.EMAIL_SMTP_PORT = '1234'
|
CONFIG.EMAIL_SMTP_PORT = '1234'
|
||||||
CONFIG.EMAIL_USERNAME = 'user'
|
CONFIG.EMAIL_USERNAME = 'user'
|
||||||
CONFIG.EMAIL_PASSWORD = 'pwd'
|
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', () => {
|
jest.mock('nodemailer', () => {
|
||||||
return {
|
return {
|
||||||
__esModule: true,
|
__esModule: true,
|
||||||
@ -25,12 +46,13 @@ jest.mock('nodemailer', () => {
|
|||||||
|
|
||||||
describe('sendEMail', () => {
|
describe('sendEMail', () => {
|
||||||
let result: boolean
|
let result: boolean
|
||||||
|
describe('logger', () => {
|
||||||
|
it('initializes the logger', () => {
|
||||||
|
expect(getLogger).toBeCalledWith('backend.mailer.sendEMail')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('config email is false', () => {
|
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 () => {
|
beforeEach(async () => {
|
||||||
result = await sendEMail({
|
result = await sendEMail({
|
||||||
to: 'receiver@mail.org',
|
to: 'receiver@mail.org',
|
||||||
@ -39,13 +61,8 @@ describe('sendEMail', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(() => {
|
it('logs warining', () => {
|
||||||
// eslint-disable-next-line no-console
|
expect(logger.info).toBeCalledWith('Emails are disabled via config...')
|
||||||
console.log = consoleLog
|
|
||||||
})
|
|
||||||
|
|
||||||
it('logs warining to console', () => {
|
|
||||||
expect(consoleLogMock).toBeCalledWith('Emails are disabled via config')
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns false', () => {
|
it('returns false', () => {
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
import log4js from '@/server/logger'
|
import { getLogger } from '@/server/logger'
|
||||||
import { createTransport } from 'nodemailer'
|
import { createTransport } from 'nodemailer'
|
||||||
|
|
||||||
import CONFIG from '@/config'
|
import CONFIG from '@/config'
|
||||||
|
|
||||||
const logger = log4js.getLogger('backend.mailer.sendEMail')
|
export const logger = getLogger('backend.mailer.sendEMail')
|
||||||
|
|
||||||
export const sendEMail = async (emailDef: {
|
export const sendEMail = async (emailDef: {
|
||||||
to: string
|
to: string
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user