use of com.amplifyframework.auth.result.step.AuthNextUpdateAttributeStep in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testUpdateUserAttribute.
/**
* Tests that a successful request to update a user attribute will propagate a completion
* back through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testUpdateUserAttribute() throws InterruptedException {
// Arrange an invocation of the success Action
AuthUserAttribute attribute = new AuthUserAttribute(AuthUserAttributeKey.custom(ATTRIBUTE_KEY), ATTRIBUTE_VAL);
AuthUpdateAttributeResult expected = new AuthUpdateAttributeResult(true, new AuthNextUpdateAttributeStep(AuthUpdateAttributeStep.DONE, Collections.emptyMap(), null));
doAnswer(invocation -> {
Consumer<AuthUpdateAttributeResult> onCompletion = invocation.getArgument(1);
onCompletion.accept(expected);
return null;
}).when(delegate).updateUserAttribute(any(), anyConsumer(), anyConsumer());
// Act: call the binding
TestObserver<AuthUpdateAttributeResult> observer = auth.updateUserAttribute(attribute).test();
// Assert: Completable completes with success
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoErrors().assertValue(expected);
}
use of com.amplifyframework.auth.result.step.AuthNextUpdateAttributeStep 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);
}
use of com.amplifyframework.auth.result.step.AuthNextUpdateAttributeStep in project amplify-android by aws-amplify.
the class AWSCognitoAuthPlugin method updateUserAttributes.
@Override
public void updateUserAttributes(@NonNull List<AuthUserAttribute> attributes, @NonNull AuthUpdateUserAttributesOptions options, @NonNull Consumer<Map<AuthUserAttributeKey, AuthUpdateAttributeResult>> onSuccess, @NonNull Consumer<AuthException> onError) {
final Map<String, String> clientMetadata = new HashMap<>();
if (options instanceof AWSCognitoAuthUpdateUserAttributesOptions) {
AWSCognitoAuthUpdateUserAttributesOptions cognitoOptions = (AWSCognitoAuthUpdateUserAttributesOptions) options;
clientMetadata.putAll(cognitoOptions.getMetadata());
}
Map<String, String> attributesMap = new HashMap<>();
for (AuthUserAttribute attribute : attributes) {
attributesMap.put(attribute.getKey().getKeyString(), attribute.getValue());
}
awsMobileClient.updateUserAttributes(attributesMap, clientMetadata, new Callback<List<UserCodeDeliveryDetails>>() {
@Override
public void onResult(List<UserCodeDeliveryDetails> result) {
Map<String, UserCodeDeliveryDetails> codeDetailsMap = new HashMap<>();
Map<AuthUserAttributeKey, AuthUpdateAttributeResult> resultMap = new HashMap<>();
for (UserCodeDeliveryDetails details : result) {
codeDetailsMap.put(details.getAttributeName(), details);
}
for (String attributeKey : attributesMap.keySet()) {
if (codeDetailsMap.containsKey(attributeKey)) {
resultMap.put(AuthUserAttributeKey.custom(attributeKey), new AuthUpdateAttributeResult(true, new AuthNextUpdateAttributeStep(AuthUpdateAttributeStep.CONFIRM_ATTRIBUTE_WITH_CODE, Collections.emptyMap(), convertCodeDeliveryDetails(codeDetailsMap.get(attributeKey)))));
} else {
resultMap.put(AuthUserAttributeKey.custom(attributeKey), new AuthUpdateAttributeResult(true, new AuthNextUpdateAttributeStep(AuthUpdateAttributeStep.DONE, Collections.emptyMap(), null)));
}
}
onSuccess.accept(resultMap);
}
@Override
public void onError(Exception error) {
onError.accept(new AuthException("Failed to update user attributes", error, "See attached exception for more details"));
}
});
}
use of com.amplifyframework.auth.result.step.AuthNextUpdateAttributeStep in project amplify-android by aws-amplify.
the class AWSCognitoAuthPlugin method updateUserAttribute.
@Override
public void updateUserAttribute(@NonNull AuthUserAttribute attribute, @NonNull AuthUpdateUserAttributeOptions options, @NonNull Consumer<AuthUpdateAttributeResult> onSuccess, @NonNull Consumer<AuthException> onError) {
final Map<String, String> clientMetadata = new HashMap<>();
if (options instanceof AWSCognitoAuthUpdateUserAttributeOptions) {
AWSCognitoAuthUpdateUserAttributeOptions cognitoOptions = (AWSCognitoAuthUpdateUserAttributeOptions) options;
clientMetadata.putAll(cognitoOptions.getMetadata());
}
awsMobileClient.updateUserAttributes(Collections.singletonMap(attribute.getKey().getKeyString(), attribute.getValue()), clientMetadata, new Callback<List<UserCodeDeliveryDetails>>() {
@Override
public void onResult(List<UserCodeDeliveryDetails> result) {
if (result.size() == 0) {
onSuccess.accept(new AuthUpdateAttributeResult(true, new AuthNextUpdateAttributeStep(AuthUpdateAttributeStep.DONE, Collections.emptyMap(), null)));
} else {
onSuccess.accept(new AuthUpdateAttributeResult(true, new AuthNextUpdateAttributeStep(AuthUpdateAttributeStep.CONFIRM_ATTRIBUTE_WITH_CODE, Collections.emptyMap(), convertCodeDeliveryDetails(result.get(0)))));
}
}
@Override
public void onError(Exception error) {
onError.accept(new AuthException("Failed to update user attributes", error, "See attached exception for more details"));
}
});
}
Aggregations