Skip to content

Commit

Permalink
Merge pull request #12758 from woocommerce/login/fix-application-pass…
Browse files Browse the repository at this point in the history
…words-url

[Login] Pass the correct authorization URL to the application passwords tutorial
  • Loading branch information
irfano authored Oct 3, 2024
2 parents 1b5cd81 + 2946ca4 commit 286d336
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ class LoginSiteCredentialsViewModel @Inject constructor(
if (site.fullAuthorizationUrl.isNotNullOrEmpty()) {
triggerEvent(
ShowApplicationPasswordTutorialScreen(
url = site.applicationPasswordsAuthorizeUrl,
url = site.fullAuthorizationUrl!!,
errorMessage = errorMessage
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -386,4 +387,25 @@ 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()))
whenever(wpApiSiteRepository.fetchSite(siteAddress, testUsername, testPassword))
.thenReturn(Result.success(testSite.apply { applicationPasswordsAuthorizeUrl = urlAuthBase }))
}

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)
}
}

0 comments on commit 286d336

Please sign in to comment.