BIT-1663: Display toast when auth request is declined or approved (#968)

This commit is contained in:
David Perez 2024-02-06 12:50:35 -06:00 committed by Álison Fernandes
parent 8cb167d522
commit b8e2f7856a
2 changed files with 20 additions and 3 deletions

View file

@ -99,7 +99,7 @@ class LoginApprovalViewModel @Inject constructor(
private fun handleApproveRequestClicked() {
viewModelScope.launch {
trySendAction(
LoginApprovalAction.Internal.DeclineRequestResultReceive(
LoginApprovalAction.Internal.ApproveRequestResultReceive(
result = authRepository.updateAuthRequest(
requestId = mutableStateFlow.value.requestId,
masterPasswordHash = mutableStateFlow.value.masterPasswordHash,
@ -195,6 +195,7 @@ class LoginApprovalViewModel @Inject constructor(
) {
when (action.result) {
is AuthRequestResult.Success -> {
sendEvent(LoginApprovalEvent.ShowToast(R.string.log_in_denied.asText()))
sendEvent(LoginApprovalEvent.NavigateBack)
}

View file

@ -2,6 +2,7 @@ package com.x8bit.bitwarden.ui.platform.feature.settings.accountsecurity.loginap
import androidx.lifecycle.SavedStateHandle
import app.cash.turbine.test
import com.x8bit.bitwarden.R
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
import com.x8bit.bitwarden.data.auth.repository.model.AuthRequest
import com.x8bit.bitwarden.data.auth.repository.model.AuthRequestResult
@ -13,6 +14,7 @@ import com.x8bit.bitwarden.data.platform.manager.model.SpecialCircumstance
import com.x8bit.bitwarden.data.platform.repository.model.Environment
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.ui.platform.base.BaseViewModelTest
import com.x8bit.bitwarden.ui.platform.base.util.asText
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.every
@ -176,7 +178,14 @@ class LoginApprovalViewModelTest : BaseViewModelTest() {
)
} returns AuthRequestResult.Success(AUTH_REQUEST)
viewModel.eventFlow.test {
viewModel.trySendAction(LoginApprovalAction.ApproveRequestClick)
assertEquals(
LoginApprovalEvent.ShowToast(R.string.login_approved.asText()),
awaitItem(),
)
assertEquals(LoginApprovalEvent.NavigateBack, awaitItem())
}
coVerify {
mockAuthRepository.updateAuthRequest(
@ -200,7 +209,14 @@ class LoginApprovalViewModelTest : BaseViewModelTest() {
)
} returns AuthRequestResult.Success(AUTH_REQUEST)
viewModel.eventFlow.test {
viewModel.trySendAction(LoginApprovalAction.DeclineRequestClick)
assertEquals(
LoginApprovalEvent.ShowToast(R.string.log_in_denied.asText()),
awaitItem(),
)
assertEquals(LoginApprovalEvent.NavigateBack, awaitItem())
}
coVerify {
mockAuthRepository.updateAuthRequest(