Updated on 2026-08-14
This commit is contained in:
parent
cb6fdddcde
commit
1ed65c48cc
28 changed files with 172 additions and 266 deletions
|
|
@ -28,7 +28,7 @@ internal class AccountListConverter @AssistedInject constructor(
|
|||
|
||||
override fun convert(value: GetWalletAccountsResponse): AccountList {
|
||||
return AccountList(
|
||||
userWallet = userWallet,
|
||||
userWalletId = userWallet.walletId,
|
||||
accounts = value.accounts.map(cryptoPortfolioConverter::convert).toSet(),
|
||||
totalAccounts = value.wallet.totalAccounts,
|
||||
sortType = TokensSortTypeConverter.convert(value.wallet.sort),
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ internal class FetchWalletAccountsErrorHandler @Inject constructor(
|
|||
}
|
||||
|
||||
private fun createDefaultAccountDTOs(userWallet: UserWallet): List<WalletAccountDTO> {
|
||||
val accounts = AccountList.empty(userWallet).accounts
|
||||
val accounts = AccountList.empty(userWallet.walletId).accounts
|
||||
.filterIsInstance<Account.CryptoPortfolio>()
|
||||
|
||||
val converter = cryptoPortfolioCF.create(userWallet = userWallet)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import arrow.core.some
|
|||
import com.tangem.datasource.local.userwallet.UserWalletsStore
|
||||
import com.tangem.domain.account.models.AccountList
|
||||
import com.tangem.domain.account.producer.MultiAccountListProducer
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
|
|
@ -35,10 +36,11 @@ internal class DefaultMultiAccountListProducer @AssistedInject constructor(
|
|||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
override fun produce(): Flow<List<AccountList>> {
|
||||
return userWalletsStore.userWallets
|
||||
.map { it.map(UserWallet::walletId) }
|
||||
.distinctUntilChanged()
|
||||
.flatMapLatest { userWallets ->
|
||||
.flatMapLatest { ids ->
|
||||
combine(
|
||||
flows = userWallets.map(walletAccountListFlowFactory::create),
|
||||
flows = ids.map(walletAccountListFlowFactory::create),
|
||||
transform = ::listOf,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package com.tangem.data.account.producer
|
|||
|
||||
import arrow.core.Option
|
||||
import arrow.core.none
|
||||
import com.tangem.datasource.local.userwallet.UserWalletsStore
|
||||
import com.tangem.domain.account.models.AccountList
|
||||
import com.tangem.domain.account.producer.SingleAccountListProducer
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
|
|
@ -11,16 +10,13 @@ import dagger.assisted.AssistedFactory
|
|||
import dagger.assisted.AssistedInject
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.mapNotNull
|
||||
|
||||
/**
|
||||
* Default implementation of [SingleAccountListProducer].
|
||||
* Produces a list of [AccountList] for a specific user wallet.
|
||||
*
|
||||
* @property params params containing the user wallet ID
|
||||
* @property userWalletsStore store that provides user wallets
|
||||
* @property walletAccountListFlowFactory builder to create flows of [AccountList] for each wallet
|
||||
* @property dispatchers coroutine dispatchers provider
|
||||
*
|
||||
|
|
@ -28,7 +24,6 @@ import kotlinx.coroutines.flow.mapNotNull
|
|||
*/
|
||||
internal class DefaultSingleAccountListProducer @AssistedInject constructor(
|
||||
@Assisted val params: SingleAccountListProducer.Params,
|
||||
private val userWalletsStore: UserWalletsStore,
|
||||
private val walletAccountListFlowFactory: WalletAccountListFlowFactory,
|
||||
private val dispatchers: CoroutineDispatcherProvider,
|
||||
) : SingleAccountListProducer {
|
||||
|
|
@ -37,11 +32,7 @@ internal class DefaultSingleAccountListProducer @AssistedInject constructor(
|
|||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
override fun produce(): Flow<AccountList> {
|
||||
return userWalletsStore.userWallets
|
||||
.mapNotNull { userWallets ->
|
||||
userWallets.firstOrNull { it.walletId == params.userWalletId }
|
||||
}
|
||||
.flatMapLatest(walletAccountListFlowFactory::create)
|
||||
return walletAccountListFlowFactory.create(userWalletId = params.userWalletId)
|
||||
.flowOn(dispatchers.default)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,9 +4,11 @@ import com.tangem.data.account.converter.AccountListConverter
|
|||
import com.tangem.data.account.store.AccountsResponseStore
|
||||
import com.tangem.data.account.store.AccountsResponseStoreFactory
|
||||
import com.tangem.data.common.currency.CardCryptoCurrencyFactory
|
||||
import com.tangem.datasource.local.userwallet.UserWalletsStore
|
||||
import com.tangem.domain.account.models.AccountList
|
||||
import com.tangem.domain.card.common.util.cardTypesResolver
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.domain.models.wallet.isMultiCurrency
|
||||
import com.tangem.domain.models.wallet.requireColdWallet
|
||||
import kotlinx.coroutines.flow.*
|
||||
|
|
@ -22,12 +24,15 @@ import javax.inject.Inject
|
|||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
internal class WalletAccountListFlowFactory @Inject constructor(
|
||||
private val userWalletsStore: UserWalletsStore,
|
||||
private val accountsResponseStoreFactory: AccountsResponseStoreFactory,
|
||||
private val accountListConverterFactory: AccountListConverter.Factory,
|
||||
private val cardCryptoCurrencyFactory: CardCryptoCurrencyFactory,
|
||||
) {
|
||||
|
||||
fun create(userWallet: UserWallet): Flow<AccountList> {
|
||||
fun create(userWalletId: UserWalletId): Flow<AccountList> {
|
||||
val userWallet = userWalletsStore.getSyncStrict(userWalletId)
|
||||
|
||||
return if (userWallet.isMultiCurrency) {
|
||||
createForMultiWallet(userWallet)
|
||||
} else {
|
||||
|
|
@ -53,6 +58,6 @@ internal class WalletAccountListFlowFactory @Inject constructor(
|
|||
setOf(cardCryptoCurrencyFactory.createPrimaryCurrencyForSingleCurrencyCard(userWallet = userWallet))
|
||||
}
|
||||
|
||||
return AccountList.empty(userWallet = userWallet, cryptoCurrencies = currencies)
|
||||
return AccountList.empty(userWalletId = userWallet.walletId, cryptoCurrencies = currencies)
|
||||
}
|
||||
}
|
||||
|
|
@ -101,12 +101,12 @@ internal class DefaultAccountsCRUDRepository(
|
|||
}
|
||||
|
||||
override suspend fun saveAccounts(accountList: AccountList) {
|
||||
val userWalletId = accountList.userWallet.walletId
|
||||
val userWallet = userWalletsStore.getSyncStrict(accountList.userWalletId)
|
||||
|
||||
val converter = convertersContainer.getWalletAccountsResponseCF.create(userWallet = accountList.userWallet)
|
||||
val converter = convertersContainer.getWalletAccountsResponseCF.create(userWallet = userWallet)
|
||||
val accountsResponse = converter.convert(value = accountList)
|
||||
|
||||
walletAccountsSaver.pushAndStore(userWalletId = userWalletId, response = accountsResponse)
|
||||
walletAccountsSaver.pushAndStore(userWalletId = userWallet.walletId, response = accountsResponse)
|
||||
}
|
||||
|
||||
override suspend fun getTotalAccountsCountSync(userWalletId: UserWalletId): Option<Int> = option {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import com.tangem.domain.models.TokensGroupType
|
|||
import com.tangem.domain.models.TokensSortType
|
||||
import com.tangem.domain.models.account.Account
|
||||
import com.tangem.domain.models.account.AccountName
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
|
||||
internal fun createWalletAccountDTO(
|
||||
|
|
@ -72,13 +71,13 @@ internal fun createGetWalletAccountsResponse(
|
|||
}
|
||||
|
||||
internal fun createAccountList(
|
||||
userWallet: UserWallet,
|
||||
userWalletId: UserWalletId,
|
||||
sortType: TokensSortType = TokensSortType.BALANCE,
|
||||
groupType: TokensGroupType = TokensGroupType.NETWORK,
|
||||
): AccountList {
|
||||
return AccountList(
|
||||
userWallet = userWallet,
|
||||
accounts = setOf(createCryptoPortfolio(userWallet.walletId)),
|
||||
userWalletId = userWalletId,
|
||||
accounts = setOf(createCryptoPortfolio(userWalletId)),
|
||||
totalAccounts = 1,
|
||||
sortType = sortType,
|
||||
groupType = groupType,
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ class AccountListConverterTest {
|
|||
),
|
||||
expected = Result.success(
|
||||
createAccountList(
|
||||
userWallet = userWallet,
|
||||
userWalletId = userWallet.walletId,
|
||||
sortType = TokensSortType.BALANCE,
|
||||
groupType = TokensGroupType.NETWORK,
|
||||
),
|
||||
|
|
@ -110,7 +110,7 @@ class AccountListConverterTest {
|
|||
),
|
||||
expected = Result.success(
|
||||
createAccountList(
|
||||
userWallet = userWallet,
|
||||
userWalletId = userWallet.walletId,
|
||||
sortType = TokensSortType.NONE,
|
||||
groupType = TokensGroupType.NONE,
|
||||
),
|
||||
|
|
@ -124,7 +124,7 @@ class AccountListConverterTest {
|
|||
),
|
||||
expected = Result.success(
|
||||
createAccountList(
|
||||
userWallet = userWallet,
|
||||
userWalletId = userWallet.walletId,
|
||||
sortType = TokensSortType.NONE,
|
||||
groupType = TokensGroupType.NONE,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class GetWalletAccountsResponseConverterTest {
|
|||
@Test
|
||||
fun `cryptoPortfolioConverter throws exception`() {
|
||||
// Arrange
|
||||
val domain = createAccountList(userWallet = userWallet)
|
||||
val domain = createAccountList(userWalletId = userWallet.walletId)
|
||||
val exception = IllegalStateException("Test exception")
|
||||
|
||||
every { cryptoPortfolioConverter.convertBack(any()) } throws exception
|
||||
|
|
@ -92,7 +92,7 @@ class GetWalletAccountsResponseConverterTest {
|
|||
return listOf(
|
||||
ConvertModel(
|
||||
value = createAccountList(
|
||||
userWallet = userWallet,
|
||||
userWalletId = userWallet.walletId,
|
||||
sortType = TokensSortType.BALANCE,
|
||||
groupType = TokensGroupType.NETWORK,
|
||||
),
|
||||
|
|
@ -106,7 +106,7 @@ class GetWalletAccountsResponseConverterTest {
|
|||
),
|
||||
ConvertModel(
|
||||
value = createAccountList(
|
||||
userWallet = userWallet,
|
||||
userWalletId = userWallet.walletId,
|
||||
sortType = TokensSortType.NONE,
|
||||
groupType = TokensGroupType.NONE,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -6,10 +6,7 @@ import com.tangem.datasource.api.tangemTech.models.account.WalletAccountDTO
|
|||
import com.tangem.domain.account.models.AccountList
|
||||
import com.tangem.domain.models.account.Account
|
||||
import com.tangem.domain.models.account.AccountName
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
|
||||
|
|
@ -19,13 +16,11 @@ class SaveWalletAccountsResponseConverterTest {
|
|||
@Test
|
||||
fun convert() {
|
||||
// Arrange
|
||||
val userWallet = mockk<UserWallet> {
|
||||
every { this@mockk.walletId } returns UserWalletId("011")
|
||||
}
|
||||
val userWalletId = UserWalletId("011")
|
||||
|
||||
val accountList = AccountList(
|
||||
userWallet = userWallet,
|
||||
accounts = setOf(Account.CryptoPortfolio.createMainAccount(userWalletId = userWallet.walletId)),
|
||||
userWalletId = userWalletId,
|
||||
accounts = setOf(Account.CryptoPortfolio.createMainAccount(userWalletId = userWalletId)),
|
||||
totalAccounts = 1,
|
||||
)
|
||||
.getOrNull()!!
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ class FetchWalletAccountsErrorHandlerTest {
|
|||
// Arrange
|
||||
val error = ApiResponseError.TimeoutException()
|
||||
|
||||
val accounts = AccountList.empty(userWallet).accounts
|
||||
val accounts = AccountList.empty(userWalletId).accounts
|
||||
.filterIsInstance<Account.CryptoPortfolio>()
|
||||
|
||||
val accountDTO = WalletAccountDTO(
|
||||
|
|
|
|||
|
|
@ -51,8 +51,8 @@ class DefaultMultiAccountListProducerTest {
|
|||
val userWalletsFlow = MutableStateFlow(value = listOf(userWallet))
|
||||
every { userWalletsStore.userWallets } returns userWalletsFlow
|
||||
|
||||
val accountList = AccountList.empty(userWallet)
|
||||
every { walletAccountListFlowFactory.create(userWallet) } returns flowOf(accountList)
|
||||
val accountList = AccountList.empty(userWalletId)
|
||||
every { walletAccountListFlowFactory.create(userWalletId) } returns flowOf(accountList)
|
||||
|
||||
// Act
|
||||
val actual = producer.produce().let(::getEmittedValues)
|
||||
|
|
@ -63,7 +63,7 @@ class DefaultMultiAccountListProducerTest {
|
|||
|
||||
coVerify(ordering = Ordering.SEQUENCE) {
|
||||
userWalletsStore.userWallets
|
||||
walletAccountListFlowFactory.create(userWallet)
|
||||
walletAccountListFlowFactory.create(userWalletId)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -73,11 +73,11 @@ class DefaultMultiAccountListProducerTest {
|
|||
val userWalletsFlow = MutableStateFlow(value = listOf(userWallet))
|
||||
every { userWalletsStore.userWallets } returns userWalletsFlow
|
||||
|
||||
val accountList = AccountList.empty(userWallet)
|
||||
val updatedAccountList = AccountList.empty(userWallet = userWallet, sortType = TokensSortType.NONE)
|
||||
val accountList = AccountList.empty(userWalletId)
|
||||
val updatedAccountList = AccountList.empty(userWalletId = userWalletId, sortType = TokensSortType.NONE)
|
||||
val factoryFlow = MutableStateFlow<AccountList?>(null)
|
||||
|
||||
every { walletAccountListFlowFactory.create(userWallet) } returns factoryFlow.filterNotNull()
|
||||
every { walletAccountListFlowFactory.create(userWalletId) } returns factoryFlow.filterNotNull()
|
||||
|
||||
// Act (first emission)
|
||||
factoryFlow.value = accountList
|
||||
|
|
@ -95,9 +95,9 @@ class DefaultMultiAccountListProducerTest {
|
|||
|
||||
coVerify(ordering = Ordering.SEQUENCE) {
|
||||
userWalletsStore.userWallets
|
||||
walletAccountListFlowFactory.create(userWallet)
|
||||
walletAccountListFlowFactory.create(userWalletId)
|
||||
userWalletsStore.userWallets
|
||||
walletAccountListFlowFactory.create(userWallet)
|
||||
walletAccountListFlowFactory.create(userWalletId)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -107,10 +107,10 @@ class DefaultMultiAccountListProducerTest {
|
|||
val userWalletsFlow = MutableStateFlow(value = listOf(userWallet))
|
||||
every { userWalletsStore.userWallets } returns userWalletsFlow
|
||||
|
||||
val accountList = AccountList.empty(userWallet)
|
||||
val accountList = AccountList.empty(userWalletId)
|
||||
val factoryFlow = MutableStateFlow<AccountList?>(null)
|
||||
|
||||
every { walletAccountListFlowFactory.create(userWallet) } returns factoryFlow.filterNotNull()
|
||||
every { walletAccountListFlowFactory.create(userWalletId) } returns factoryFlow.filterNotNull()
|
||||
|
||||
// Act (first emission)
|
||||
factoryFlow.value = accountList
|
||||
|
|
@ -128,9 +128,9 @@ class DefaultMultiAccountListProducerTest {
|
|||
|
||||
coVerify(ordering = Ordering.SEQUENCE) {
|
||||
userWalletsStore.userWallets
|
||||
walletAccountListFlowFactory.create(userWallet)
|
||||
walletAccountListFlowFactory.create(userWalletId)
|
||||
userWalletsStore.userWallets
|
||||
walletAccountListFlowFactory.create(userWallet)
|
||||
walletAccountListFlowFactory.create(userWalletId)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -141,7 +141,7 @@ class DefaultMultiAccountListProducerTest {
|
|||
every { userWalletsStore.userWallets } returns userWalletsFlow
|
||||
|
||||
val exception = RuntimeException("Converter error")
|
||||
every { walletAccountListFlowFactory.create(userWallet) } throws exception
|
||||
every { walletAccountListFlowFactory.create(userWalletId) } throws exception
|
||||
|
||||
// Act
|
||||
val actual = producer.produceWithFallback().let(::getEmittedValues)
|
||||
|
|
@ -152,7 +152,7 @@ class DefaultMultiAccountListProducerTest {
|
|||
|
||||
coVerify(ordering = Ordering.SEQUENCE) {
|
||||
userWalletsStore.userWallets
|
||||
walletAccountListFlowFactory.create(userWallet)
|
||||
walletAccountListFlowFactory.create(userWalletId)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -178,7 +178,7 @@ class DefaultMultiAccountListProducerTest {
|
|||
val userWalletsFlow = MutableStateFlow(value = listOf(userWallet))
|
||||
every { userWalletsStore.userWallets } returns userWalletsFlow
|
||||
|
||||
every { walletAccountListFlowFactory.create(userWallet) } returns emptyFlow()
|
||||
every { walletAccountListFlowFactory.create(userWalletId) } returns emptyFlow()
|
||||
|
||||
// Act
|
||||
val actual = producer.produce().let(::getEmittedValues)
|
||||
|
|
@ -188,7 +188,7 @@ class DefaultMultiAccountListProducerTest {
|
|||
|
||||
coVerify(ordering = Ordering.SEQUENCE) {
|
||||
userWalletsStore.userWallets
|
||||
walletAccountListFlowFactory.create(userWallet)
|
||||
walletAccountListFlowFactory.create(userWalletId)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -203,9 +203,9 @@ class DefaultMultiAccountListProducerTest {
|
|||
val userWalletsFlow = MutableStateFlow(listOf(userWallet, userWallet2))
|
||||
every { userWalletsStore.userWallets } returns userWalletsFlow
|
||||
|
||||
val accountList = AccountList.empty(userWallet)
|
||||
every { walletAccountListFlowFactory.create(userWallet) } returns flowOf(accountList)
|
||||
every { walletAccountListFlowFactory.create(userWallet2) } returns emptyFlow()
|
||||
val accountList = AccountList.empty(userWalletId)
|
||||
every { walletAccountListFlowFactory.create(userWalletId) } returns flowOf(accountList)
|
||||
every { walletAccountListFlowFactory.create(userWalletId2) } returns emptyFlow()
|
||||
|
||||
// Act
|
||||
val actual = producer.produce().let(::getEmittedValues)
|
||||
|
|
@ -215,8 +215,8 @@ class DefaultMultiAccountListProducerTest {
|
|||
|
||||
coVerify(ordering = Ordering.SEQUENCE) {
|
||||
userWalletsStore.userWallets
|
||||
walletAccountListFlowFactory.create(userWallet)
|
||||
walletAccountListFlowFactory.create(userWallet2)
|
||||
walletAccountListFlowFactory.create(userWalletId)
|
||||
walletAccountListFlowFactory.create(userWalletId2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,6 @@ package com.tangem.data.account.producer
|
|||
|
||||
import com.google.common.truth.Truth
|
||||
import com.tangem.common.test.utils.getEmittedValues
|
||||
import com.tangem.datasource.local.userwallet.UserWalletsStore
|
||||
import com.tangem.domain.account.models.AccountList
|
||||
import com.tangem.domain.account.producer.SingleAccountListProducer
|
||||
import com.tangem.domain.models.TokensSortType
|
||||
|
|
@ -11,7 +10,6 @@ import com.tangem.domain.models.wallet.UserWalletId
|
|||
import com.tangem.utils.coroutines.TestingCoroutineDispatcherProvider
|
||||
import io.mockk.*
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.emptyFlow
|
||||
import kotlinx.coroutines.flow.filterNotNull
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.test.runTest
|
||||
|
|
@ -26,7 +24,6 @@ import org.junit.jupiter.api.TestInstance
|
|||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class DefaultSingleAccountListProducerTest {
|
||||
|
||||
private val userWalletsStore: UserWalletsStore = mockk()
|
||||
private val walletAccountListFlowFactory: WalletAccountListFlowFactory = mockk()
|
||||
|
||||
private val userWalletId = UserWalletId("011")
|
||||
|
|
@ -36,24 +33,22 @@ class DefaultSingleAccountListProducerTest {
|
|||
|
||||
private val producer = DefaultSingleAccountListProducer(
|
||||
params = SingleAccountListProducer.Params(userWalletId = userWalletId),
|
||||
userWalletsStore = userWalletsStore,
|
||||
walletAccountListFlowFactory = walletAccountListFlowFactory,
|
||||
dispatchers = TestingCoroutineDispatcherProvider(),
|
||||
)
|
||||
|
||||
@AfterEach
|
||||
fun tearDownEach() {
|
||||
clearMocks(userWalletsStore, walletAccountListFlowFactory)
|
||||
clearMocks(walletAccountListFlowFactory)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun produce() = runTest {
|
||||
// Arrange
|
||||
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
|
||||
every { userWalletsStore.userWallets } returns userWalletsFlow
|
||||
MutableStateFlow(listOf(userWallet))
|
||||
|
||||
val accountList = AccountList.empty(userWallet)
|
||||
every { walletAccountListFlowFactory.create(userWallet) } returns flowOf(accountList)
|
||||
val accountList = AccountList.empty(userWalletId)
|
||||
every { walletAccountListFlowFactory.create(userWalletId) } returns flowOf(accountList)
|
||||
|
||||
// Act
|
||||
val actual = producer.produce().let(::getEmittedValues)
|
||||
|
|
@ -63,22 +58,18 @@ class DefaultSingleAccountListProducerTest {
|
|||
Truth.assertThat(actual).containsExactly(expected)
|
||||
|
||||
coVerify(ordering = Ordering.SEQUENCE) {
|
||||
userWalletsStore.userWallets
|
||||
walletAccountListFlowFactory.create(userWallet)
|
||||
walletAccountListFlowFactory.create(userWalletId)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `flow will updated if factoryFlow is updated`() = runTest {
|
||||
// Arrange
|
||||
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
|
||||
every { userWalletsStore.userWallets } returns userWalletsFlow
|
||||
|
||||
val accountList = AccountList.empty(userWallet)
|
||||
val updatedAccountList = AccountList.empty(userWallet = userWallet, sortType = TokensSortType.NONE)
|
||||
val accountList = AccountList.empty(userWalletId)
|
||||
val updatedAccountList = AccountList.empty(userWalletId = userWalletId, sortType = TokensSortType.NONE)
|
||||
val factoryFlow = MutableStateFlow<AccountList?>(null)
|
||||
|
||||
every { walletAccountListFlowFactory.create(userWallet) } returns factoryFlow.filterNotNull()
|
||||
every { walletAccountListFlowFactory.create(userWalletId) } returns factoryFlow.filterNotNull()
|
||||
|
||||
// Act (first emission)
|
||||
factoryFlow.value = accountList
|
||||
|
|
@ -95,23 +86,18 @@ class DefaultSingleAccountListProducerTest {
|
|||
Truth.assertThat(secondEmission).containsExactly(updatedAccountList)
|
||||
|
||||
coVerifyOrder {
|
||||
userWalletsStore.userWallets
|
||||
walletAccountListFlowFactory.create(userWallet)
|
||||
userWalletsStore.userWallets
|
||||
walletAccountListFlowFactory.create(userWallet)
|
||||
walletAccountListFlowFactory.create(userWalletId)
|
||||
walletAccountListFlowFactory.create(userWalletId)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `flow is filtered the same response`() = runTest {
|
||||
// Arrange
|
||||
val userWalletsFlow = MutableStateFlow(value = listOf(userWallet))
|
||||
every { userWalletsStore.userWallets } returns userWalletsFlow
|
||||
|
||||
val accountList = AccountList.empty(userWallet)
|
||||
val accountList = AccountList.empty(userWalletId)
|
||||
val factoryFlow = MutableStateFlow<AccountList?>(null)
|
||||
|
||||
every { walletAccountListFlowFactory.create(userWallet) } returns factoryFlow.filterNotNull()
|
||||
every { walletAccountListFlowFactory.create(userWalletId) } returns factoryFlow.filterNotNull()
|
||||
|
||||
// Act (first emission)
|
||||
factoryFlow.value = accountList
|
||||
|
|
@ -128,71 +114,8 @@ class DefaultSingleAccountListProducerTest {
|
|||
Truth.assertThat(secondEmission).containsExactly(accountList)
|
||||
|
||||
coVerify(ordering = Ordering.SEQUENCE) {
|
||||
userWalletsStore.userWallets
|
||||
walletAccountListFlowFactory.create(userWallet)
|
||||
userWalletsStore.userWallets
|
||||
walletAccountListFlowFactory.create(userWallet)
|
||||
walletAccountListFlowFactory.create(userWalletId)
|
||||
walletAccountListFlowFactory.create(userWalletId)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `flow is empty if factory throws exception`() = runTest {
|
||||
// Arrange
|
||||
val userWalletsFlow = MutableStateFlow(value = listOf(userWallet))
|
||||
every { userWalletsStore.userWallets } returns userWalletsFlow
|
||||
|
||||
val exception = RuntimeException("Converter error")
|
||||
every { walletAccountListFlowFactory.create(userWallet) } throws exception
|
||||
|
||||
// Act
|
||||
val actual = producer.produceWithFallback().let(::getEmittedValues)
|
||||
|
||||
// Assert
|
||||
Truth.assertThat(actual).isEmpty() // no emissions
|
||||
|
||||
coVerify(ordering = Ordering.SEQUENCE) {
|
||||
userWalletsStore.userWallets
|
||||
walletAccountListFlowFactory.create(userWallet)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `flow is empty if userWalletsFlow returns empty flow`() = runTest {
|
||||
// Arrange
|
||||
val userWalletsFlow = emptyFlow<List<UserWallet>>()
|
||||
every { userWalletsStore.userWallets } returns userWalletsFlow
|
||||
|
||||
// Act
|
||||
val actual = producer.produce().let(::getEmittedValues)
|
||||
|
||||
// Assert
|
||||
Truth.assertThat(actual).isEmpty() // no emissions
|
||||
|
||||
coVerify(exactly = 1) { userWalletsStore.userWallets }
|
||||
coVerify(inverse = true) { walletAccountListFlowFactory.create(any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `flow is empty if userWalletsFlow doesn't contains userWalletId from params`() = runTest {
|
||||
// Arrange
|
||||
val unknownId = UserWalletId("012")
|
||||
val unknownWallet = mockk<UserWallet> {
|
||||
every { this@mockk.walletId } returns unknownId
|
||||
}
|
||||
|
||||
val userWalletsFlow = MutableStateFlow(listOf(unknownWallet))
|
||||
every { userWalletsStore.userWallets } returns userWalletsFlow
|
||||
|
||||
// Act
|
||||
val actual = producer.produce().let(::getEmittedValues)
|
||||
|
||||
// Assert
|
||||
Truth.assertThat(actual).isEmpty() // no emissions
|
||||
|
||||
coVerify(ordering = Ordering.SEQUENCE) {
|
||||
userWalletsStore.userWallets
|
||||
}
|
||||
|
||||
coVerify(inverse = true) { walletAccountListFlowFactory.create(any()) }
|
||||
}
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ import com.tangem.data.account.store.AccountsResponseStore
|
|||
import com.tangem.data.account.store.AccountsResponseStoreFactory
|
||||
import com.tangem.data.common.currency.CardCryptoCurrencyFactory
|
||||
import com.tangem.datasource.api.tangemTech.models.account.GetWalletAccountsResponse
|
||||
import com.tangem.datasource.local.userwallet.UserWalletsStore
|
||||
import com.tangem.domain.account.models.AccountList
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
|
|
@ -28,6 +29,7 @@ import org.junit.jupiter.api.TestInstance
|
|||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class WalletAccountListFlowFactoryTest {
|
||||
|
||||
private val userWalletsStore: UserWalletsStore = mockk()
|
||||
private val accountsResponseStoreFactory: AccountsResponseStoreFactory = mockk()
|
||||
private val accountsResponseStore: AccountsResponseStore = mockk()
|
||||
private val accountsResponseStoreFlow = MutableStateFlow<GetWalletAccountsResponse?>(value = null)
|
||||
|
|
@ -38,6 +40,7 @@ class WalletAccountListFlowFactoryTest {
|
|||
private val cardCryptoCurrencyFactory: CardCryptoCurrencyFactory = mockk()
|
||||
|
||||
private val factory = WalletAccountListFlowFactory(
|
||||
userWalletsStore = userWalletsStore,
|
||||
accountsResponseStoreFactory = accountsResponseStoreFactory,
|
||||
accountListConverterFactory = accountListConverterFactory,
|
||||
cardCryptoCurrencyFactory = cardCryptoCurrencyFactory,
|
||||
|
|
@ -49,6 +52,7 @@ class WalletAccountListFlowFactoryTest {
|
|||
@AfterEach
|
||||
fun tearDownEach() {
|
||||
clearMocks(
|
||||
userWalletsStore,
|
||||
accountsResponseStoreFactory,
|
||||
accountsResponseStore,
|
||||
accountListConverterFactory,
|
||||
|
|
@ -66,17 +70,19 @@ class WalletAccountListFlowFactoryTest {
|
|||
every { this@mockk.isMultiCurrency } returns true
|
||||
}
|
||||
|
||||
every { userWalletsStore.getSyncStrict(userWalletId) } returns userWallet
|
||||
|
||||
val accountsResponse = createGetWalletAccountsResponse(userWalletId)
|
||||
every { accountsResponseStoreFactory.create(userWalletId) } returns accountsResponseStore
|
||||
every { accountsResponseStore.data } returns accountsResponseStoreFlow
|
||||
accountsResponseStoreFlow.value = accountsResponse
|
||||
|
||||
val accountList = AccountList.empty(userWallet)
|
||||
val accountList = AccountList.empty(userWalletId)
|
||||
every { accountListConverterFactory.create(userWallet) } returns accountListConverter
|
||||
every { accountListConverter.convert(accountsResponse) } returns accountList
|
||||
|
||||
// Act
|
||||
val actual = factory.create(userWallet).let(::getEmittedValues)
|
||||
val actual = factory.create(userWalletId).let(::getEmittedValues)
|
||||
|
||||
// Assert
|
||||
val expected = accountList
|
||||
|
|
@ -99,14 +105,16 @@ class WalletAccountListFlowFactoryTest {
|
|||
fun `create for single wallet`() = runTest {
|
||||
val userWallet = MockUserWalletFactory.create().copy(isMultiCurrency = false)
|
||||
|
||||
every { userWalletsStore.getSyncStrict(userWallet.walletId) } returns userWallet
|
||||
|
||||
val currency = cryptoCurrencyFactory.ethereum
|
||||
every { cardCryptoCurrencyFactory.createPrimaryCurrencyForSingleCurrencyCard(userWallet) } returns currency
|
||||
|
||||
// Act
|
||||
val actual = factory.create(userWallet).let(::getEmittedValues)
|
||||
val actual = factory.create(userWallet.walletId).let(::getEmittedValues)
|
||||
|
||||
// Assert
|
||||
val expected = AccountList.empty(userWallet = userWallet, cryptoCurrencies = setOf(currency))
|
||||
val expected = AccountList.empty(userWalletId = userWallet.walletId, cryptoCurrencies = setOf(currency))
|
||||
Truth.assertThat(actual).containsExactly(expected)
|
||||
|
||||
coVerify(ordering = Ordering.SEQUENCE) {
|
||||
|
|
@ -126,16 +134,18 @@ class WalletAccountListFlowFactoryTest {
|
|||
fun `flow is created for single wallet with token`() = runTest {
|
||||
val nodl = MockUserWalletFactory.createSingleWalletWithToken()
|
||||
|
||||
every { userWalletsStore.getSyncStrict(nodl.walletId) } returns nodl
|
||||
|
||||
val currencies = cryptoCurrencyFactory.ethereumAndStellar.toSet()
|
||||
every {
|
||||
cardCryptoCurrencyFactory.createCurrenciesForSingleCurrencyCardWithToken(userWallet = nodl)
|
||||
} returns currencies.toList()
|
||||
|
||||
// Act
|
||||
val actual = factory.create(nodl).let(::getEmittedValues)
|
||||
val actual = factory.create(nodl.walletId).let(::getEmittedValues)
|
||||
|
||||
// Assert
|
||||
val expected = AccountList.empty(userWallet = nodl, cryptoCurrencies = currencies)
|
||||
val expected = AccountList.empty(userWalletId = nodl.walletId, cryptoCurrencies = currencies)
|
||||
Truth.assertThat(actual).containsExactly(expected)
|
||||
|
||||
coVerify(ordering = Ordering.SEQUENCE) {
|
||||
|
|
|
|||
|
|
@ -584,7 +584,7 @@ class DefaultAccountsCRUDRepositoryTest {
|
|||
every { this@mockk.walletId } returns userWalletId
|
||||
}
|
||||
|
||||
val accountList = AccountList.empty(userWallet = userWallet)
|
||||
val accountList = AccountList.empty(userWalletId = userWalletId)
|
||||
|
||||
val accountsResponse = mockk<GetWalletAccountsResponse>()
|
||||
accountsResponseStoreFlow.value = accountsResponse
|
||||
|
|
@ -593,6 +593,8 @@ class DefaultAccountsCRUDRepositoryTest {
|
|||
every { this@mockk.convert(accountList) } returns accountsResponse
|
||||
}
|
||||
|
||||
every { userWalletsStore.getSyncStrict(userWalletId) } returns userWallet
|
||||
|
||||
every {
|
||||
convertersContainer.getWalletAccountsResponseCF.create(userWallet = userWallet)
|
||||
} returns converter
|
||||
|
|
@ -617,7 +619,7 @@ class DefaultAccountsCRUDRepositoryTest {
|
|||
every { this@mockk.walletId } returns userWalletId
|
||||
}
|
||||
|
||||
val accountList = AccountList.empty(userWallet = userWallet)
|
||||
val accountList = AccountList.empty(userWalletId = userWalletId)
|
||||
|
||||
val accountsResponse = mockk<GetWalletAccountsResponse>()
|
||||
accountsResponseStoreFlow.value = accountsResponse
|
||||
|
|
@ -626,6 +628,8 @@ class DefaultAccountsCRUDRepositoryTest {
|
|||
every { this@mockk.convert(accountList) } returns accountsResponse
|
||||
}
|
||||
|
||||
every { userWalletsStore.getSyncStrict(userWalletId) } returns userWallet
|
||||
|
||||
every {
|
||||
convertersContainer.getWalletAccountsResponseCF.create(userWallet = userWallet)
|
||||
} returns converter
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue