Skip to content

Commit

Permalink
add tests for dropping the database
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed May 30, 2024
1 parent 404d7be commit 3542e80
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
61 changes: 61 additions & 0 deletions example/src/tests/groupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,33 @@ test('can delete a local database', async () => {
return true
})

test('can drop a local database', async () => {
const [client, anotherClient] = await createClients(2)

const group = await client.conversations.newGroup([anotherClient.address])
await client.conversations.syncGroups()
assert(
(await client.conversations.listGroups()).length === 1,
`should have a group size of 1 but was ${
(await client.conversations.listGroups()).length
}`
)

await client.dropLocalDatabaseConnection()

try {
await group.send('hi')
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (error) {
await client.reconnectLocalDatabase()
await group.send('hi')
return true
}
throw new Error(

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

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎····'should·throw·when·local·database·not·connected'⏎··` with `'should·throw·when·local·database·not·connected'`
'should throw when local database not connected'
)
})

test('can make a MLS V3 client from bundle', async () => {
const key = new Uint8Array([
233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64,
Expand Down Expand Up @@ -510,6 +537,40 @@ test('can remove members from a group', async () => {
return true
})

test('can remove and add members from a group by inbox id', async () => {
// Create three MLS enabled Clients
const [alixClient, boClient, caroClient] = await createClients(3)

// alix creates a group
const alixGroup = await alixClient.conversations.newGroup([
boClient.address,
caroClient.address,
])

// alix can confirm memberInboxIds
await alixGroup.sync()
const memberInboxIds = await alixGroup.memberInboxIds()
if (memberInboxIds.length !== 3) {
throw new Error('num group members should be 3')
}

await alixGroup.removeMembersByInboxId([caroClient.inboxId])
await alixGroup.sync()
const alixGroupMembers = await alixGroup.memberInboxIds()
if (alixGroupMembers.length !== 2) {
throw new Error('num group members should be 2')
}

await alixGroup.addMembersByInboxId([caroClient.inboxId])
await alixGroup.sync()
const alixGroupMembers2 = await alixGroup.memberInboxIds()
if (alixGroupMembers2.length !== 3) {
throw new Error('num group members should be 3')
}

return true
})

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

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function deleteLocalDatabase(address: string) {
return XMTPModule.deleteLocalDatabase(address)
}

export function dropLocalDatabaseConnection(address: string) {
export async function dropLocalDatabaseConnection(address: string) {
return XMTPModule.dropLocalDatabaseConnection(address)
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ export class Client<
/**
* Drop the local database connection. This function is delicate and should be used with caution. App will error if database not properly reconnected. See: reconnectLocalDatabase()
*/
dropLocalDatabaseConnection() {
return XMTPModule.dropLocalDatabaseConnection(this.address)
async dropLocalDatabaseConnection() {
return await XMTPModule.dropLocalDatabaseConnection(this.address)
}

/**
Expand Down

0 comments on commit 3542e80

Please sign in to comment.