Untitled
unknown
plain_text
a year ago
2.0 kB
6
Indexable
import { EngagementInsuranceHandler } from './EngagementInsuranceHandler';
import { QuotesHandler } from './QuotesHandler';
import { LoggerInterface } from './LoggerInterface'; // Adjust the import based on your structure
jest.mock('./QuotesHandler');
jest.mock('./LoggerInterface');
describe('EngagementInsuranceHandler', () => {
let handler: EngagementInsuranceHandler;
let mockQuotesHandler: QuotesHandler;
let mockLogger: LoggerInterface;
beforeEach(() => {
mockQuotesHandler = new QuotesHandler() as jest.Mocked<QuotesHandler>;
mockLogger = new LoggerInterface() as jest.Mocked<LoggerInterface>;
handler = new EngagementInsuranceHandler(mockQuotesHandler);
handler['log'] = mockLogger; // Injecting the mocked logger
});
afterEach(() => {
jest.clearAllMocks();
});
it('should log message type and process quotes when a message is provided', () => {
const message = { type: 'QUOTE_REQUEST' }; // Example message
handler.handle(message);
expect(mockLogger.info).toHaveBeenCalledWith('Message type: ' + message.type);
expect(mockLogger.info).toHaveBeenCalledWith('PROCESS_QUOTES');
expect(mockQuotesHandler.processQuotes).toHaveBeenCalledWith(message);
});
it('should not process when the message is null', () => {
handler.handle(null);
expect(mockLogger.info).not.toHaveBeenCalled();
expect(mockQuotesHandler.processQuotes).not.toHaveBeenCalled();
});
it('should log error when an exception is thrown', () => {
const message = { type: 'QUOTE_REQUEST' }; // Example message
mockQuotesHandler.processQuotes.mockImplementation(() => {
throw new Error('Processing error');
});
handler.handle(message);
expect(mockLogger.error).toHaveBeenCalledWith(expect.stringContaining('ENGAGEMENT_INSURANCE_HANDLER_ERROR'));
});
});
Editor is loading...
Leave a Comment