Search in sources :

Example 1 with AuthCodeDeliveryDetails

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

the class RxAuthBindingTest method testResendUserAttributeConfirmationCode.

/**
 * Tests that a successful request to resend user attribute confirmation code will propagate a
 * completion back through the binding.
 * @throws InterruptedException If test observer is interrupted while awaiting terminal event
 */
@Test
public void testResendUserAttributeConfirmationCode() throws InterruptedException {
    // Arrange an invocation of the success Action
    AuthUserAttributeKey attributeKey = AuthUserAttributeKey.custom(ATTRIBUTE_KEY);
    AuthCodeDeliveryDetails expected = new AuthCodeDeliveryDetails(DESTINATION, DeliveryMedium.EMAIL, ATTRIBUTE_NAME);
    doAnswer(invocation -> {
        Consumer<AuthCodeDeliveryDetails> onCompletion = invocation.getArgument(1);
        onCompletion.accept(expected);
        return null;
    }).when(delegate).resendUserAttributeConfirmationCode(any(), anyConsumer(), anyConsumer());
    // Act: call the binding
    TestObserver<AuthCodeDeliveryDetails> observer = auth.resendUserAttributeConfirmationCode(attributeKey).test();
    // Assert: Completable completes with success
    observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
    observer.assertNoErrors().assertValue(expected);
}
Also used : AuthCodeDeliveryDetails(com.amplifyframework.auth.AuthCodeDeliveryDetails) AuthUserAttributeKey(com.amplifyframework.auth.AuthUserAttributeKey) Test(org.junit.Test)

Example 2 with AuthCodeDeliveryDetails

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

the class RxAuthBindingTest method testConfirmSignInSucceeds.

/**
 * Validates that a successful call to confirm sign-in will propagate the result
 * back through the binding.
 * @throws InterruptedException If test observer is interrupted while awaiting terminal event
 */
@Test
public void testConfirmSignInSucceeds() throws InterruptedException {
    String confirmationCode = RandomString.string();
    // Arrange a successful result.
    AuthSignInStep step = AuthSignInStep.CONFIRM_SIGN_IN_WITH_SMS_MFA_CODE;
    AuthCodeDeliveryDetails details = new AuthCodeDeliveryDetails(RandomString.string(), DeliveryMedium.UNKNOWN);
    AuthNextSignInStep nextStep = new AuthNextSignInStep(step, Collections.emptyMap(), details);
    AuthSignInResult expected = new AuthSignInResult(true, nextStep);
    doAnswer(invocation -> {
        // 0 = confirm code, 1 = onResult, 2 = onFailure
        int positionOfResultConsumer = 1;
        Consumer<AuthSignInResult> onResult = invocation.getArgument(positionOfResultConsumer);
        onResult.accept(expected);
        return null;
    }).when(delegate).confirmSignIn(eq(confirmationCode), anyConsumer(), anyConsumer());
    // Act: call the binding
    TestObserver<AuthSignInResult> observer = auth.confirmSignIn(confirmationCode).test();
    // Assert: result is furnished
    observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
    observer.assertNoErrors().assertValue(expected);
}
Also used : AuthCodeDeliveryDetails(com.amplifyframework.auth.AuthCodeDeliveryDetails) AuthNextSignInStep(com.amplifyframework.auth.result.step.AuthNextSignInStep) RandomString(com.amplifyframework.testutils.random.RandomString) AuthSignInResult(com.amplifyframework.auth.result.AuthSignInResult) AuthSignInStep(com.amplifyframework.auth.result.step.AuthSignInStep) Test(org.junit.Test)

Example 3 with AuthCodeDeliveryDetails

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

the class RxAuthBindingTest method testSignUpSucceeds.

/**
 * Validates that a sign-up result are passed through the binding.
 * @throws InterruptedException If test observer is interrupted while awaiting terminal event
 */
@Test
public void testSignUpSucceeds() throws InterruptedException {
    // Arrange a response from delegate
    String username = RandomString.string();
    String password = RandomString.string();
    AuthSignUpOptions options = AuthSignUpOptions.builder().build();
    // Arrange a result on the result consumer
    AuthCodeDeliveryDetails details = new AuthCodeDeliveryDetails(RandomString.string(), DeliveryMedium.SMS);
    AuthSignUpStep step = AuthSignUpStep.CONFIRM_SIGN_UP_STEP;
    AuthNextSignUpStep nextStep = new AuthNextSignUpStep(step, Collections.emptyMap(), details);
    AuthSignUpResult result = new AuthSignUpResult(false, nextStep, null);
    doAnswer(invocation -> {
        // 0 = username, 1 = pass, 2 = options, 3 = onSuccess, 4 = onFailure
        int positionOfSuccessConsumer = 3;
        Consumer<AuthSignUpResult> onResult = invocation.getArgument(positionOfSuccessConsumer);
        onResult.accept(result);
        return null;
    }).when(delegate).signUp(eq(username), eq(password), eq(options), anyConsumer(), anyConsumer());
    // Act: call the binding
    TestObserver<AuthSignUpResult> observer = auth.signUp(username, password, options).test();
    // Assert: the result was furnished to the Rx Single
    observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
    observer.assertNoErrors().assertValue(result);
}
Also used : AuthSignUpStep(com.amplifyframework.auth.result.step.AuthSignUpStep) AuthCodeDeliveryDetails(com.amplifyframework.auth.AuthCodeDeliveryDetails) AuthNextSignUpStep(com.amplifyframework.auth.result.step.AuthNextSignUpStep) AuthSignUpResult(com.amplifyframework.auth.result.AuthSignUpResult) AuthSignUpOptions(com.amplifyframework.auth.options.AuthSignUpOptions) RandomString(com.amplifyframework.testutils.random.RandomString) Test(org.junit.Test)

