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());
}
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);
}
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();
}
Aggregations