mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 07:05:35 +03:00
Log user out when clicking 'not you' on trusted device screen (#1160)
This commit is contained in:
parent
d7b553e4ef
commit
232ffe93ca
2 changed files with 19 additions and 5 deletions
|
@ -2,6 +2,7 @@ package com.x8bit.bitwarden.ui.auth.feature.trusteddevice
|
|||
|
||||
import android.os.Parcelable
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
|
||||
import com.x8bit.bitwarden.data.platform.repository.EnvironmentRepository
|
||||
import com.x8bit.bitwarden.ui.platform.base.BaseViewModel
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.Text
|
||||
|
@ -20,6 +21,7 @@ private const val KEY_STATE = "state"
|
|||
class TrustedDeviceViewModel @Inject constructor(
|
||||
savedStateHandle: SavedStateHandle,
|
||||
environmentRepository: EnvironmentRepository,
|
||||
private val authRepository: AuthRepository,
|
||||
) : BaseViewModel<TrustedDeviceState, TrustedDeviceEvent, TrustedDeviceAction>(
|
||||
initialState = savedStateHandle[KEY_STATE]
|
||||
?: run {
|
||||
|
@ -71,7 +73,7 @@ class TrustedDeviceViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
private fun handleNotYouClick() {
|
||||
sendEvent(TrustedDeviceEvent.ShowToast("Not yet implemented".asText()))
|
||||
authRepository.logout()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,16 +2,25 @@ package com.x8bit.bitwarden.ui.auth.feature.trusteddevice
|
|||
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import app.cash.turbine.test
|
||||
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
|
||||
import com.x8bit.bitwarden.data.platform.repository.EnvironmentRepository
|
||||
import com.x8bit.bitwarden.data.platform.repository.util.FakeEnvironmentRepository
|
||||
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
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class TrustedDeviceViewModelTest : BaseViewModelTest() {
|
||||
|
||||
private val authRepository: AuthRepository = mockk {
|
||||
every { logout() } just runs
|
||||
}
|
||||
private val environmentRepo: FakeEnvironmentRepository = FakeEnvironmentRepository()
|
||||
|
||||
@Test
|
||||
|
@ -78,18 +87,20 @@ class TrustedDeviceViewModelTest : BaseViewModelTest() {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun `on NotYouClick emits ShowToast`() = runTest {
|
||||
fun `on NotYouClick emits ShowToast`() {
|
||||
val viewModel = createViewModel()
|
||||
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.trySendAction(TrustedDeviceAction.NotYouClick)
|
||||
assertEquals(TrustedDeviceEvent.ShowToast("Not yet implemented".asText()), awaitItem())
|
||||
viewModel.trySendAction(TrustedDeviceAction.NotYouClick)
|
||||
|
||||
verify(exactly = 1) {
|
||||
authRepository.logout()
|
||||
}
|
||||
}
|
||||
|
||||
private fun createViewModel(
|
||||
state: TrustedDeviceState? = null,
|
||||
environmentRepository: EnvironmentRepository = environmentRepo,
|
||||
authorizationRepository: AuthRepository = authRepository,
|
||||
): TrustedDeviceViewModel =
|
||||
TrustedDeviceViewModel(
|
||||
savedStateHandle = SavedStateHandle().apply {
|
||||
|
@ -97,6 +108,7 @@ class TrustedDeviceViewModelTest : BaseViewModelTest() {
|
|||
set("email_address", "email@bitwarden.com")
|
||||
},
|
||||
environmentRepository = environmentRepository,
|
||||
authRepository = authorizationRepository,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue