fix logger
This commit is contained in:
@@ -4,7 +4,7 @@ import { PlaywrightAuthSessionService } from '../../../../core/automation/infras
|
||||
import type { PlaywrightBrowserSession } from '../../../../core/automation/infrastructure/adapters/automation/core/PlaywrightBrowserSession';
|
||||
import type { SessionCookieStore } from '../../../../core/automation/infrastructure/adapters/automation/auth/SessionCookieStore';
|
||||
import type { IPlaywrightAuthFlow } from '../../../../core/automation/infrastructure/adapters/automation/auth/PlaywrightAuthFlow';
|
||||
import type { LoggerPort as ILogger } from '../../../../core/automation/application/ports/LoggerPort';
|
||||
import type { LoggerPort as Logger } from '../../../../core/automation/application/ports/LoggerPort';
|
||||
import { AuthenticationState } from '@gridpilot/automation/domain/value-objects/AuthenticationState';
|
||||
import { Result } from '../../../../core/shared/result/Result';
|
||||
|
||||
@@ -14,7 +14,7 @@ describe('PlaywrightAuthSessionService.initiateLogin browser mode behaviour', ()
|
||||
let mockBrowserSession: PlaywrightBrowserSession;
|
||||
let mockCookieStore: SessionCookieStore;
|
||||
let mockAuthFlow: IPlaywrightAuthFlow;
|
||||
let mockLogger: ILogger;
|
||||
let mockLogger: Logger;
|
||||
let mockPage: Page;
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { Page, Locator } from 'playwright';
|
||||
import { PlaywrightAuthSessionService } from '../../../../core/automation/infrastructure/adapters/automation/auth/PlaywrightAuthSessionService';
|
||||
import { AuthenticationState } from '@gridpilot/automation/domain/value-objects/AuthenticationState';
|
||||
import { BrowserAuthenticationState } from '@gridpilot/automation/domain/value-objects/BrowserAuthenticationState';
|
||||
import type { LoggerPort as ILogger } from '../../../../core/automation/application/ports/LoggerPort';
|
||||
import type { LoggerPort as Logger } from '../../../../core/automation/application/ports/LoggerPort';
|
||||
import type { Result } from '../../../../core/shared/result/Result';
|
||||
import type { PlaywrightBrowserSession } from '../../../../core/automation/infrastructure/adapters/automation/core/PlaywrightBrowserSession';
|
||||
import type { SessionCookieStore } from '../../../../core/automation/infrastructure/adapters/automation/auth/SessionCookieStore';
|
||||
@@ -16,7 +16,7 @@ describe('PlaywrightAuthSessionService.verifyPageAuthentication', () => {
|
||||
hasAuthUi: boolean;
|
||||
cookieState: AuthenticationState;
|
||||
}) {
|
||||
const mockLogger: ILogger = {
|
||||
const mockLogger: Logger = {
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warn: vi.fn(),
|
||||
|
||||
69
tests/shared/ConsoleLogger.test.ts
Normal file
69
tests/shared/ConsoleLogger.test.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { vi } from 'vitest';
|
||||
import { ConsoleLogger } from '../../../logging/ConsoleLogger'; // Assuming ConsoleLogger is here
|
||||
|
||||
describe('ConsoleLogger', () => {
|
||||
let logger: ConsoleLogger;
|
||||
let consoleDebugSpy: vi.SpyInstance;
|
||||
let consoleInfoSpy: vi.SpyInstance;
|
||||
let consoleWarnSpy: vi.SpyInstance;
|
||||
let consoleErrorSpy: vi.SpyInstance;
|
||||
let consoleLogSpy: vi.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
logger = new ConsoleLogger();
|
||||
consoleDebugSpy = vi.spyOn(console, 'debug').mockImplementation(() => {});
|
||||
consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
|
||||
consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
||||
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
||||
consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
consoleDebugSpy.mockRestore();
|
||||
consoleInfoSpy.mockRestore();
|
||||
consoleWarnSpy.mockRestore();
|
||||
consoleErrorSpy.mockRestore();
|
||||
consoleLogSpy.mockRestore();
|
||||
});
|
||||
|
||||
it('should call console.debug with the correct arguments when debug is called', () => {
|
||||
const message = 'Debug message';
|
||||
const context = { key: 'value' };
|
||||
logger.debug(message, context);
|
||||
expect(consoleDebugSpy).toHaveBeenCalledTimes(1);
|
||||
expect(consoleDebugSpy).toHaveBeenCalledWith(message, context);
|
||||
});
|
||||
|
||||
it('should call console.info with the correct arguments when info is called', () => {
|
||||
const message = 'Info message';
|
||||
const context = { key: 'value' };
|
||||
logger.info(message, context);
|
||||
expect(consoleInfoSpy).toHaveBeenCalledTimes(1);
|
||||
expect(consoleInfoSpy).toHaveBeenCalledWith(message, context);
|
||||
});
|
||||
|
||||
it('should call console.warn with the correct arguments when warn is called', () => {
|
||||
const message = 'Warn message';
|
||||
const context = { key: 'value' };
|
||||
logger.warn(message, context);
|
||||
expect(consoleWarnSpy).toHaveBeenCalledTimes(1);
|
||||
expect(consoleWarnSpy).toHaveBeenCalledWith(message, context);
|
||||
});
|
||||
|
||||
it('should call console.error with the correct arguments when error is called', () => {
|
||||
const message = 'Error message';
|
||||
const error = new Error('Something went wrong');
|
||||
const context = { key: 'value' };
|
||||
logger.error(message, error, context);
|
||||
expect(consoleErrorSpy).toHaveBeenCalledTimes(1);
|
||||
expect(consoleErrorSpy).toHaveBeenCalledWith(message, error, context);
|
||||
});
|
||||
|
||||
it('should call console.log with the correct arguments when log is called', () => {
|
||||
const message = 'Log message';
|
||||
const context = { key: 'value' };
|
||||
logger.log(message, context);
|
||||
expect(consoleLogSpy).toHaveBeenCalledTimes(1);
|
||||
expect(consoleLogSpy).toHaveBeenCalledWith(message, context);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user