Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return all incoming calls [WPB-10430] #3068

Open
wants to merge 2 commits into
base: release/candidate
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading