feat(logging): emit sanitized structured app logs
This commit is contained in:
@@ -17,6 +17,15 @@ const mockClient = {
|
||||
db: jest.fn().mockReturnValue(mockDb)
|
||||
}
|
||||
|
||||
const mockMongoLoggerError = jest.fn()
|
||||
|
||||
jest.mock('./logger', () => ({
|
||||
dbLogger: { error: mockMongoLoggerError },
|
||||
getSafeErrorDetails: (error: unknown) => ({
|
||||
errorName: error instanceof Error ? error.name : 'Error'
|
||||
})
|
||||
}))
|
||||
|
||||
// The connect method should resolve to the client itself
|
||||
mockClient.connect.mockResolvedValue(mockClient)
|
||||
|
||||
@@ -39,6 +48,7 @@ describe('MongoDB Connection (Unit Tests)', () => {
|
||||
MONGODB_DB: 'test'
|
||||
}
|
||||
jest.clearAllMocks()
|
||||
mockMongoLoggerError.mockReset()
|
||||
|
||||
// Reset the mock implementation
|
||||
MockedMongoClient.mockImplementation(() => mockClient as any)
|
||||
@@ -116,6 +126,7 @@ describe('MongoDB Connection (Unit Tests)', () => {
|
||||
|
||||
const result = await checkMongoConnection()
|
||||
expect(result).toBe(false)
|
||||
expect(mockMongoLoggerError).toHaveBeenCalledWith('MongoDB connection check failed', { errorName: 'Error' })
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user