Search in sources :

Example 1 with WelcomeBackIdpPrompt

use of com.firebase.ui.auth.ui.idp.WelcomeBackIdpPrompt in project FirebaseUI-Android by firebase.

the class SocialProviderResponseHandlerTest method testSignInIdp_anonymousUserUpgradeEnabledAndExistingIdpUserWithDifferentIdp_expectMergeFailure.

@Test
public void testSignInIdp_anonymousUserUpgradeEnabledAndExistingIdpUserWithDifferentIdp_expectMergeFailure() {
    mHandler.getOperation().observeForever(mResultObserver);
    setupAnonymousUpgrade();
    when(mMockAuth.getCurrentUser().linkWithCredential(any(AuthCredential.class))).thenReturn(AutoCompleteTask.forFailure(new FirebaseAuthUserCollisionException("foo", "bar")));
    // Case 2 & 3: trying to link with an account that has 1 idp, which is different from the
    // one that we're trying to log in with
    when(mMockAuth.fetchSignInMethodsForEmail(any(String.class))).thenReturn(AutoCompleteTask.forSuccess(new FakeSignInMethodQueryResult(Collections.singletonList(FacebookAuthProvider.FACEBOOK_SIGN_IN_METHOD))));
    IdpResponse response = new IdpResponse.Builder(new User.Builder(GoogleAuthProvider.PROVIDER_ID, TestConstants.EMAIL).build()).setToken(TestConstants.TOKEN).build();
    mHandler.startSignIn(response);
    verify(mMockAuth.getCurrentUser()).linkWithCredential(any(AuthCredential.class));
    InOrder inOrder = inOrder(mResultObserver);
    inOrder.verify(mResultObserver).onChanged(argThat(ResourceMatchers.isLoading()));
    ArgumentCaptor<Resource<IdpResponse>> resolveCaptor = ArgumentCaptor.forClass(Resource.class);
    inOrder.verify(mResultObserver).onChanged(resolveCaptor.capture());
    // Make sure that we are trying to start the WelcomeBackIdpPrompt activity
    IntentRequiredException e = ((IntentRequiredException) resolveCaptor.getValue().getException());
    assertThat(e.getIntent().getComponent().getClassName()).isEqualTo(WelcomeBackIdpPrompt.class.toString().split(" ")[1]);
    assertThat(IdpResponse.fromResultIntent(e.getIntent())).isEqualTo(response);
}
Also used : AuthCredential(com.google.firebase.auth.AuthCredential) FakeSignInMethodQueryResult(com.firebase.ui.auth.testhelpers.FakeSignInMethodQueryResult) IntentRequiredException(com.firebase.ui.auth.data.model.IntentRequiredException) InOrder(org.mockito.InOrder) Resource(com.firebase.ui.auth.data.model.Resource) FirebaseAuthUserCollisionException(com.google.firebase.auth.FirebaseAuthUserCollisionException) WelcomeBackIdpPrompt(com.firebase.ui.auth.ui.idp.WelcomeBackIdpPrompt) IdpResponse(com.firebase.ui.auth.IdpResponse) Test(org.junit.Test)

Aggregations

IdpResponse (com.firebase.ui.auth.IdpResponse)1 IntentRequiredException (com.firebase.ui.auth.data.model.IntentRequiredException)1 Resource (com.firebase.ui.auth.data.model.Resource)1 FakeSignInMethodQueryResult (com.firebase.ui.auth.testhelpers.FakeSignInMethodQueryResult)1 WelcomeBackIdpPrompt (com.firebase.ui.auth.ui.idp.WelcomeBackIdpPrompt)1 AuthCredential (com.google.firebase.auth.AuthCredential)1 FirebaseAuthUserCollisionException (com.google.firebase.auth.FirebaseAuthUserCollisionException)1 Test (org.junit.Test)1 InOrder (org.mockito.InOrder)1