Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JcMinarro committed Dec 11, 2024
1 parent 73b5e24 commit 37572d9
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import io.getstream.chat.android.models.Message
import io.getstream.chat.android.test.TestCall
import io.getstream.chat.android.test.TestCoroutineRule
import io.getstream.chat.android.test.callFrom
import io.getstream.chat.android.ui.common.model.MessageResult
import io.getstream.result.Error
import io.getstream.result.Result
import io.getstream.result.call.Call
Expand Down Expand Up @@ -80,6 +81,7 @@ internal class PinnedMessageListControllerTest {
// given
val pinnedMessages = generatePinnedMessages(count = 1)
val returnValue = callFrom { pinnedMessages }
val expectedResult = pinnedMessages.map { MessageResult(it, null) }
val controller = PinnedMessageListController(cid, mockChannelClient(returnValue))
// when
val loadingState = controller.state.value
Expand All @@ -93,14 +95,15 @@ internal class PinnedMessageListControllerTest {
// verify loaded state
loadedState.canLoadMore `should be equal to` false
loadedState.isLoading `should be equal to` false
loadedState.results `should be equal to` pinnedMessages
loadedState.results `should be equal to` expectedResult
}

@Test
fun `Given loading new messages When the call returns not all messages Then can load more`() = runTest {
// given
val pinnedMessages = generatePinnedMessages(count = 30)
val returnValue = callFrom { pinnedMessages }
val expectedResult = pinnedMessages.map { MessageResult(it, null) }
val controller = PinnedMessageListController(cid, mockChannelClient(returnValue))
// when
val loadingState = controller.state.value
Expand All @@ -114,14 +117,15 @@ internal class PinnedMessageListControllerTest {
// verify loaded state
loadedState.canLoadMore `should be equal to` true
loadedState.isLoading `should be equal to` false
loadedState.results `should be equal to` pinnedMessages
loadedState.results `should be equal to` expectedResult
}

@Test
fun `Given loading more messages When all messages are loaded Then call is ignored`() = runTest {
// given
val pinnedMessages = generatePinnedMessages(count = 1)
val returnValue = callFrom { pinnedMessages }
val expectedResult = pinnedMessages.map { MessageResult(it, null) }
val channelClient = mockChannelClient(returnValue)
val controller = PinnedMessageListController(cid, channelClient)
// when
Expand All @@ -132,7 +136,7 @@ internal class PinnedMessageListControllerTest {
// verify loaded state
loadedState.canLoadMore `should be equal to` false
loadedState.isLoading `should be equal to` false
loadedState.results `should be equal to` pinnedMessages
loadedState.results `should be equal to` expectedResult
// verify channelClient.getPinnedMessages was called only twice
verify(channelClient, times(1)).getPinnedMessages(any(), any(), any())
}
Expand Down

0 comments on commit 37572d9

Please sign in to comment.