@apistudio/apim-cli
Version:
CLI for API Management Products
46 lines (36 loc) • 1.19 kB
text/typescript
/**
* Copyright IBM Corp. 2024, 2025
*/
import { Components, Logger, LoggerConfig } from '@apic/studio-logger';
import { LogIntializer, LogWrapper } from '../../src/service/log-wrapper.js';
jest.mock('@apic/studio-logger', () => ({
Logger: jest.fn().mockImplementation(() => ({
logInfo: jest.fn(),
})),
LoggerBase: jest.fn().mockImplementation(() => ({
logInfo: jest.fn(),
})),
Components: {
TestComponent: 'TestComponent',
},
LoggerConfig: {
isLoggerEnabled: jest.fn(),
},
}));
describe('LogIntializer', () => {
afterEach(() => {
jest.clearAllMocks();
});
it('should initialize Logger and call logInfo if LoggerConfig is enabled', () => {
(LoggerConfig.isLoggerEnabled as jest.Mock).mockReturnValue(true);
new LogIntializer();
expect(Logger).toHaveBeenCalledWith(Components.TestComponent);
expect(LogWrapper.logInfo).toHaveBeenCalledWith('0001', 'Test');
});
it('should not initialize Logger if LoggerConfig is not enabled', () => {
(LoggerConfig.isLoggerEnabled as jest.Mock).mockReturnValue(false);
new LogIntializer();
expect(Logger).not.toHaveBeenCalled();
expect(LogWrapper.logInfo).not.toHaveBeenCalledWith('0001', 'Test');
});
});