use of com.firebase.ui.auth.util.data.AuthOperationManager in project FirebaseUI-Android by firebase.
the class EmailLinkSignInHandlerTest method testStartSignIn_linkingFlowWithAnonymousUpgradeEnabled_failedLinkPropagated.
@Test
@SuppressWarnings("all")
public void testStartSignIn_linkingFlowWithAnonymousUpgradeEnabled_failedLinkPropagated() {
mHandler.getOperation().observeForever(mResponseObserver);
setupAnonymousUpgrade();
when(mMockAuth.isSignInWithEmailLink(any(String.class))).thenReturn(true);
mPersistenceManager.saveEmail(ApplicationProvider.getApplicationContext(), TestConstants.EMAIL, TestConstants.SESSION_ID, TestConstants.UID);
mPersistenceManager.saveIdpResponseForLinking(ApplicationProvider.getApplicationContext(), buildFacebookIdpResponse());
// Need to control FirebaseAuth's return values
AuthOperationManager authOperationManager = AuthOperationManager.getInstance();
authOperationManager.mScratchAuth = mScratchMockAuth;
when(mScratchMockAuth.signInWithCredential(any(AuthCredential.class))).thenReturn(AutoCompleteTask.forSuccess(mMockAuthResult));
// Mock linking with Facebook to always work
when(mMockAuthResult.getUser().linkWithCredential(any(AuthCredential.class))).thenReturn(AutoContinueTask.<AuthResult>forFailure(new Exception("FAILED")));
mHandler.startSignIn();
// Verify sign in was called
verify(mScratchMockAuth).signInWithCredential(any(AuthCredential.class));
// Validate linking was called
verify(mMockAuthResult.getUser()).linkWithCredential(any(FacebookAuthCredential.class));
// Validate that the data was cleared
assertThat(mPersistenceManager.retrieveSessionRecord(ApplicationProvider.getApplicationContext())).isNull();
// Validate failure
ArgumentCaptor<Resource<IdpResponse>> captor = ArgumentCaptor.forClass(Resource.class);
InOrder inOrder = inOrder(mResponseObserver);
inOrder.verify(mResponseObserver).onChanged(argThat(ResourceMatchers.<IdpResponse>isLoading()));
inOrder.verify(mResponseObserver).onChanged(captor.capture());
assertThat(captor.getValue().getException()).isNotNull();
}
use of com.firebase.ui.auth.util.data.AuthOperationManager in project FirebaseUI-Android by firebase.
the class GenericIdpAnonymousUpgradeLinkingHandlerTest method testStartSignIn_anonymousUpgradeLinkingFlow_expectIdpResponseWithCredential.
@Test
public void testStartSignIn_anonymousUpgradeLinkingFlow_expectIdpResponseWithCredential() {
setupAnonymousUpgrade();
AuthOperationManager authOperationManager = AuthOperationManager.getInstance();
authOperationManager.mScratchAuth = mScratchMockAuth;
when(mScratchMockAuth.startActivityForSignInWithProvider(any(HelperActivityBase.class), any(OAuthProvider.class))).thenReturn(AutoCompleteTask.forSuccess(mMockAuthResult));
AuthCredential credential = OAuthProvider.newCredentialBuilder(MICROSOFT_PROVIDER).setIdToken(ID_TOKEN).setAccessToken(ACCESS_TOKEN).build();
when(mMockAuthResult.getCredential()).thenReturn(credential);
when(mMockAuthResult.getUser()).thenReturn(mMockUser);
when(mMockUser.getDisplayName()).thenReturn(DISPLAY_NAME);
when(mMockUser.getPhotoUrl()).thenReturn(new Uri.Builder().build());
mockOAuthProvider(MICROSOFT_PROVIDER);
mHandler.startSignIn(mMockAuth, mMockActivity, MICROSOFT_PROVIDER);
ArgumentCaptor<OAuthProvider> providerCaptor = ArgumentCaptor.forClass(OAuthProvider.class);
verify(mScratchMockAuth).startActivityForSignInWithProvider(eq(mMockActivity), providerCaptor.capture());
assertThat(providerCaptor.getValue().getProviderId()).isEqualTo(MICROSOFT_PROVIDER);
InOrder inOrder = inOrder(mResponseObserver);
inOrder.verify(mResponseObserver).onChanged(argThat(ResourceMatchers.isLoading()));
ArgumentCaptor<Resource<IdpResponse>> resolveCaptor = ArgumentCaptor.forClass(Resource.class);
inOrder.verify(mResponseObserver).onChanged(resolveCaptor.capture());
IdpResponse idpResponse = resolveCaptor.getValue().getValue();
assertThat(idpResponse.getCredentialForLinking()).isNotNull();
}
Aggregations