From 680196b83778496945eb6e215a3b133307ab6938 Mon Sep 17 00:00:00 2001 From: Hicham Boushaba Date: Thu, 3 Oct 2024 10:38:34 +0100 Subject: [PATCH] Pass the correct authorization URL to the application passwords tutorial --- .../LoginSiteCredentialsViewModel.kt | 2 +- .../LoginSiteCredentialsViewModelTest.kt | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/login/sitecredentials/LoginSiteCredentialsViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/login/sitecredentials/LoginSiteCredentialsViewModel.kt index 3acf1d422fe..cfe241dae71 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/login/sitecredentials/LoginSiteCredentialsViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/login/sitecredentials/LoginSiteCredentialsViewModel.kt @@ -312,7 +312,7 @@ class LoginSiteCredentialsViewModel @Inject constructor( if (site.fullAuthorizationUrl.isNotNullOrEmpty()) { triggerEvent( ShowApplicationPasswordTutorialScreen( - url = site.applicationPasswordsAuthorizeUrl, + url = site.fullAuthorizationUrl!!, errorMessage = errorMessage ) ) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/login/sitecredentials/LoginSiteCredentialsViewModelTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/login/sitecredentials/LoginSiteCredentialsViewModelTest.kt index 2214017c931..d253ea464ab 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/login/sitecredentials/LoginSiteCredentialsViewModelTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/login/sitecredentials/LoginSiteCredentialsViewModelTest.kt @@ -15,6 +15,7 @@ import com.woocommerce.android.ui.login.WPApiSiteRepository.CookieNonceAuthentic import com.woocommerce.android.ui.login.sitecredentials.LoginSiteCredentialsViewModel.LoggedIn import com.woocommerce.android.ui.login.sitecredentials.LoginSiteCredentialsViewModel.ShowApplicationPasswordsUnavailableScreen import com.woocommerce.android.ui.login.sitecredentials.LoginSiteCredentialsViewModel.ShowNonWooErrorScreen +import com.woocommerce.android.util.getOrAwaitValue import com.woocommerce.android.util.observeForTesting import com.woocommerce.android.util.runAndCaptureValues import com.woocommerce.android.viewmodel.BaseUnitTest @@ -386,4 +387,23 @@ class LoginSiteCredentialsViewModelTest : BaseUnitTest() { assertThat(viewModel.event.value) .isEqualTo(ShowApplicationPasswordsUnavailableScreen(siteAddress, isJetpackConnected)) } + + @Test + fun `given application passwords enabled and login fails for an unknown reason, when user attempts to sign-in, then show WebView login flow`() = testBlocking { + setup { + whenever(wpApiSiteRepository.login(siteAddress, testUsername, testPassword)) + .thenReturn(Result.failure(Exception())) + } + + val event = viewModel.event.runAndCaptureValues { + viewModel.onUsernameChanged(testUsername) + viewModel.onPasswordChanged(testPassword) + viewModel.viewState.getOrAwaitValue() + viewModel.onContinueClick() + }.last() + + assertThat(event).isInstanceOf(LoginSiteCredentialsViewModel.ShowApplicationPasswordTutorialScreen::class.java) + assertThat((event as LoginSiteCredentialsViewModel.ShowApplicationPasswordTutorialScreen).url) + .isEqualTo(urlAuthFull) + } }