Search in sources :

Example 1 with AuthSignUpOptions

use of com.amplifyframework.auth.options.AuthSignUpOptions 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 2 with AuthSignUpOptions

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

the class RxAuthBindingTest method testSignUpFails.

/**
 * Validates that a sign-up failure are passed through the binding.
 * @throws InterruptedException If test observer is interrupted while awaiting terminal event
 */
@Test
public void testSignUpFails() throws InterruptedException {
    String username = RandomString.string();
    String password = RandomString.string();
    AuthSignUpOptions options = AuthSignUpOptions.builder().build();
    // Arrange a callback on the failure consumer
    AuthException failure = new AuthException("Sign up", "has failed");
    doAnswer(invocation -> {
        // 0 = username, 1 = pass, 2 = options, 3 = onSuccess, 4 = onFailure
        int positionOfFailureConsumer = 4;
        Consumer<AuthException> onFailure = invocation.getArgument(positionOfFailureConsumer);
        onFailure.accept(failure);
        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: error is furnished via Rx single.
    observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
    observer.assertNoValues().assertError(failure);
}
Also used : AuthSignUpResult(com.amplifyframework.auth.result.AuthSignUpResult) AuthSignUpOptions(com.amplifyframework.auth.options.AuthSignUpOptions) AuthException(com.amplifyframework.auth.AuthException) RandomString(com.amplifyframework.testutils.random.RandomString) Test(org.junit.Test)

Aggregations

AuthSignUpOptions (com.amplifyframework.auth.options.AuthSignUpOptions)2 AuthSignUpResult (com.amplifyframework.auth.result.AuthSignUpResult)2 RandomString (com.amplifyframework.testutils.random.RandomString)2 Test (org.junit.Test)2 AuthCodeDeliveryDetails (com.amplifyframework.auth.AuthCodeDeliveryDetails)1 AuthException (com.amplifyframework.auth.AuthException)1 AuthNextSignUpStep (com.amplifyframework.auth.result.step.AuthNextSignUpStep)1 AuthSignUpStep (com.amplifyframework.auth.result.step.AuthSignUpStep)1