Skip to content

Commit

Permalink
chore: use selfTeamIdProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
ohassine committed Nov 21, 2024
1 parent 646017f commit 953dfc9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1890,6 +1890,7 @@ class UserSessionScope internal constructor(
certificateRevocationListRepository,
incrementalSyncRepository,
sessionManager,
selfTeamId,
checkRevocationList,
syncFeatureConfigsUseCase,
userScopedLogger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
package com.wire.kalium.logic.feature.personaltoteamaccount

import com.wire.kalium.logic.configuration.server.ServerConfigRepository
import com.wire.kalium.logic.data.user.UserRepository
import com.wire.kalium.logic.data.id.SelfTeamIdProvider
import com.wire.kalium.logic.functional.fold
import com.wire.kalium.network.session.SessionManager

/**
Expand All @@ -35,11 +36,14 @@ interface CanMigrateFromPersonalToTeamUseCase {
internal class CanMigrateFromPersonalToTeamUseCaseImpl(
val sessionManager: SessionManager,
val serverConfigRepository: ServerConfigRepository,
val userRepository: UserRepository
val selfTeamIdProvider: SelfTeamIdProvider
) : CanMigrateFromPersonalToTeamUseCase {
override suspend fun invoke(): Boolean {
val commonApiVersion = sessionManager.serverConfig().metaData.commonApiVersion.version
val minApi = serverConfigRepository.minimumApiVersionForPersonalToTeamAccountMigration
return userRepository.getSelfUser()?.teamId == null && commonApiVersion >= minApi
return selfTeamIdProvider().fold(
{ false },
{ teamId -> teamId == null && commonApiVersion >= minApi }
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.wire.kalium.logic.data.e2ei.CertificateRevocationListRepository
import com.wire.kalium.logic.data.e2ei.E2EIRepository
import com.wire.kalium.logic.data.e2ei.RevocationListChecker
import com.wire.kalium.logic.data.id.CurrentClientIdProvider
import com.wire.kalium.logic.data.id.SelfTeamIdProvider
import com.wire.kalium.logic.data.properties.UserPropertyRepository
import com.wire.kalium.logic.data.session.SessionRepository
import com.wire.kalium.logic.data.sync.IncrementalSyncRepository
Expand Down Expand Up @@ -113,6 +114,7 @@ class UserScope internal constructor(
private val certificateRevocationListRepository: CertificateRevocationListRepository,
private val incrementalSyncRepository: IncrementalSyncRepository,
private val sessionManager: SessionManager,
private val selfTeamIdProvider: SelfTeamIdProvider,
private val checkRevocationList: RevocationListChecker,
private val syncFeatureConfigs: SyncFeatureConfigsUseCase,
private val userScopedLogger: KaliumLogger
Expand Down Expand Up @@ -232,7 +234,7 @@ class UserScope internal constructor(
CanMigrateFromPersonalToTeamUseCaseImpl(
sessionManager = sessionManager,
serverConfigRepository = serverConfigRepository,
userRepository = userRepository
selfTeamIdProvider = selfTeamIdProvider
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
*/
package com.wire.kalium.logic.feature.personaltoteamaccount

import com.wire.kalium.logic.CoreFailure
import com.wire.kalium.logic.configuration.server.ServerConfigRepository
import com.wire.kalium.logic.data.id.SelfTeamIdProvider
import com.wire.kalium.logic.data.id.TeamId
import com.wire.kalium.logic.data.user.UserRepository
import com.wire.kalium.logic.framework.TestUser
import com.wire.kalium.logic.functional.Either
import com.wire.kalium.network.api.unbound.configuration.ApiVersionDTO
import com.wire.kalium.network.session.SessionManager
import com.wire.kalium.network.utils.TestRequestHandler.Companion.TEST_BACKEND_CONFIG
import io.mockative.Mock
import io.mockative.coEvery
import io.mockative.every
import io.mockative.mock
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import kotlin.test.Test
import kotlin.test.assertFalse
Expand All @@ -39,9 +39,9 @@ class CanMigrateFromPersonalToTeamUseCaseTest {
@Test
fun givenAPIVersionBelowMinimumAndUserNotInATeam_whenInvoking_thenReturnsFalse() = runTest {
// Given
val (arrangement, useCase) = Arrangement()
val (_, useCase) = Arrangement()
.withRepositoryReturningMinimumApiVersion()
.withTeamId(null)
.withTeamId(Either.Right(null))
.withServerConfig(6)
.arrange()

Expand All @@ -54,12 +54,12 @@ class CanMigrateFromPersonalToTeamUseCaseTest {

@Test
fun givenAPIVersionEqualToMinimumAndUserNotInATeam_whenInvoking_thenReturnsTrue() =
runBlocking {
runTest {
// Given
val (arrangement, useCase) = Arrangement()
val (_, useCase) = Arrangement()
.withRepositoryReturningMinimumApiVersion()
.withServerConfig(7)
.withTeamId(null)
.withTeamId(Either.Right(null))
.arrange()

// When
Expand All @@ -70,11 +70,28 @@ class CanMigrateFromPersonalToTeamUseCaseTest {
}

@Test
fun givenAPIVersionAboveMinimumAndUserInATeam_whenInvoking_thenReturnsFalse() = runBlocking {
fun givenAPIVersionAboveMinimumAndUserInATeam_whenInvoking_thenReturnsFalse() = runTest {
// Given
val (arrangement, useCase) = Arrangement()
val (_, useCase) = Arrangement()
.withRepositoryReturningMinimumApiVersion()
.withTeamId(TeamId("teamId"))
.withTeamId(Either.Right(TeamId("teamId")))
.withServerConfig(9)
.arrange()

// When
val result = useCase.invoke()

// Then
assertFalse(result)
}


@Test
fun givenSelfTeamIdProviderFailure_whenInvoking_thenReturnsFalse() = runTest {
// Given
val (_, useCase) = Arrangement()
.withRepositoryReturningMinimumApiVersion()
.withTeamId(Either.Left(CoreFailure.MissingClientRegistration))
.withServerConfig(9)
.arrange()

Expand All @@ -94,12 +111,12 @@ class CanMigrateFromPersonalToTeamUseCaseTest {
val sessionManager = mock(SessionManager::class)

@Mock
val userRepository = mock(UserRepository::class)
val selfTeamIdProvider = mock(SelfTeamIdProvider::class)

suspend fun withTeamId(result: TeamId?) = apply {
suspend fun withTeamId(result: Either<CoreFailure, TeamId?>) = apply {
coEvery {
userRepository.getSelfUser()
}.returns(TestUser.SELF.copy(teamId = result))
selfTeamIdProvider()
}.returns(result)
}

fun withRepositoryReturningMinimumApiVersion() = apply {
Expand All @@ -122,7 +139,7 @@ class CanMigrateFromPersonalToTeamUseCaseTest {
fun arrange() = this to CanMigrateFromPersonalToTeamUseCaseImpl(
sessionManager = sessionManager,
serverConfigRepository = serverConfigRepository,
userRepository = userRepository
selfTeamIdProvider = selfTeamIdProvider
)
}

Expand Down

0 comments on commit 953dfc9

Please sign in to comment.