Updated on 2026-08-14
This commit is contained in:
parent
077b2e9ecf
commit
34f07ed52d
9 changed files with 781 additions and 31 deletions
|
|
@ -176,6 +176,27 @@ sealed interface Account {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a main account for the given user wallet ID
|
||||
*
|
||||
* @param userWalletId the ID of the user wallet
|
||||
*/
|
||||
fun createMainAccount(userWalletId: UserWalletId): CryptoPortfolio {
|
||||
// TODO: [REDACTED_JIRA]
|
||||
return CryptoPortfolio(
|
||||
accountId = AccountId(userWalletId = userWalletId, value = "main_account"),
|
||||
name = AccountName.Main,
|
||||
icon = CryptoPortfolioIcon.ofMainAccount(userWalletId),
|
||||
derivationIndex = 0,
|
||||
isArchived = false,
|
||||
cryptoCurrencyList = CryptoCurrencyList(
|
||||
currencies = emptySet(),
|
||||
sortType = TokensSortType.NONE,
|
||||
groupType = TokensGroupType.NONE,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -44,8 +44,13 @@ data class AccountName private constructor(
|
|||
|
||||
companion object {
|
||||
|
||||
private const val MAIN_ACCOUNT_NAME = "Main Account"
|
||||
private const val MAX_LENGTH = 20
|
||||
|
||||
/** Default name for the main account */
|
||||
val Main: AccountName
|
||||
get() = AccountName(value = MAIN_ACCOUNT_NAME)
|
||||
|
||||
/**
|
||||
* Factory method to create an `AccountName` instance.
|
||||
* Validates the input string to ensure it is not blank and does not exceed the maximum length.
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.tangem.domain.models.account
|
|||
import arrow.core.Either
|
||||
import arrow.core.left
|
||||
import com.google.common.truth.Truth
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.MethodSource
|
||||
|
|
@ -13,6 +14,16 @@ import org.junit.jupiter.params.provider.MethodSource
|
|||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class AccountNameTest {
|
||||
|
||||
@Test
|
||||
fun main_returnsMainAccountName() {
|
||||
// Act
|
||||
val main = AccountName.Main.value
|
||||
|
||||
// Assert
|
||||
val expected = "Main Account"
|
||||
Truth.assertThat(main).isEqualTo(expected)
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideTestModels")
|
||||
fun invoke(model: InvokeTestModel) {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.tangem.domain.models.account
|
|||
import com.google.common.truth.Truth
|
||||
import com.tangem.domain.models.TokensGroupType
|
||||
import com.tangem.domain.models.TokensSortType
|
||||
import com.tangem.domain.models.account.Account.CryptoPortfolio
|
||||
import com.tangem.domain.models.account.Account.CryptoPortfolio.CryptoCurrencyList
|
||||
import com.tangem.domain.models.account.Account.CryptoPortfolio.Error.AccountNameError
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
|
|
@ -99,7 +100,7 @@ class AccountTest {
|
|||
val name = ""
|
||||
|
||||
// Act
|
||||
val actual = Account.CryptoPortfolio(
|
||||
val actual = CryptoPortfolio(
|
||||
accountId = mockk(),
|
||||
name = name,
|
||||
accountIcon = mockk(),
|
||||
|
|
@ -120,7 +121,7 @@ class AccountTest {
|
|||
val derivationIndex = -1
|
||||
|
||||
// Act
|
||||
val actual = Account.CryptoPortfolio(
|
||||
val actual = CryptoPortfolio(
|
||||
accountId = mockk(),
|
||||
name = "Test Account",
|
||||
accountIcon = mockk(),
|
||||
|
|
@ -131,14 +132,14 @@ class AccountTest {
|
|||
.leftOrNull()!!
|
||||
|
||||
// Assert
|
||||
val expected = Account.CryptoPortfolio.Error.NegativeDerivationIndex
|
||||
val expected = CryptoPortfolio.Error.NegativeDerivationIndex
|
||||
Truth.assertThat(actual).isEqualTo(expected)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `invoke returns CryptoPortfolio`() {
|
||||
// Act
|
||||
val actual = Account.CryptoPortfolio(
|
||||
val actual = CryptoPortfolio(
|
||||
accountId = AccountId(
|
||||
value = "value",
|
||||
userWalletId = UserWalletId("011"),
|
||||
|
|
@ -159,6 +160,32 @@ class AccountTest {
|
|||
val expected = createCryptoPortfolioStub()
|
||||
Truth.assertThat(actual).isEqualTo(expected)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun createMainAccount() {
|
||||
// Arrange
|
||||
val userWalletId = UserWalletId("011")
|
||||
|
||||
// Act
|
||||
val actual = CryptoPortfolio.createMainAccount(userWalletId = userWalletId)
|
||||
|
||||
// Assert
|
||||
// TODO: [REDACTED_JIRA]
|
||||
val expected = CryptoPortfolio(
|
||||
accountId = AccountId(userWalletId = userWalletId, value = "main_account"),
|
||||
accountName = AccountName.Main,
|
||||
accountIcon = CryptoPortfolioIcon.ofMainAccount(userWalletId),
|
||||
derivationIndex = 0,
|
||||
isArchived = false,
|
||||
cryptoCurrencyList = CryptoCurrencyList(
|
||||
currencies = emptySet(),
|
||||
sortType = TokensSortType.NONE,
|
||||
groupType = TokensGroupType.NONE,
|
||||
),
|
||||
).getOrNull()
|
||||
|
||||
Truth.assertThat(actual).isEqualTo(expected)
|
||||
}
|
||||
}
|
||||
|
||||
private fun createCryptoPortfolioStub(
|
||||
|
|
@ -166,8 +193,8 @@ class AccountTest {
|
|||
name: String = "Test Account",
|
||||
derivationIndex: Int = 0,
|
||||
currencies: Set<CryptoCurrency> = emptySet(),
|
||||
): Account.CryptoPortfolio {
|
||||
return Account.CryptoPortfolio.invoke(
|
||||
): CryptoPortfolio {
|
||||
return CryptoPortfolio.invoke(
|
||||
accountId = AccountId(
|
||||
value = "value",
|
||||
userWalletId = userWalletId,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue