Skip to content

Commit

Permalink
Merge branch 'develop' into chore/gh-workflow-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Garzas authored Jun 27, 2024
2 parents 0aa1265 + 853e76f commit 5d6589c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5d6589c

Please sign in to comment.