From d1d696e28df5591b9a99d0b4c6e1c3fbe44d211c Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Fri, 15 Nov 2024 10:44:44 -0800 Subject: [PATCH] update to account for additional sync group in sync --- example/src/tests/conversationTests.ts | 83 -------------------------- example/src/tests/groupTests.ts | 22 ++++--- 2 files changed, 13 insertions(+), 92 deletions(-) diff --git a/example/src/tests/conversationTests.ts b/example/src/tests/conversationTests.ts index 057bd49c..34ff5231 100644 --- a/example/src/tests/conversationTests.ts +++ b/example/src/tests/conversationTests.ts @@ -1,14 +1,10 @@ -import RNFS from 'react-native-fs' import { Test, assert, createClients, delayToPropogate } from './test-utils' import { - Client, - ConsentListEntry, Conversation, ConversationId, ConversationVersion, } from '../../../src/index' -import { Wallet } from 'ethers' export const conversationTests: Test[] = [] let counter = 1 @@ -552,82 +548,3 @@ test('can streamAllMessages from multiple clients - swapped', async () => { return true }) - -test('can sync consent', async () => { - const [bo] = await createClients(1) - const keyBytes = new Uint8Array([ - 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, - 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, - ]) - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const dbDirPath = `${RNFS.DocumentDirectoryPath}/xmtp_db` - const dbDirPath2 = `${RNFS.DocumentDirectoryPath}/xmtp_db2` - const directoryExists = await RNFS.exists(dbDirPath) - if (!directoryExists) { - await RNFS.mkdir(dbDirPath) - } - const directoryExists2 = await RNFS.exists(dbDirPath2) - if (!directoryExists2) { - await RNFS.mkdir(dbDirPath2) - } - const alixWallet = Wallet.createRandom() - - const alix = await Client.create(alixWallet, { - env: 'local', - appVersion: 'Testing/0.0.0', - dbEncryptionKey: keyBytes, - dbDirectory: dbDirPath, - }) - - // Create DM conversation - const dm = await alix.conversations.findOrCreateDm(bo.address) - await dm.updateConsent('denied') - const consentState = await dm.consentState() - assert(consentState === 'denied', `Expected 'denied', got ${consentState}`) - - await bo.conversations.sync() - const boDm = await bo.conversations.findConversation(dm.id) - - const alix2 = await Client.create(alixWallet, { - env: 'local', - appVersion: 'Testing/0.0.0', - dbEncryptionKey: keyBytes, - dbDirectory: dbDirPath2, - }) - - const state = await alix2.inboxState(true) - assert( - state.installations.length === 2, - `Expected 2 installations, got ${state.installations.length}` - ) - - // Sync conversations - await bo.conversations.sync() - if (boDm) await boDm.sync() - await alix.conversations.sync() - await alix2.conversations.sync() - await alix2.preferences.syncConsent() - await alix.conversations.syncAllConversations() - await delayToPropogate(2000) - await alix2.conversations.syncAllConversations() - await delayToPropogate(2000) - - const dm2 = await alix2.conversations.findConversation(dm.id) - const consentState2 = await dm2?.consentState() - assert(consentState2 === 'denied', `Expected 'denied', got ${consentState2}`) - - await alix2.preferences.setConsentState( - new ConsentListEntry(dm2!.id, 'conversation_id', 'allowed') - ) - - const convoState = await alix2.preferences.conversationConsentState(dm2!.id) - assert(convoState === 'allowed', `Expected 'allowed', got ${convoState}`) - - const updatedConsentState = await dm2?.consentState() - assert( - updatedConsentState === 'allowed', - `Expected 'allowed', got ${updatedConsentState}` - ) - - return true -}) diff --git a/example/src/tests/groupTests.ts b/example/src/tests/groupTests.ts index 517e2f0d..e8b04e71 100644 --- a/example/src/tests/groupTests.ts +++ b/example/src/tests/groupTests.ts @@ -1,5 +1,4 @@ import { Wallet } from 'ethers' -import { DecodedMessage } from 'xmtp-react-native-sdk/lib/DecodedMessage' import { Test, @@ -15,6 +14,7 @@ import { GroupUpdatedContent, GroupUpdatedCodec, ConsentListEntry, + DecodedMessage, } from '../../../src/index' export const groupTests: Test[] = [] @@ -751,13 +751,17 @@ test('can list groups with params', async () => { assert( boGroupsOrderCreated.map((group: any) => group.id).toString() === [boGroup1.id, boGroup2.id].toString(), - `Group order should be group1 then group2 but was ${boGroupsOrderCreated.map((group: any) => group.id).toString()}` + `Group order should be group1 then group2 but was ${boGroupsOrderCreated + .map((group: any) => group.id) + .toString()}` ) assert( boGroupsOrderLastMessage.map((group: any) => group.id).toString() === [boGroup2.id, boGroup1.id].toString(), - `Group order should be group2 then group1 but was ${boGroupsOrderLastMessage.map((group: any) => group.id).toString()}` + `Group order should be group2 then group1 but was ${boGroupsOrderLastMessage + .map((group: any) => group.id) + .toString()}` ) const messages = await boGroupsOrderLastMessage[0].messages() @@ -1502,8 +1506,8 @@ test('can sync all groups', async () => { `messages should be 4 after sync but was ${boGroup?.messages?.length}` ) assert( - numGroupsSynced === 50, - `should have synced 50 groups but synced ${numGroupsSynced}` + numGroupsSynced === 51, + `should have synced 51 groups but synced ${numGroupsSynced}` ) for (const group of groups) { @@ -1513,15 +1517,15 @@ test('can sync all groups', async () => { // First syncAllConversations after removal will still sync each group to set group inactive const numGroupsSynced2 = await bo.conversations.syncAllConversations() assert( - numGroupsSynced2 === 50, - `should have synced 50 groups but synced ${numGroupsSynced2}` + numGroupsSynced2 === 51, + `should have synced 51 groups but synced ${numGroupsSynced2}` ) // Next syncAllConversations will not sync inactive groups const numGroupsSynced3 = await bo.conversations.syncAllConversations() assert( - numGroupsSynced3 === 0, - `should have synced 0 groups but synced ${numGroupsSynced3}` + numGroupsSynced3 === 1, + `should have synced 1 groups but synced ${numGroupsSynced3}` ) return true })