use of com.amazonaws.mobile.client.results.UserCodeDeliveryDetails in project amplify-android by aws-amplify.
the class AuthComponentTest method resendSignUpCodeWithOptions.
/**
* Tests that the resendSignUpCode method of the Auth wrapper of AWSMobileClient (AMC) calls AMC.resendSignUp with
* the username and options it received.
* Also ensures that in the onResult case, the success callback receives a valid AuthSignUpResult.
* @throws AuthException test fails if this gets thrown since method should succeed
*/
@Test
// Casts final parameter to Callback to differentiate methods
@SuppressWarnings("unchecked")
public void resendSignUpCodeWithOptions() throws AuthException {
SignUpResult amcResult = new SignUpResult(false, new UserCodeDeliveryDetails(DESTINATION, DELIVERY_MEDIUM, ATTRIBUTE_NAME), USER_SUB);
AWSCognitoAuthResendSignUpCodeOptions.CognitoBuilder options = AWSCognitoAuthResendSignUpCodeOptions.builder();
Map<String, String> metadata = new HashMap<String, String>();
metadata.put("key", "value");
options.metadata(metadata);
AWSCognitoAuthResendSignUpCodeOptions builtOptions = options.build();
doAnswer(invocation -> {
Callback<SignUpResult> callback = invocation.getArgument(2);
callback.onResult(amcResult);
return null;
}).when(mobileClient).resendSignUp(any(), any(), (Callback<SignUpResult>) any());
AuthSignUpResult result = synchronousAuth.resendSignUpCode(USERNAME, builtOptions);
validateSignUpResult(result, AuthSignUpStep.CONFIRM_SIGN_UP_STEP);
verify(mobileClient).resendSignUp(eq(USERNAME), eq(metadata), (Callback<SignUpResult>) any());
}
use of com.amazonaws.mobile.client.results.UserCodeDeliveryDetails in project amplify-android by aws-amplify.
the class AuthComponentTest method signUp.
/**
* Tests that the signUp method of the Auth wrapper of AWSMobileClient (AMC) calls AMC.signUp() with the username
* and password it received and, if included, the userAttributes and validationData sent in the options object.
* Also ensures that in the onResult case, the success callback receives a valid AuthSignUpResult.
* @throws AuthException test fails if this gets thrown since method should succeed
*/
@Test
public void signUp() throws AuthException {
SignUpResult amcResult = new SignUpResult(false, new UserCodeDeliveryDetails(DESTINATION, DELIVERY_MEDIUM, ATTRIBUTE_NAME), USER_SUB);
doAnswer(invocation -> {
Callback<SignUpResult> callback = invocation.getArgument(5);
callback.onResult(amcResult);
return null;
}).when(mobileClient).signUp(any(), any(), any(), any(), any(), Mockito.<Callback<SignUpResult>>any());
AWSCognitoAuthSignUpOptions options = AWSCognitoAuthSignUpOptions.builder().userAttribute(AuthUserAttributeKey.email(), ATTRIBUTE_VAL).validationData(VALIDATIONDATA).clientMetadata(CLIENTMETADATA).build();
AuthSignUpResult result = synchronousAuth.signUp(USERNAME, PASSWORD, options);
validateSignUpResult(result, AuthSignUpStep.CONFIRM_SIGN_UP_STEP);
Map<String, String> expectedAttributeMap = Collections.singletonMap(ATTRIBUTE_KEY, ATTRIBUTE_VAL);
verify(mobileClient).signUp(eq(USERNAME), eq(PASSWORD), eq(expectedAttributeMap), eq(VALIDATIONDATA), eq(CLIENTMETADATA), Mockito.<Callback<SignUpResult>>any());
}
use of com.amazonaws.mobile.client.results.UserCodeDeliveryDetails 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.amazonaws.mobile.client.results.UserCodeDeliveryDetails in project amplify-android by aws-amplify.
the class AuthComponentTest method confirmSignInWithOptions.
/**
* Tests that the confirmSignIn method of the Auth wrapper of AWSMobileClient (AMC) calls AMC.confirmSignIn with
* the confirmation code and options it received and the success callback receives a valid AuthSignInResult.
* @throws AuthException test fails if this gets thrown since method should succeed
*/
@Test
// Casts final parameter to Callback to differentiate methods
@SuppressWarnings("unchecked")
public void confirmSignInWithOptions() throws AuthException {
SignInResult amcResult = new SignInResult(SignInState.DONE, new UserCodeDeliveryDetails(DESTINATION, DELIVERY_MEDIUM, ATTRIBUTE_NAME));
Tokens tokensResult = new Tokens(ACCESS_TOKEN, ID_TOKEN, REFRESH_TOKEN);
AWSCognitoAuthConfirmSignInOptions.CognitoBuilder options = AWSCognitoAuthConfirmSignInOptions.builder();
Map<String, String> metadata = new HashMap<String, String>();
AuthUserAttribute attribute = new AuthUserAttribute(AuthUserAttributeKey.email(), "test@test.test");
List<AuthUserAttribute> attributes = Collections.singletonList(attribute);
Map<String, String> attributeMap = Collections.singletonMap("email", "test@test.test");
metadata.put("key", "value");
options.metadata(metadata);
options.userAttributes(attributes);
AWSCognitoAuthConfirmSignInOptions builtOptions = options.build();
doAnswer(invocation -> {
Callback<Tokens> callback = invocation.getArgument(0);
callback.onResult(tokensResult);
return null;
}).when(mobileClient).getTokens(any());
doAnswer(invocation -> {
Callback<SignInResult> callback = invocation.getArgument(3);
callback.onResult(amcResult);
return null;
}).when(mobileClient).confirmSignIn(any(String.class), any(), any(), (Callback<SignInResult>) any());
AuthSignInResult result = synchronousAuth.confirmSignIn(CONFIRMATION_CODE, builtOptions);
validateSignInResult(result, true, AuthSignInStep.DONE);
verify(mobileClient).confirmSignIn(eq(CONFIRMATION_CODE), eq(metadata), eq(attributeMap), (Callback<SignInResult>) any());
}
use of com.amazonaws.mobile.client.results.UserCodeDeliveryDetails in project amplify-android by aws-amplify.
the class AuthComponentTest method resendSignUpCode.
/**
* Tests that the resendSignUpCode method of the Auth wrapper of AWSMobileClient (AMC) calls AMC.resendSignUp with
* the username it received .
* Also ensures that in the onResult case, the success callback receives a valid AuthSignUpResult.
* @throws AuthException test fails if this gets thrown since method should succeed
*/
@Test
// Casts final parameter to Callback to differentiate methods
@SuppressWarnings("unchecked")
public void resendSignUpCode() throws AuthException {
SignUpResult amcResult = new SignUpResult(false, new UserCodeDeliveryDetails(DESTINATION, DELIVERY_MEDIUM, ATTRIBUTE_NAME), USER_SUB);
doAnswer(invocation -> {
Callback<SignUpResult> callback = invocation.getArgument(2);
callback.onResult(amcResult);
return null;
}).when(mobileClient).resendSignUp(any(), any(), (Callback<SignUpResult>) any());
AuthSignUpResult result = synchronousAuth.resendSignUpCode(USERNAME);
validateSignUpResult(result, AuthSignUpStep.CONFIRM_SIGN_UP_STEP);
verify(mobileClient).resendSignUp(eq(USERNAME), any(), (Callback<SignUpResult>) any());
}
Aggregations