Search in sources :

Example 6 with AuthUserAttributeKey

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

the class AuthComponentTest method resendUserAttributeConfirmationCodeWithOptions.

/**
 * Tests the resendUserAttributeConfirmationCode method of the Auth wrapper of AWSMobileClient (AMC) Calls
 * AMC.verifyUserAttribute with the user attribute key to be verified and options it received.
 * @throws AuthException test fails if this gets thrown since method should succeed
 */
@Test
public void resendUserAttributeConfirmationCodeWithOptions() throws AuthException {
    AuthUserAttributeKey attributeKey = AuthUserAttributeKey.custom(ATTRIBUTE_KEY);
    UserCodeDeliveryDetails userCodeDeliveryDetails = new UserCodeDeliveryDetails(DESTINATION, DELIVERY_MEDIUM, ATTRIBUTE_NAME);
    AWSCognitoAuthResendUserAttributeConfirmationCodeOptions.CognitoBuilder options = AWSCognitoAuthResendUserAttributeConfirmationCodeOptions.builder();
    Map<String, String> metadata = new HashMap<String, String>();
    metadata.put("key", "value");
    options.metadata(metadata);
    AWSCognitoAuthResendUserAttributeConfirmationCodeOptions builtOptions = options.build();
    doAnswer(invocation -> {
        Callback<UserCodeDeliveryDetails> callback = invocation.getArgument(2);
        callback.onResult(userCodeDeliveryDetails);
        return null;
    }).when(mobileClient).verifyUserAttribute(any(), any(), Mockito.<Callback<UserCodeDeliveryDetails>>any());
    AuthCodeDeliveryDetails result = synchronousAuth.resendUserAttributeConfirmationCode(attributeKey, builtOptions);
    validateCodeDeliveryDetails(result);
    verify(mobileClient).verifyUserAttribute(eq(attributeKey.getKeyString()), eq(metadata), Mockito.<Callback<UserCodeDeliveryDetails>>any());
}
Also used : AuthCodeDeliveryDetails(com.amplifyframework.auth.AuthCodeDeliveryDetails) AWSCognitoAuthResendUserAttributeConfirmationCodeOptions(com.amplifyframework.auth.cognito.options.AWSCognitoAuthResendUserAttributeConfirmationCodeOptions) HashMap(java.util.HashMap) UserCodeDeliveryDetails(com.amazonaws.mobile.client.results.UserCodeDeliveryDetails) AuthUserAttributeKey(com.amplifyframework.auth.AuthUserAttributeKey) RandomString(com.amplifyframework.testutils.random.RandomString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 7 with AuthUserAttributeKey

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

Example 8 with AuthUserAttributeKey

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

the class RxAuthBindingTest method testConfirmUserAttribute.

/**
 * Validates that a successful request to confirm user attribute will propagate up into the binding.
 * @throws InterruptedException If test observer is interrupted while awaiting terminal event
 */
@Test
public void testConfirmUserAttribute() throws InterruptedException {
    // Arrange an invocation of the success Action
    AuthUserAttributeKey attributeKey = AuthUserAttributeKey.custom(ATTRIBUTE_KEY);
    doAnswer(invocation -> {
        Action onComplete = invocation.getArgument(2);
        onComplete.call();
        return null;
    }).when(delegate).confirmUserAttribute(any(), any(), anyAction(), anyConsumer());
    // Act: call the binding
    TestObserver<Void> observer = auth.confirmUserAttribute(attributeKey, CONFIRMATION_CODE).test();
    // Assert: Completable completes successfully
    observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
    observer.assertNoErrors().assertComplete();
}
Also used : Matchers.anyAction(com.amplifyframework.rx.Matchers.anyAction) Action(com.amplifyframework.core.Action) AuthUserAttributeKey(com.amplifyframework.auth.AuthUserAttributeKey) Test(org.junit.Test)

Aggregations

AuthUserAttributeKey (com.amplifyframework.auth.AuthUserAttributeKey)8 Test (org.junit.Test)8 UserCodeDeliveryDetails (com.amazonaws.mobile.client.results.UserCodeDeliveryDetails)4 AuthCodeDeliveryDetails (com.amplifyframework.auth.AuthCodeDeliveryDetails)4 HashMap (java.util.HashMap)4 AuthUserAttribute (com.amplifyframework.auth.AuthUserAttribute)3 AuthUpdateAttributeResult (com.amplifyframework.auth.result.AuthUpdateAttributeResult)3 RandomString (com.amplifyframework.testutils.random.RandomString)3 ArrayList (java.util.ArrayList)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 List (java.util.List)2 AWSCognitoAuthResendUserAttributeConfirmationCodeOptions (com.amplifyframework.auth.cognito.options.AWSCognitoAuthResendUserAttributeConfirmationCodeOptions)1 AWSCognitoAuthUpdateUserAttributesOptions (com.amplifyframework.auth.cognito.options.AWSCognitoAuthUpdateUserAttributesOptions)1 AuthNextUpdateAttributeStep (com.amplifyframework.auth.result.step.AuthNextUpdateAttributeStep)1 Action (com.amplifyframework.core.Action)1 Matchers.anyAction (com.amplifyframework.rx.Matchers.anyAction)1 Map (java.util.Map)1