Skip to content

Commit

Permalink
write a bunch of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Jan 17, 2025
1 parent 9de265c commit d89c4c8
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}
Expand Down
27 changes: 24 additions & 3 deletions library/src/androidTest/java/org/xmtp/android/library/DmTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
57 changes: 54 additions & 3 deletions library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit d89c4c8

Please sign in to comment.