use of com.amplifyframework.auth.result.AuthUpdateAttributeResult in project amplify-android by aws-amplify.
the class AuthComponentTest method updateUserAttribute.
/**
* Tests that updateUserAttribute method of the Auth wrapper of AWSMobileClient (AMC) calls
* AMC.updateUserAttributes with the user attribute it received.
* Also ensures that in the onResult case, the success callback receives a valid AuthUpdateAttributeResult and in
* the onError case, the error call back receives an AuthException with the root cause attached.
* @throws AuthException test fails if this gets thrown since method should succeed
*/
@Test
public void updateUserAttribute() throws AuthException {
AuthUserAttribute attribute = new AuthUserAttribute(AuthUserAttributeKey.custom(ATTRIBUTE_KEY), ATTRIBUTE_VAL);
Map<String, String> attributeMap = Collections.singletonMap(attribute.getKey().getKeyString(), attribute.getValue());
List<UserCodeDeliveryDetails> userCodeDeliveryDetailsList = Collections.singletonList(new UserCodeDeliveryDetails(DESTINATION, DELIVERY_MEDIUM, ATTRIBUTE_NAME));
doAnswer(invocation -> {
Callback<List<UserCodeDeliveryDetails>> callback = invocation.getArgument(2);
callback.onResult(userCodeDeliveryDetailsList);
return null;
}).when(mobileClient).updateUserAttributes(any(), any(), Mockito.<Callback<List<UserCodeDeliveryDetails>>>any());
AuthUpdateAttributeResult result = synchronousAuth.updateUserAttribute(attribute);
assertTrue(result.isUpdated());
assertEquals(AuthUpdateAttributeStep.CONFIRM_ATTRIBUTE_WITH_CODE, result.getNextStep().getUpdateAttributeStep());
validateCodeDeliveryDetails(result.getNextStep().getCodeDeliveryDetails());
verify(mobileClient).updateUserAttributes(eq(attributeMap), any(), Mockito.<Callback<List<UserCodeDeliveryDetails>>>any());
}
use of com.amplifyframework.auth.result.AuthUpdateAttributeResult in project amplify-android by aws-amplify.
the class AuthComponentTest method updateUserAttributesWithOptions.
/**
* Tests that updateUserAttributes method of the Auth wrapper of AWSMobileClient (AMC) Calls
* AMC.updateUserAttributes with the user attributes and options it received.
* Also ensures that in the onResult case, the success callback receives a valid Map which maps
* AuthUserAttributeKey into AuthUpdateAttributeResult, and in the onError case, the error call
* back receives an AuthException with the root cause attached.
* @throws AuthException test fails if this gets thrown since method should succeed
*/
@Test
public void updateUserAttributesWithOptions() throws AuthException {
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<String, String> attributesMap = new HashMap<>();
for (AuthUserAttribute attribute : attributes) {
attributesMap.put(attribute.getKey().getKeyString(), attribute.getValue());
}
List<UserCodeDeliveryDetails> userCodeDeliveryDetailsList = Collections.singletonList(new UserCodeDeliveryDetails(DESTINATION, DELIVERY_MEDIUM, ATTRIBUTE_NAME));
AWSCognitoAuthUpdateUserAttributesOptions.CognitoBuilder options = AWSCognitoAuthUpdateUserAttributesOptions.builder();
Map<String, String> metadata = new HashMap<String, String>();
metadata.put("key", "value");
options.metadata(metadata);
AWSCognitoAuthUpdateUserAttributesOptions builtOptions = options.build();
doAnswer(invocation -> {
Callback<List<UserCodeDeliveryDetails>> callback = invocation.getArgument(2);
callback.onResult(userCodeDeliveryDetailsList);
return null;
}).when(mobileClient).updateUserAttributes(any(), any(), Mockito.<Callback<List<UserCodeDeliveryDetails>>>any());
Map<AuthUserAttributeKey, AuthUpdateAttributeResult> result = synchronousAuth.updateUserAttributes(attributes, builtOptions);
assertTrue(result.get(attributeKey).isUpdated());
assertTrue(result.get(attributeKeyWithoutCode).isUpdated());
assertEquals(AuthUpdateAttributeStep.CONFIRM_ATTRIBUTE_WITH_CODE, result.get(attributeKey).getNextStep().getUpdateAttributeStep());
assertEquals(AuthUpdateAttributeStep.DONE, result.get(attributeKeyWithoutCode).getNextStep().getUpdateAttributeStep());
validateCodeDeliveryDetails(result.get(attributeKey).getNextStep().getCodeDeliveryDetails());
verify(mobileClient).updateUserAttributes(eq(attributesMap), eq(metadata), Mockito.<Callback<List<UserCodeDeliveryDetails>>>any());
}
use of com.amplifyframework.auth.result.AuthUpdateAttributeResult in project amplify-android by aws-amplify.
the class AuthComponentTest method updateUserAttributes.
/**
* Tests that updateUserAttributes method of the Auth wrapper of AWSMobileClient (AMC) Calls
* AMC.updateUserAttributes with the user attributes it received.
* Also ensures that in the onResult case, the success callback receives a valid Map which maps
* AuthUserAttributeKey into AuthUpdateAttributeResult, and in the onError case, the error call
* back receives an AuthException with the root cause attached.
* @throws AuthException test fails if this gets thrown since method should succeed
*/
@Test
public void updateUserAttributes() throws AuthException {
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<String, String> attributesMap = new HashMap<>();
for (AuthUserAttribute attribute : attributes) {
attributesMap.put(attribute.getKey().getKeyString(), attribute.getValue());
}
List<UserCodeDeliveryDetails> userCodeDeliveryDetailsList = Collections.singletonList(new UserCodeDeliveryDetails(DESTINATION, DELIVERY_MEDIUM, ATTRIBUTE_NAME));
doAnswer(invocation -> {
Callback<List<UserCodeDeliveryDetails>> callback = invocation.getArgument(2);
callback.onResult(userCodeDeliveryDetailsList);
return null;
}).when(mobileClient).updateUserAttributes(any(), any(), Mockito.<Callback<List<UserCodeDeliveryDetails>>>any());
Map<AuthUserAttributeKey, AuthUpdateAttributeResult> result = synchronousAuth.updateUserAttributes(attributes);
assertTrue(result.get(attributeKey).isUpdated());
assertTrue(result.get(attributeKeyWithoutCode).isUpdated());
assertEquals(AuthUpdateAttributeStep.CONFIRM_ATTRIBUTE_WITH_CODE, result.get(attributeKey).getNextStep().getUpdateAttributeStep());
assertEquals(AuthUpdateAttributeStep.DONE, result.get(attributeKeyWithoutCode).getNextStep().getUpdateAttributeStep());
validateCodeDeliveryDetails(result.get(attributeKey).getNextStep().getCodeDeliveryDetails());
verify(mobileClient).updateUserAttributes(eq(attributesMap), any(), Mockito.<Callback<List<UserCodeDeliveryDetails>>>any());
}
use of com.amplifyframework.auth.result.AuthUpdateAttributeResult in project amplify-android by aws-amplify.
the class AuthComponentTest method updateUserAttributeWithOptions.
/**
* Tests that updateUserAttribute method of the Auth wrapper of AWSMobileClient (AMC) calls
* AMC.updateUserAttributes with the user attribute and options it received.
* Also ensures that in the onResult case, the success callback receives a valid AuthUpdateAttributeResult and in
* the onError case, the error call back receives an AuthException with the root cause attached.
* @throws AuthException test fails if this gets thrown since method should succeed
*/
@Test
public void updateUserAttributeWithOptions() throws AuthException {
AuthUserAttribute attribute = new AuthUserAttribute(AuthUserAttributeKey.custom(ATTRIBUTE_KEY), ATTRIBUTE_VAL);
Map<String, String> attributeMap = Collections.singletonMap(attribute.getKey().getKeyString(), attribute.getValue());
List<UserCodeDeliveryDetails> userCodeDeliveryDetailsList = Collections.singletonList(new UserCodeDeliveryDetails(DESTINATION, DELIVERY_MEDIUM, ATTRIBUTE_NAME));
AWSCognitoAuthUpdateUserAttributeOptions.CognitoBuilder options = AWSCognitoAuthUpdateUserAttributeOptions.builder();
Map<String, String> metadata = new HashMap<String, String>();
metadata.put("key", "value");
options.metadata(metadata);
AWSCognitoAuthUpdateUserAttributeOptions builtOptions = options.build();
doAnswer(invocation -> {
Callback<List<UserCodeDeliveryDetails>> callback = invocation.getArgument(2);
callback.onResult(userCodeDeliveryDetailsList);
return null;
}).when(mobileClient).updateUserAttributes(any(), any(), Mockito.<Callback<List<UserCodeDeliveryDetails>>>any());
AuthUpdateAttributeResult result = synchronousAuth.updateUserAttribute(attribute, builtOptions);
assertTrue(result.isUpdated());
assertEquals(AuthUpdateAttributeStep.CONFIRM_ATTRIBUTE_WITH_CODE, result.getNextStep().getUpdateAttributeStep());
validateCodeDeliveryDetails(result.getNextStep().getCodeDeliveryDetails());
verify(mobileClient).updateUserAttributes(eq(attributeMap), eq(metadata), Mockito.<Callback<List<UserCodeDeliveryDetails>>>any());
}
use of com.amplifyframework.auth.result.AuthUpdateAttributeResult 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);
}
Aggregations