Search in sources :

Example 31 with MockApiClient

use of com.kickstarter.services.MockApiClient in project android-oss by kickstarter.

the class TwoFactorViewModelTest method testTwoFactorViewModel_GenericError.

@Test
public void testTwoFactorViewModel_GenericError() {
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<AccessTokenEnvelope> login(@NonNull final String email, @NonNull final String password, @NonNull final String code) {
            return Observable.error(ApiExceptionFactory.apiError(ErrorEnvelope.builder().httpCode(400).build()));
        }
    };
    final Environment environment = environment().toBuilder().apiClient(apiClient).build();
    final Intent intent = new Intent();
    intent.putExtra(IntentKey.EMAIL, "gina@kickstarter.com");
    intent.putExtra(IntentKey.PASSWORD, "hello");
    intent.putExtra(IntentKey.FACEBOOK_LOGIN, false);
    intent.putExtra(IntentKey.FACEBOOK_TOKEN, "");
    final TwoFactorViewModel vm = new TwoFactorViewModel(environment);
    vm.intent(intent);
    final TestSubscriber<Void> tfaSuccess = new TestSubscriber<>();
    vm.outputs.tfaSuccess().subscribe(tfaSuccess);
    final TestSubscriber<Boolean> formSubmitting = new TestSubscriber<>();
    vm.outputs.formSubmitting().subscribe(formSubmitting);
    final TestSubscriber<Void> genericTfaError = new TestSubscriber<>();
    vm.errors.genericTfaError().subscribe(genericTfaError);
    vm.inputs.code("88888");
    vm.inputs.loginClick();
    formSubmitting.assertValues(true, false);
    tfaSuccess.assertNoValues();
    genericTfaError.assertValueCount(1);
    koalaTest.assertValues("Two-factor Authentication Confirm View", "Errored User Login");
}
Also used : MockApiClient(com.kickstarter.services.MockApiClient) Intent(android.content.Intent) ApiClientType(com.kickstarter.services.ApiClientType) AccessTokenEnvelope(com.kickstarter.services.apiresponses.AccessTokenEnvelope) NonNull(android.support.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) Test(org.junit.Test)

Aggregations

MockApiClient (com.kickstarter.services.MockApiClient)31 Test (org.junit.Test)30 Environment (com.kickstarter.libs.Environment)21 TestSubscriber (rx.observers.TestSubscriber)21 ApiClientType (com.kickstarter.services.ApiClientType)20 Intent (android.content.Intent)16 NonNull (android.support.annotation.NonNull)14 Project (com.kickstarter.models.Project)7 DiscoveryParams (com.kickstarter.services.DiscoveryParams)7 AccessTokenEnvelope (com.kickstarter.services.apiresponses.AccessTokenEnvelope)7 Uri (android.net.Uri)6 User (com.kickstarter.models.User)6 CurrentUserType (com.kickstarter.libs.CurrentUserType)3 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)3 Update (com.kickstarter.models.Update)3 List (java.util.List)3 KSRobolectricTestCase (com.kickstarter.KSRobolectricTestCase)2 ProjectFactory (com.kickstarter.factories.ProjectFactory)2 IntentKey (com.kickstarter.ui.IntentKey)2 Request (okhttp3.Request)2