use of com.amplifyframework.auth.result.AuthSignUpResult in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testResendSignUpCodeFails.
/**
* Validates that a failed call to resend the sign-up code will propagate the failure
* back through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testResendSignUpCodeFails() throws InterruptedException {
String username = RandomString.string();
// Arrange a failure on the failure consumer
AuthException failure = new AuthException("Reset sign up", " has failed.");
doAnswer(invocation -> {
// 0 = username, 1 = onResult, 2 = onFailure
int positionOfFailureConsumer = 2;
Consumer<AuthException> onFailure = invocation.getArgument(positionOfFailureConsumer);
onFailure.accept(failure);
return null;
}).when(delegate).resendSignUpCode(eq(username), anyConsumer(), anyConsumer());
// Act: call the binding
TestObserver<AuthSignUpResult> observer = auth.resendSignUpCode(username).test();
// Assert: the result was furnished to the Rx Single
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoValues().assertError(failure);
}
use of com.amplifyframework.auth.result.AuthSignUpResult in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testSignUpSucceeds.
/**
* Validates that a sign-up result are passed through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testSignUpSucceeds() throws InterruptedException {
// Arrange a response from delegate
String username = RandomString.string();
String password = RandomString.string();
AuthSignUpOptions options = AuthSignUpOptions.builder().build();
// Arrange a result on the result consumer
AuthCodeDeliveryDetails details = new AuthCodeDeliveryDetails(RandomString.string(), DeliveryMedium.SMS);
AuthSignUpStep step = AuthSignUpStep.CONFIRM_SIGN_UP_STEP;
AuthNextSignUpStep nextStep = new AuthNextSignUpStep(step, Collections.emptyMap(), details);
AuthSignUpResult result = new AuthSignUpResult(false, nextStep, null);
doAnswer(invocation -> {
// 0 = username, 1 = pass, 2 = options, 3 = onSuccess, 4 = onFailure
int positionOfSuccessConsumer = 3;
Consumer<AuthSignUpResult> onResult = invocation.getArgument(positionOfSuccessConsumer);
onResult.accept(result);
return null;
}).when(delegate).signUp(eq(username), eq(password), eq(options), anyConsumer(), anyConsumer());
// Act: call the binding
TestObserver<AuthSignUpResult> observer = auth.signUp(username, password, options).test();
// Assert: the result was furnished to the Rx Single
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoErrors().assertValue(result);
}
use of com.amplifyframework.auth.result.AuthSignUpResult in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testResendSignUpCodeSucceeds.
/**
* Validates that a successful call to resend the sign-up code will propagate the result
* back through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testResendSignUpCodeSucceeds() throws InterruptedException {
String username = RandomString.string();
// Arrange a result on the result consumer
AuthCodeDeliveryDetails details = new AuthCodeDeliveryDetails(RandomString.string(), DeliveryMedium.EMAIL);
AuthSignUpStep step = AuthSignUpStep.CONFIRM_SIGN_UP_STEP;
AuthNextSignUpStep nextStep = new AuthNextSignUpStep(step, Collections.emptyMap(), details);
AuthSignUpResult result = new AuthSignUpResult(false, nextStep, null);
doAnswer(invocation -> {
// 0 = username, 1 = onResult, 2 = onFailure
int positionOfResultConsumer = 1;
Consumer<AuthSignUpResult> onResult = invocation.getArgument(positionOfResultConsumer);
onResult.accept(result);
return null;
}).when(delegate).resendSignUpCode(eq(username), anyConsumer(), anyConsumer());
// Act: call the binding
TestObserver<AuthSignUpResult> observer = auth.resendSignUpCode(username).test();
// Assert: the result was furnished to the Rx Single
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoErrors().assertValue(result);
}
use of com.amplifyframework.auth.result.AuthSignUpResult 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.result.AuthSignUpResult 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());
}
Aggregations