mirror of
https://github.com/bitwarden/android.git
synced 2026-11-19 17:40:12 -06:00
BIT-467: Implement Lock Now functionality (#327)
This commit is contained in:
committed by
Álison Fernandes
parent
a7dc5fe08f
commit
c72053f935
@@ -469,6 +469,31 @@ class VaultRepositoryTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `lockVaultForCurrentUser should lock the vault for the current user if it is currently unlocked`() =
|
||||
runTest {
|
||||
fakeAuthDiskSource.userState = MOCK_USER_STATE
|
||||
val userId = "mockId-1"
|
||||
verifyUnlockedVault(userId = userId)
|
||||
|
||||
assertEquals(
|
||||
VaultState(
|
||||
unlockedVaultUserIds = setOf(userId),
|
||||
),
|
||||
vaultRepository.vaultStateFlow.value,
|
||||
)
|
||||
|
||||
vaultRepository.lockVaultForCurrentUser()
|
||||
|
||||
assertEquals(
|
||||
VaultState(
|
||||
unlockedVaultUserIds = emptySet(),
|
||||
),
|
||||
vaultRepository.vaultStateFlow.value,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `lockVaultIfNecessary should lock the given account if it is currently unlocked`() =
|
||||
runTest {
|
||||
|
||||
+11
-5
@@ -3,10 +3,13 @@ package com.x8bit.bitwarden.ui.platform.feature.settings.accountsecurity
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import app.cash.turbine.test
|
||||
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
|
||||
import com.x8bit.bitwarden.data.vault.repository.VaultRepository
|
||||
import com.x8bit.bitwarden.ui.platform.base.BaseViewModelTest
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
import io.mockk.every
|
||||
import io.mockk.just
|
||||
import io.mockk.mockk
|
||||
import io.mockk.runs
|
||||
import io.mockk.verify
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
@@ -80,12 +83,13 @@ class AccountSecurityViewModelTest : BaseViewModelTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on LockNowClick should emit ShowToast`() = runTest {
|
||||
val viewModel = createViewModel()
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.trySendAction(AccountSecurityAction.LockNowClick)
|
||||
assertEquals(AccountSecurityEvent.ShowToast("Lock the app.".asText()), awaitItem())
|
||||
fun `on LockNowClick should call lockVaultForCurrentUser`() {
|
||||
val vaultRepository = mockk<VaultRepository>(relaxed = true) {
|
||||
every { lockVaultForCurrentUser() } just runs
|
||||
}
|
||||
val viewModel = createViewModel(vaultRepository = vaultRepository)
|
||||
viewModel.trySendAction(AccountSecurityAction.LockNowClick)
|
||||
verify { vaultRepository.lockVaultForCurrentUser() }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -230,11 +234,13 @@ class AccountSecurityViewModelTest : BaseViewModelTest() {
|
||||
|
||||
private fun createViewModel(
|
||||
authRepository: AuthRepository = mockk(relaxed = true),
|
||||
vaultRepository: VaultRepository = mockk(relaxed = true),
|
||||
savedStateHandle: SavedStateHandle = SavedStateHandle().apply {
|
||||
set("state", DEFAULT_STATE)
|
||||
},
|
||||
): AccountSecurityViewModel = AccountSecurityViewModel(
|
||||
authRepository = authRepository,
|
||||
vaultRepository = vaultRepository,
|
||||
savedStateHandle = savedStateHandle,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user