|
| 1 | +package org.xmtp.android.library |
| 2 | + |
| 3 | +import androidx.test.ext.junit.runners.AndroidJUnit4 |
| 4 | +import org.junit.Assert.assertEquals |
| 5 | +import org.junit.Test |
| 6 | +import org.junit.runner.RunWith |
| 7 | +import org.xmtp.android.library.messages.walletAddress |
| 8 | +import uniffi.xmtp_dh.org.xmtp.android.library.codecs.ContentTypeGroupChatMemberAdded |
| 9 | +import uniffi.xmtp_dh.org.xmtp.android.library.codecs.ContentTypeGroupTitleChangedAdded |
| 10 | +import uniffi.xmtp_dh.org.xmtp.android.library.codecs.GroupChatMemberAdded |
| 11 | +import uniffi.xmtp_dh.org.xmtp.android.library.codecs.GroupChatTitleChanged |
| 12 | + |
| 13 | +@RunWith(AndroidJUnit4::class) |
| 14 | +class GroupChatTest { |
| 15 | + @Test |
| 16 | + fun testCanAddMemberToGroupChatCodec() { |
| 17 | + val fixtures = fixtures() |
| 18 | + val aliceClient = fixtures.aliceClient |
| 19 | + aliceClient.enableGroupChat() |
| 20 | + val aliceConversation = |
| 21 | + aliceClient.conversations.newConversation(fixtures.bob.walletAddress) |
| 22 | + |
| 23 | + val personAdded = GroupChatMemberAdded( |
| 24 | + member = fixtures.steve.walletAddress, |
| 25 | + ) |
| 26 | + |
| 27 | + aliceConversation.send( |
| 28 | + content = personAdded, |
| 29 | + options = SendOptions(contentType = ContentTypeGroupChatMemberAdded), |
| 30 | + ) |
| 31 | + val messages = aliceConversation.messages() |
| 32 | + assertEquals(messages.size, 1) |
| 33 | + val content: GroupChatMemberAdded? = messages[0].content() |
| 34 | + assertEquals(fixtures.steve.walletAddress, content?.member) |
| 35 | + } |
| 36 | + |
| 37 | + @Test |
| 38 | + fun testCanChangeGroupChatNameCodec() { |
| 39 | + val fixtures = fixtures() |
| 40 | + val aliceClient = fixtures.aliceClient |
| 41 | + aliceClient.enableGroupChat() |
| 42 | + val aliceConversation = |
| 43 | + aliceClient.conversations.newConversation(fixtures.bob.walletAddress) |
| 44 | + |
| 45 | + val titleChange = GroupChatTitleChanged( |
| 46 | + newTitle = "New Title", |
| 47 | + ) |
| 48 | + |
| 49 | + aliceConversation.send( |
| 50 | + content = titleChange, |
| 51 | + options = SendOptions(contentType = ContentTypeGroupTitleChangedAdded), |
| 52 | + ) |
| 53 | + val messages = aliceConversation.messages() |
| 54 | + assertEquals(messages.size, 1) |
| 55 | + val content: GroupChatTitleChanged? = messages[0].content() |
| 56 | + assertEquals("New Title", content?.newTitle) |
| 57 | + } |
| 58 | +} |
0 commit comments