Skip to content
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

Test streaming group messages from self #293

Draft
wants to merge 1 commit into
base: beta
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading