Skip to content

Commit

Permalink
Added converting to Group and Conversation to test
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronvoell committed Feb 14, 2024
1 parent b9b6d36 commit c9bbb45
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions example/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
RemoteAttachmentContent,
Group,
} from '../../src/index'
import { DefaultContentTypes } from 'xmtp-react-native-sdk/lib/types/DefaultContentType'

Check warning on line 17 in example/src/tests.ts

View workflow job for this annotation

GitHub Actions / lint

`xmtp-react-native-sdk/lib/types/DefaultContentType` import should occur before import of `../../src/index`

Check warning on line 17 in example/src/tests.ts

View workflow job for this annotation

GitHub Actions / lint

'DefaultContentTypes' is defined but never used

type EncodedContent = content.EncodedContent
type ContentTypeId = content.ContentTypeId
Expand Down Expand Up @@ -579,7 +580,7 @@ test('can stream groups', async () => {
return true
})

test('can stream groups and conversations', async () => {
test('can stream all groups and conversations', async () => {
// Create three MLS enabled Clients
const aliceClient = await Client.createRandom({
env: 'local',
Expand All @@ -594,20 +595,25 @@ test('can stream groups and conversations', async () => {
enableAlphaMls: true,
})

// Start streaming groups
const groups: ConversationContainer<any>[] = []
// Start streaming groups and conversations
const containers: ConversationContainer<any>[] = []
const cancelStreamAll = await aliceClient.conversations.streamAll(
async (conversationContainer: ConversationContainer<any>) => {
groups.push(conversationContainer)
containers.push(conversationContainer)
}
)

// Cam creates a group with Alice, so stream callback is fired
// Bob creates a group with Alice, so stream callback is fired
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const camGroup = await camClient.conversations.newGroup([aliceClient.address])
const bobGroup = await bobClient.conversations.newGroup([aliceClient.address])
await delayToPropogate()
if ((groups.length as number) !== 1) {
throw Error('Unexpected num groups (should be 1): ' + groups.length)
if ((containers.length as number) !== 1) {
throw Error('Unexpected num groups (should be 1): ' + containers.length)
}
if (containers[0].isGroup()) {
(containers[0] as Group).sync()

Check warning on line 614 in example/src/tests.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `;`
} else {
throw Error('Unexpected first ConversationContainer should be a group')
}

// Bob creates a v2 Conversation with Alice so a stream callback is fired
Expand All @@ -616,8 +622,12 @@ test('can stream groups and conversations', async () => {
aliceClient.address
)
await delayToPropogate()
if ((groups.length as number) !== 2) {
throw Error('Unexpected num groups (should be 2): ' + groups.length)
if ((containers.length as number) !== 2) {
throw Error('Unexpected num groups (should be 2): ' + containers.length)
}

if(bobConversation.conversationID != (containers[1] as Conversation<any>).conversationID) {

Check warning on line 629 in example/src/tests.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `(bobConversation.conversationID·!=·(containers[1]·as·Conversation<any>).conversationID` with `·(⏎····bobConversation.conversationID·!=⏎····(containers[1]·as·Conversation<any>).conversationID⏎··`

Check warning on line 629 in example/src/tests.ts

View workflow job for this annotation

GitHub Actions / lint

Expected '!==' and instead saw '!='
throw Error('Conversation from streamed all should match conversationID with created conversation')

Check warning on line 630 in example/src/tests.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `'Conversation·from·streamed·all·should·match·conversationID·with·created·conversation'` with `⏎······'Conversation·from·streamed·all·should·match·conversationID·with·created·conversation'⏎····`
}

// * Note Alice creating a v2 Conversation does trigger alice conversations
Expand All @@ -629,21 +639,21 @@ test('can stream groups and conversations', async () => {
camClient.address
)
await delayToPropogate()
if (groups.length !== 3) {
throw Error('Expected group length 3 but it is: ' + groups.length)
if (containers.length !== 3) {
throw Error('Expected group length 3 but it is: ' + containers.length)
}

cancelStreamAll()
await delayToPropogate()

// Creating a group should no longer trigger stream groups
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const camSecond = await camClient.conversations.newGroup([
const camConversation = await camClient.conversations.newGroup([
aliceClient.address,
])
await delayToPropogate()
if ((groups.length as number) !== 3) {
throw Error('Unexpected num groups (should be 3): ' + groups.length)
if ((containers.length as number) !== 3) {
throw Error('Unexpected num groups (should be 3): ' + containers.length)
}

return true
Expand Down

0 comments on commit c9bbb45

Please sign in to comment.