From e1df4a3bad46c25c0881785cb725bde3d35e345a Mon Sep 17 00:00:00 2001 From: Raju Ahmed Date: Fri, 15 Nov 2024 20:21:25 +0600 Subject: [PATCH] more test --- .../batch_event_processor.spec.ts | 35 ++++++++++++++++++- vitest.config.mts | 2 +- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/event_processor/batch_event_processor.spec.ts b/lib/event_processor/batch_event_processor.spec.ts index 1555702d2..68bfb2902 100644 --- a/lib/event_processor/batch_event_processor.spec.ts +++ b/lib/event_processor/batch_event_processor.spec.ts @@ -26,7 +26,8 @@ import { advanceTimersByTime } from '../../tests/testUtils'; import { getMockLogger } from '../tests/mock/mock_logger'; import { getMockRepeater } from '../tests/mock/mock_repeater'; import * as retry from '../utils/executor/backoff_retry_runner'; -import { ServiceState } from '../service'; +import { ServiceState, StartupLog } from '../service'; +import { LogLevel } from '../modules/logging'; const getMockDispatcher = () => { return { @@ -50,6 +51,38 @@ describe('QueueingEventProcessor', async () => { }); describe('start', () => { + it.only('should log startupLogs on start', () => { + const startupLogs: StartupLog[] = [ + { + level: LogLevel.WARNING, + message: 'warn message', + params: [1, 2] + }, + { + level: LogLevel.ERROR, + message: 'error message', + params: [3, 4] + }, + ]; + + const logger = getMockLogger(); + + const processor = new BatchEventProcessor({ + eventDispatcher: getMockDispatcher(), + dispatchRepeater: getMockRepeater(), + batchSize: 1000, + startupLogs, + }); + + processor.setLogger(logger); + processor.start(); + + + expect(logger.log).toHaveBeenCalledTimes(2); + expect(logger.log).toHaveBeenNthCalledWith(1, LogLevel.WARNING, 'warn message', 1, 2); + expect(logger.log).toHaveBeenNthCalledWith(2, LogLevel.ERROR, 'error message', 3, 4); + }); + it('should resolve onRunning() when start() is called', async () => { const eventDispatcher = getMockDispatcher(); const processor = new BatchEventProcessor({ diff --git a/vitest.config.mts b/vitest.config.mts index 3cdb0691b..61452ea16 100644 --- a/vitest.config.mts +++ b/vitest.config.mts @@ -20,7 +20,7 @@ export default defineConfig({ test: { onConsoleLog: () => true, environment: 'happy-dom', - include: ['**/service.spec.ts'], + include: ['**/batch_event_processor.spec.ts'], typecheck: { tsconfig: 'tsconfig.spec.json', },