Skip to content

Commit

Permalink
Add a test in dev env for streaming groups and messages at the same time
Browse files Browse the repository at this point in the history
  • Loading branch information
nmalzieu committed Sep 12, 2024
1 parent 5a0c1ca commit 20b7962
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
29 changes: 29 additions & 0 deletions example/src/tests/groupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,35 @@ test('can stream all groups and conversations', async () => {
return true
})

test('can stream groups and messages', async () => {
for (const env of ['local', 'dev'] as const) {
const [alixClient, boClient] = await createClients(2, env)

// Start streaming groups
const groups: Group<any>[] = []
await alixClient.conversations.streamGroups(async (group: Group<any>) => {
groups.push(group)
})
// Also stream messages
await alixClient.conversations.streamAllMessages(
async (message) => {},
true
)

// bo creates a group with alix so a stream callback is fired
// eslint-disable-next-line @typescript-eslint/no-unused-vars
await boClient.conversations.newGroup([alixClient.address])
await delayToPropogate()
if ((groups.length as number) !== 1) {
throw Error(
`Test fails in env ${env}: Unexpected num groups (should be 1): ${groups.length}`
)
}
}

return true
})

test('canMessage', async () => {
const [bo, alix, caro] = await createClients(3)

Expand Down
7 changes: 5 additions & 2 deletions example/src/tests/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ export function assert(condition: boolean, msg: string) {
}
}

export async function createClients(numClients: number): Promise<Client[]> {
export async function createClients(
numClients: number,
env: 'dev' | 'local' | 'production' = 'local'
): Promise<Client[]> {
const clients = []
for (let i = 0; i < numClients; i++) {
const keyBytes = new Uint8Array([
Expand All @@ -30,7 +33,7 @@ export async function createClients(numClients: number): Promise<Client[]> {
145,
])
const client = await Client.createRandom({
env: 'local',
env,
enableV3: true,
dbEncryptionKey: keyBytes,
})
Expand Down

0 comments on commit 20b7962

Please sign in to comment.