Search in sources :

Example 1 with AuthProvider

use of com.amplifyframework.auth.AuthProvider in project amplify-android by aws-amplify.

the class RxAuthBindingTest method testSignInWithSocialWebUISucceeds.

/**
 * Validates that a successful call to sign-in with social web UI will propagate the result
 * back through the binding.
 * @throws InterruptedException If test observer is interrupted while awaiting terminal event
 */
@Test
public void testSignInWithSocialWebUISucceeds() throws InterruptedException {
    AuthProvider provider = AuthProvider.amazon();
    Activity activity = new Activity();
    // Arrange a successful result
    AuthSignInStep step = AuthSignInStep.CONFIRM_SIGN_IN_WITH_SMS_MFA_CODE;
    AuthCodeDeliveryDetails details = new AuthCodeDeliveryDetails(RandomString.string(), DeliveryMedium.PHONE);
    AuthNextSignInStep nextStep = new AuthNextSignInStep(step, Collections.emptyMap(), details);
    AuthSignInResult result = new AuthSignInResult(false, nextStep);
    doAnswer(invocation -> {
        // 0 = provider, 1 = activity, 2 = result consumer, 3 = failure consumer
        int positionOfResultConsumer = 2;
        Consumer<AuthSignInResult> onResult = invocation.getArgument(positionOfResultConsumer);
        onResult.accept(result);
        return null;
    }).when(delegate).signInWithSocialWebUI(eq(provider), eq(activity), anyConsumer(), anyConsumer());
    // Act: call the binding
    TestObserver<AuthSignInResult> observer = auth.signInWithSocialWebUI(provider, activity).test();
    // Assert: result is furnished the via the Rx Single
    observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
    observer.assertNoErrors().assertValue(result);
}
Also used : AuthCodeDeliveryDetails(com.amplifyframework.auth.AuthCodeDeliveryDetails) Activity(android.app.Activity) AuthProvider(com.amplifyframework.auth.AuthProvider) AuthNextSignInStep(com.amplifyframework.auth.result.step.AuthNextSignInStep) AuthSignInResult(com.amplifyframework.auth.result.AuthSignInResult) AuthSignInStep(com.amplifyframework.auth.result.step.AuthSignInStep) Test(org.junit.Test)

Example 2 with AuthProvider

use of com.amplifyframework.auth.AuthProvider in project amplify-android by aws-amplify.

the class RxAuthBindingTest method testSignInWithSocialWebUIFails.

/**
 * Validates that a failed call to sign-in with social web UI will propagate the failure
 * back through the binding.
 * @throws InterruptedException If test observer is interrupted while awaiting terminal event
 */
@Test
public void testSignInWithSocialWebUIFails() throws InterruptedException {
    AuthProvider provider = AuthProvider.amazon();
    Activity activity = new Activity();
    // Arrange a failure
    AuthException failure = new AuthException("Sign in with social provider", " has failed");
    doAnswer(invocation -> {
        // 0 = provider, 1 = activity, 2 = result consumer, 3 = failure consumer
        int positionOfFailureConsumer = 3;
        Consumer<AuthException> onFailure = invocation.getArgument(positionOfFailureConsumer);
        onFailure.accept(failure);
        return null;
    }).when(delegate).signInWithSocialWebUI(eq(provider), eq(activity), anyConsumer(), anyConsumer());
    // Act: call the binding
    TestObserver<AuthSignInResult> observer = auth.signInWithSocialWebUI(provider, activity).test();
    // Assert: failure is furnished the via the Rx Single
    observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
    observer.assertNoValues().assertError(failure);
}
Also used : Activity(android.app.Activity) AuthException(com.amplifyframework.auth.AuthException) AuthProvider(com.amplifyframework.auth.AuthProvider) AuthSignInResult(com.amplifyframework.auth.result.AuthSignInResult) Test(org.junit.Test)

Aggregations

Activity (android.app.Activity)2 AuthProvider (com.amplifyframework.auth.AuthProvider)2 AuthSignInResult (com.amplifyframework.auth.result.AuthSignInResult)2 Test (org.junit.Test)2 AuthCodeDeliveryDetails (com.amplifyframework.auth.AuthCodeDeliveryDetails)1 AuthException (com.amplifyframework.auth.AuthException)1 AuthNextSignInStep (com.amplifyframework.auth.result.step.AuthNextSignInStep)1 AuthSignInStep (com.amplifyframework.auth.result.step.AuthSignInStep)1