diff --git a/example/src/tests/groupTests.ts b/example/src/tests/groupTests.ts index 939b03209..1756c733f 100644 --- a/example/src/tests/groupTests.ts +++ b/example/src/tests/groupTests.ts @@ -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( + '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, @@ -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) diff --git a/src/index.ts b/src/index.ts index 9d1b8e6f3..96ad52471 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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) } diff --git a/src/lib/Client.ts b/src/lib/Client.ts index a675772d6..1143fd67e 100644 --- a/src/lib/Client.ts +++ b/src/lib/Client.ts @@ -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) } /**