From 0ee25a3dd5fa225a2f08d17586c6e55da4e548c7 Mon Sep 17 00:00:00 2001 From: David Perez Date: Mon, 8 Jan 2024 11:29:55 -0600 Subject: [PATCH] Ensure hasPremium value is set on profile (#534) --- .../data/auth/repository/util/UserStateJsonExtensions.kt | 8 +++++--- .../auth/repository/util/UserStateJsonExtensionsTest.kt | 2 ++ .../data/vault/repository/VaultRepositoryTest.kt | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/x8bit/bitwarden/data/auth/repository/util/UserStateJsonExtensions.kt b/app/src/main/java/com/x8bit/bitwarden/data/auth/repository/util/UserStateJsonExtensions.kt index 5b873451c..28df080e4 100644 --- a/app/src/main/java/com/x8bit/bitwarden/data/auth/repository/util/UserStateJsonExtensions.kt +++ b/app/src/main/java/com/x8bit/bitwarden/data/auth/repository/util/UserStateJsonExtensions.kt @@ -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 diff --git a/app/src/test/java/com/x8bit/bitwarden/data/auth/repository/util/UserStateJsonExtensionsTest.kt b/app/src/test/java/com/x8bit/bitwarden/data/auth/repository/util/UserStateJsonExtensionsTest.kt index 76d9d2115..d3a7c9e96 100644 --- a/app/src/test/java/com/x8bit/bitwarden/data/auth/repository/util/UserStateJsonExtensionsTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/data/auth/repository/util/UserStateJsonExtensionsTest.kt @@ -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 } }, ), diff --git a/app/src/test/java/com/x8bit/bitwarden/data/vault/repository/VaultRepositoryTest.kt b/app/src/test/java/com/x8bit/bitwarden/data/vault/repository/VaultRepositoryTest.kt index bcd27d754..926b2cc3b 100644 --- a/app/src/test/java/com/x8bit/bitwarden/data/vault/repository/VaultRepositoryTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/data/vault/repository/VaultRepositoryTest.kt @@ -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,