Search in sources :

Example 1 with AuthNextSignUpStep

use of com.amplifyframework.auth.result.step.AuthNextSignUpStep 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 AuthNextSignUpStep

use of com.amplifyframework.auth.result.step.AuthNextSignUpStep 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 3 with AuthNextSignUpStep

use of com.amplifyframework.auth.result.step.AuthNextSignUpStep in project amplify-android by aws-amplify.

the class AuthComponentTest method validateSignUpResult.

/**
 * Validate the sign up result is what was expected.
 * @param result The received result
 * @param targetStep The correct value for the next step (the only part of the response that varies in these tests)
 */
private void validateSignUpResult(AuthSignUpResult result, AuthSignUpStep targetStep) {
    AuthNextSignUpStep nextStep = result.getNextStep();
    validateCodeDeliveryDetails(nextStep.getCodeDeliveryDetails());
    assertTrue(result.isSignUpComplete());
    assertEquals(targetStep, nextStep.getSignUpStep());
    assertEquals(USER_SUB, result.getUser().getUserId());
    assertEquals(USERNAME, result.getUser().getUsername());
}
Also used : AuthNextSignUpStep(com.amplifyframework.auth.result.step.AuthNextSignUpStep)

Example 4 with AuthNextSignUpStep

use of com.amplifyframework.auth.result.step.AuthNextSignUpStep in project amplify-android by aws-amplify.

the class AWSCognitoAuthPlugin method convertSignUpResult.

private AuthSignUpResult convertSignUpResult(@NonNull SignUpResult result, @NonNull String username) {
    UserCodeDeliveryDetails details = Objects.requireNonNull(result).getUserCodeDeliveryDetails();
    AuthCodeDeliveryDetails newDetails = details != null ? new AuthCodeDeliveryDetails(details.getDestination(), AuthCodeDeliveryDetails.DeliveryMedium.fromString(details.getDeliveryMedium()), details.getAttributeName()) : null;
    return new AuthSignUpResult(true, new AuthNextSignUpStep(result.getConfirmationState() ? AuthSignUpStep.DONE : AuthSignUpStep.CONFIRM_SIGN_UP_STEP, Collections.emptyMap(), newDetails), result.getUserSub() != null ? new AuthUser(result.getUserSub(), username) : null);
}
Also used : AuthCodeDeliveryDetails(com.amplifyframework.auth.AuthCodeDeliveryDetails) AuthNextSignUpStep(com.amplifyframework.auth.result.step.AuthNextSignUpStep) UserCodeDeliveryDetails(com.amazonaws.mobile.client.results.UserCodeDeliveryDetails) AuthSignUpResult(com.amplifyframework.auth.result.AuthSignUpResult) AuthUser(com.amplifyframework.auth.AuthUser)

Aggregations

AuthNextSignUpStep (com.amplifyframework.auth.result.step.AuthNextSignUpStep)4 AuthCodeDeliveryDetails (com.amplifyframework.auth.AuthCodeDeliveryDetails)3 AuthSignUpResult (com.amplifyframework.auth.result.AuthSignUpResult)3 AuthSignUpStep (com.amplifyframework.auth.result.step.AuthSignUpStep)2 RandomString (com.amplifyframework.testutils.random.RandomString)2 Test (org.junit.Test)2 UserCodeDeliveryDetails (com.amazonaws.mobile.client.results.UserCodeDeliveryDetails)1 AuthUser (com.amplifyframework.auth.AuthUser)1 AuthSignUpOptions (com.amplifyframework.auth.options.AuthSignUpOptions)1