Search in sources :

Example 1 with AccessTokenEnvelope

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

the class TwoFactorViewModelTest method testTwoFactorViewModel_CodeMismatchError.

@Test
public void testTwoFactorViewModel_CodeMismatchError() {
    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.tfaFailed());
        }
    };
    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> tfaCodeMismatchError = new TestSubscriber<>();
    vm.errors.tfaCodeMismatchError().subscribe(tfaCodeMismatchError);
    vm.inputs.code("88888");
    vm.inputs.loginClick();
    formSubmitting.assertValues(true, false);
    tfaSuccess.assertNoValues();
    tfaCodeMismatchError.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)

Example 2 with AccessTokenEnvelope

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

the class SignupViewModelTest method testSignupViewModel_ApiValidationError.

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

        @Override
        @NonNull
        public Observable<AccessTokenEnvelope> signup(@NonNull final String name, @NonNull final String email, @NonNull final String password, @NonNull final String passwordConfirmation, final boolean sendNewsletters) {
            return Observable.error(ApiExceptionFactory.apiError(ErrorEnvelope.builder().httpCode(422).build()));
        }
    };
    final Environment environment = environment().toBuilder().apiClient(apiClient).build();
    final SignupViewModel vm = new SignupViewModel(environment);
    final TestSubscriber<Void> signupSuccessTest = new TestSubscriber<>();
    vm.outputs.signupSuccess().subscribe(signupSuccessTest);
    final TestSubscriber<String> signupErrorTest = new TestSubscriber<>();
    vm.errors.signupError().subscribe(signupErrorTest);
    final TestSubscriber<Boolean> formSubmittingTest = new TestSubscriber<>();
    vm.outputs.formSubmitting().subscribe(formSubmittingTest);
    vm.inputs.fullName("brandon");
    vm.inputs.email("hello@kickstarter.com");
    vm.inputs.email("incorrect@kickstarter");
    vm.inputs.password("danisawesome");
    vm.inputs.sendNewslettersClick(true);
    vm.inputs.signupClick();
    formSubmittingTest.assertValues(true, false);
    signupSuccessTest.assertValueCount(0);
    signupErrorTest.assertValueCount(1);
    koalaTest.assertValues("User Signup", "Signup Newsletter Toggle", "Errored User Signup");
}
Also used : MockApiClient(com.kickstarter.services.MockApiClient) 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)

Example 3 with AccessTokenEnvelope

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

the class LoginViewModelTest method testLoginApiValidationError.

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

        @Override
        @NonNull
        public Observable<AccessTokenEnvelope> login(@NonNull final String email, @NonNull final String password) {
            return Observable.error(ApiExceptionFactory.invalidLoginException());
        }
    };
    final Environment environment = environment().toBuilder().apiClient(apiClient).build();
    final LoginViewModel vm = new LoginViewModel(environment);
    final TestSubscriber<String> invalidLoginError = new TestSubscriber<>();
    vm.errors.invalidLoginError().subscribe(invalidLoginError);
    final TestSubscriber<Void> loginSuccess = new TestSubscriber<>();
    vm.outputs.loginSuccess().subscribe(loginSuccess);
    vm.inputs.email("typo@kickstartr.com");
    vm.inputs.password("danisawesome");
    vm.inputs.loginClick();
    loginSuccess.assertNoValues();
    invalidLoginError.assertValueCount(1);
}
Also used : AccessTokenEnvelope(com.kickstarter.services.apiresponses.AccessTokenEnvelope) MockApiClient(com.kickstarter.services.MockApiClient) NonNull(android.support.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Example 4 with AccessTokenEnvelope

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

the class LoginViewModelTest method testLoginApiError.

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

        @Override
        @NonNull
        public Observable<AccessTokenEnvelope> login(@NonNull final String email, @NonNull final String password) {
            return Observable.error(ApiExceptionFactory.badRequestException());
        }
    };
    final Environment environment = environment().toBuilder().apiClient(apiClient).build();
    final LoginViewModel vm = new LoginViewModel(environment);
    final TestSubscriber<Void> loginSuccess = new TestSubscriber<>();
    vm.outputs.loginSuccess().subscribe(loginSuccess);
    final TestSubscriber<String> genericLoginError = new TestSubscriber<>();
    vm.errors.genericLoginError().subscribe(genericLoginError);
    vm.inputs.email("incorrect@kickstarter.com");
    vm.inputs.password("danisawesome");
    vm.inputs.loginClick();
    loginSuccess.assertNoValues();
    genericLoginError.assertValueCount(1);
}
Also used : AccessTokenEnvelope(com.kickstarter.services.apiresponses.AccessTokenEnvelope) MockApiClient(com.kickstarter.services.MockApiClient) NonNull(android.support.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Example 5 with AccessTokenEnvelope

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

the class LoginViewModelTest method testLoginTfaChallenge.

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

        @Override
        @NonNull
        public Observable<AccessTokenEnvelope> login(@NonNull final String email, @NonNull final String password) {
            return Observable.error(ApiExceptionFactory.tfaRequired());
        }
    };
    final Environment environment = environment().toBuilder().apiClient(apiClient).build();
    final LoginViewModel vm = new LoginViewModel(environment);
    final TestSubscriber<Void> tfaChallenge = new TestSubscriber<>();
    vm.errors.tfaChallenge().subscribe(tfaChallenge);
    final TestSubscriber<Void> loginSuccess = new TestSubscriber<>();
    vm.outputs.loginSuccess().subscribe(loginSuccess);
    vm.inputs.email("hello@kickstarter.com");
    vm.inputs.password("danisawesome");
    vm.inputs.loginClick();
    loginSuccess.assertNoValues();
    tfaChallenge.assertValueCount(1);
}
Also used : AccessTokenEnvelope(com.kickstarter.services.apiresponses.AccessTokenEnvelope) MockApiClient(com.kickstarter.services.MockApiClient) NonNull(android.support.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Aggregations

NonNull (android.support.annotation.NonNull)7 Environment (com.kickstarter.libs.Environment)7 ApiClientType (com.kickstarter.services.ApiClientType)7 MockApiClient (com.kickstarter.services.MockApiClient)7 AccessTokenEnvelope (com.kickstarter.services.apiresponses.AccessTokenEnvelope)7 Test (org.junit.Test)7 TestSubscriber (rx.observers.TestSubscriber)7 Intent (android.content.Intent)2