Ensure hasPremium value is set on profile (#534)

This commit is contained in:
David Perez 2024-01-08 11:29:55 -06:00 committed by Álison Fernandes
parent ab5ea4ebaa
commit 0ee25a3dd5
3 changed files with 8 additions and 4 deletions

View file

@ -17,14 +17,16 @@ import com.x8bit.bitwarden.ui.platform.base.util.toHexColorRepresentation
fun UserStateJson.toUpdatedUserStateJson(
syncResponse: SyncResponseJson,
): UserStateJson {
val userId = syncResponse.profile.id
val syncProfile = syncResponse.profile
val userId = syncProfile.id
val account = this.accounts[userId] ?: return this
val profile = account.profile
// TODO: Update additional missing UserStateJson properties (BIT-916)
val updatedProfile = profile
.copy(
avatarColorHex = syncResponse.profile.avatarColor,
stamp = syncResponse.profile.securityStamp,
avatarColorHex = syncProfile.avatarColor,
stamp = syncProfile.securityStamp,
hasPremium = syncProfile.isPremium || syncProfile.isPremiumFromOrganization,
)
val updatedAccount = account.copy(profile = updatedProfile)
return this

View file

@ -83,6 +83,8 @@ class UserStateJsonExtensionsTest {
every { id } returns "activeUserId"
every { avatarColor } returns "avatarColor"
every { securityStamp } returns "securityStamp"
every { isPremium } returns true
every { isPremiumFromOrganization } returns true
}
},
),

View file

@ -2121,7 +2121,7 @@ private val MOCK_PROFILE = AccountJson.Profile(
stamp = null,
organizationId = null,
avatarColorHex = null,
hasPremium = true,
hasPremium = false,
forcePasswordResetReason = null,
kdfType = null,
kdfIterations = null,