Updated on 2026-08-14
This commit is contained in:
parent
4c8af6b8e9
commit
1472431435
54 changed files with 370 additions and 352 deletions
|
|
@ -5,6 +5,7 @@ import arrow.core.getOrElse
|
|||
import com.tangem.domain.account.featuretoggle.AccountsFeatureToggles
|
||||
import com.tangem.domain.account.repository.AccountsCRUDRepository
|
||||
import com.tangem.domain.common.wallets.UserWalletsListRepository
|
||||
import com.tangem.domain.common.wallets.loadAndGet
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.domain.models.wallet.isMultiCurrency
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import com.tangem.domain.models.wallet.UserWallet
|
|||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.domain.models.wallet.isMultiCurrency
|
||||
import io.mockk.*
|
||||
import kotlinx.coroutines.flow.emptyFlow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
|
|
@ -25,7 +25,7 @@ import org.junit.jupiter.api.TestInstance
|
|||
class IsAccountsModeEnabledUseCaseTest {
|
||||
|
||||
private val accountsCRUDRepository: AccountsCRUDRepository = mockk()
|
||||
private val userWalletsListRepository: UserWalletsListRepository = mockk()
|
||||
private val userWalletsListRepository: UserWalletsListRepository = mockk(relaxUnitFun = true)
|
||||
private val featureToggles: AccountsFeatureToggles = mockk()
|
||||
|
||||
private val useCase = IsAccountsModeEnabledUseCase(
|
||||
|
|
@ -55,27 +55,10 @@ class IsAccountsModeEnabledUseCaseTest {
|
|||
Truth.assertThat(actual).isFalse()
|
||||
|
||||
verify(exactly = 1) { featureToggles.isFeatureEnabled }
|
||||
verify(inverse = true) { userWalletsListRepository.loadAndGet() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `returns false when loadAndGet emits empty flow`() = runTest {
|
||||
// Arrange
|
||||
every { featureToggles.isFeatureEnabled } returns true
|
||||
every { userWalletsListRepository.loadAndGet() } returns emptyFlow()
|
||||
|
||||
// Act
|
||||
val actual = useCase.invoke().firstOrNull()
|
||||
|
||||
// Assert
|
||||
Truth.assertThat(actual).isFalse()
|
||||
|
||||
verifyOrder {
|
||||
featureToggles.isFeatureEnabled
|
||||
userWalletsListRepository.loadAndGet()
|
||||
coVerify(inverse = true) {
|
||||
userWalletsListRepository.load()
|
||||
userWalletsListRepository.userWallets
|
||||
}
|
||||
|
||||
verify(inverse = true) { accountsCRUDRepository.getTotalActiveAccountsCount(any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -84,7 +67,7 @@ class IsAccountsModeEnabledUseCaseTest {
|
|||
val wallet = createUserWallet(isMultiCurrency = false)
|
||||
|
||||
every { featureToggles.isFeatureEnabled } returns true
|
||||
every { userWalletsListRepository.loadAndGet() } returns flowOf(listOf(wallet))
|
||||
every { userWalletsListRepository.userWallets } returns MutableStateFlow(listOf(wallet))
|
||||
|
||||
// Act
|
||||
val actual = useCase.invoke().first()
|
||||
|
|
@ -92,9 +75,10 @@ class IsAccountsModeEnabledUseCaseTest {
|
|||
// Assert
|
||||
Truth.assertThat(actual).isFalse()
|
||||
|
||||
verifyOrder {
|
||||
coVerifyOrder {
|
||||
featureToggles.isFeatureEnabled
|
||||
userWalletsListRepository.loadAndGet()
|
||||
userWalletsListRepository.load()
|
||||
userWalletsListRepository.userWallets
|
||||
}
|
||||
|
||||
verify(inverse = true) { accountsCRUDRepository.getTotalActiveAccountsCount(any()) }
|
||||
|
|
@ -106,7 +90,7 @@ class IsAccountsModeEnabledUseCaseTest {
|
|||
val wallet = createUserWallet(isMultiCurrency = true)
|
||||
|
||||
every { featureToggles.isFeatureEnabled } returns true
|
||||
every { userWalletsListRepository.loadAndGet() } returns flowOf(listOf(wallet))
|
||||
every { userWalletsListRepository.userWallets } returns MutableStateFlow(listOf(wallet))
|
||||
every { accountsCRUDRepository.getTotalActiveAccountsCount(wallet.walletId) } returns flowOf(2.some())
|
||||
|
||||
// Act
|
||||
|
|
@ -115,9 +99,10 @@ class IsAccountsModeEnabledUseCaseTest {
|
|||
// Assert
|
||||
Truth.assertThat(actual).isTrue()
|
||||
|
||||
verifyOrder {
|
||||
coVerifyOrder {
|
||||
featureToggles.isFeatureEnabled
|
||||
userWalletsListRepository.loadAndGet()
|
||||
userWalletsListRepository.load()
|
||||
userWalletsListRepository.userWallets
|
||||
accountsCRUDRepository.getTotalActiveAccountsCount(wallet.walletId)
|
||||
}
|
||||
}
|
||||
|
|
@ -128,7 +113,7 @@ class IsAccountsModeEnabledUseCaseTest {
|
|||
val wallet = createUserWallet(isMultiCurrency = true)
|
||||
|
||||
every { featureToggles.isFeatureEnabled } returns true
|
||||
every { userWalletsListRepository.loadAndGet() } returns flowOf(listOf(wallet))
|
||||
every { userWalletsListRepository.userWallets } returns MutableStateFlow(listOf(wallet))
|
||||
every { accountsCRUDRepository.getTotalActiveAccountsCount(wallet.walletId) } returns flowOf(none())
|
||||
|
||||
// Act
|
||||
|
|
@ -137,9 +122,10 @@ class IsAccountsModeEnabledUseCaseTest {
|
|||
// Assert
|
||||
Truth.assertThat(actual).isFalse()
|
||||
|
||||
verifyOrder {
|
||||
coVerifyOrder {
|
||||
featureToggles.isFeatureEnabled
|
||||
userWalletsListRepository.loadAndGet()
|
||||
userWalletsListRepository.load()
|
||||
userWalletsListRepository.userWallets
|
||||
accountsCRUDRepository.getTotalActiveAccountsCount(wallet.walletId)
|
||||
}
|
||||
}
|
||||
|
|
@ -151,7 +137,7 @@ class IsAccountsModeEnabledUseCaseTest {
|
|||
val wallet2 = createUserWallet(isMultiCurrency = true)
|
||||
|
||||
every { featureToggles.isFeatureEnabled } returns true
|
||||
every { userWalletsListRepository.loadAndGet() } returns flowOf(listOf(wallet1, wallet2))
|
||||
every { userWalletsListRepository.userWallets } returns MutableStateFlow(listOf(wallet1, wallet2))
|
||||
every { accountsCRUDRepository.getTotalActiveAccountsCount(wallet2.walletId) } returns flowOf(2.some())
|
||||
|
||||
// Act
|
||||
|
|
@ -160,9 +146,10 @@ class IsAccountsModeEnabledUseCaseTest {
|
|||
// Assert
|
||||
Truth.assertThat(actual).isTrue()
|
||||
|
||||
verifyOrder {
|
||||
coVerifyOrder {
|
||||
featureToggles.isFeatureEnabled
|
||||
userWalletsListRepository.loadAndGet()
|
||||
userWalletsListRepository.load()
|
||||
userWalletsListRepository.userWallets
|
||||
accountsCRUDRepository.getTotalActiveAccountsCount(wallet2.walletId)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import arrow.core.some
|
|||
import com.tangem.domain.account.models.AccountStatusList
|
||||
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
|
||||
import com.tangem.domain.common.wallets.UserWalletsListRepository
|
||||
import com.tangem.domain.common.wallets.loadAndGet
|
||||
import com.tangem.domain.core.flow.FlowProducerTools
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import dagger.assisted.Assisted
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import com.tangem.domain.account.models.AccountList
|
|||
import com.tangem.domain.account.models.AccountStatusList
|
||||
import com.tangem.domain.account.supplier.SingleAccountListSupplier
|
||||
import com.tangem.domain.common.wallets.UserWalletsListRepository
|
||||
import com.tangem.domain.common.wallets.getSyncStrict
|
||||
import com.tangem.domain.core.flow.FlowProducerTools
|
||||
import com.tangem.domain.core.utils.lceContent
|
||||
import com.tangem.domain.core.utils.lceLoading
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.tangem.domain.account.status.producer.SingleAccountStatusListProducer
|
|||
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
|
||||
import com.tangem.domain.account.status.utils.AccountCryptoCurrencyStatusFinder
|
||||
import com.tangem.domain.common.wallets.UserWalletsListRepository
|
||||
import com.tangem.domain.common.wallets.getSyncStrict
|
||||
import com.tangem.domain.models.account.AccountId
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.tokens.GetCryptoCurrencyActionsUseCase
|
||||
|
|
|
|||
|
|
@ -9,7 +9,10 @@ import com.tangem.domain.models.wallet.UserWallet
|
|||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.test.core.getEmittedValues
|
||||
import com.tangem.utils.coroutines.TestingCoroutineDispatcherProvider
|
||||
import io.mockk.*
|
||||
import io.mockk.clearMocks
|
||||
import io.mockk.coVerifySequence
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.test.runTest
|
||||
|
|
@ -21,7 +24,7 @@ import org.junit.jupiter.api.TestInstance
|
|||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class DefaultMultiAccountStatusListProducerTest {
|
||||
|
||||
private val userWalletsListRepository: UserWalletsListRepository = mockk()
|
||||
private val userWalletsListRepository: UserWalletsListRepository = mockk(relaxUnitFun = true)
|
||||
private val singleAccountStatusListSupplier: SingleAccountStatusListSupplier = mockk()
|
||||
private val dispatchers = TestingCoroutineDispatcherProvider()
|
||||
private val flowProducerTools: FlowProducerTools = mockk()
|
||||
|
|
@ -55,7 +58,7 @@ class DefaultMultiAccountStatusListProducerTest {
|
|||
val wallets = listOf(userWallet1, userWallet2)
|
||||
val walletsFlow = MutableStateFlow(wallets)
|
||||
|
||||
every { userWalletsListRepository.loadAndGet() } returns walletsFlow
|
||||
every { userWalletsListRepository.userWallets } returns walletsFlow
|
||||
val accountStatusList1 = mockk<AccountStatusList>()
|
||||
val accountStatusList2 = mockk<AccountStatusList>()
|
||||
|
||||
|
|
@ -78,8 +81,9 @@ class DefaultMultiAccountStatusListProducerTest {
|
|||
val expected = listOf(accountStatusList1, accountStatusList2)
|
||||
Truth.assertThat(actual).containsExactly(expected)
|
||||
|
||||
coVerify(ordering = Ordering.SEQUENCE) {
|
||||
userWalletsListRepository.loadAndGet()
|
||||
coVerifySequence {
|
||||
userWalletsListRepository.load()
|
||||
userWalletsListRepository.userWallets
|
||||
singleAccountStatusListSupplier(
|
||||
params = SingleAccountStatusListProducer.Params(userWalletId1),
|
||||
)
|
||||
|
|
@ -93,7 +97,7 @@ class DefaultMultiAccountStatusListProducerTest {
|
|||
fun `produce returns empty flow if userWallets is empty list`() = runTest {
|
||||
// Arrange
|
||||
val walletsFlow = MutableStateFlow<List<UserWallet>>(emptyList())
|
||||
every { userWalletsListRepository.loadAndGet() } returns walletsFlow
|
||||
every { userWalletsListRepository.userWallets } returns walletsFlow
|
||||
|
||||
// Act
|
||||
val actual = producer.produce().let(::getEmittedValues)
|
||||
|
|
@ -101,16 +105,17 @@ class DefaultMultiAccountStatusListProducerTest {
|
|||
// Assert
|
||||
Truth.assertThat(actual).isEmpty()
|
||||
|
||||
coVerify(ordering = Ordering.SEQUENCE) {
|
||||
userWalletsListRepository.loadAndGet()
|
||||
coVerifySequence {
|
||||
userWalletsListRepository.load()
|
||||
userWalletsListRepository.userWallets
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `produce returns empty flow if userWallets is null`() = runTest {
|
||||
// Arrange
|
||||
val walletsFlow = flowOf<List<UserWallet>>(emptyList())
|
||||
every { userWalletsListRepository.loadAndGet() } returns walletsFlow
|
||||
val walletsFlow = MutableStateFlow<List<UserWallet>>(emptyList())
|
||||
every { userWalletsListRepository.userWallets } returns walletsFlow
|
||||
|
||||
// Act
|
||||
val actual = producer.produce().let(::getEmittedValues)
|
||||
|
|
@ -118,8 +123,9 @@ class DefaultMultiAccountStatusListProducerTest {
|
|||
// Assert
|
||||
Truth.assertThat(actual).isEmpty()
|
||||
|
||||
coVerify(ordering = Ordering.SEQUENCE) {
|
||||
userWalletsListRepository.loadAndGet()
|
||||
coVerifySequence {
|
||||
userWalletsListRepository.load()
|
||||
userWalletsListRepository.userWallets
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -130,7 +136,7 @@ class DefaultMultiAccountStatusListProducerTest {
|
|||
val userWallet3 = mockk<UserWallet> { every { walletId } returns userWalletId3 }
|
||||
|
||||
val walletsFlow = MutableStateFlow(listOf(userWallet1, userWallet2))
|
||||
every { userWalletsListRepository.loadAndGet() } returns walletsFlow
|
||||
every { userWalletsListRepository.userWallets } returns walletsFlow
|
||||
|
||||
val accountStatusList1 = mockk<AccountStatusList>()
|
||||
val accountStatusList2 = mockk<AccountStatusList>()
|
||||
|
|
@ -169,8 +175,9 @@ class DefaultMultiAccountStatusListProducerTest {
|
|||
val expected2 = listOf(accountStatusList1, accountStatusList2, accountStatusList3)
|
||||
Truth.assertThat(actual2).containsExactly(expected2)
|
||||
|
||||
coVerify(ordering = Ordering.SEQUENCE) {
|
||||
userWalletsListRepository.loadAndGet()
|
||||
coVerifySequence {
|
||||
userWalletsListRepository.load()
|
||||
userWalletsListRepository.userWallets
|
||||
singleAccountStatusListSupplier(
|
||||
params = SingleAccountStatusListProducer.Params(userWalletId1),
|
||||
)
|
||||
|
|
@ -186,7 +193,8 @@ class DefaultMultiAccountStatusListProducerTest {
|
|||
singleAccountStatusListSupplier(
|
||||
params = SingleAccountStatusListProducer.Params(userWalletId3),
|
||||
)
|
||||
userWalletsListRepository.loadAndGet()
|
||||
userWalletsListRepository.load()
|
||||
userWalletsListRepository.userWallets
|
||||
singleAccountStatusListSupplier(
|
||||
params = SingleAccountStatusListProducer.Params(userWalletId1),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue