Remove AccountOAuthContract.State.authorizationState

This commit is contained in:
cketti 2023-08-16 13:11:14 +02:00
parent 40d7db53f4
commit 476cd91624
7 changed files with 14 additions and 37 deletions

View file

@ -20,7 +20,7 @@ interface DomainContract {
}
fun interface FinishOAuthSignIn {
suspend fun execute(authorizationState: AuthorizationState, intent: Intent): AuthorizationResult
suspend fun execute(intent: Intent): AuthorizationResult
}
fun interface CheckIsGoogleSignIn {

View file

@ -9,12 +9,12 @@ import app.k9mail.feature.account.oauth.domain.entity.AuthorizationState
class FinishOAuthSignIn(
private val repository: DomainContract.AuthorizationRepository,
) : UseCase.FinishOAuthSignIn {
override suspend fun execute(authorizationState: AuthorizationState, intent: Intent): AuthorizationResult {
override suspend fun execute(intent: Intent): AuthorizationResult {
val response = repository.getAuthorizationResponse(intent)
val exception = repository.getAuthorizationException(intent)
return if (response != null) {
repository.getExchangeToken(authorizationState, response)
repository.getExchangeToken(AuthorizationState(), response)
} else if (exception != null) {
AuthorizationResult.Failure(exception)
} else {

View file

@ -14,7 +14,6 @@ interface AccountOAuthContract {
data class State(
val hostname: String = "",
val emailAddress: String = "",
val authorizationState: AuthorizationState = AuthorizationState(),
val wizardNavigationBarState: WizardNavigationBarState = WizardNavigationBarState(
isNextEnabled = false,
),

View file

@ -7,6 +7,7 @@ import app.k9mail.core.ui.compose.common.mvi.BaseViewModel
import app.k9mail.feature.account.oauth.domain.DomainContract.UseCase
import app.k9mail.feature.account.oauth.domain.entity.AuthorizationIntentResult
import app.k9mail.feature.account.oauth.domain.entity.AuthorizationResult
import app.k9mail.feature.account.oauth.domain.entity.AuthorizationState
import app.k9mail.feature.account.oauth.ui.AccountOAuthContract.Effect
import app.k9mail.feature.account.oauth.ui.AccountOAuthContract.Error
import app.k9mail.feature.account.oauth.ui.AccountOAuthContract.Event
@ -90,18 +91,15 @@ class AccountOAuthViewModel(
)
}
viewModelScope.launch {
when (val result = finishOAuthSignIn.execute(state.value.authorizationState, data)) {
when (val result = finishOAuthSignIn.execute(data)) {
AuthorizationResult.BrowserNotAvailable -> updateErrorState(Error.BrowserNotAvailable)
AuthorizationResult.Canceled -> updateErrorState(Error.Canceled)
is AuthorizationResult.Failure -> updateErrorState(Error.Unknown(result.error))
is AuthorizationResult.Success -> {
updateState { state ->
state.copy(
authorizationState = result.state,
isLoading = false,
)
state.copy(isLoading = false)
}
navigateNext()
navigateNext(authorizationState = result.state)
}
}
}
@ -116,5 +114,7 @@ class AccountOAuthViewModel(
private fun navigateBack() = emitEffect(Effect.NavigateBack)
private fun navigateNext() = emitEffect(Effect.NavigateNext(state.value.authorizationState))
private fun navigateNext(authorizationState: AuthorizationState) {
emitEffect(Effect.NavigateNext(authorizationState))
}
}

View file

@ -19,7 +19,6 @@ class FinishOAuthSignInTest {
@Test
fun `should return failure when intent has encoded exception`() = runTest {
val authorizationState = AuthorizationState()
val intent = Intent()
val exception = AuthorizationException(
AuthorizationException.TYPE_GENERAL_ERROR,
@ -36,10 +35,7 @@ class FinishOAuthSignInTest {
repository = repository,
)
val result = testSubject.execute(
authorizationState = authorizationState,
intent = intent,
)
val result = testSubject.execute(intent)
assertThat(result).isEqualTo(AuthorizationResult.Failure(exception))
assertThat(repository.recordedGetAuthorizationExceptionIntent).isEqualTo(intent)
@ -47,16 +43,7 @@ class FinishOAuthSignInTest {
@Test
fun `should return canceled when intent has no response and no exception`() = runTest {
val authorizationState = AuthorizationState()
val intent = Intent()
val exception = AuthorizationException(
AuthorizationException.TYPE_GENERAL_ERROR,
1,
"error",
"error_description",
null,
null,
)
val repository = FakeAuthorizationRepository(
answerGetAuthorizationResponse = null,
answerGetAuthorizationException = null,
@ -65,10 +52,7 @@ class FinishOAuthSignInTest {
repository = repository,
)
val result = testSubject.execute(
authorizationState = authorizationState,
intent = intent,
)
val result = testSubject.execute(intent)
assertThat(result).isEqualTo(AuthorizationResult.Canceled)
assertThat(repository.recordedGetAuthorizationResponseIntent).isEqualTo(intent)
@ -89,10 +73,7 @@ class FinishOAuthSignInTest {
repository = repository,
)
val result = testSubject.execute(
authorizationState = authorizationState,
intent = intent,
)
val result = testSubject.execute(intent)
assertThat(result).isEqualTo(AuthorizationResult.Success(authorizationState))
assertThat(repository.recordedGetAuthorizationResponseIntent).isEqualTo(intent)

View file

@ -1,7 +1,6 @@
package app.k9mail.feature.account.oauth.ui
import app.k9mail.feature.account.common.ui.WizardNavigationBarState
import app.k9mail.feature.account.oauth.domain.entity.AuthorizationState
import app.k9mail.feature.account.oauth.ui.AccountOAuthContract.State
import assertk.all
import assertk.assertThat
@ -18,7 +17,6 @@ class AccountOAuthStateTest {
assertThat(state).all {
prop(State::hostname).isEqualTo("")
prop(State::emailAddress).isEqualTo("")
prop(State::authorizationState).isEqualTo(AuthorizationState())
prop(State::wizardNavigationBarState).isEqualTo(
WizardNavigationBarState(
isNextEnabled = false,

View file

@ -198,7 +198,6 @@ class AccountOAuthViewModelTest {
val successState = loadingState.copy(
isLoading = false,
authorizationState = authorizationState,
)
assertThat(stateTurbine.awaitItem()).isEqualTo(successState)
@ -371,7 +370,7 @@ class AccountOAuthViewModelTest {
getOAuthRequestIntent = { _, _ ->
authorizationIntentResult
},
finishOAuthSignIn = { _, _ ->
finishOAuthSignIn = { _ ->
delay(50)
authorizationResult
},