diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/call/usecase/EndCallUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/call/usecase/EndCallUseCase.kt index dca2a094f4e..e8e7541a317 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/call/usecase/EndCallUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/call/usecase/EndCallUseCase.kt @@ -55,8 +55,12 @@ internal class EndCallUseCaseImpl( override suspend operator fun invoke(conversationId: ConversationId) = withContext(dispatchers.default) { callRepository.callsFlow().first().find { // This use case can be invoked while joining the call or when the call is established. - it.conversationId == conversationId && - (it.status == CallStatus.STILL_ONGOING || it.status == CallStatus.ESTABLISHED) + it.conversationId == conversationId && it.status in listOf( + CallStatus.STARTED, + CallStatus.INCOMING, + CallStatus.STILL_ONGOING, + CallStatus.ESTABLISHED + ) }?.let { if (it.conversationType == Conversation.Type.GROUP) { callingLogger.d("[EndCallUseCase] -> Updating call status to CLOSED_INTERNALLY") diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/call/usecase/EndCallUseCaseTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/call/usecase/EndCallUseCaseTest.kt index 0c9c0407476..3e3d10c7c28 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/call/usecase/EndCallUseCaseTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/call/usecase/EndCallUseCaseTest.kt @@ -108,7 +108,58 @@ class EndCallUseCaseTest { coVerify { callRepository.updateCallStatusById(eq(conversationId), eq(CallStatus.CLOSED_INTERNALLY)) }.wasInvoked(once) + } + + @Test + fun givenStartedOutgoingCall_whenEndCallIsInvoked_thenUpdateStatusAndInvokeEndCallOnce() = runTest(TestKaliumDispatcher.main) { + val stillOngoingCall = call.copy( + status = CallStatus.STARTED, + conversationType = Conversation.Type.GROUP + ) + + coEvery { + callRepository.callsFlow() + }.returns(flowOf(listOf(stillOngoingCall))) + + endCall.invoke(conversationId) + coVerify { + callManager.endCall(eq(conversationId)) + }.wasInvoked(once) + + verify { + callRepository.updateIsCameraOnById(eq(conversationId), eq(false)) + }.wasInvoked(once) + + coVerify { + callRepository.updateCallStatusById(eq(conversationId), eq(CallStatus.CLOSED_INTERNALLY)) + }.wasInvoked(once) + } + + @Test + fun givenIncomingCall_whenEndCallIsInvoked_thenUpdateStatusAndInvokeEndCallOnce() = runTest(TestKaliumDispatcher.main) { + val stillOngoingCall = call.copy( + status = CallStatus.INCOMING, + conversationType = Conversation.Type.GROUP + ) + + coEvery { + callRepository.callsFlow() + }.returns(flowOf(listOf(stillOngoingCall))) + + endCall.invoke(conversationId) + + coVerify { + callManager.endCall(eq(conversationId)) + }.wasInvoked(once) + + verify { + callRepository.updateIsCameraOnById(eq(conversationId), eq(false)) + }.wasInvoked(once) + + coVerify { + callRepository.updateCallStatusById(eq(conversationId), eq(CallStatus.CLOSED_INTERNALLY)) + }.wasInvoked(once) } @Test