use of com.amplifyframework.auth.cognito.options.AWSCognitoAuthResendSignUpCodeOptions 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.amplifyframework.auth.cognito.options.AWSCognitoAuthResendSignUpCodeOptions in project amplify-android by aws-amplify.
the class AWSCognitoAuthPlugin method resendSignUpCode.
@Override
public void resendSignUpCode(@NonNull String username, @NonNull AuthResendSignUpCodeOptions options, @NonNull Consumer<AuthSignUpResult> onSuccess, @NonNull Consumer<AuthException> onException) {
final Map<String, String> clientMetadata = new HashMap<>();
if (options instanceof AWSCognitoAuthResendSignUpCodeOptions) {
AWSCognitoAuthResendSignUpCodeOptions cognitoOptions = (AWSCognitoAuthResendSignUpCodeOptions) options;
clientMetadata.putAll(cognitoOptions.getMetadata());
}
awsMobileClient.resendSignUp(username, clientMetadata, new Callback<SignUpResult>() {
@Override
public void onResult(SignUpResult result) {
onSuccess.accept(convertSignUpResult(result, username));
}
@Override
public void onError(Exception error) {
onException.accept(CognitoAuthExceptionConverter.lookup(error, "Resend confirmation code failed"));
}
});
}
Aggregations