Skip to content

Commit

Permalink
Fixed cherry-pick problems
Browse files Browse the repository at this point in the history
  • Loading branch information
borichellow committed Jul 17, 2024
1 parent 164f073 commit 1b5c41b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* along with this program. If not, see http://www.gnu.org/licenses/.
*/


package com.wire.kalium.logic.feature.client

import com.wire.kalium.logic.CoreFailure
Expand All @@ -32,13 +31,8 @@ import com.wire.kalium.logic.util.arrangement.usecase.RegisterMLSClientUseCaseAr
import com.wire.kalium.logic.util.arrangement.usecase.RegisterMLSClientUseCaseArrangementImpl
import com.wire.kalium.util.DelicateKaliumApi
import io.mockative.any
<<<<<<< HEAD
import io.mockative.coEvery
import io.mockative.coVerify
import io.mockative.mock
=======
import io.mockative.verify
>>>>>>> c7792e365a (fix: Stuck on Setting up Wire after canceling E2EI during login [WPB-10046] (#2882))
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import kotlin.test.Test
import kotlin.test.assertEquals
Expand Down Expand Up @@ -112,36 +106,23 @@ class VerifyExistingClientUseCaseTest {
}.wasNotInvoked()
}

private fun arrange(block: Arrangement.() -> Unit) = Arrangement(block).arrange()
private fun arrange(block: suspend Arrangement.() -> Unit) = Arrangement(block).arrange()

<<<<<<< HEAD
@Mock
val clientRepository = mock(ClientRepository::class)
=======
@OptIn(DelicateKaliumApi::class)
private class Arrangement(private val block: Arrangement.() -> Unit) :
private class Arrangement(private val block: suspend Arrangement.() -> Unit) :
RegisterMLSClientUseCaseArrangement by RegisterMLSClientUseCaseArrangementImpl(),
ClientRepositoryArrangement by ClientRepositoryArrangementImpl(),
IsAllowedToRegisterMLSClientUseCaseArrangement by IsAllowedToRegisterMLSClientUseCaseArrangementImpl() {
>>>>>>> c7792e365a (fix: Stuck on Setting up Wire after canceling E2EI during login [WPB-10046] (#2882))

fun arrange() = run {
block()
runBlocking { block() }

<<<<<<< HEAD
suspend fun withSelfClientsResult(result: Either<NetworkFailure, List<Client>>): Arrangement {
coEvery {
clientRepository.selfListOfClients()
}.returns(result)
return this
=======
this@Arrangement to VerifyExistingClientUseCaseImpl(
TestUser.USER_ID,
clientRepository,
isAllowedToRegisterMLSClientUseCase,
registerMLSClientUseCase
)
>>>>>>> c7792e365a (fix: Stuck on Setting up Wire after canceling E2EI during login [WPB-10046] (#2882))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import com.wire.kalium.logic.data.client.ClientRepository
import com.wire.kalium.logic.data.client.OtherUserClient
import com.wire.kalium.logic.data.conversation.ClientId
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.feature.client.VerifyExistingClientUseCaseTest
import com.wire.kalium.logic.functional.Either
import com.wire.kalium.persistence.dao.client.InsertClientParam
import io.mockative.Mock
Expand All @@ -46,35 +45,23 @@ internal interface ClientRepositoryArrangement {
redundantClientsOfUsers: Matcher<Map<UserId, List<ClientId>>> = AnyMatcher(valueOf())
)

<<<<<<< HEAD
suspend fun withStoreUserClientIdList(
=======
fun withStoreUserClientIdList(
>>>>>>> c7792e365a (fix: Stuck on Setting up Wire after canceling E2EI during login [WPB-10046] (#2882))
result: Either<StorageFailure, Unit>,
userId: Matcher<UserId> = AnyMatcher(valueOf()),
clientIds: Matcher<List<ClientId>> = AnyMatcher(valueOf())
)

<<<<<<< HEAD
suspend fun withStoreMapOfUserToClientId(
=======
fun withStoreMapOfUserToClientId(
>>>>>>> c7792e365a (fix: Stuck on Setting up Wire after canceling E2EI during login [WPB-10046] (#2882))
result: Either<StorageFailure, Unit>,
mapUserToClientId: Matcher<Map<UserId, List<ClientId>>> = AnyMatcher(valueOf())
)

<<<<<<< HEAD
suspend fun withStoreUserClientListAndRemoveRedundantClients(
=======
fun withStoreUserClientListAndRemoveRedundantClients(
>>>>>>> c7792e365a (fix: Stuck on Setting up Wire after canceling E2EI during login [WPB-10046] (#2882))
result: Either<StorageFailure, Unit>,
clients: Matcher<List<InsertClientParam>> = AnyMatcher(valueOf())
)

fun withSelfClientsResult(result: Either<NetworkFailure, List<Client>>)
suspend fun withSelfClientsResult(result: Either<NetworkFailure, List<Client>>)
}

internal open class ClientRepositoryArrangementImpl : ClientRepositoryArrangement {
Expand All @@ -97,16 +84,9 @@ internal open class ClientRepositoryArrangementImpl : ClientRepositoryArrangemen
result: Either<StorageFailure, List<UserId>>,
redundantClientsOfUsers: Matcher<Map<UserId, List<ClientId>>>
) {
<<<<<<< HEAD
coEvery {
clientRepository.removeClientsAndReturnUsersWithNoClients(matches { redundantClientsOfUsers.matches(it) })
}.returns(result)
=======
given(clientRepository)
.suspendFunction(clientRepository::removeClientsAndReturnUsersWithNoClients)
.whenInvokedWith(redundantClientsOfUsers)
.thenReturn(result)
>>>>>>> c7792e365a (fix: Stuck on Setting up Wire after canceling E2EI during login [WPB-10046] (#2882))
}

override suspend fun withStoreUserClientIdList(
Expand Down Expand Up @@ -137,10 +117,7 @@ internal open class ClientRepositoryArrangementImpl : ClientRepositoryArrangemen
}.returns(result)
}

override fun withSelfClientsResult(result: Either<NetworkFailure, List<Client>>) {
given(clientRepository)
.suspendFunction(clientRepository::selfListOfClients)
.whenInvoked()
.thenReturn(result)
override suspend fun withSelfClientsResult(result: Either<NetworkFailure, List<Client>>) {
coEvery { clientRepository.selfListOfClients() }.returns(result)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,24 @@ package com.wire.kalium.logic.util.arrangement.usecase

import com.wire.kalium.logic.feature.client.IsAllowedToRegisterMLSClientUseCase
import com.wire.kalium.util.DelicateKaliumApi
import io.mockative.given
import io.mockative.coEvery
import io.mockative.mock

@OptIn(DelicateKaliumApi::class)
interface IsAllowedToRegisterMLSClientUseCaseArrangement {

val isAllowedToRegisterMLSClientUseCase: IsAllowedToRegisterMLSClientUseCase

fun withIsAllowedToRegisterMLSClient(isAllowed: Boolean)
suspend fun withIsAllowedToRegisterMLSClient(isAllowed: Boolean)
}

@OptIn(DelicateKaliumApi::class)
class IsAllowedToRegisterMLSClientUseCaseArrangementImpl : IsAllowedToRegisterMLSClientUseCaseArrangement {

override val isAllowedToRegisterMLSClientUseCase: IsAllowedToRegisterMLSClientUseCase = mock(IsAllowedToRegisterMLSClientUseCase::class)

override fun withIsAllowedToRegisterMLSClient(isAllowed: Boolean) {
given(isAllowedToRegisterMLSClientUseCase)
.suspendFunction(isAllowedToRegisterMLSClientUseCase::invoke)
.whenInvoked()
.thenReturn(isAllowed)
override suspend fun withIsAllowedToRegisterMLSClient(isAllowed: Boolean) {
coEvery { isAllowedToRegisterMLSClientUseCase() }.returns(isAllowed)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,21 @@ import com.wire.kalium.logic.feature.client.RegisterMLSClientResult
import com.wire.kalium.logic.feature.client.RegisterMLSClientUseCase
import com.wire.kalium.logic.functional.Either
import io.mockative.any
import io.mockative.given
import io.mockative.coEvery
import io.mockative.mock

interface RegisterMLSClientUseCaseArrangement {

val registerMLSClientUseCase: RegisterMLSClientUseCase

fun withRegisterMLSClient(result: Either<CoreFailure, RegisterMLSClientResult>)
suspend fun withRegisterMLSClient(result: Either<CoreFailure, RegisterMLSClientResult>)
}

class RegisterMLSClientUseCaseArrangementImpl : RegisterMLSClientUseCaseArrangement {
override val registerMLSClientUseCase: RegisterMLSClientUseCase = mock(RegisterMLSClientUseCase::class)

override fun withRegisterMLSClient(result: Either<CoreFailure, RegisterMLSClientResult>) {
given(registerMLSClientUseCase)
.suspendFunction(registerMLSClientUseCase::invoke)
.whenInvokedWith(any())
.thenReturn(result)
override suspend fun withRegisterMLSClient(result: Either<CoreFailure, RegisterMLSClientResult>) {
coEvery { registerMLSClientUseCase(any()) }.returns(result)
}

}

0 comments on commit 1b5c41b

Please sign in to comment.