Search in sources :

Example 11 with AuthCodeDeliveryDetails

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

the class RxAuthBindingTest method testSignInSucceeds.

/**
 * Validates that a successful call to sign-in will propagate the result
 * back through the binding.
 * @throws InterruptedException If test observer is interrupted while awaiting terminal event
 */
@Test
public void testSignInSucceeds() throws InterruptedException {
    String username = RandomString.string();
    String password = RandomString.string();
    // Arrange a result on the result consumer
    AuthCodeDeliveryDetails details = new AuthCodeDeliveryDetails(RandomString.string(), DeliveryMedium.EMAIL);
    AuthSignInStep step = AuthSignInStep.CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE;
    AuthNextSignInStep nextStep = new AuthNextSignInStep(step, Collections.emptyMap(), details);
    AuthSignInResult result = new AuthSignInResult(false, nextStep);
    doAnswer(invocation -> {
        // 0 = username, 1 = password, 2 = onResult, 3 = onFailure
        int positionOfResultConsumer = 2;
        Consumer<AuthSignInResult> onResult = invocation.getArgument(positionOfResultConsumer);
        onResult.accept(result);
        return null;
    }).when(delegate).signIn(eq(username), eq(password), anyConsumer(), anyConsumer());
    // Act: call the binding
    TestObserver<AuthSignInResult> observer = auth.signIn(username, password).test();
    // Assert: the result was furnished to the Rx Single
    observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
    observer.assertNoErrors().assertValue(result);
}
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 12 with AuthCodeDeliveryDetails

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

the class RxAuthBindingTest method testUpdateUserAttributes.

/**
 * Tests that a successful request to update user attributes will propagate a completion
 * back through the binding.
 * @throws InterruptedException If test observer is interrupted while awaiting terminal event
 */
@Test
public void testUpdateUserAttributes() throws InterruptedException {
    // Arrange an invocation of the success Action
    List<AuthUserAttribute> attributes = new ArrayList<>();
    AuthUserAttributeKey attributeKey = AuthUserAttributeKey.custom(ATTRIBUTE_KEY);
    AuthUserAttributeKey attributeKeyWithoutCode = AuthUserAttributeKey.custom(ATTRIBUTE_KEY_WITHOUT_CODE_DELIVERY);
    attributes.add(new AuthUserAttribute(attributeKey, ATTRIBUTE_VAL));
    attributes.add(new AuthUserAttribute(attributeKeyWithoutCode, ATTRIBUTE_VAL_WITHOUT_CODE_DELIVERY));
    Map<AuthUserAttributeKey, AuthUpdateAttributeResult> attributeResultMap = new HashMap<>();
    attributeResultMap.put(attributeKey, new AuthUpdateAttributeResult(true, new AuthNextUpdateAttributeStep(AuthUpdateAttributeStep.CONFIRM_ATTRIBUTE_WITH_CODE, Collections.emptyMap(), new AuthCodeDeliveryDetails(DESTINATION, DeliveryMedium.EMAIL, ATTRIBUTE_NAME))));
    attributeResultMap.put(attributeKeyWithoutCode, new AuthUpdateAttributeResult(true, new AuthNextUpdateAttributeStep(AuthUpdateAttributeStep.DONE, Collections.emptyMap(), null)));
    doAnswer(invocation -> {
        Consumer<Map<AuthUserAttributeKey, AuthUpdateAttributeResult>> onCompletion = invocation.getArgument(1);
        onCompletion.accept(attributeResultMap);
        return null;
    }).when(delegate).updateUserAttributes(any(), anyConsumer(), anyConsumer());
    // Act: call the binding
    TestObserver<Map<AuthUserAttributeKey, AuthUpdateAttributeResult>> observer = auth.updateUserAttributes(attributes).test();
    // Assert: Completable completes with success
    observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
    observer.assertNoErrors().assertValue(attributeResultMap);
}
Also used : AuthUserAttribute(com.amplifyframework.auth.AuthUserAttribute) AuthUpdateAttributeResult(com.amplifyframework.auth.result.AuthUpdateAttributeResult) AuthNextUpdateAttributeStep(com.amplifyframework.auth.result.step.AuthNextUpdateAttributeStep) AuthCodeDeliveryDetails(com.amplifyframework.auth.AuthCodeDeliveryDetails) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AuthUserAttributeKey(com.amplifyframework.auth.AuthUserAttributeKey) HashMap(java.util.HashMap) Map(java.util.Map) 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