Skip to content

Commit

Permalink
Added test for streaming group msg from self
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronvoell committed Mar 7, 2024
1 parent c6d0be1 commit befbb92
Showing 1 changed file with 56 additions and 20 deletions.
76 changes: 56 additions & 20 deletions example/src/tests/groupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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) {
Expand Down

0 comments on commit befbb92

Please sign in to comment.