Skip to content

Commit aef60d8

Browse files
committed
add tests for event marks handling in NotifierWorker
1 parent f38ad92 commit aef60d8

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

workers/grouper/tests/index.test.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,78 @@ describe('GrouperWorker', () => {
589589
});
590590
});
591591

592+
describe('Event marks handling', () => {
593+
describe('Ignored events', () => {
594+
it('should not add task for NotifierWorker when event is marked as ignored', async () => {
595+
const mockAddTask = jest
596+
.spyOn(worker as any, 'addTask')
597+
.mockImplementation(() => Promise.resolve());
598+
599+
// Create an event first
600+
const firstTask = generateTask({ title: 'Test ignored event' });
601+
await worker.handle(firstTask);
602+
603+
// Mark the event as ignored by updating it in database
604+
const eventHash = await (worker as any).getUniqueEventHash(firstTask);
605+
await eventsCollection.updateOne(
606+
{ groupHash: eventHash },
607+
{ $set: { marks: { ignored: true } } }
608+
);
609+
610+
// Handle the same event again (repetition)
611+
const secondTask = generateTask({ title: 'Test ignored event' });
612+
await worker.handle(secondTask);
613+
614+
// Verify that addTask was called only once (for the first occurrence)
615+
expect(mockAddTask).toHaveBeenCalledTimes(1);
616+
617+
mockAddTask.mockRestore();
618+
});
619+
620+
it('should add task for NotifierWorker when event is not marked as ignored', async () => {
621+
const mockAddTask = jest
622+
.spyOn(worker as any, 'addTask')
623+
.mockImplementation(() => Promise.resolve());
624+
625+
// Create an event first
626+
const firstTask = generateTask({ title: 'Test non-ignored event' });
627+
await worker.handle(firstTask);
628+
629+
// Handle the same event again (repetition) - without marking as ignored
630+
const secondTask = generateTask({ title: 'Test non-ignored event' });
631+
await worker.handle(secondTask);
632+
633+
// Verify that addTask was called twice (for both occurrences)
634+
expect(mockAddTask).toHaveBeenCalledTimes(2);
635+
636+
mockAddTask.mockRestore();
637+
});
638+
639+
it('should add task for NotifierWorker for first occurrence even if marks field is undefined', async () => {
640+
const mockAddTask = jest
641+
.spyOn(worker as any, 'addTask')
642+
.mockImplementation(() => Promise.resolve());
643+
644+
// Create a new event (first occurrence)
645+
const task = generateTask({ title: 'Test new event without marks' });
646+
await worker.handle(task);
647+
648+
// Verify that addTask was called for the first occurrence
649+
expect(mockAddTask).toHaveBeenCalledTimes(1);
650+
expect(mockAddTask).toHaveBeenCalledWith('notifier', {
651+
projectId: task.projectId,
652+
event: {
653+
title: task.payload.title,
654+
groupHash: expect.any(String),
655+
isNew: true,
656+
},
657+
});
658+
659+
mockAddTask.mockRestore();
660+
});
661+
});
662+
});
663+
592664
afterAll(async () => {
593665
await redisClient.quit();
594666
await worker.finish();

0 commit comments

Comments
 (0)