From befbb92b80503b18d1e22668e9769f2d36103b53 Mon Sep 17 00:00:00 2001 From: cameronvoell Date: Thu, 7 Mar 2024 07:30:42 -0800 Subject: [PATCH] Added test for streaming group msg from self --- example/src/tests/groupTests.ts | 76 ++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 20 deletions(-) diff --git a/example/src/tests/groupTests.ts b/example/src/tests/groupTests.ts index ca1d1fb26..9371e7b1f 100644 --- a/example/src/tests/groupTests.ts +++ b/example/src/tests/groupTests.ts @@ -744,44 +744,80 @@ test('canMessage', async () => { test('can stream group messages', async () => { // Create three MLS enabled Clients - const aliceClient = await Client.createRandom({ - env: 'local', - enableAlphaMls: true, - }) - const bobClient = await Client.createRandom({ - env: 'local', - enableAlphaMls: true, - }) - const camClient = await Client.createRandom({ - env: 'local', - enableAlphaMls: true, - }) + const [alix, bo, caro] = await createClients(3) // Alice creates a group - const aliceGroup = await aliceClient.conversations.newGroup([ - bobClient.address, - camClient.address, + const alixGroup = await alix.conversations.newGroup([ + bo.address, + caro.address, ]) // Record message stream for this group const groupMessages: DecodedMessage[] = [] - const cancelGroupMessageStream = await aliceGroup.streamGroupMessages( + const cancelGroupMessageStream = await alixGroup.streamGroupMessages( async (message) => { groupMessages.push(message) } ) // Bob's num groups == 1 - const bobGroup = (await bobClient.conversations.listGroups())[0] - + const boGroup = (await bo.conversations.listGroups())[0] for (let i = 0; i < 5; i++) { - await bobGroup.send({ text: `Message ${i}` }) + await boGroup.send({ text: `Message ${i}` }) await delayToPropogate() } + if (groupMessages.length !== 5) { + throw Error('Unexpected group messages count ' + groupMessages.length) + } + for (let i = 0; i < 5; i++) { + if (groupMessages[i].content() !== `Message ${i}`) { + throw Error( + 'Unexpected group message content ' + groupMessages[i].content() + ) + } + } + + cancelGroupMessageStream() + for (let i = 0; i < 5; i++) { + await boGroup.send({ text: `Message ${i}` }) + } + if (groupMessages.length !== 5) { throw Error('Unexpected convo messages count ' + groupMessages.length) } + + return true +}) + +test('can stream group messages from self', async () => { + // Create three MLS enabled Clients + const [alix, bo, caro] = await createClients(3) + + // Alice creates a group + const alixGroup = await alix.conversations.newGroup([ + bo.address, + caro.address, + ]) + + // Record message stream for this group + const groupMessages: DecodedMessage[] = [] + const cancelGroupMessageStream = await alixGroup.streamGroupMessages( + async (message) => { + groupMessages.push(message) + } + ) + + for (let i = 0; i < 5; i++) { + await alixGroup.send({ text: `Message ${i}` }) + await delayToPropogate(200) + } + + await delayToPropogate(1000) + + if (groupMessages.length !== 5) { + throw Error('Unexpected group messages count ' + groupMessages.length) + } for (let i = 0; i < 5; i++) { if (groupMessages[i].content() !== `Message ${i}`) { throw Error( @@ -792,7 +828,7 @@ test('can stream group messages', async () => { cancelGroupMessageStream() for (let i = 0; i < 5; i++) { - await bobGroup.send({ text: `Message ${i}` }) + await alixGroup.send({ text: `Message ${i}` }) } if (groupMessages.length !== 5) {