Skip to content

Commit

Permalink
add mapper for E2EIConversationState
Browse files Browse the repository at this point in the history
  • Loading branch information
mchenani committed Oct 20, 2023
1 parent 39e3792 commit 7ea780b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.wire.kalium.logic.data.conversation

import com.wire.kalium.cryptography.E2EIConversationState
import com.wire.kalium.logic.data.connection.ConnectionStatusMapper
import com.wire.kalium.logic.data.id.IdMapper
import com.wire.kalium.logic.data.id.NetworkQualifiedId
Expand Down Expand Up @@ -545,3 +546,9 @@ internal fun Protocol.toModel(): Conversation.Protocol = when (this) {
Protocol.MIXED -> Conversation.Protocol.MIXED
Protocol.MLS -> Conversation.Protocol.MLS
}

internal fun E2EIConversationState.toModel(): Conversation.VerificationStatus = when (this) {
E2EIConversationState.VERIFIED -> Conversation.VerificationStatus.VERIFIED
E2EIConversationState.NOT_VERIFIED -> Conversation.VerificationStatus.NOT_VERIFIED
E2EIConversationState.NOT_ENABLED -> Conversation.VerificationStatus.NOT_VERIFIED
}
Original file line number Diff line number Diff line change
Expand Up @@ -513,13 +513,7 @@ internal class MLSConversationDataSource(
override suspend fun getConversationVerificationStatus(groupID: GroupID): Either<CoreFailure, Conversation.VerificationStatus> =
mlsClientProvider.getMLSClient().flatMap { mlsClient ->
wrapMLSRequest { mlsClient.isGroupVerified(idMapper.toCryptoModel(groupID)) }
}.map {
when (it) {
E2EIConversationState.VERIFIED -> Conversation.VerificationStatus.VERIFIED
E2EIConversationState.NOT_VERIFIED -> Conversation.VerificationStatus.NOT_VERIFIED
E2EIConversationState.NOT_ENABLED -> Conversation.VerificationStatus.NOT_VERIFIED
}
}
}.map { it.toModel() }

private suspend fun retryOnCommitFailure(
groupID: GroupID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,24 @@ class MLSConversationRepositoryTest {
.wasInvoked(once)
}

@Test
fun givenNotEnabledE2EIForConversation_whenGetGroupVerify_thenNotVerifiedReturned() = runTest {
val (arrangement, mlsConversationRepository) = Arrangement()
.withGetMLSClientSuccessful()
.withGetGroupVerifyReturn(E2EIConversationState.NOT_ENABLED)
.arrange()

assertEquals(
Either.Right(Conversation.VerificationStatus.NOT_VERIFIED),
mlsConversationRepository.getConversationVerificationStatus(Arrangement.GROUP_ID)
)

verify(arrangement.mlsClient)
.suspendFunction(arrangement.mlsClient::isGroupVerified)
.with(any())
.wasInvoked(once)
}

@Test
fun givenNoMLSClient_whenGetGroupVerify_thenErrorReturned() = runTest {
val failure = CoreFailure.Unknown(RuntimeException("Error!"))
Expand Down

0 comments on commit 7ea780b

Please sign in to comment.