Search in sources :

Example 1 with AuthSignUpResult

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

the class RxAuthBindingTest method testResendSignUpCodeFails.

/**
 * Validates that a failed call to resend the sign-up code will propagate the failure
 * back through the binding.
 * @throws InterruptedException If test observer is interrupted while awaiting terminal event
 */
@Test
public void testResendSignUpCodeFails() throws InterruptedException {
    String username = RandomString.string();
    // Arrange a failure on the failure consumer
    AuthException failure = new AuthException("Reset sign up", " has failed.");
    doAnswer(invocation -> {
        // 0 = username, 1 = onResult, 2 = onFailure
        int positionOfFailureConsumer = 2;
        Consumer<AuthException> onFailure = invocation.getArgument(positionOfFailureConsumer);
        onFailure.accept(failure);
        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.assertNoValues().assertError(failure);
}
Also used : AuthSignUpResult(com.amplifyframework.auth.result.AuthSignUpResult) AuthException(com.amplifyframework.auth.AuthException) RandomString(com.amplifyframework.testutils.random.RandomString) Test(org.junit.Test)

Example 2 with AuthSignUpResult

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

use of com.amplifyframework.auth.result.AuthSignUpResult 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 4 with AuthSignUpResult

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

the class AuthComponentTest method resendSignUpCodeWithOptions.

/**
 * Tests that the resendSignUpCode method of the Auth wrapper of AWSMobileClient (AMC) calls AMC.resendSignUp with
 * the username and options it received.
 * Also ensures that in the onResult case, the success callback receives a valid AuthSignUpResult.
 * @throws AuthException test fails if this gets thrown since method should succeed
 */
@Test
// Casts final parameter to Callback to differentiate methods
@SuppressWarnings("unchecked")
public void resendSignUpCodeWithOptions() throws AuthException {
    SignUpResult amcResult = new SignUpResult(false, new UserCodeDeliveryDetails(DESTINATION, DELIVERY_MEDIUM, ATTRIBUTE_NAME), USER_SUB);
    AWSCognitoAuthResendSignUpCodeOptions.CognitoBuilder options = AWSCognitoAuthResendSignUpCodeOptions.builder();
    Map<String, String> metadata = new HashMap<String, String>();
    metadata.put("key", "value");
    options.metadata(metadata);
    AWSCognitoAuthResendSignUpCodeOptions builtOptions = options.build();
    doAnswer(invocation -> {
        Callback<SignUpResult> callback = invocation.getArgument(2);
        callback.onResult(amcResult);
        return null;
    }).when(mobileClient).resendSignUp(any(), any(), (Callback<SignUpResult>) any());
    AuthSignUpResult result = synchronousAuth.resendSignUpCode(USERNAME, builtOptions);
    validateSignUpResult(result, AuthSignUpStep.CONFIRM_SIGN_UP_STEP);
    verify(mobileClient).resendSignUp(eq(USERNAME), eq(metadata), (Callback<SignUpResult>) any());
}
Also used : HashMap(java.util.HashMap) UserCodeDeliveryDetails(com.amazonaws.mobile.client.results.UserCodeDeliveryDetails) AuthSignUpResult(com.amplifyframework.auth.result.AuthSignUpResult) RandomString(com.amplifyframework.testutils.random.RandomString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AWSCognitoAuthResendSignUpCodeOptions(com.amplifyframework.auth.cognito.options.AWSCognitoAuthResendSignUpCodeOptions) AuthSignUpResult(com.amplifyframework.auth.result.AuthSignUpResult) SignUpResult(com.amazonaws.mobile.client.results.SignUpResult) Test(org.junit.Test)

Example 5 with AuthSignUpResult

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

the class AuthComponentTest method signUp.

/**
 * Tests that the signUp method of the Auth wrapper of AWSMobileClient (AMC) calls AMC.signUp() with the username
 * and password it received and, if included, the userAttributes and validationData sent in the options object.
 * Also ensures that in the onResult case, the success callback receives a valid AuthSignUpResult.
 * @throws AuthException test fails if this gets thrown since method should succeed
 */
@Test
public void signUp() throws AuthException {
    SignUpResult amcResult = new SignUpResult(false, new UserCodeDeliveryDetails(DESTINATION, DELIVERY_MEDIUM, ATTRIBUTE_NAME), USER_SUB);
    doAnswer(invocation -> {
        Callback<SignUpResult> callback = invocation.getArgument(5);
        callback.onResult(amcResult);
        return null;
    }).when(mobileClient).signUp(any(), any(), any(), any(), any(), Mockito.<Callback<SignUpResult>>any());
    AWSCognitoAuthSignUpOptions options = AWSCognitoAuthSignUpOptions.builder().userAttribute(AuthUserAttributeKey.email(), ATTRIBUTE_VAL).validationData(VALIDATIONDATA).clientMetadata(CLIENTMETADATA).build();
    AuthSignUpResult result = synchronousAuth.signUp(USERNAME, PASSWORD, options);
    validateSignUpResult(result, AuthSignUpStep.CONFIRM_SIGN_UP_STEP);
    Map<String, String> expectedAttributeMap = Collections.singletonMap(ATTRIBUTE_KEY, ATTRIBUTE_VAL);
    verify(mobileClient).signUp(eq(USERNAME), eq(PASSWORD), eq(expectedAttributeMap), eq(VALIDATIONDATA), eq(CLIENTMETADATA), Mockito.<Callback<SignUpResult>>any());
}
Also used : AWSCognitoAuthSignUpOptions(com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignUpOptions) UserCodeDeliveryDetails(com.amazonaws.mobile.client.results.UserCodeDeliveryDetails) AuthSignUpResult(com.amplifyframework.auth.result.AuthSignUpResult) RandomString(com.amplifyframework.testutils.random.RandomString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AuthSignUpResult(com.amplifyframework.auth.result.AuthSignUpResult) SignUpResult(com.amazonaws.mobile.client.results.SignUpResult) Test(org.junit.Test)

Aggregations

AuthSignUpResult (com.amplifyframework.auth.result.AuthSignUpResult)13 Test (org.junit.Test)9 SignUpResult (com.amazonaws.mobile.client.results.SignUpResult)8 RandomString (com.amplifyframework.testutils.random.RandomString)7 UserCodeDeliveryDetails (com.amazonaws.mobile.client.results.UserCodeDeliveryDetails)6 AuthException (com.amplifyframework.auth.AuthException)5 HashMap (java.util.HashMap)5 AuthNavigationException (com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthNavigationException)3 NotAuthorizedException (com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException)3 AmplifyException (com.amplifyframework.AmplifyException)3 AuthCodeDeliveryDetails (com.amplifyframework.auth.AuthCodeDeliveryDetails)3 AuthNextSignUpStep (com.amplifyframework.auth.result.step.AuthNextSignUpStep)3 JSONException (org.json.JSONException)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 AWSCognitoAuthConfirmSignUpOptions (com.amplifyframework.auth.cognito.options.AWSCognitoAuthConfirmSignUpOptions)2 AWSCognitoAuthResendSignUpCodeOptions (com.amplifyframework.auth.cognito.options.AWSCognitoAuthResendSignUpCodeOptions)2 AWSCognitoAuthSignUpOptions (com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignUpOptions)2 AuthSignUpOptions (com.amplifyframework.auth.options.AuthSignUpOptions)2 AuthSignUpStep (com.amplifyframework.auth.result.step.AuthSignUpStep)2 AuthUser (com.amplifyframework.auth.AuthUser)1