use of com.amplifyframework.auth.AuthCodeDeliveryDetails 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);
}
use of com.amplifyframework.auth.AuthCodeDeliveryDetails in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testUpdateUserAttributes.
/**
* Tests that a successful request to update user attributes will propagate a completion
* back through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testUpdateUserAttributes() throws InterruptedException {
// Arrange an invocation of the success Action
List<AuthUserAttribute> attributes = new ArrayList<>();
AuthUserAttributeKey attributeKey = AuthUserAttributeKey.custom(ATTRIBUTE_KEY);
AuthUserAttributeKey attributeKeyWithoutCode = AuthUserAttributeKey.custom(ATTRIBUTE_KEY_WITHOUT_CODE_DELIVERY);
attributes.add(new AuthUserAttribute(attributeKey, ATTRIBUTE_VAL));
attributes.add(new AuthUserAttribute(attributeKeyWithoutCode, ATTRIBUTE_VAL_WITHOUT_CODE_DELIVERY));
Map<AuthUserAttributeKey, AuthUpdateAttributeResult> attributeResultMap = new HashMap<>();
attributeResultMap.put(attributeKey, new AuthUpdateAttributeResult(true, new AuthNextUpdateAttributeStep(AuthUpdateAttributeStep.CONFIRM_ATTRIBUTE_WITH_CODE, Collections.emptyMap(), new AuthCodeDeliveryDetails(DESTINATION, DeliveryMedium.EMAIL, ATTRIBUTE_NAME))));
attributeResultMap.put(attributeKeyWithoutCode, new AuthUpdateAttributeResult(true, new AuthNextUpdateAttributeStep(AuthUpdateAttributeStep.DONE, Collections.emptyMap(), null)));
doAnswer(invocation -> {
Consumer<Map<AuthUserAttributeKey, AuthUpdateAttributeResult>> onCompletion = invocation.getArgument(1);
onCompletion.accept(attributeResultMap);
return null;
}).when(delegate).updateUserAttributes(any(), anyConsumer(), anyConsumer());
// Act: call the binding
TestObserver<Map<AuthUserAttributeKey, AuthUpdateAttributeResult>> observer = auth.updateUserAttributes(attributes).test();
// Assert: Completable completes with success
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoErrors().assertValue(attributeResultMap);
}
Aggregations