Add 'isPremium' boolean to account info (#278)

This commit is contained in:
David Perez 2023-11-27 12:20:30 -06:00 committed by Álison Fernandes
parent 636600114b
commit acfc39ae3c
7 changed files with 22 additions and 4 deletions

View file

@ -31,6 +31,7 @@ data class UserState(
* @property email The user's email address.
* @property name The user's name (if applicable).
* @property avatarColorHex Hex color value for a user's avatar in the "#AARRGGBB" format.
* @property isPremium `true` if the account has a premium membership.
* @property isVaultUnlocked Whether or not the user's vault is currently unlocked.
*/
data class Account(
@ -38,6 +39,7 @@ data class UserState(
val name: String?,
val email: String,
val avatarColorHex: String,
val isPremium: Boolean,
val isVaultUnlocked: Boolean,
)
}

View file

@ -53,6 +53,7 @@ fun UserStateJson.toUserState(
email = accountJson.profile.email,
// TODO Calculate default color (BIT-1191)
avatarColorHex = accountJson.profile.avatarColorHex ?: "#00aaaa",
isPremium = accountJson.profile.hasPremium == true,
isVaultUnlocked = userId in vaultState.unlockedVaultUserIds,
)
},

View file

@ -96,6 +96,7 @@ class UserStateJsonExtensionsTest {
name = "activeName",
email = "activeEmail",
avatarColorHex = "activeAvatarColorHex",
isPremium = false,
isVaultUnlocked = true,
),
),
@ -104,11 +105,12 @@ class UserStateJsonExtensionsTest {
activeUserId = "activeUserId",
accounts = mapOf(
"activeUserId" to AccountJson(
profile = mockk() {
profile = mockk {
every { userId } returns "activeUserId"
every { name } returns "activeName"
every { email } returns "activeEmail"
every { avatarColorHex } returns "activeAvatarColorHex"
every { hasPremium } returns null
},
tokens = mockk(),
settings = mockk(),
@ -134,6 +136,7 @@ class UserStateJsonExtensionsTest {
name = "activeName",
email = "activeEmail",
avatarColorHex = "activeAvatarColorHex",
isPremium = true,
isVaultUnlocked = false,
),
),
@ -142,18 +145,18 @@ class UserStateJsonExtensionsTest {
activeUserId = "activeUserId",
accounts = mapOf(
"activeUserId" to AccountJson(
profile = mockk() {
profile = mockk {
every { userId } returns "activeUserId"
every { name } returns "activeName"
every { email } returns "activeEmail"
every { avatarColorHex } returns "activeAvatarColorHex"
every { hasPremium } returns true
},
tokens = mockk(),
settings = mockk(),
),
),
)
)
.toUserState(
vaultState = VaultState(
unlockedVaultUserIds = emptySet(),

View file

@ -229,6 +229,7 @@ private val DEFAULT_USER_STATE = UserState(
name = "Active User",
email = "active@bitwarden.com",
avatarColorHex = "#aa00aa",
isPremium = true,
isVaultUnlocked = true,
),
),

View file

@ -33,6 +33,7 @@ class RootNavViewModelTest : BaseViewModelTest() {
name = "name",
email = "email",
avatarColorHex = "avatarColorHex",
isPremium = true,
isVaultUnlocked = true,
),
),
@ -53,6 +54,7 @@ class RootNavViewModelTest : BaseViewModelTest() {
name = "name",
email = "email",
avatarColorHex = "avatarColorHex",
isPremium = true,
isVaultUnlocked = false,
),
),

View file

@ -65,6 +65,7 @@ class VaultViewModelTest : BaseViewModelTest() {
name = "Other User",
email = "active@bitwarden.com",
avatarColorHex = "#00aaaa",
isPremium = true,
isVaultUnlocked = true,
),
),
@ -356,6 +357,7 @@ private val DEFAULT_USER_STATE = UserState(
name = "Active User",
email = "active@bitwarden.com",
avatarColorHex = "#aa00aa",
isPremium = true,
isVaultUnlocked = true,
),
),

View file

@ -40,6 +40,7 @@ class UserStateExtensionsTest {
name = "activeName",
email = "activeEmail",
avatarColorHex = "activeAvatarColorHex",
isPremium = true,
isVaultUnlocked = true,
),
UserState.Account(
@ -47,6 +48,7 @@ class UserStateExtensionsTest {
name = "lockedName",
email = "lockedEmail",
avatarColorHex = "lockedAvatarColorHex",
isPremium = false,
isVaultUnlocked = false,
),
UserState.Account(
@ -54,6 +56,7 @@ class UserStateExtensionsTest {
name = "unlockedName",
email = "unlockedEmail",
avatarColorHex = "unlockedAvatarColorHex",
isPremium = true,
isVaultUnlocked = true,
),
),
@ -77,6 +80,7 @@ class UserStateExtensionsTest {
name = "name",
email = "email",
avatarColorHex = "avatarColorHex",
isPremium = true,
isVaultUnlocked = true,
)
.toAccountSummary(isActive = true),
@ -98,6 +102,7 @@ class UserStateExtensionsTest {
name = "name",
email = "email",
avatarColorHex = "avatarColorHex",
isPremium = false,
isVaultUnlocked = false,
)
.toAccountSummary(isActive = false),
@ -119,6 +124,7 @@ class UserStateExtensionsTest {
name = "name",
email = "email",
avatarColorHex = "avatarColorHex",
isPremium = true,
isVaultUnlocked = true,
)
.toAccountSummary(isActive = false),
@ -144,6 +150,7 @@ class UserStateExtensionsTest {
name = "name",
email = "email",
avatarColorHex = "avatarColorHex",
isPremium = true,
isVaultUnlocked = true,
),
),