use of com.amplifyframework.auth.result.step.AuthNextSignInStep 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.result.step.AuthNextSignInStep 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);
}
use of com.amplifyframework.auth.result.step.AuthNextSignInStep in project amplify-android by aws-amplify.
the class AuthComponentTest method validateSignInResult.
private void validateSignInResult(AuthSignInResult result, boolean targetIsSignedIn, AuthSignInStep targetStep) {
AuthNextSignInStep nextStep = result.getNextStep();
validateCodeDeliveryDetails(nextStep.getCodeDeliveryDetails());
assertEquals(targetIsSignedIn, result.isSignInComplete());
assertEquals(targetStep, nextStep.getSignInStep());
}
use of com.amplifyframework.auth.result.step.AuthNextSignInStep in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testSignInWithWebUISucceeds.
/**
* Validates that a successful call to sign-in with web UI will propagate the result
* back through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testSignInWithWebUISucceeds() throws InterruptedException {
Activity activity = new Activity();
// Arrange a result
AuthSignInStep step = AuthSignInStep.CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE;
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 = activity, 1 = result consumer, 2 = failure consumer
int positionOfResultConsumer = 1;
Consumer<AuthSignInResult> onResult = invocation.getArgument(positionOfResultConsumer);
onResult.accept(result);
return null;
}).when(delegate).signInWithWebUI(eq(activity), anyConsumer(), anyConsumer());
// Act: call the binding
TestObserver<AuthSignInResult> observer = auth.signInWithWebUI(activity).test();
// Assert: result is furnished the via the Rx Single
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoErrors().assertValue(result);
}
use of com.amplifyframework.auth.result.step.AuthNextSignInStep in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testSignInSucceeds.
/**
* Validates that a successful call to sign-in will propagate the result
* back through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testSignInSucceeds() throws InterruptedException {
String username = RandomString.string();
String password = RandomString.string();
// Arrange a result on the result consumer
AuthCodeDeliveryDetails details = new AuthCodeDeliveryDetails(RandomString.string(), DeliveryMedium.EMAIL);
AuthSignInStep step = AuthSignInStep.CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE;
AuthNextSignInStep nextStep = new AuthNextSignInStep(step, Collections.emptyMap(), details);
AuthSignInResult result = new AuthSignInResult(false, nextStep);
doAnswer(invocation -> {
// 0 = username, 1 = password, 2 = onResult, 3 = onFailure
int positionOfResultConsumer = 2;
Consumer<AuthSignInResult> onResult = invocation.getArgument(positionOfResultConsumer);
onResult.accept(result);
return null;
}).when(delegate).signIn(eq(username), eq(password), anyConsumer(), anyConsumer());
// Act: call the binding
TestObserver<AuthSignInResult> observer = auth.signIn(username, password).test();
// Assert: the result was furnished to the Rx Single
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoErrors().assertValue(result);
}
Aggregations