Move the 'isPremiumUser' flag from a common VaultItem property to a Login specific property (#486)

This commit is contained in:
David Perez 2024-01-03 13:34:11 -06:00 committed by Álison Fernandes
parent c88825f134
commit 11fcaa6678
7 changed files with 18 additions and 34 deletions

View file

@ -96,7 +96,7 @@ fun VaultItemLoginContent(
item {
Spacer(modifier = Modifier.height(8.dp))
TotpField(
isPremiumUser = commonState.isPremiumUser,
isPremiumUser = loginItemState.isPremiumUser,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp),

View file

@ -496,7 +496,6 @@ data class VaultItemState(
* @property lastUpdated A formatted date string indicating when the item was last
* updated.
* @property notes Contains general notes taken by the user.
* @property isPremiumUser Indicates if the user has subscribed to a premium account.
* @property customFields A list of custom fields that user has added.
* @property requiresReprompt Indicates if a master password prompt is required to view
* secure fields.
@ -506,7 +505,6 @@ data class VaultItemState(
val name: String,
val lastUpdated: String,
val notes: String?,
val isPremiumUser: Boolean,
val customFields: List<Custom>,
val requiresReprompt: Boolean,
) : Parcelable {
@ -570,8 +568,11 @@ data class VaultItemState(
* @property passwordHistoryCount An integer indicating how many times the password
* has been changed.
* @property uris The URI associated with the login item.
* @property passwordRevisionDate
* @property totp
* @property passwordRevisionDate An optional string indicating the last time the
* password was changed.
* @property totp The optional TOTP string value to be displayed.
* @property isPremiumUser Indicates if the user has subscribed to a premium
* account.
*/
@Parcelize
data class Login(
@ -581,6 +582,7 @@ data class VaultItemState(
val uris: List<UriData>,
val passwordRevisionDate: String?,
val totp: String?,
val isPremiumUser: Boolean,
) : ItemType() {
/**

View file

@ -32,7 +32,6 @@ fun CipherView.toViewState(
VaultItemState.ViewState.Content(
common = VaultItemState.ViewState.Content.Common(
name = name,
isPremiumUser = isPremiumUser,
requiresReprompt = reprompt == CipherRepromptType.PASSWORD,
customFields = fields.orEmpty().map { it.toCustomField() },
lastUpdated = dateTimeFormatter.format(revisionDate),
@ -55,6 +54,7 @@ fun CipherView.toViewState(
},
passwordHistoryCount = passwordHistory?.count(),
totp = loginValues.totp,
isPremiumUser = isPremiumUser,
)
}

View file

@ -528,6 +528,7 @@ class VaultItemScreenTest : BaseComposeTest() {
uris = emptyList(),
passwordRevisionDate = null,
totp = null,
isPremiumUser = true,
),
),
)
@ -1064,7 +1065,6 @@ private val DEFAULT_COMMON: VaultItemState.ViewState.Content.Common =
lastUpdated = "12/31/69 06:16 PM",
name = "cipher",
notes = "Lots of notes",
isPremiumUser = true,
customFields = listOf(
VaultItemState.ViewState.Content.Common.Custom.TextField(
name = "text",
@ -1102,6 +1102,7 @@ private val DEFAULT_LOGIN: VaultItemState.ViewState.Content.ItemType.Login =
),
passwordRevisionDate = "4/14/83 3:56 PM",
totp = "otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example",
isPremiumUser = true,
)
private val DEFAULT_IDENTITY: VaultItemState.ViewState.Content.ItemType.Identity =
@ -1122,7 +1123,6 @@ private val EMPTY_COMMON: VaultItemState.ViewState.Content.Common =
name = "cipher",
lastUpdated = "12/31/69 06:16 PM",
notes = null,
isPremiumUser = true,
customFields = emptyList(),
requiresReprompt = true,
)
@ -1135,6 +1135,7 @@ private val EMPTY_LOGIN_TYPE: VaultItemState.ViewState.Content.ItemType.Login =
uris = emptyList(),
passwordRevisionDate = null,
totp = null,
isPremiumUser = true,
)
private val EMPTY_IDENTITY_TYPE: VaultItemState.ViewState.Content.ItemType.Identity =

View file

@ -681,6 +681,7 @@ class VaultItemViewModelTest : BaseViewModelTest() {
passwordRevisionDate = "12/31/69 06:16 PM",
totp = "otpauth://totp/Example:alice@google.com" +
"?secret=JBSWY3DPEHPK3PXP&issuer=Example",
isPremiumUser = true,
)
private val DEFAULT_COMMON: VaultItemState.ViewState.Content.Common =
@ -688,7 +689,6 @@ class VaultItemViewModelTest : BaseViewModelTest() {
name = "login cipher",
lastUpdated = "12/31/69 06:16 PM",
notes = "Lots of notes",
isPremiumUser = true,
customFields = listOf(
VaultItemState.ViewState.Content.Common.Custom.TextField(
name = "text",

View file

@ -45,8 +45,8 @@ class CipherViewExtensionsTest {
assertEquals(
VaultItemState.ViewState.Content(
common = createCommonContent(isEmpty = false).copy(isPremiumUser = isPremiumUser),
type = createLoginContent(isEmpty = false),
common = createCommonContent(isEmpty = false),
type = createLoginContent(isEmpty = false).copy(isPremiumUser = isPremiumUser),
),
viewState,
)
@ -66,9 +66,8 @@ class CipherViewExtensionsTest {
)
}
@Suppress("MaxLineLength")
@Test
fun `toViewState should transform full CipherView into ViewState Identity Content with premium`() {
fun `toViewState should transform full CipherView into ViewState Identity Content`() {
val viewState = createCipherView(type = CipherType.IDENTITY, isEmpty = false)
.toViewState(isPremiumUser = true)
@ -81,22 +80,6 @@ class CipherViewExtensionsTest {
)
}
@Suppress("MaxLineLength")
@Test
fun `toViewState should transform full CipherView into ViewState Identity Content without premium`() {
val isPremiumUser = false
val viewState = createCipherView(type = CipherType.IDENTITY, isEmpty = false)
.toViewState(isPremiumUser = isPremiumUser)
assertEquals(
VaultItemState.ViewState.Content(
common = createCommonContent(isEmpty = false).copy(isPremiumUser = isPremiumUser),
type = createIdentityContent(isEmpty = false),
),
viewState,
)
}
@Test
fun `toViewState should transform empty CipherView into ViewState Identity Content`() {
val viewState = createCipherView(type = CipherType.IDENTITY, isEmpty = true)
@ -171,9 +154,8 @@ class CipherViewExtensionsTest {
)
}
@Suppress("MaxLineLength")
@Test
fun `toViewState should transform full CipherView into ViewState Secure Note Content with premium`() {
fun `toViewState should transform full CipherView into ViewState Secure Note Content`() {
val viewState = createCipherView(type = CipherType.SECURE_NOTE, isEmpty = false)
.toViewState(isPremiumUser = true)
@ -193,7 +175,7 @@ class CipherViewExtensionsTest {
.toViewState(isPremiumUser = true)
val expectedState = VaultItemState.ViewState.Content(
common = createCommonContent(isEmpty = true).copy(isPremiumUser = true),
common = createCommonContent(isEmpty = true),
type = VaultItemState.ViewState.Content.ItemType.SecureNote,
)

View file

@ -137,7 +137,6 @@ fun createCommonContent(isEmpty: Boolean): VaultItemState.ViewState.Content.Comm
name = "mockName",
lastUpdated = "1/1/70 12:16 AM",
notes = null,
isPremiumUser = true,
customFields = emptyList(),
requiresReprompt = true,
)
@ -146,7 +145,6 @@ fun createCommonContent(isEmpty: Boolean): VaultItemState.ViewState.Content.Comm
name = "mockName",
lastUpdated = "1/1/70 12:16 AM",
notes = "Lots of notes",
isPremiumUser = true,
customFields = listOf(
VaultItemState.ViewState.Content.Common.Custom.TextField(
name = "text",
@ -199,6 +197,7 @@ fun createLoginContent(isEmpty: Boolean): VaultItemState.ViewState.Content.ItemT
passwordRevisionDate = "1/1/70 12:16 AM".takeUnless { isEmpty },
totp = "otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example"
.takeUnless { isEmpty },
isPremiumUser = true,
)
fun createIdentityContent(