Skip to content

Commit

Permalink
fix: return all incoming calls [WPB-10430] 🍒 (#3073)
Browse files Browse the repository at this point in the history
* fix: return all incoming calls [WPB-10430] (#3068)

* fix: return all incoming calls [WPB-10430]

* add test

* trigger build

---------

Co-authored-by: Michał Saleniuk <[email protected]>
Co-authored-by: Michał Saleniuk <[email protected]>
  • Loading branch information
3 people authored Oct 24, 2024
1 parent 2ddb183 commit ebcf95a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ internal class GetIncomingCallsUseCaseImpl internal constructor(
val callIds = calls.map { call -> call.conversationId }.joinToString()
logger.d("$TAG; Found calls: $callIds")
}
.distinctUntilChanged { old, new ->
old.firstOrNull()?.conversationId == new.firstOrNull()?.conversationId
}
.distinctUntilChanged()
}

private fun Flow<List<Call>>.onlyCallsInNotMutedConversations(): Flow<List<Call>> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import io.mockative.Mock
import io.mockative.any
import io.mockative.coEvery
import io.mockative.mock
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.runTest
Expand Down Expand Up @@ -74,6 +75,31 @@ class GetIncomingCallsUseCaseTest {
}
}

@Test
fun givenIncomingCall_whenInvokingGetIncomingCallsUseCaseAndAnotherCallAppears_thenPropagateUpdatedList() = runTest {
val incomingCallsFlow = MutableStateFlow(listOf(incomingCall(0)))
val (_, getIncomingCalls) = Arrangement()
.withSelfUserStatus(UserAvailabilityStatus.AVAILABLE)
.withConversationDetails { id -> Either.Right(conversationWithMuteStatus(id, MutedConversationStatus.AllAllowed)) }
.withIncomingCallsFlow(incomingCallsFlow)
.arrange()

getIncomingCalls().test {
// initially there is only one incoming call
awaitItem().let {
assertEquals(1, it.size)
assertEquals(TestConversation.id(0), it[0].conversationId)
}
// then new incoming call appears
incomingCallsFlow.value = listOf(incomingCall(0), incomingCall(1))
awaitItem().let {
assertEquals(2, it.size)
assertEquals(TestConversation.id(0), it[0].conversationId)
assertEquals(TestConversation.id(1), it[1].conversationId)
}
}
}

@Test
fun givenUserWithAwayStatus_whenIncomingCallComes_thenNoCallsPropagated() = runTest {
val (_, getIncomingCalls) = Arrangement()
Expand Down Expand Up @@ -198,6 +224,12 @@ class GetIncomingCallsUseCaseTest {
return this
}

suspend fun withIncomingCallsFlow(callsFlow: Flow<List<Call>>): Arrangement = apply {
coEvery {
callRepository.incomingCallsFlow()
}.returns(callsFlow)
}

suspend fun withSelfUserStatus(status: UserAvailabilityStatus): Arrangement {
coEvery {
userRepository.observeSelfUser()
Expand Down

0 comments on commit ebcf95a

Please sign in to comment.