Skip to content

Commit

Permalink
fix up the testing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Sep 27, 2024
1 parent 3ccc716 commit 4fd09a0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
14 changes: 7 additions & 7 deletions example/src/tests/groupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Platform } from 'expo-modules-core'
import RNFS from 'react-native-fs'
import { DecodedMessage } from 'xmtp-react-native-sdk/lib/DecodedMessage'

import { Test, assert, createClients, delayToPropogate } from './test-utils'
import { Test, assert, createClients, createGroups, delayToPropogate } from './test-utils'

Check warning on line 6 in example/src/tests/groupTests.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `·Test,·assert,·createClients,·createGroups,·delayToPropogate·` with `⏎··Test,⏎··assert,⏎··createClients,⏎··createGroups,⏎··delayToPropogate,⏎`
import {
Client,
Conversation,
Expand Down Expand Up @@ -927,7 +927,7 @@ test('can cancel streams', async () => {

assert(
messageCallbacks === 1,
'message stream should have received 1 message'
`message stream should have received 1 message but recieved ${messageCallbacks}`
)

await bo.conversations.cancelStreamAllMessages()
Expand All @@ -941,19 +941,19 @@ test('can cancel streams', async () => {

assert(
messageCallbacks === 1,
'message stream should still only received 1 message'
`message stream should still only received 1 message but recieved ${messageCallbacks}`
)

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

await group.send('hello')
await delayToPropogate()
await delayToPropogate(10000)

assert(
messageCallbacks === 2,
'message stream should have received 2 message'
`message stream should have received 2 message but recieved ${messageCallbacks}`
)

return true
Expand Down Expand Up @@ -2171,7 +2171,7 @@ test('can create new installation without breaking group', async () => {

test('can list many groups members in parallel', async () => {
const [alix, bo] = await createClients(2)
const groups: Group[] = await createGroups(alix, [bo], 20, 0)
const groups: Group[] = await createGroups(alix, [bo], 20)

try {
await Promise.all(groups.slice(0, 10).map((g) => g.membersList()))
Expand All @@ -2190,7 +2190,7 @@ test('can list many groups members in parallel', async () => {

test('can sync all groups', async () => {
const [alix, bo] = await createClients(2)
const groups: Group[] = await createGroups(alix, [bo], 50, 0)
const groups: Group[] = await createGroups(alix, [bo], 50)

const alixGroup = groups[0]
await bo.conversations.syncGroups()
Expand Down
20 changes: 19 additions & 1 deletion example/src/tests/test-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Platform } from 'expo-modules-core'
import { Client, GroupUpdatedCodec } from 'xmtp-react-native-sdk'
import { Client, GroupUpdatedCodec, Group } from 'xmtp-react-native-sdk'

export type Test = {
name: string
Expand Down Expand Up @@ -65,3 +65,21 @@ export async function createV3TestingClients(): Promise<Client[]> {
clients.push(alix, bo, caro)
return clients
}

export async function createGroups(
client: Client,
peers: Client[],
numGroups: number
): Promise<Group[]> {
const groups = []
const addresses: string[] = peers.map((client) => client.address)
for (let i = 0; i < numGroups; i++) {
const group = await client.conversations.newGroup(addresses, {
name: `group ${i}`,
imageUrlSquare: `www.group${i}.com`,
description: `group ${i}`,
})
groups.push(group)
}
return groups
}

0 comments on commit 4fd09a0

Please sign in to comment.