Skip to content

Commit

Permalink
more test
Browse files Browse the repository at this point in the history
  • Loading branch information
raju-opti committed Nov 15, 2024
1 parent e92f027 commit e1df4a3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
35 changes: 34 additions & 1 deletion lib/event_processor/batch_event_processor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand Down

0 comments on commit e1df4a3

Please sign in to comment.