renaming success type to something more concrete
This commit is contained in:
parent
88167a0287
commit
befcfe8c5b
|
@ -273,40 +273,37 @@ class OnboardingViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun internalRegisterAction(action: RegisterAction, overrideNextStage: (() -> Unit)? = null) {
|
private suspend fun internalRegisterAction(action: RegisterAction, overrideNextStage: (() -> Unit)? = null) {
|
||||||
runCatching { registrationActionHandler.processAction(awaitState().selectedHomeserver, action) }
|
runCatching { registrationActionHandler.processAction(awaitState().selectedHomeserver, action) }.fold(
|
||||||
.fold(
|
onSuccess = {
|
||||||
onSuccess = {
|
when (it) {
|
||||||
when (it) {
|
RegistrationActionHandler.Result.Ignored -> {
|
||||||
RegistrationActionHandler.Result.Ignored -> {
|
// do nothing
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
is RegistrationActionHandler.Result.NextStage -> {
|
|
||||||
overrideNextStage?.invoke() ?: _viewEvents.post(OnboardingViewEvents.DisplayRegistrationStage(it.stage))
|
|
||||||
}
|
|
||||||
is RegistrationActionHandler.Result.Success -> onSessionCreated(
|
|
||||||
it.session,
|
|
||||||
authenticationDescription = awaitState().selectedAuthenticationState.description
|
|
||||||
?: AuthenticationDescription.Register(AuthenticationDescription.AuthenticationType.Other)
|
|
||||||
)
|
|
||||||
RegistrationActionHandler.Result.StartRegistration -> _viewEvents.post(OnboardingViewEvents.DisplayStartRegistration)
|
|
||||||
RegistrationActionHandler.Result.UnsupportedStage -> _viewEvents.post(OnboardingViewEvents.DisplayRegistrationFallback)
|
|
||||||
is RegistrationActionHandler.Result.SendEmailSuccess -> _viewEvents.post(OnboardingViewEvents.OnSendEmailSuccess(it.email))
|
|
||||||
is RegistrationActionHandler.Result.Error -> _viewEvents.post(OnboardingViewEvents.Failure(it.cause))
|
|
||||||
RegistrationActionHandler.Result.MissingNextStage -> {
|
|
||||||
_viewEvents.post(OnboardingViewEvents.Failure(IllegalStateException("No next registration stage found")))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onFailure = {
|
|
||||||
if (it !is CancellationException) {
|
|
||||||
_viewEvents.post(OnboardingViewEvents.Failure(it))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
is RegistrationActionHandler.Result.NextStage -> {
|
||||||
|
overrideNextStage?.invoke() ?: _viewEvents.post(OnboardingViewEvents.DisplayRegistrationStage(it.stage))
|
||||||
|
}
|
||||||
|
is RegistrationActionHandler.Result.RegistrationComplete -> onSessionCreated(
|
||||||
|
it.session,
|
||||||
|
authenticationDescription = awaitState().selectedAuthenticationState.description
|
||||||
|
?: AuthenticationDescription.Register(AuthenticationDescription.AuthenticationType.Other)
|
||||||
|
)
|
||||||
|
RegistrationActionHandler.Result.StartRegistration -> _viewEvents.post(OnboardingViewEvents.DisplayStartRegistration)
|
||||||
|
RegistrationActionHandler.Result.UnsupportedStage -> _viewEvents.post(OnboardingViewEvents.DisplayRegistrationFallback)
|
||||||
|
is RegistrationActionHandler.Result.SendEmailSuccess -> _viewEvents.post(OnboardingViewEvents.OnSendEmailSuccess(it.email))
|
||||||
|
is RegistrationActionHandler.Result.Error -> _viewEvents.post(OnboardingViewEvents.Failure(it.cause))
|
||||||
|
RegistrationActionHandler.Result.MissingNextStage -> {
|
||||||
|
_viewEvents.post(OnboardingViewEvents.Failure(IllegalStateException("No next registration stage found")))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onFailure = {
|
||||||
|
if (it !is CancellationException) {
|
||||||
|
_viewEvents.post(OnboardingViewEvents.Failure(it))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun OnboardingViewState.hasSelectedMatrixOrg() = selectedHomeserver.userFacingUrl == matrixOrgUrl
|
|
||||||
|
|
||||||
private fun handleRegisterWith(action: AuthenticateAction.Register) {
|
private fun handleRegisterWith(action: AuthenticateAction.Register) {
|
||||||
setState {
|
setState {
|
||||||
val authDescription = AuthenticationDescription.Register(AuthenticationDescription.AuthenticationType.Password)
|
val authDescription = AuthenticationDescription.Register(AuthenticationDescription.AuthenticationType.Password)
|
||||||
|
|
|
@ -45,7 +45,7 @@ class RegistrationActionHandler @Inject constructor(
|
||||||
return when {
|
return when {
|
||||||
action.ignoresResult() -> Result.Ignored
|
action.ignoresResult() -> Result.Ignored
|
||||||
else -> when (result) {
|
else -> when (result) {
|
||||||
is RegistrationResult.Complete -> Result.Success(result.session)
|
is RegistrationResult.Complete -> Result.RegistrationComplete(result.session)
|
||||||
is RegistrationResult.NextStep -> processFlowResult(result, state)
|
is RegistrationResult.NextStep -> processFlowResult(result, state)
|
||||||
is RegistrationResult.SendEmailSuccess -> Result.SendEmailSuccess(result.email)
|
is RegistrationResult.SendEmailSuccess -> Result.SendEmailSuccess(result.email)
|
||||||
is RegistrationResult.Error -> Result.Error(result.cause)
|
is RegistrationResult.Error -> Result.Error(result.cause)
|
||||||
|
@ -91,7 +91,7 @@ class RegistrationActionHandler @Inject constructor(
|
||||||
private fun SelectedHomeserverState.hasSelectedMatrixOrg() = userFacingUrl == matrixOrgUrl
|
private fun SelectedHomeserverState.hasSelectedMatrixOrg() = userFacingUrl == matrixOrgUrl
|
||||||
|
|
||||||
sealed interface Result {
|
sealed interface Result {
|
||||||
data class Success(val session: Session) : Result
|
data class RegistrationComplete(val session: Session) : Result
|
||||||
data class NextStage(val stage: Stage) : Result
|
data class NextStage(val stage: Stage) : Result
|
||||||
data class Error(val cause: Throwable) : Result
|
data class Error(val cause: Throwable) : Result
|
||||||
data class SendEmailSuccess(val email: String) : Result
|
data class SendEmailSuccess(val email: String) : Result
|
||||||
|
|
|
@ -31,8 +31,8 @@ import im.vector.app.test.fakes.FakeContext
|
||||||
import im.vector.app.test.fakes.FakeDirectLoginUseCase
|
import im.vector.app.test.fakes.FakeDirectLoginUseCase
|
||||||
import im.vector.app.test.fakes.FakeHomeServerConnectionConfigFactory
|
import im.vector.app.test.fakes.FakeHomeServerConnectionConfigFactory
|
||||||
import im.vector.app.test.fakes.FakeHomeServerHistoryService
|
import im.vector.app.test.fakes.FakeHomeServerHistoryService
|
||||||
import im.vector.app.test.fakes.FakeRegistrationActionHandler
|
|
||||||
import im.vector.app.test.fakes.FakeLoginWizard
|
import im.vector.app.test.fakes.FakeLoginWizard
|
||||||
|
import im.vector.app.test.fakes.FakeRegistrationActionHandler
|
||||||
import im.vector.app.test.fakes.FakeSession
|
import im.vector.app.test.fakes.FakeSession
|
||||||
import im.vector.app.test.fakes.FakeStartAuthenticationFlowUseCase
|
import im.vector.app.test.fakes.FakeStartAuthenticationFlowUseCase
|
||||||
import im.vector.app.test.fakes.FakeStringProvider
|
import im.vector.app.test.fakes.FakeStringProvider
|
||||||
|
@ -316,7 +316,7 @@ class OnboardingViewModelTest {
|
||||||
fun `given personalisation enabled, when registering account, then updates state and emits account created event`() = runTest {
|
fun `given personalisation enabled, when registering account, then updates state and emits account created event`() = runTest {
|
||||||
fakeVectorFeatures.givenPersonalisationEnabled()
|
fakeVectorFeatures.givenPersonalisationEnabled()
|
||||||
givenSuccessfullyCreatesAccount(A_HOMESERVER_CAPABILITIES)
|
givenSuccessfullyCreatesAccount(A_HOMESERVER_CAPABILITIES)
|
||||||
givenRegistrationResultFor(RegisterAction.StartRegistration, RegistrationActionHandler.Result.Success(fakeSession))
|
givenRegistrationResultFor(RegisterAction.StartRegistration, RegistrationActionHandler.Result.RegistrationComplete(fakeSession))
|
||||||
val test = viewModel.test()
|
val test = viewModel.test()
|
||||||
|
|
||||||
viewModel.handle(OnboardingAction.PostRegisterAction(RegisterAction.StartRegistration))
|
viewModel.handle(OnboardingAction.PostRegisterAction(RegisterAction.StartRegistration))
|
||||||
|
|
|
@ -61,12 +61,12 @@ class RegistrationActionHandlerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given wizard delegate returns success, when handling action, then returns success`() = runTest {
|
fun `given wizard delegate returns success, when handling action, then returns RegistrationComplete`() = runTest {
|
||||||
fakeWizardActionDelegate.givenResultsFor(listOf(RegisterAction.StartRegistration to RegistrationResult.Complete(A_SESSION)))
|
fakeWizardActionDelegate.givenResultsFor(listOf(RegisterAction.StartRegistration to RegistrationResult.Complete(A_SESSION)))
|
||||||
|
|
||||||
val result = registrationActionHandler.processAction(RegisterAction.StartRegistration)
|
val result = registrationActionHandler.processAction(RegisterAction.StartRegistration)
|
||||||
|
|
||||||
result shouldBeEqualTo RegistrationActionHandler.Result.Success(A_SESSION)
|
result shouldBeEqualTo RegistrationActionHandler.Result.RegistrationComplete(A_SESSION)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -154,7 +154,7 @@ class RegistrationActionHandlerTest {
|
||||||
|
|
||||||
val result = registrationActionHandler.processAction(RegisterAction.StartRegistration)
|
val result = registrationActionHandler.processAction(RegisterAction.StartRegistration)
|
||||||
|
|
||||||
result shouldBeEqualTo RegistrationActionHandler.Result.Success(A_SESSION)
|
result shouldBeEqualTo RegistrationActionHandler.Result.RegistrationComplete(A_SESSION)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun givenFlowResult(stages: List<Stage>) {
|
private fun givenFlowResult(stages: List<Stage>) {
|
||||||
|
|
Loading…
Reference in New Issue