use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.
the class EmailLinkSignInHandlerTest method testStartSignIn_differentDeviceLinkWithValidSessionInfo_expectInvalidLinkError.
@Test
@SuppressWarnings("all")
public void testStartSignIn_differentDeviceLinkWithValidSessionInfo_expectInvalidLinkError() {
String differentSessionId = SessionUtils.generateRandomAlphaNumericString(10);
initializeHandlerWithSessionInfo(differentSessionId, null, null, false);
mHandler.getOperation().observeForever(mResponseObserver);
when(mMockAuth.isSignInWithEmailLink(any(String.class))).thenReturn(true);
when(mMockAuth.checkActionCode(any(String.class))).thenReturn(AutoCompleteTask.<ActionCodeResult>forFailure(new Exception("foo")));
mHandler.startSignIn();
verify(mMockAuth).isSignInWithEmailLink(any(String.class));
verify(mMockAuth).checkActionCode(any(String.class));
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());
FirebaseUiException exception = (FirebaseUiException) captor.getValue().getException();
assertThat(exception).isNotNull();
assertThat(exception.getErrorCode()).isEqualTo(ErrorCodes.INVALID_EMAIL_LINK_ERROR);
}
use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.
the class GenericIdpSignInHandlerTest method testStartSignIn_normalSignInFlow_expectSuccess.
@Test
public void testStartSignIn_normalSignInFlow_expectSuccess() {
mHandler.getOperation().observeForever(mResponseObserver);
when(mMockAuth.startActivityForSignInWithProvider(any(Activity.class), any(OAuthProvider.class))).thenReturn(AutoCompleteTask.forSuccess(FakeAuthResult.INSTANCE));
mockOAuthProvider(MICROSOFT_PROVIDER);
mHandler.startSignIn(mMockAuth, mMockActivity, MICROSOFT_PROVIDER);
ArgumentCaptor<OAuthProvider> providerCaptor = ArgumentCaptor.forClass(OAuthProvider.class);
verify(mMockAuth).startActivityForSignInWithProvider(eq(mMockActivity), providerCaptor.capture());
assertThat(providerCaptor.getValue().getProviderId()).isEqualTo(MICROSOFT_PROVIDER);
HashMap<String, String> customArgs = (HashMap<String, String>) mHandler.getArguments().getParams().getSerializable(ExtraConstants.GENERIC_OAUTH_CUSTOM_PARAMETERS);
assertThat(customArgs).isNotNull();
assertThat(customArgs).hasSize(1);
InOrder inOrder = inOrder(mResponseObserver);
inOrder.verify(mResponseObserver).onChanged(argThat(ResourceMatchers.isLoading()));
ArgumentCaptor<Resource<IdpResponse>> resourceCaptor = ArgumentCaptor.forClass(Resource.class);
inOrder.verify(mResponseObserver).onChanged(resourceCaptor.capture());
IdpResponse returnedIdpResponse = resourceCaptor.getValue().getValue();
assertThat(returnedIdpResponse.isSuccessful()).isTrue();
assertThat(returnedIdpResponse.getUser()).isNotNull();
}
use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.
the class PhoneProviderResponseHandlerTest method testSignIn_autoUpgradeAnonymousEnabledWithNewUser_expectSuccess.
@Test
public void testSignIn_autoUpgradeAnonymousEnabledWithNewUser_expectSuccess() {
mHandler.getOperation().observeForever(mResponseObserver);
setupAnonymousUpgrade();
when(mMockAuth.getCurrentUser().linkWithCredential(mCredential)).thenReturn(AutoCompleteTask.forSuccess(FakeAuthResult.INSTANCE));
IdpResponse response = new IdpResponse.Builder(new User.Builder(PhoneAuthProvider.PROVIDER_ID, TestConstants.EMAIL).build()).build();
mHandler.startSignIn(mCredential, response);
verify(mMockAuth.getCurrentUser()).linkWithCredential(mCredential);
verify(mResponseObserver).onChanged(argThat(ResourceMatchers.isSuccess()));
}
use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.
the class PhoneProviderResponseHandlerTest method testSignIn_withValidCredentialAndNewUser_expectSuccess.
@Test
public void testSignIn_withValidCredentialAndNewUser_expectSuccess() {
mHandler.getOperation().observeForever(mResponseObserver);
when(mMockAuth.signInWithCredential(mCredential)).thenReturn(AutoCompleteTask.forSuccess(FakeAuthResult.INSTANCE));
IdpResponse response = new IdpResponse.Builder(new User.Builder(PhoneAuthProvider.PROVIDER_ID, TestConstants.EMAIL).build()).build();
mHandler.startSignIn(mCredential, response);
verify(mMockAuth).signInWithCredential(mCredential);
verify(mResponseObserver).onChanged(argThat(ResourceMatchers.isSuccess()));
}
use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.
the class AnonymousSignInHandlerTest method testStartSignIn_expectSuccess.
@Test
public void testStartSignIn_expectSuccess() {
mHandler.getOperation().observeForever(mResponseObserver);
when(mMockAuth.signInAnonymously()).thenReturn(AutoCompleteTask.forSuccess(FakeAuthResult.INSTANCE));
mHandler.startSignIn(mMockActivity);
verify(mMockAuth).signInAnonymously();
InOrder inOrder = inOrder(mResponseObserver);
inOrder.verify(mResponseObserver).onChanged(argThat(ResourceMatchers.isLoading()));
ArgumentCaptor<Resource<IdpResponse>> captor = ArgumentCaptor.forClass(Resource.class);
inOrder.verify(mResponseObserver).onChanged(captor.capture());
assertThat(captor.getValue().getState()).isEqualTo(State.SUCCESS);
IdpResponse response = captor.getValue().getValue();
assertThat(response.isNewUser()).isFalse();
}
Aggregations