From 853e76f2b3797856d88182fb5d44e1b2de1e3b44 Mon Sep 17 00:00:00 2001 From: Alexandre Ferris Date: Thu, 27 Jun 2024 12:13:31 +0200 Subject: [PATCH] fix: end call update status (WPB-9878) (#2844) * fix: add call status for incoming and outgoing * fix: add tests for ending a call when its incoming or outgoing --- .../feature/call/usecase/EndCallUseCase.kt | 8 ++- .../call/usecase/EndCallUseCaseTest.kt | 51 +++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) 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