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

Fix group streaming #409

Closed
wants to merge 2 commits into from
Closed
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
54 changes: 52 additions & 2 deletions example/src/tests/groupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,46 @@ test('can remove and add members from a group by inbox id', async () => {
return true
})

test('stream groups and all messages', async () => {
const [alixClient, boClient] = await createClients(2)
console.log('Created clients')

const aliceGroups = await alixClient.conversations.listGroups()
console.log('Listed groups')
assert(aliceGroups.length === 0, 'alice should have no groups')

let groupCallbacks = 0
let messageCallbacks = 0

await alixClient.conversations.streamGroups(async () => {
groupCallbacks++
})

await alixClient.conversations.streamAllMessages(async () => {
messageCallbacks++
}, true)

console.log('setup streams')

await delayToPropogate()

const group = await boClient.conversations.newGroup([alixClient.address])
await group.send('hello')

console.log('created group')
assert(group instanceof Group, 'group should be a Group')

await delayToPropogate()

assert(groupCallbacks === 1, 'group stream should have received 1 group')
assert(
messageCallbacks === 1,
'message stream should have received 1 message'
)

return true
})

test('can stream groups', async () => {
const [alixClient, boClient, caroClient] = await createClients(3)

Expand Down Expand Up @@ -718,6 +758,16 @@ test('can stream groups', async () => {
throw Error('Expected group length 3 but it is: ' + groups.length)
}

// bo creates a group with caro and then adds alix so a stream callback is fired
const boCaroGroup = await boClient.conversations.newGroup([
caroClient.address,
])
await boCaroGroup.addMembers([alixClient.address])
await delayToPropogate()
if ((groups.length as number) !== 4) {
throw Error('Unexpected num groups (should be 4): ' + groups.length)
}

cancelStreamGroups()
await delayToPropogate()

Expand All @@ -727,8 +777,8 @@ test('can stream groups', async () => {
alixClient.address,
])
await delayToPropogate()
if ((groups.length as number) !== 3) {
throw Error('Unexpected num groups (should be 3): ' + groups.length)
if ((groups.length as number) !== 4) {
throw Error('Unexpected num groups (should be 4): ' + groups.length)
}

return true
Expand Down
Loading