Create single helper method to clean up the MainViewModelTest (#4126)

This commit is contained in:
David Perez 2024-10-21 15:42:11 -05:00 committed by GitHub
parent b82614e5fa
commit df6e842201
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,7 +8,6 @@ import com.bitwarden.vault.CipherView
import com.x8bit.bitwarden.data.auth.datasource.disk.model.OnboardingStatus
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
import com.x8bit.bitwarden.data.auth.repository.model.EmailTokenResult
import com.x8bit.bitwarden.data.platform.manager.model.FirstTimeState
import com.x8bit.bitwarden.data.auth.repository.model.SwitchAccountResult
import com.x8bit.bitwarden.data.auth.repository.model.UserState
import com.x8bit.bitwarden.data.auth.util.getCompleteRegistrationDataIntentOrNull
@ -37,6 +36,7 @@ import com.x8bit.bitwarden.data.platform.manager.SpecialCircumstanceManager
import com.x8bit.bitwarden.data.platform.manager.SpecialCircumstanceManagerImpl
import com.x8bit.bitwarden.data.platform.manager.garbage.GarbageCollectionManager
import com.x8bit.bitwarden.data.platform.manager.model.CompleteRegistrationData
import com.x8bit.bitwarden.data.platform.manager.model.FirstTimeState
import com.x8bit.bitwarden.data.platform.manager.model.PasswordlessRequestData
import com.x8bit.bitwarden.data.platform.manager.model.SpecialCircumstance
import com.x8bit.bitwarden.data.platform.repository.EnvironmentRepository
@ -128,7 +128,9 @@ class MainViewModelTest : BaseViewModelTest() {
Intent::getAutofillSaveItemOrNull,
Intent::getAutofillSelectionDataOrNull,
Intent::getCompleteRegistrationDataIntentOrNull,
Intent::getFido2AssertionRequestOrNull,
Intent::getFido2CredentialRequestOrNull,
Intent::getFido2GetCredentialsRequestOrNull,
)
mockkStatic(
Intent::isMyVaultShortcut,
@ -145,6 +147,9 @@ class MainViewModelTest : BaseViewModelTest() {
Intent::getAutofillSaveItemOrNull,
Intent::getAutofillSelectionDataOrNull,
Intent::getCompleteRegistrationDataIntentOrNull,
Intent::getFido2AssertionRequestOrNull,
Intent::getFido2CredentialRequestOrNull,
Intent::getFido2GetCredentialsRequestOrNull,
)
unmockkStatic(
Intent::isMyVaultShortcut,
@ -306,17 +311,8 @@ class MainViewModelTest : BaseViewModelTest() {
@Test
fun `on ReceiveFirstIntent with TOTP data should set the special circumstance to AddTotpLoginItem`() {
val viewModel = createViewModel()
val mockIntent = mockk<Intent>()
val totpData = mockk<TotpData>()
every { mockIntent.getTotpDataOrNull() } returns totpData
every { mockIntent.getPasswordlessRequestDataIntentOrNull() } returns null
every { mockIntent.getAutofillSaveItemOrNull() } returns null
every { mockIntent.getAutofillSelectionDataOrNull() } returns null
every { mockIntent.getCompleteRegistrationDataIntentOrNull() } returns null
every { intentManager.getShareDataFromIntent(mockIntent) } returns null
every { mockIntent.isMyVaultShortcut } returns false
every { mockIntent.isPasswordGeneratorShortcut } returns false
every { mockIntent.isAccountSecurityShortcut } returns false
val mockIntent = createMockIntent(mockTotpData = totpData)
viewModel.trySendAction(MainAction.ReceiveFirstIntent(intent = mockIntent))
assertEquals(
@ -329,17 +325,9 @@ class MainViewModelTest : BaseViewModelTest() {
@Test
fun `on ReceiveFirstIntent with share data should set the special circumstance to ShareNewSend`() {
val viewModel = createViewModel()
val mockIntent = mockk<Intent>()
val mockIntent = createMockIntent()
val shareData = mockk<IntentManager.ShareData>()
every { mockIntent.getTotpDataOrNull() } returns null
every { mockIntent.getPasswordlessRequestDataIntentOrNull() } returns null
every { mockIntent.getAutofillSaveItemOrNull() } returns null
every { mockIntent.getAutofillSelectionDataOrNull() } returns null
every { mockIntent.getCompleteRegistrationDataIntentOrNull() } returns null
every { intentManager.getShareDataFromIntent(mockIntent) } returns shareData
every { mockIntent.isMyVaultShortcut } returns false
every { mockIntent.isPasswordGeneratorShortcut } returns false
every { mockIntent.isAccountSecurityShortcut } returns false
viewModel.trySendAction(
MainAction.ReceiveFirstIntent(
@ -359,17 +347,8 @@ class MainViewModelTest : BaseViewModelTest() {
@Test
fun `on ReceiveFirstIntent with autofill data should set the special circumstance to AutofillSelection`() {
val viewModel = createViewModel()
val mockIntent = mockk<Intent>()
val autofillSelectionData = mockk<AutofillSelectionData>()
every { mockIntent.getTotpDataOrNull() } returns null
every { mockIntent.getPasswordlessRequestDataIntentOrNull() } returns null
every { mockIntent.getAutofillSaveItemOrNull() } returns null
every { mockIntent.getCompleteRegistrationDataIntentOrNull() } returns null
every { mockIntent.getAutofillSelectionDataOrNull() } returns autofillSelectionData
every { intentManager.getShareDataFromIntent(mockIntent) } returns null
every { mockIntent.isMyVaultShortcut } returns false
every { mockIntent.isPasswordGeneratorShortcut } returns false
every { mockIntent.isAccountSecurityShortcut } returns false
val mockIntent = createMockIntent(mockAutofillSelectionData = autofillSelectionData)
viewModel.trySendAction(
MainAction.ReceiveFirstIntent(
@ -393,17 +372,7 @@ class MainViewModelTest : BaseViewModelTest() {
every { email } returns "email"
every { verificationToken } returns "token"
}
val mockIntent = mockk<Intent> {
every { getTotpDataOrNull() } returns null
every { getPasswordlessRequestDataIntentOrNull() } returns null
every { getAutofillSaveItemOrNull() } returns null
every { getCompleteRegistrationDataIntentOrNull() } returns completeRegistrationData
every { getAutofillSelectionDataOrNull() } returns null
every { isMyVaultShortcut } returns false
every { isPasswordGeneratorShortcut } returns false
every { isAccountSecurityShortcut } returns false
}
every { intentManager.getShareDataFromIntent(mockIntent) } returns null
val mockIntent = createMockIntent(mockCompleteRegistrationData = completeRegistrationData)
every { authRepository.activeUserId } returns null
viewModel.trySendAction(
@ -430,17 +399,7 @@ class MainViewModelTest : BaseViewModelTest() {
every { email } returns "email"
every { verificationToken } returns "token"
}
val mockIntent = mockk<Intent> {
every { getTotpDataOrNull() } returns null
every { getPasswordlessRequestDataIntentOrNull() } returns null
every { getAutofillSaveItemOrNull() } returns null
every { getCompleteRegistrationDataIntentOrNull() } returns completeRegistrationData
every { getAutofillSelectionDataOrNull() } returns null
every { isMyVaultShortcut } returns false
every { isPasswordGeneratorShortcut } returns false
every { isAccountSecurityShortcut } returns false
}
every { intentManager.getShareDataFromIntent(mockIntent) } returns null
val mockIntent = createMockIntent(mockCompleteRegistrationData = completeRegistrationData)
every { authRepository.activeUserId } returns "activeId"
every { authRepository.hasPendingAccountAddition = true } just runs
@ -469,17 +428,7 @@ class MainViewModelTest : BaseViewModelTest() {
every { email } returns intentEmail
every { verificationToken } returns token
}
val mockIntent = mockk<Intent> {
every { getTotpDataOrNull() } returns null
every { getPasswordlessRequestDataIntentOrNull() } returns null
every { getAutofillSaveItemOrNull() } returns null
every { getCompleteRegistrationDataIntentOrNull() } returns completeRegistrationData
every { getAutofillSelectionDataOrNull() } returns null
every { isMyVaultShortcut } returns false
every { isPasswordGeneratorShortcut } returns false
every { isAccountSecurityShortcut } returns false
}
every { intentManager.getShareDataFromIntent(mockIntent) } returns null
val mockIntent = createMockIntent(mockCompleteRegistrationData = completeRegistrationData)
every { authRepository.activeUserId } returns null
coEvery {
authRepository.validateEmailToken(
@ -510,17 +459,9 @@ class MainViewModelTest : BaseViewModelTest() {
every { email } returns intentEmail
every { verificationToken } returns token
}
val mockIntent = mockk<Intent> {
every { getTotpDataOrNull() } returns null
every { getPasswordlessRequestDataIntentOrNull() } returns null
every { getAutofillSaveItemOrNull() } returns null
every { getCompleteRegistrationDataIntentOrNull() } returns completeRegistrationData
every { getAutofillSelectionDataOrNull() } returns null
every { isMyVaultShortcut } returns false
every { isPasswordGeneratorShortcut } returns false
every { isAccountSecurityShortcut } returns false
}
every { intentManager.getShareDataFromIntent(mockIntent) } returns null
val mockIntent = createMockIntent(
mockCompleteRegistrationData = completeRegistrationData,
)
every { authRepository.activeUserId } returns null
coEvery {
authRepository.validateEmailToken(
@ -553,17 +494,9 @@ class MainViewModelTest : BaseViewModelTest() {
every { email } returns intentEmail
every { verificationToken } returns token
}
val mockIntent = mockk<Intent> {
every { getTotpDataOrNull() } returns null
every { getPasswordlessRequestDataIntentOrNull() } returns null
every { getAutofillSaveItemOrNull() } returns null
every { getCompleteRegistrationDataIntentOrNull() } returns completeRegistrationData
every { getAutofillSelectionDataOrNull() } returns null
every { isMyVaultShortcut } returns false
every { isPasswordGeneratorShortcut } returns false
every { isAccountSecurityShortcut } returns false
}
every { intentManager.getShareDataFromIntent(mockIntent) } returns null
val mockIntent = createMockIntent(
mockCompleteRegistrationData = completeRegistrationData,
)
every { authRepository.activeUserId } returns null
val expectedMessage = "expectedMessage"
@ -591,17 +524,8 @@ class MainViewModelTest : BaseViewModelTest() {
@Test
fun `on ReceiveFirstIntent with an autofill save item should set the special circumstance to AutofillSave`() {
val viewModel = createViewModel()
val mockIntent = mockk<Intent>()
val autofillSaveItem = mockk<AutofillSaveItem>()
every { mockIntent.getTotpDataOrNull() } returns null
every { mockIntent.getPasswordlessRequestDataIntentOrNull() } returns null
every { mockIntent.getAutofillSaveItemOrNull() } returns autofillSaveItem
every { mockIntent.getAutofillSelectionDataOrNull() } returns null
every { mockIntent.getCompleteRegistrationDataIntentOrNull() } returns null
every { intentManager.getShareDataFromIntent(mockIntent) } returns null
every { mockIntent.isMyVaultShortcut } returns false
every { mockIntent.isPasswordGeneratorShortcut } returns false
every { mockIntent.isAccountSecurityShortcut } returns false
val mockIntent = createMockIntent(mockAutofillSaveItem = autofillSaveItem)
viewModel.trySendAction(
MainAction.ReceiveFirstIntent(
@ -620,19 +544,8 @@ class MainViewModelTest : BaseViewModelTest() {
@Test
fun `on ReceiveFirstIntent with a passwordless request data should set the special circumstance to PasswordlessRequest`() {
val viewModel = createViewModel()
val mockIntent = mockk<Intent>()
val passwordlessRequestData = DEFAULT_PASSWORDLESS_REQUEST_DATA
every {
mockIntent.getPasswordlessRequestDataIntentOrNull()
} returns passwordlessRequestData
every { mockIntent.getTotpDataOrNull() } returns null
every { mockIntent.getAutofillSaveItemOrNull() } returns null
every { mockIntent.getAutofillSelectionDataOrNull() } returns null
every { mockIntent.getCompleteRegistrationDataIntentOrNull() } returns null
every { intentManager.getShareDataFromIntent(mockIntent) } returns null
every { mockIntent.isMyVaultShortcut } returns false
every { mockIntent.isPasswordGeneratorShortcut } returns false
every { mockIntent.isAccountSecurityShortcut } returns false
val mockIntent = createMockIntent(mockPasswordlessRequestData = passwordlessRequestData)
viewModel.trySendAction(
MainAction.ReceiveFirstIntent(
@ -659,9 +572,8 @@ class MainViewModelTest : BaseViewModelTest() {
signingInfo = SigningInfo(),
origin = "mockOrigin",
)
val fido2Intent = createMockFido2RegistrationIntent(fido2CredentialRequest)
val fido2Intent = createMockIntent(mockFido2CredentialRequest = fido2CredentialRequest)
every { intentManager.getShareDataFromIntent(fido2Intent) } returns null
coEvery {
fido2CredentialManager.validateOrigin(
fido2CredentialRequest.callingAppInfo,
@ -686,7 +598,9 @@ class MainViewModelTest : BaseViewModelTest() {
@Test
fun `on ReceiveFirstIntent with fido2 request data should set the user to unverified`() {
val viewModel = createViewModel()
val fido2Intent = createMockFido2RegistrationIntent()
val fido2Intent = createMockIntent(
mockFido2CredentialRequest = createMockFido2CredentialRequest(number = 1),
)
viewModel.trySendAction(
MainAction.ReceiveFirstIntent(
@ -711,18 +625,7 @@ class MainViewModelTest : BaseViewModelTest() {
signingInfo = SigningInfo(),
origin = "mockOrigin",
)
val mockIntent = mockk<Intent> {
every { getTotpDataOrNull() } returns null
every { getFido2CredentialRequestOrNull() } returns fido2CredentialRequest
every { getPasswordlessRequestDataIntentOrNull() } returns null
every { getAutofillSelectionDataOrNull() } returns null
every { getAutofillSaveItemOrNull() } returns null
every { getCompleteRegistrationDataIntentOrNull() } returns null
every { isMyVaultShortcut } returns false
every { isPasswordGeneratorShortcut } returns false
every { isAccountSecurityShortcut } returns false
}
every { intentManager.getShareDataFromIntent(mockIntent) } returns null
val mockIntent = createMockIntent(mockFido2CredentialRequest = fido2CredentialRequest)
coEvery {
fido2CredentialManager.validateOrigin(
fido2CredentialRequest.callingAppInfo,
@ -750,18 +653,7 @@ class MainViewModelTest : BaseViewModelTest() {
signingInfo = SigningInfo(),
origin = "mockOrigin",
)
val mockIntent = mockk<Intent> {
every { getFido2CredentialRequestOrNull() } returns fido2CredentialRequest
every { getTotpDataOrNull() } returns null
every { getPasswordlessRequestDataIntentOrNull() } returns null
every { getAutofillSelectionDataOrNull() } returns null
every { getAutofillSaveItemOrNull() } returns null
every { getCompleteRegistrationDataIntentOrNull() } returns null
every { isMyVaultShortcut } returns false
every { isPasswordGeneratorShortcut } returns false
every { isAccountSecurityShortcut } returns false
}
every { intentManager.getShareDataFromIntent(mockIntent) } returns null
val mockIntent = createMockIntent(mockFido2CredentialRequest = fido2CredentialRequest)
coEvery {
fido2CredentialManager.validateOrigin(
fido2CredentialRequest.callingAppInfo,
@ -783,9 +675,9 @@ class MainViewModelTest : BaseViewModelTest() {
fun `on ReceiveFirstIntent with FIDO 2 assertion request data should set the special circumstance to Fido2Assertion`() {
val viewModel = createViewModel()
val mockAssertionRequest = createMockFido2CredentialAssertionRequest(number = 1)
val fido2AssertionIntent = createMockFido2AssertionIntent(mockAssertionRequest)
every { intentManager.getShareDataFromIntent(fido2AssertionIntent) } returns null
val fido2AssertionIntent = createMockIntent(
mockFido2CredentialAssertionRequest = mockAssertionRequest,
)
viewModel.trySendAction(
MainAction.ReceiveFirstIntent(
@ -804,9 +696,9 @@ class MainViewModelTest : BaseViewModelTest() {
fun `on ReceiveFirstIntent with fido2 get credentials request data should set the special circumstance to Fido2GetCredentials`() {
val viewModel = createViewModel()
val mockGetCredentialsRequest = createMockFido2GetCredentialsRequest(number = 1)
val mockIntent = createMockFido2GetCredentialsIntent(mockGetCredentialsRequest)
every { intentManager.getShareDataFromIntent(mockIntent) } returns null
val mockIntent = createMockIntent(
mockFido2GetCredentialsRequest = mockGetCredentialsRequest,
)
viewModel.trySendAction(
MainAction.ReceiveFirstIntent(
@ -824,17 +716,9 @@ class MainViewModelTest : BaseViewModelTest() {
@Test
fun `on ReceiveNewIntent with share data should set the special circumstance to ShareNewSend`() {
val viewModel = createViewModel()
val mockIntent = mockk<Intent>()
val mockIntent = createMockIntent()
val shareData = mockk<IntentManager.ShareData>()
every { mockIntent.getTotpDataOrNull() } returns null
every { mockIntent.getPasswordlessRequestDataIntentOrNull() } returns null
every { mockIntent.getAutofillSaveItemOrNull() } returns null
every { mockIntent.getAutofillSelectionDataOrNull() } returns null
every { mockIntent.getCompleteRegistrationDataIntentOrNull() } returns null
every { intentManager.getShareDataFromIntent(mockIntent) } returns shareData
every { mockIntent.isMyVaultShortcut } returns false
every { mockIntent.isPasswordGeneratorShortcut } returns false
every { mockIntent.isAccountSecurityShortcut } returns false
viewModel.trySendAction(
MainAction.ReceiveNewIntent(
@ -854,17 +738,8 @@ class MainViewModelTest : BaseViewModelTest() {
@Test
fun `on ReceiveNewIntent with TOTP data should set the special circumstance to AddTotpLoginItem`() {
val viewModel = createViewModel()
val mockIntent = mockk<Intent>()
val totpData = mockk<TotpData>()
every { mockIntent.getTotpDataOrNull() } returns totpData
every { mockIntent.getPasswordlessRequestDataIntentOrNull() } returns null
every { mockIntent.getAutofillSaveItemOrNull() } returns null
every { mockIntent.getAutofillSelectionDataOrNull() } returns null
every { mockIntent.getCompleteRegistrationDataIntentOrNull() } returns null
every { intentManager.getShareDataFromIntent(mockIntent) } returns null
every { mockIntent.isMyVaultShortcut } returns false
every { mockIntent.isPasswordGeneratorShortcut } returns false
every { mockIntent.isAccountSecurityShortcut } returns false
val mockIntent = createMockIntent(mockTotpData = totpData)
viewModel.trySendAction(MainAction.ReceiveNewIntent(intent = mockIntent))
assertEquals(
@ -877,17 +752,8 @@ class MainViewModelTest : BaseViewModelTest() {
@Test
fun `on ReceiveNewIntent with autofill data should set the special circumstance to AutofillSelection`() {
val viewModel = createViewModel()
val mockIntent = mockk<Intent>()
val autofillSelectionData = mockk<AutofillSelectionData>()
every { mockIntent.getTotpDataOrNull() } returns null
every { mockIntent.getPasswordlessRequestDataIntentOrNull() } returns null
every { mockIntent.getAutofillSaveItemOrNull() } returns null
every { mockIntent.getCompleteRegistrationDataIntentOrNull() } returns null
every { mockIntent.getAutofillSelectionDataOrNull() } returns autofillSelectionData
every { intentManager.getShareDataFromIntent(mockIntent) } returns null
every { mockIntent.isMyVaultShortcut } returns false
every { mockIntent.isPasswordGeneratorShortcut } returns false
every { mockIntent.isAccountSecurityShortcut } returns false
val mockIntent = createMockIntent(mockAutofillSelectionData = autofillSelectionData)
viewModel.trySendAction(
MainAction.ReceiveNewIntent(
@ -907,17 +773,8 @@ class MainViewModelTest : BaseViewModelTest() {
@Test
fun `on ReceiveNewIntent with an autofill save item should set the special circumstance to AutofillSave`() {
val viewModel = createViewModel()
val mockIntent = mockk<Intent>()
val autofillSaveItem = mockk<AutofillSaveItem>()
every { mockIntent.getTotpDataOrNull() } returns null
every { mockIntent.getPasswordlessRequestDataIntentOrNull() } returns null
every { mockIntent.getAutofillSaveItemOrNull() } returns autofillSaveItem
every { mockIntent.getAutofillSelectionDataOrNull() } returns null
every { mockIntent.getCompleteRegistrationDataIntentOrNull() } returns null
every { intentManager.getShareDataFromIntent(mockIntent) } returns null
every { mockIntent.isMyVaultShortcut } returns false
every { mockIntent.isPasswordGeneratorShortcut } returns false
every { mockIntent.isAccountSecurityShortcut } returns false
val mockIntent = createMockIntent(mockAutofillSaveItem = autofillSaveItem)
viewModel.trySendAction(
MainAction.ReceiveNewIntent(
@ -936,19 +793,8 @@ class MainViewModelTest : BaseViewModelTest() {
@Test
fun `on ReceiveNewIntent with a passwordless auth request data should set the special circumstance to PasswordlessRequest`() {
val viewModel = createViewModel()
val mockIntent = mockk<Intent>()
val passwordlessRequestData = DEFAULT_PASSWORDLESS_REQUEST_DATA
every {
mockIntent.getPasswordlessRequestDataIntentOrNull()
} returns passwordlessRequestData
every { mockIntent.getTotpDataOrNull() } returns null
every { mockIntent.getAutofillSaveItemOrNull() } returns null
every { mockIntent.getAutofillSelectionDataOrNull() } returns null
every { mockIntent.getCompleteRegistrationDataIntentOrNull() } returns null
every { intentManager.getShareDataFromIntent(mockIntent) } returns null
every { mockIntent.isMyVaultShortcut } returns false
every { mockIntent.isPasswordGeneratorShortcut } returns false
every { mockIntent.isAccountSecurityShortcut } returns false
val mockIntent = createMockIntent(mockPasswordlessRequestData = passwordlessRequestData)
viewModel.trySendAction(
MainAction.ReceiveNewIntent(
@ -968,17 +814,7 @@ class MainViewModelTest : BaseViewModelTest() {
@Test
fun `on ReceiveNewIntent with a Vault deeplink data should set the special circumstance to VaultShortcut`() {
val viewModel = createViewModel()
val mockIntent = mockk<Intent> {
every { getTotpDataOrNull() } returns null
every { getPasswordlessRequestDataIntentOrNull() } returns null
every { getAutofillSaveItemOrNull() } returns null
every { getAutofillSelectionDataOrNull() } returns null
every { getCompleteRegistrationDataIntentOrNull() } returns null
every { isMyVaultShortcut } returns true
every { isPasswordGeneratorShortcut } returns false
every { isAccountSecurityShortcut } returns false
}
every { intentManager.getShareDataFromIntent(mockIntent) } returns null
val mockIntent = createMockIntent(mockIsMyVaultShortcut = true)
viewModel.trySendAction(
MainAction.ReceiveNewIntent(
@ -995,17 +831,7 @@ class MainViewModelTest : BaseViewModelTest() {
@Test
fun `on ReceiveNewIntent with account security deeplink data should set the special circumstance to AccountSecurityShortcut `() {
val viewModel = createViewModel()
val mockIntent = mockk<Intent> {
every { getTotpDataOrNull() } returns null
every { getPasswordlessRequestDataIntentOrNull() } returns null
every { getAutofillSaveItemOrNull() } returns null
every { getAutofillSelectionDataOrNull() } returns null
every { getCompleteRegistrationDataIntentOrNull() } returns null
every { isMyVaultShortcut } returns false
every { isPasswordGeneratorShortcut } returns false
every { isAccountSecurityShortcut } returns true
}
every { intentManager.getShareDataFromIntent(mockIntent) } returns null
val mockIntent = createMockIntent(mockIsAccountSecurityShortcut = true)
viewModel.trySendAction(
MainAction.ReceiveNewIntent(
@ -1022,17 +848,7 @@ class MainViewModelTest : BaseViewModelTest() {
@Test
fun `on ReceiveNewIntent with a password generator deeplink data should set the special circumstance to GeneratorShortcut`() {
val viewModel = createViewModel()
val mockIntent = mockk<Intent> {
every { getTotpDataOrNull() } returns null
every { getPasswordlessRequestDataIntentOrNull() } returns null
every { getAutofillSaveItemOrNull() } returns null
every { getAutofillSelectionDataOrNull() } returns null
every { getCompleteRegistrationDataIntentOrNull() } returns null
every { isMyVaultShortcut } returns false
every { isPasswordGeneratorShortcut } returns true
every { isAccountSecurityShortcut } returns false
}
every { intentManager.getShareDataFromIntent(mockIntent) } returns null
val mockIntent = createMockIntent(mockIsPasswordGeneratorShortcut = true)
viewModel.trySendAction(
MainAction.ReceiveNewIntent(
@ -1109,20 +925,9 @@ class MainViewModelTest : BaseViewModelTest() {
fun `on ReceiveNewIntent with a passwordless auth request data userId that doesn't match activeUserId and the vault is not locked should switchAccount`() {
val userId = "userId"
val viewModel = createViewModel()
val mockIntent = mockk<Intent>()
val passwordlessRequestData = mockk<PasswordlessRequestData>()
val mockIntent = createMockIntent(mockPasswordlessRequestData = passwordlessRequestData)
every { vaultRepository.isVaultUnlocked(ACTIVE_USER_ID) } returns false
every {
mockIntent.getPasswordlessRequestDataIntentOrNull()
} returns passwordlessRequestData
every { mockIntent.getTotpDataOrNull() } returns null
every { mockIntent.getAutofillSaveItemOrNull() } returns null
every { mockIntent.getAutofillSelectionDataOrNull() } returns null
every { mockIntent.getCompleteRegistrationDataIntentOrNull() } returns null
every { intentManager.getShareDataFromIntent(mockIntent) } returns null
every { mockIntent.isMyVaultShortcut } returns false
every { mockIntent.isPasswordGeneratorShortcut } returns false
every { mockIntent.isAccountSecurityShortcut } returns false
every { passwordlessRequestData.userId } returns userId
viewModel.trySendAction(
@ -1195,51 +1000,31 @@ private val DEFAULT_PASSWORDLESS_REQUEST_DATA = PasswordlessRequestData(
loginRequestId = "",
)
private fun createMockFido2RegistrationIntent(
fido2CredentialRequest: Fido2CredentialRequest = createMockFido2CredentialRequest(number = 1),
@Suppress("LongParameterList")
private fun createMockIntent(
mockTotpData: TotpData? = null,
mockPasswordlessRequestData: PasswordlessRequestData? = null,
mockAutofillSaveItem: AutofillSaveItem? = null,
mockAutofillSelectionData: AutofillSelectionData? = null,
mockCompleteRegistrationData: CompleteRegistrationData? = null,
mockFido2CredentialAssertionRequest: Fido2CredentialAssertionRequest? = null,
mockFido2CredentialRequest: Fido2CredentialRequest? = null,
mockFido2GetCredentialsRequest: Fido2GetCredentialsRequest? = null,
mockIsMyVaultShortcut: Boolean = false,
mockIsPasswordGeneratorShortcut: Boolean = false,
mockIsAccountSecurityShortcut: Boolean = false,
): Intent = mockk<Intent> {
every { getFido2CredentialRequestOrNull() } returns fido2CredentialRequest
every { getTotpDataOrNull() } returns null
every { getPasswordlessRequestDataIntentOrNull() } returns null
every { getAutofillSelectionDataOrNull() } returns null
every { getAutofillSaveItemOrNull() } returns null
every { getCompleteRegistrationDataIntentOrNull() } returns null
every { isMyVaultShortcut } returns false
every { isPasswordGeneratorShortcut } returns false
every { isAccountSecurityShortcut } returns false
}
private fun createMockFido2AssertionIntent(
fido2CredentialAssertionRequest: Fido2CredentialAssertionRequest =
createMockFido2CredentialAssertionRequest(number = 1),
): Intent = mockk<Intent> {
every { getFido2AssertionRequestOrNull() } returns fido2CredentialAssertionRequest
every { getTotpDataOrNull() } returns null
every { getPasswordlessRequestDataIntentOrNull() } returns null
every { getAutofillSelectionDataOrNull() } returns null
every { getAutofillSaveItemOrNull() } returns null
every { getCompleteRegistrationDataIntentOrNull() } returns null
every { isMyVaultShortcut } returns false
every { isPasswordGeneratorShortcut } returns false
every { isAccountSecurityShortcut } returns false
}
private fun createMockFido2GetCredentialsIntent(
fido2GetCredentialsRequest: Fido2GetCredentialsRequest = createMockFido2GetCredentialsRequest(
number = 1,
),
): Intent = mockk<Intent> {
every { getFido2GetCredentialsRequestOrNull() } returns fido2GetCredentialsRequest
every { getTotpDataOrNull() } returns null
every { getPasswordlessRequestDataIntentOrNull() } returns null
every { getAutofillSelectionDataOrNull() } returns null
every { getAutofillSaveItemOrNull() } returns null
every { getFido2CredentialRequestOrNull() } returns null
every { getFido2AssertionRequestOrNull() } returns null
every { getCompleteRegistrationDataIntentOrNull() } returns null
every { isMyVaultShortcut } returns false
every { isPasswordGeneratorShortcut } returns false
every { isAccountSecurityShortcut } returns false
every { getTotpDataOrNull() } returns mockTotpData
every { getPasswordlessRequestDataIntentOrNull() } returns mockPasswordlessRequestData
every { getAutofillSaveItemOrNull() } returns mockAutofillSaveItem
every { getAutofillSelectionDataOrNull() } returns mockAutofillSelectionData
every { getCompleteRegistrationDataIntentOrNull() } returns mockCompleteRegistrationData
every { getFido2AssertionRequestOrNull() } returns mockFido2CredentialAssertionRequest
every { getFido2CredentialRequestOrNull() } returns mockFido2CredentialRequest
every { getFido2GetCredentialsRequestOrNull() } returns mockFido2GetCredentialsRequest
every { isMyVaultShortcut } returns mockIsMyVaultShortcut
every { isPasswordGeneratorShortcut } returns mockIsPasswordGeneratorShortcut
every { isAccountSecurityShortcut } returns mockIsAccountSecurityShortcut
}
private val FIXED_CLOCK: Clock = Clock.fixed(