From 08870c1d037801b6c1baaa847c8603ffc7d6982a Mon Sep 17 00:00:00 2001 From: cameronvoell Date: Wed, 28 Feb 2024 10:06:30 -0700 Subject: [PATCH] Added test for streaming group msg from self --- example/src/tests/groupTests.ts | 78 ++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 21 deletions(-) diff --git a/example/src/tests/groupTests.ts b/example/src/tests/groupTests.ts index f583ff873..dafc0bf61 100644 --- a/example/src/tests/groupTests.ts +++ b/example/src/tests/groupTests.ts @@ -1,7 +1,7 @@ import RNFS from 'react-native-fs' import { DecodedMessage } from 'xmtp-react-native-sdk/lib/DecodedMessage' -import { Test, assert, delayToPropogate, isIos } from './test-utils' +import { Test, assert, createClients, delayToPropogate, isIos } from './test-utils' import { Client, Conversation, @@ -686,44 +686,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( @@ -734,7 +770,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) {