use of com.amplifyframework.auth.AuthCodeDeliveryDetails in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testResendUserAttributeConfirmationCode.
/**
* Tests that a successful request to resend user attribute confirmation code will propagate a
* completion back through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testResendUserAttributeConfirmationCode() throws InterruptedException {
// Arrange an invocation of the success Action
AuthUserAttributeKey attributeKey = AuthUserAttributeKey.custom(ATTRIBUTE_KEY);
AuthCodeDeliveryDetails expected = new AuthCodeDeliveryDetails(DESTINATION, DeliveryMedium.EMAIL, ATTRIBUTE_NAME);
doAnswer(invocation -> {
Consumer<AuthCodeDeliveryDetails> onCompletion = invocation.getArgument(1);
onCompletion.accept(expected);
return null;
}).when(delegate).resendUserAttributeConfirmationCode(any(), anyConsumer(), anyConsumer());
// Act: call the binding
TestObserver<AuthCodeDeliveryDetails> observer = auth.resendUserAttributeConfirmationCode(attributeKey).test();
// Assert: Completable completes with success
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoErrors().assertValue(expected);
}
use of com.amplifyframework.auth.AuthCodeDeliveryDetails in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testConfirmSignInSucceeds.
/**
* Validates that a successful call to confirm sign-in will propagate the result
* back through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testConfirmSignInSucceeds() throws InterruptedException {
String confirmationCode = RandomString.string();
// Arrange a successful result.
AuthSignInStep step = AuthSignInStep.CONFIRM_SIGN_IN_WITH_SMS_MFA_CODE;
AuthCodeDeliveryDetails details = new AuthCodeDeliveryDetails(RandomString.string(), DeliveryMedium.UNKNOWN);
AuthNextSignInStep nextStep = new AuthNextSignInStep(step, Collections.emptyMap(), details);
AuthSignInResult expected = new AuthSignInResult(true, nextStep);
doAnswer(invocation -> {
// 0 = confirm code, 1 = onResult, 2 = onFailure
int positionOfResultConsumer = 1;
Consumer<AuthSignInResult> onResult = invocation.getArgument(positionOfResultConsumer);
onResult.accept(expected);
return null;
}).when(delegate).confirmSignIn(eq(confirmationCode), anyConsumer(), anyConsumer());
// Act: call the binding
TestObserver<AuthSignInResult> observer = auth.confirmSignIn(confirmationCode).test();
// Assert: result is furnished
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoErrors().assertValue(expected);
}
use of com.amplifyframework.auth.AuthCodeDeliveryDetails 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.AuthCodeDeliveryDetails 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.AuthCodeDeliveryDetails in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testSignInWithSocialWebUISucceeds.
/**
* Validates that a successful call to sign-in with social web UI will propagate the result
* back through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testSignInWithSocialWebUISucceeds() throws InterruptedException {
AuthProvider provider = AuthProvider.amazon();
Activity activity = new Activity();
// Arrange a successful result
AuthSignInStep step = AuthSignInStep.CONFIRM_SIGN_IN_WITH_SMS_MFA_CODE;
AuthCodeDeliveryDetails details = new AuthCodeDeliveryDetails(RandomString.string(), DeliveryMedium.PHONE);
AuthNextSignInStep nextStep = new AuthNextSignInStep(step, Collections.emptyMap(), details);
AuthSignInResult result = new AuthSignInResult(false, nextStep);
doAnswer(invocation -> {
// 0 = provider, 1 = activity, 2 = result consumer, 3 = failure consumer
int positionOfResultConsumer = 2;
Consumer<AuthSignInResult> onResult = invocation.getArgument(positionOfResultConsumer);
onResult.accept(result);
return null;
}).when(delegate).signInWithSocialWebUI(eq(provider), eq(activity), anyConsumer(), anyConsumer());
// Act: call the binding
TestObserver<AuthSignInResult> observer = auth.signInWithSocialWebUI(provider, activity).test();
// Assert: result is furnished the via the Rx Single
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoErrors().assertValue(result);
}
Aggregations