From d89c4c8cc1fbbf5df18dc449d34e6d6597a1da29 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Thu, 16 Jan 2025 20:45:27 -0800 Subject: [PATCH] write a bunch of tests --- .../xmtp/android/library/ConversationsTest.kt | 59 ++++++++++++++++--- .../java/org/xmtp/android/library/DmTest.kt | 27 ++++++++- .../android/library/GroupPermissionsTest.kt | 34 +++++++++++ .../org/xmtp/android/library/GroupTest.kt | 57 +++++++++++++++++- 4 files changed, 164 insertions(+), 13 deletions(-) diff --git a/library/src/androidTest/java/org/xmtp/android/library/ConversationsTest.kt b/library/src/androidTest/java/org/xmtp/android/library/ConversationsTest.kt index 78aab7c7..b7bf3353 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/ConversationsTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/ConversationsTest.kt @@ -78,18 +78,29 @@ class ConversationsTest { runBlocking { boClient.conversations.newGroup(listOf(caro.walletAddress)) } assertEquals(runBlocking { boClient.conversations.list().size }, 2) assertEquals( - runBlocking { boClient.conversations.list(consentState = ConsentState.ALLOWED).size }, + runBlocking { boClient.conversations.list(consentStates = listOf(ConsentState.ALLOWED)).size }, 2 ) runBlocking { group.updateConsentState(ConsentState.DENIED) } assertEquals( - runBlocking { boClient.conversations.list(consentState = ConsentState.ALLOWED).size }, + runBlocking { boClient.conversations.list(consentStates = listOf(ConsentState.ALLOWED)).size }, 1 ) assertEquals( - runBlocking { boClient.conversations.list(consentState = ConsentState.DENIED).size }, + runBlocking { boClient.conversations.list(consentStates = listOf(ConsentState.DENIED)).size }, 1 ) + assertEquals( + runBlocking { + boClient.conversations.list( + consentStates = listOf( + ConsentState.DENIED, + ConsentState.ALLOWED + ) + ).size + }, + 2 + ) assertEquals(runBlocking { boClient.conversations.list().size }, 2) } @@ -119,17 +130,51 @@ class ConversationsTest { runBlocking { boClient.conversations.newGroup(listOf(caro.walletAddress)) } assert(runBlocking { boClient.conversations.syncAllConversations() }.toInt() >= 2) assert( - runBlocking { boClient.conversations.syncAllConversations(consentState = ConsentState.ALLOWED) }.toInt() >= 2 + runBlocking { + boClient.conversations.syncAllConversations( + consentStates = listOf( + ConsentState.ALLOWED + ) + ) + }.toInt() >= 2 ) assert( - runBlocking { boClient.conversations.syncAllConversations(consentState = ConsentState.DENIED) }.toInt() <= 1 + runBlocking { + boClient.conversations.syncAllConversations( + consentStates = listOf( + ConsentState.DENIED + ) + ) + }.toInt() <= 1 ) runBlocking { group.updateConsentState(ConsentState.DENIED) } assert( - runBlocking { boClient.conversations.syncAllConversations(consentState = ConsentState.ALLOWED) }.toInt() <= 2 + runBlocking { + boClient.conversations.syncAllConversations( + consentStates = listOf( + ConsentState.ALLOWED + ) + ) + }.toInt() <= 2 + ) + assert( + runBlocking { + boClient.conversations.syncAllConversations( + consentStates = listOf( + ConsentState.DENIED + ) + ) + }.toInt() <= 2 ) assert( - runBlocking { boClient.conversations.syncAllConversations(consentState = ConsentState.DENIED) }.toInt() <= 2 + runBlocking { + boClient.conversations.syncAllConversations( + consentStates = listOf( + ConsentState.DENIED, + ConsentState.ALLOWED + ) + ) + }.toInt() >= 2 ) assert(runBlocking { boClient.conversations.syncAllConversations() }.toInt() >= 2) } diff --git a/library/src/androidTest/java/org/xmtp/android/library/DmTest.kt b/library/src/androidTest/java/org/xmtp/android/library/DmTest.kt index fac8b927..acbf1379 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/DmTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/DmTest.kt @@ -61,6 +61,16 @@ class DmTest { } } + @Test + fun testCanCreateADmWithInboxId() { + runBlocking { + val convo1 = boClient.conversations.findOrCreateDmWithInboxId(alixClient.inboxId) + alixClient.conversations.sync() + val sameConvo1 = alixClient.conversations.findOrCreateDmWithInboxId(boClient.inboxId) + assertEquals(convo1.id, sameConvo1.id) + } + } + @Test fun testsCanFindDmByInboxId() { runBlocking { @@ -156,18 +166,29 @@ class DmTest { val dm = runBlocking { boClient.conversations.findOrCreateDm(alix.walletAddress) } assertEquals(runBlocking { boClient.conversations.listDms().size }, 2) assertEquals( - runBlocking { boClient.conversations.listDms(consentState = ConsentState.ALLOWED).size }, + runBlocking { boClient.conversations.listDms(consentStates = listOf(ConsentState.ALLOWED)).size }, 2 ) runBlocking { dm.updateConsentState(ConsentState.DENIED) } assertEquals( - runBlocking { boClient.conversations.listDms(consentState = ConsentState.ALLOWED).size }, + runBlocking { boClient.conversations.listDms(consentStates = listOf(ConsentState.ALLOWED)).size }, 1 ) assertEquals( - runBlocking { boClient.conversations.listDms(consentState = ConsentState.DENIED).size }, + runBlocking { boClient.conversations.listDms(consentStates = listOf(ConsentState.DENIED)).size }, 1 ) + assertEquals( + runBlocking { + boClient.conversations.listDms( + consentStates = listOf( + ConsentState.ALLOWED, + ConsentState.DENIED + ) + ).size + }, + 2 + ) assertEquals(runBlocking { boClient.conversations.listDms().size }, 2) } diff --git a/library/src/androidTest/java/org/xmtp/android/library/GroupPermissionsTest.kt b/library/src/androidTest/java/org/xmtp/android/library/GroupPermissionsTest.kt index c2dbd17d..ede331f8 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/GroupPermissionsTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/GroupPermissionsTest.kt @@ -506,4 +506,38 @@ class GroupPermissionsTest { runBlocking { alixClient.conversations.sync() } assert(runBlocking { alixClient.conversations.listGroups() }.size == 1) } + + @Test + fun canCreateGroupWithInboxIdCustomPermissions() { + val permissionPolicySet = PermissionPolicySet( + addMemberPolicy = PermissionOption.Admin, + removeMemberPolicy = PermissionOption.Deny, + addAdminPolicy = PermissionOption.Admin, + removeAdminPolicy = PermissionOption.SuperAdmin, + updateGroupNamePolicy = PermissionOption.Admin, + updateGroupDescriptionPolicy = PermissionOption.Allow, + updateGroupImagePolicy = PermissionOption.Admin, + updateGroupPinnedFrameUrlPolicy = PermissionOption.Deny, + updateMessageExpirationPolicy = PermissionOption.Admin, + ) + val boGroup = runBlocking { + boClient.conversations.newGroupCustomPermissionsWithInboxId( + inboxIds = listOf(alixClient.inboxId, caroClient.inboxId), + permissionPolicySet = permissionPolicySet, + ) + } + runBlocking { alixClient.conversations.sync() } + val alixGroup = runBlocking { alixClient.conversations.listGroups().first() } + + // Verify permission look correct + val alixPermissionSet = alixGroup.permissionPolicySet() + assert(alixPermissionSet.addMemberPolicy == PermissionOption.Admin) + assert(alixPermissionSet.removeMemberPolicy == PermissionOption.Deny) + assert(alixPermissionSet.addAdminPolicy == PermissionOption.Admin) + assert(alixPermissionSet.removeAdminPolicy == PermissionOption.SuperAdmin) + assert(alixPermissionSet.updateGroupNamePolicy == PermissionOption.Admin) + assert(alixPermissionSet.updateGroupDescriptionPolicy == PermissionOption.Allow) + assert(alixPermissionSet.updateGroupImagePolicy == PermissionOption.Admin) + assert(alixPermissionSet.updateGroupPinnedFrameUrlPolicy == PermissionOption.Deny) + } } diff --git a/library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt b/library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt index a823fa1d..b3577a4f 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt @@ -164,6 +164,46 @@ class GroupTest { assert(!runBlocking { alixGroup.isCreator() }) } + @Test + fun testCanCreateAGroupWithInboxIdsDefaultPermissions() { + val boGroup = runBlocking { + boClient.conversations.newGroupWithInboxId(listOf(alixClient.inboxId)) + } + runBlocking { + alixClient.conversations.sync() + boGroup.sync() + } + val alixGroup = runBlocking { alixClient.conversations.listGroups().first() } + assert(boGroup.id.isNotEmpty()) + assert(alixGroup.id.isNotEmpty()) + + runBlocking { + alixGroup.addMembers(listOf(caro.walletAddress)) + boGroup.sync() + } + assertEquals(runBlocking { alixGroup.members().size }, 3) + assertEquals(runBlocking { boGroup.members().size }, 3) + + // All members also defaults remove to admin only now. + assertThrows(XMTPException::class.java) { + runBlocking { + alixGroup.removeMembers(listOf(caro.walletAddress)) + boGroup.sync() + } + } + + assertEquals(runBlocking { alixGroup.members().size }, 3) + assertEquals(runBlocking { boGroup.members().size }, 3) + + assertEquals(boGroup.permissionPolicySet().addMemberPolicy, PermissionOption.Allow) + assertEquals(alixGroup.permissionPolicySet().addMemberPolicy, PermissionOption.Allow) + assertEquals(boGroup.isSuperAdmin(boClient.inboxId), true) + assertEquals(boGroup.isSuperAdmin(alixClient.inboxId), false) + assertEquals(alixGroup.isSuperAdmin(boClient.inboxId), true) + assertEquals(alixGroup.isSuperAdmin(alixClient.inboxId), false) + assert(!runBlocking { alixGroup.isCreator() }) + } + @Test fun testCanListGroupMembers() { val group = runBlocking { @@ -488,18 +528,29 @@ class GroupTest { runBlocking { boClient.conversations.newGroup(listOf(caro.walletAddress)) } assertEquals(runBlocking { boClient.conversations.listGroups().size }, 2) assertEquals( - runBlocking { boClient.conversations.listGroups(consentState = ConsentState.ALLOWED).size }, + runBlocking { boClient.conversations.listGroups(consentStates = listOf(ConsentState.ALLOWED)).size }, 2 ) runBlocking { group.updateConsentState(ConsentState.DENIED) } assertEquals( - runBlocking { boClient.conversations.listGroups(consentState = ConsentState.ALLOWED).size }, + runBlocking { boClient.conversations.listGroups(consentStates = listOf(ConsentState.ALLOWED)).size }, 1 ) assertEquals( - runBlocking { boClient.conversations.listGroups(consentState = ConsentState.DENIED).size }, + runBlocking { boClient.conversations.listGroups(consentStates = listOf(ConsentState.DENIED)).size }, 1 ) + assertEquals( + runBlocking { + boClient.conversations.listGroups( + consentStates = listOf( + ConsentState.ALLOWED, + ConsentState.DENIED + ) + ).size + }, + 2 + ) assertEquals(runBlocking { boClient.conversations.listGroups().size }, 2) }