Example 4 with AuthCodeDeliveryDetails

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

the class RxAuthBindingTest method testResendSignUpCodeSucceeds.

/**
 * Validates that a successful call to resend the sign-up code will propagate the result
 * back through the binding.
 * @throws InterruptedException If test observer is interrupted while awaiting terminal event
 */
@Test
public void testResendSignUpCodeSucceeds() throws InterruptedException {
    String username = RandomString.string();
    // Arrange a result on the result consumer
    AuthCodeDeliveryDetails details = new AuthCodeDeliveryDetails(RandomString.string(), DeliveryMedium.EMAIL);
    AuthSignUpStep step = AuthSignUpStep.CONFIRM_SIGN_UP_STEP;
    AuthNextSignUpStep nextStep = new AuthNextSignUpStep(step, Collections.emptyMap(), details);
    AuthSignUpResult result = new AuthSignUpResult(false, nextStep, null);
    doAnswer(invocation -> {
        // 0 = username, 1 = onResult, 2 = onFailure
        int positionOfResultConsumer = 1;
        Consumer<AuthSignUpResult> onResult = invocation.getArgument(positionOfResultConsumer);
        onResult.accept(result);
        return null;
    }).when(delegate).resendSignUpCode(eq(username), anyConsumer(), anyConsumer());
    // Act: call the binding
    TestObserver<AuthSignUpResult> observer = auth.resendSignUpCode(username).test();
    // Assert: the result was furnished to the Rx Single
    observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
    observer.assertNoErrors().assertValue(result);
}
Also used : AuthSignUpStep(com.amplifyframework.auth.result.step.AuthSignUpStep) AuthCodeDeliveryDetails(com.amplifyframework.auth.AuthCodeDeliveryDetails) AuthNextSignUpStep(com.amplifyframework.auth.result.step.AuthNextSignUpStep) AuthSignUpResult(com.amplifyframework.auth.result.AuthSignUpResult) RandomString(com.amplifyframework.testutils.random.RandomString) Test(org.junit.Test)

Example 5 with AuthCodeDeliveryDetails

use of com.amplifyframework.auth.AuthCodeDeliveryDetails 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)

Aggregations

AuthCodeDeliveryDetails (com.amplifyframework.auth.AuthCodeDeliveryDetails)12 Test (org.junit.Test)11 RandomString (com.amplifyframework.testutils.random.RandomString)6 AuthUserAttributeKey (com.amplifyframework.auth.AuthUserAttributeKey)4 AuthSignInResult (com.amplifyframework.auth.result.AuthSignInResult)4 AuthNextSignInStep (com.amplifyframework.auth.result.step.AuthNextSignInStep)4 AuthSignInStep (com.amplifyframework.auth.result.step.AuthSignInStep)4 UserCodeDeliveryDetails (com.amazonaws.mobile.client.results.UserCodeDeliveryDetails)3 AuthSignUpResult (com.amplifyframework.auth.result.AuthSignUpResult)3 AuthNextSignUpStep (com.amplifyframework.auth.result.step.AuthNextSignUpStep)3 Activity (android.app.Activity)2 AuthSignUpStep (com.amplifyframework.auth.result.step.AuthSignUpStep)2 HashMap (java.util.HashMap)2 AuthProvider (com.amplifyframework.auth.AuthProvider)1 AuthUser (com.amplifyframework.auth.AuthUser)1 AuthUserAttribute (com.amplifyframework.auth.AuthUserAttribute)1 AWSCognitoAuthResendUserAttributeConfirmationCodeOptions (com.amplifyframework.auth.cognito.options.AWSCognitoAuthResendUserAttributeConfirmationCodeOptions)1 AuthSignUpOptions (com.amplifyframework.auth.options.AuthSignUpOptions)1 AuthResetPasswordResult (com.amplifyframework.auth.result.AuthResetPasswordResult)1 AuthUpdateAttributeResult (com.amplifyframework.auth.result.AuthUpdateAttributeResult)1