feat(logging): emit sanitized structured app logs

This commit is contained in:
Do Siki
2026-09-28 09:51:40 +02:00
parent 2ad3e75c87
commit b5a8936f42
26 changed files with 429 additions and 574 deletions
+11
View File
@@ -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' })
})
})