use of com.amplifyframework.auth.result.step.AuthResetPasswordStep in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testResetPasswordSucceeds.
/**
* Tests that a successful request to reset the password will propagate a result
* back through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testResetPasswordSucceeds() throws InterruptedException {
String username = RandomString.string();
// Arrange delegate to furnish a result
AuthResetPasswordStep step = AuthResetPasswordStep.CONFIRM_RESET_PASSWORD_WITH_CODE;
AuthCodeDeliveryDetails details = new AuthCodeDeliveryDetails(RandomString.string(), DeliveryMedium.PHONE);
AuthNextResetPasswordStep nextStep = new AuthNextResetPasswordStep(step, Collections.emptyMap(), details);
AuthResetPasswordResult expected = new AuthResetPasswordResult(true, nextStep);
doAnswer(invocation -> {
// 0 = username, 1 = onResult, 2 = onFailure
int positionOfResultConsumer = 1;
Consumer<AuthResetPasswordResult> onResult = invocation.getArgument(positionOfResultConsumer);
onResult.accept(expected);
return null;
}).when(delegate).resetPassword(eq(username), anyConsumer(), anyConsumer());
// Act: call the binding
TestObserver<AuthResetPasswordResult> observer = auth.resetPassword(username).test();
// Assert: result was furnished via Rx Single
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoErrors().assertValue(expected);
}
Aggregations