Skip to content

Commit

Permalink
get all the tests updated
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Nov 8, 2024
1 parent 35502e2 commit 2551baa
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class ClientTest {

runBlocking {
client.conversations.newGroup(listOf(client2.address))
client.conversations.syncConversations()
client.conversations.sync()
assertEquals(client.conversations.listGroups().size, 1)
}

Expand All @@ -116,7 +116,7 @@ class ClientTest {
)
}
runBlocking {
client.conversations.syncConversations()
client.conversations.sync()
assertEquals(client.conversations.listGroups().size, 0)
}
}
Expand Down Expand Up @@ -216,7 +216,7 @@ class ClientTest {

runBlocking {
boClient.conversations.newGroup(listOf(alixClient.address))
boClient.conversations.syncConversations()
boClient.conversations.sync()
}

runBlocking {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ConversationsTest {
assertEquals(runBlocking { boClient.conversations.listDms().size }, 1)
assertEquals(runBlocking { boClient.conversations.listGroups().size }, 1)

runBlocking { caroClient.conversations.syncConversations() }
runBlocking { caroClient.conversations.sync() }
assertEquals(
runBlocking { caroClient.conversations.list().size },
2
Expand Down Expand Up @@ -118,7 +118,7 @@ class ConversationsTest {
runBlocking { caroClient.conversations.newGroup(listOf(bo.walletAddress)) }
val conversation =
runBlocking { boClient.conversations.findOrCreateDm(caro.walletAddress) }
runBlocking { boClient.conversations.syncConversations() }
runBlocking { boClient.conversations.sync() }

val allMessages = mutableListOf<DecodedMessage>()

Expand Down Expand Up @@ -183,11 +183,13 @@ class ConversationsTest {
)
)
}
val dm = runBlocking { alixClient.conversations.findOrCreateDm(bo.walletAddress) }
runBlocking {
val dm =
alixClient.conversations.findOrCreateDm(bo.walletAddress)
assertEquals(dm.consentState(), ConsentState.ALLOWED)
dm.updateConsentState(ConsentState.DENIED)
assertEquals(dm.consentState(), ConsentState.DENIED)
boClient.conversations.sync()
}
val boDm = runBlocking { boClient.findConversation(dm.id) }
alixClient.dropLocalDatabaseConnection()
alixClient.deleteLocalDatabase()

Expand All @@ -206,25 +208,26 @@ class ConversationsTest {
assertEquals(state.installations.size, 2)

runBlocking {
alixClient2.conversations.syncConversations()
val dm2 =
alixClient2.conversations.findOrCreateDm(bo.walletAddress)
boClient.conversations.sync()
boDm?.sync()
alixClient2.conversations.sync()
val dm2 = alixClient2.findConversation(dm.id)!!
alixClient2.syncConsent()
assertEquals(dm2.consentState(), ConsentState.ALLOWED)
assertEquals(dm2.consentState(), ConsentState.DENIED)
alixClient2.preferences.consentList.setConsentState(
listOf(
ConsentListEntry(
dm2.id,
EntryType.CONVERSATION_ID,
ConsentState.DENIED
ConsentState.ALLOWED
)
)
)
assertEquals(
alixClient2.preferences.consentList.conversationState(dm2.id),
ConsentState.DENIED
ConsentState.ALLOWED
)
assertEquals(dm2.consentState(), ConsentState.DENIED)
assertEquals(dm2.consentState(), ConsentState.ALLOWED)
}
}
}
57 changes: 50 additions & 7 deletions library/src/androidTest/java/org/xmtp/android/library/DmTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.junit.Assert.assertThrows
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.xmtp.android.library.Conversations.ConversationType
import org.xmtp.android.library.codecs.ContentTypeReaction
import org.xmtp.android.library.codecs.Reaction
import org.xmtp.android.library.codecs.ReactionAction
Expand Down Expand Up @@ -52,7 +53,7 @@ class DmTest {
fun testCanCreateADm() {
runBlocking {
val convo1 = boClient.conversations.findOrCreateDm(alix.walletAddress)
alixClient.conversations.syncConversations()
alixClient.conversations.sync()
val sameConvo1 = alixClient.conversations.findOrCreateDm(bo.walletAddress)
assertEquals(convo1.id, sameConvo1.id)
}
Expand Down Expand Up @@ -119,6 +120,48 @@ class DmTest {
}
}

@Test
fun testsCanListDmsFiltered() {
runBlocking { boClient.conversations.findOrCreateDm(caro.walletAddress) }
runBlocking { boClient.conversations.newGroup(listOf(caro.walletAddress)) }
val dm = runBlocking { boClient.conversations.findOrCreateDm(alix.walletAddress) }
assertEquals(runBlocking { boClient.conversations.listDms().size }, 2)
assertEquals(
runBlocking { boClient.conversations.listDms(consentState = ConsentState.ALLOWED).size },
2
)
runBlocking { dm.updateConsentState(ConsentState.DENIED) }
assertEquals(
runBlocking { boClient.conversations.listDms(consentState = ConsentState.ALLOWED).size },
1
)
assertEquals(
runBlocking { boClient.conversations.listDms(consentState = ConsentState.DENIED).size },
1
)
assertEquals(runBlocking { boClient.conversations.listDms().size }, 2)
}

@Test
fun testCanListDmsOrder() {
val dm1 = runBlocking { boClient.conversations.findOrCreateDm(caro.walletAddress) }
val dm2 =
runBlocking { boClient.conversations.findOrCreateDm(alix.walletAddress) }
val group =
runBlocking { boClient.conversations.newGroup(listOf(caro.walletAddress)) }
runBlocking { dm2.send("Howdy") }
runBlocking { group.send("Howdy") }
runBlocking { boClient.conversations.syncAllConversations() }
val conversations = runBlocking { boClient.conversations.listDms() }
val conversationsOrdered =
runBlocking { boClient.conversations.listDms(order = Conversations.ConversationOrder.LAST_MESSAGE) }
assertEquals(conversations.size, 2)
assertEquals(conversationsOrdered.size, 2)
assertEquals(conversations.map { it.id }, listOf(dm1.id, dm2.id))
assertEquals(conversationsOrdered.map { it.id }, listOf(dm2.id, dm1.id))
}


@Test
fun testCanSendMessageToDm() {
val dm = runBlocking { boClient.conversations.findOrCreateDm(alix.walletAddress) }
Expand All @@ -130,7 +173,7 @@ class DmTest {
assertEquals(dm.messages().first().deliveryStatus, MessageDeliveryStatus.PUBLISHED)
assertEquals(dm.messages().size, 3)

runBlocking { alixClient.conversations.syncConversations() }
runBlocking { alixClient.conversations.sync() }
val sameDm = runBlocking { alixClient.conversations.listDms().last() }
runBlocking { sameDm.sync() }
assertEquals(sameDm.messages().size, 2)
Expand All @@ -152,7 +195,7 @@ class DmTest {
assertEquals(dm.messages(deliveryStatus = MessageDeliveryStatus.UNPUBLISHED).size, 0)
assertEquals(dm.messages(deliveryStatus = MessageDeliveryStatus.PUBLISHED).size, 3)

runBlocking { alixClient.conversations.syncConversations() }
runBlocking { alixClient.conversations.sync() }
val sameDm = runBlocking { alixClient.conversations.listDms().last() }
runBlocking { sameDm.sync() }
assertEquals(sameDm.messages(deliveryStatus = MessageDeliveryStatus.PUBLISHED).size, 2)
Expand Down Expand Up @@ -194,7 +237,7 @@ class DmTest {
@Test
fun testCanStreamDmMessages() = kotlinx.coroutines.test.runTest {
val group = boClient.conversations.findOrCreateDm(alix.walletAddress.lowercase())
alixClient.conversations.syncConversations()
alixClient.conversations.sync()
val alixDm = alixClient.findDm(bo.walletAddress)
group.streamMessages().test {
alixDm?.send("hi")
Expand All @@ -207,13 +250,13 @@ class DmTest {
@Test
fun testCanStreamAllMessages() {
val boDm = runBlocking { boClient.conversations.findOrCreateDm(alix.walletAddress) }
runBlocking { alixClient.conversations.syncConversations() }
runBlocking { alixClient.conversations.sync() }

val allMessages = mutableListOf<DecodedMessage>()

val job = CoroutineScope(Dispatchers.IO).launch {
try {
alixClient.conversations.streamAllMessages().collect { message ->
alixClient.conversations.streamAllMessages(type = ConversationType.DMS).collect { message ->
allMessages.add(message)
}
} catch (e: Exception) {
Expand Down Expand Up @@ -243,7 +286,7 @@ class DmTest {

@Test
fun testCanStreamConversations() = kotlinx.coroutines.test.runTest {
boClient.conversations.stream().test {
boClient.conversations.stream(type = ConversationType.DMS).test {
val dm =
alixClient.conversations.findOrCreateDm(bo.walletAddress)
assertEquals(dm.id, awaitItem().id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class GroupPermissionsTest {
@Test
fun testGroupCreatedWithCorrectAdminList() {
val boGroup = runBlocking { boClient.conversations.newGroup(listOf(alix.walletAddress)) }
runBlocking { alixClient.conversations.syncConversations() }
runBlocking { alixClient.conversations.sync() }
val alixGroup = runBlocking { alixClient.conversations.listGroups().first() }

assert(!boGroup.isAdmin(boClient.inboxId))
Expand All @@ -75,7 +75,7 @@ class GroupPermissionsTest {
@Test
fun testGroupCanUpdateAdminList() {
val boGroup = runBlocking { boClient.conversations.newGroup(listOf(alix.walletAddress, caro.walletAddress), GroupPermissionPreconfiguration.ADMIN_ONLY) }
runBlocking { alixClient.conversations.syncConversations() }
runBlocking { alixClient.conversations.sync() }
val alixGroup = runBlocking { alixClient.conversations.listGroups().first() }

assert(!boGroup.isAdmin(boClient.inboxId))
Expand Down Expand Up @@ -169,7 +169,7 @@ class GroupPermissionsTest {
@Test
fun testGroupCanUpdateSuperAdminList() {
val boGroup = runBlocking { boClient.conversations.newGroup(listOf(alix.walletAddress, caro.walletAddress), GroupPermissionPreconfiguration.ADMIN_ONLY) }
runBlocking { alixClient.conversations.syncConversations() }
runBlocking { alixClient.conversations.sync() }
val alixGroup = runBlocking { alixClient.conversations.listGroups().first() }

assert(boGroup.isSuperAdmin(boClient.inboxId))
Expand Down Expand Up @@ -210,7 +210,7 @@ class GroupPermissionsTest {
@Test
fun testGroupMembersAndPermissionLevel() {
val group = runBlocking { boClient.conversations.newGroup(listOf(alix.walletAddress, caro.walletAddress), GroupPermissionPreconfiguration.ADMIN_ONLY) }
runBlocking { alixClient.conversations.syncConversations() }
runBlocking { alixClient.conversations.sync() }
val alixGroup = runBlocking { alixClient.conversations.listGroups().first() }

// Initial checks for group members and their permissions
Expand Down Expand Up @@ -259,7 +259,7 @@ class GroupPermissionsTest {
@Test
fun testCanCommitAfterInvalidPermissionsCommit() {
val boGroup = runBlocking { boClient.conversations.newGroup(listOf(alix.walletAddress, caro.walletAddress), GroupPermissionPreconfiguration.ALL_MEMBERS) }
runBlocking { alixClient.conversations.syncConversations() }
runBlocking { alixClient.conversations.sync() }
val alixGroup = runBlocking { alixClient.conversations.listGroups().first() }

// Verify that alix can NOT add an admin
Expand Down Expand Up @@ -290,7 +290,7 @@ class GroupPermissionsTest {
@Test
fun testCanUpdatePermissions() {
val boGroup = runBlocking { boClient.conversations.newGroup(listOf(alix.walletAddress, caro.walletAddress), GroupPermissionPreconfiguration.ADMIN_ONLY) }
runBlocking { alixClient.conversations.syncConversations() }
runBlocking { alixClient.conversations.sync() }
val alixGroup = runBlocking { alixClient.conversations.listGroups().first() }

// Verify that alix can NOT update group name
Expand Down Expand Up @@ -328,7 +328,7 @@ class GroupPermissionsTest {
@Test
fun testCanUpdatePinnedFrameUrl() {
val boGroup = runBlocking { boClient.conversations.newGroup(listOf(alix.walletAddress, caro.walletAddress), GroupPermissionPreconfiguration.ADMIN_ONLY) }
runBlocking { alixClient.conversations.syncConversations() }
runBlocking { alixClient.conversations.sync() }
val alixGroup = runBlocking { alixClient.conversations.listGroups().first() }

// Verify that alix can NOT update pinned frame
Expand Down Expand Up @@ -381,7 +381,7 @@ class GroupPermissionsTest {
permissionPolicySet = permissionPolicySet,
)
}
runBlocking { alixClient.conversations.syncConversations() }
runBlocking { alixClient.conversations.sync() }
val alixGroup = runBlocking { alixClient.conversations.listGroups().first() }

// Verify permission look correct
Expand Down Expand Up @@ -431,7 +431,7 @@ class GroupPermissionsTest {
)

// Valid custom policy works as expected
runBlocking { alixClient.conversations.syncConversations() }
runBlocking { alixClient.conversations.sync() }
assert(runBlocking { alixClient.conversations.listGroups() }.isEmpty())

val boGroup = runBlocking {
Expand All @@ -440,7 +440,7 @@ class GroupPermissionsTest {
permissionPolicySet = permissionPolicySetValid,
)
}
runBlocking { alixClient.conversations.syncConversations() }
runBlocking { alixClient.conversations.sync() }
assert(runBlocking { alixClient.conversations.listGroups() }.size == 1)
}
}
Loading

0 comments on commit 2551baa

Please sign in to comment.