-
Notifications
You must be signed in to change notification settings - Fork 3
add reaction delete summary test #567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| import { ChatClient } from '../../src/core/chat.ts'; | ||
|
|
@@ -384,4 +384,126 @@ | |
| void room.detach(); | ||
| void room2.detach(); | ||
| }); | ||
|
|
||
| it<TestContext>('should receive 4 summaries when second client adds and deletes two distinct reactions', async (context) => { | ||
| const { chat } = context; | ||
|
|
||
| const room = await getRandomRoom(chat); | ||
|
|
||
| // Attach the room | ||
| await room.attach(); | ||
|
|
||
| // Send a message from first client | ||
| const message1 = await room.messages.send({ text: 'Hello there!' }); | ||
|
|
||
| // Subscribe to reactions and add them to a list when they arrive | ||
| const found: MessageReactionSummaryEvent[] = []; | ||
|
|
||
| room.messages.reactions.subscribe((event) => { | ||
| found.push(event); | ||
| }); | ||
|
|
||
| // Create second client | ||
| const client2 = newChatClient(); | ||
| const room2 = await client2.rooms.get(room.roomId); | ||
| await room2.attach(); | ||
|
|
||
| // Second client adds two distinct reactions | ||
| await room2.messages.reactions.add(message1, { type: MessageReactionType.Distinct, name: '👍' }); | ||
|
Check failure on line 412 in test/core/messages-reactions.integration.test.ts
|
||
| await room2.messages.reactions.add(message1, { type: MessageReactionType.Distinct, name: '❤️' }); | ||
|
|
||
| // Wait for first two summaries (after adding reactions) | ||
| await vi.waitFor( | ||
| () => { | ||
| expect(found.length).toBeGreaterThanOrEqual(2); | ||
|
|
||
| // Check first summary (after adding 👍) | ||
| const firstSummary = found.find((e) => | ||
| e.summary.messageSerial === message1.serial && | ||
| e.summary.distinct?.['👍'] && | ||
| !e.summary.distinct?.['❤️'] | ||
| ); | ||
| expect(firstSummary).toMatchObject({ | ||
| type: MessageReactionEvents.Summary, | ||
|
Check failure on line 427 in test/core/messages-reactions.integration.test.ts
|
||
| summary: { | ||
| messageSerial: message1.serial, | ||
| distinct: { | ||
| '👍': { | ||
| total: 1, | ||
| clientIds: [client2.clientId], | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| // Check second summary (after adding ❤️) | ||
| const secondSummary = found.find((e) => | ||
| e.summary.messageSerial === message1.serial && | ||
| e.summary.distinct?.['👍'] && | ||
| e.summary.distinct?.['❤️'] | ||
| ); | ||
| expect(secondSummary).toMatchObject({ | ||
| type: MessageReactionEvents.Summary, | ||
| summary: { | ||
| messageSerial: message1.serial, | ||
| distinct: { | ||
| '👍': { | ||
| total: 1, | ||
| clientIds: [client2.clientId], | ||
| }, | ||
| '❤️': { | ||
| total: 1, | ||
| clientIds: [client2.clientId], | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
| }, | ||
| { timeout: 30_000 }, | ||
| ); | ||
|
|
||
| // Second client deletes both reactions | ||
| await room2.messages.reactions.delete(message1, { type: MessageReactionType.Distinct, name: '👍' }); | ||
| await room2.messages.reactions.delete(message1, { type: MessageReactionType.Distinct, name: '❤️' }); | ||
|
|
||
| // Wait for all 4 summaries | ||
| await vi.waitFor( | ||
| () => { | ||
| expect(found.length).toBeGreaterThanOrEqual(4); | ||
|
|
||
| // Check third summary (after deleting 👍) | ||
| const thirdSummary = found.find((e) => | ||
| e.summary.messageSerial === message1.serial && | ||
| !e.summary.distinct?.['👍'] && | ||
| e.summary.distinct?.['❤️'] | ||
| ); | ||
| expect(thirdSummary).toMatchObject({ | ||
| type: MessageReactionEvents.Summary, | ||
| summary: { | ||
| messageSerial: message1.serial, | ||
| distinct: { | ||
| '❤️': { | ||
| total: 1, | ||
| clientIds: [client2.clientId], | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| // Check fourth summary (after deleting ❤️ - should be empty or not have these reactions) | ||
| const fourthSummary = found.findLast((e) => e.summary.messageSerial === message1.serial); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the third one is not at index 2 (third in list), you'll find the third one here. Would it be better to just findIndex the third one, and get the other index for the fourth one? We're talking about indexes 2 and 3 for those checks, or 0 and 1 if you clear the found array. I guess the same logic for finding the summaries in the list can be done for the first two as well? |
||
| expect(fourthSummary).toMatchObject({ | ||
| type: MessageReactionEvents.Summary, | ||
| summary: { | ||
| messageSerial: message1.serial, | ||
| distinct: {}, | ||
| }, | ||
| }); | ||
| }, | ||
| { timeout: 30_000 }, | ||
| ); | ||
|
|
||
| void room.detach(); | ||
| void room2.detach(); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be a good idea to clear the
foundarray here?