Search in sources :

Example 6 with ApiClientType

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

the class ProfileViewModelTest method testProfileViewModel_EmitsBackedProjectsData.

@Test
public void testProfileViewModel_EmitsBackedProjectsData() {
    final User user = UserFactory.user().toBuilder().backedProjectsCount(5).createdProjectsCount(0).build();
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<User> fetchCurrentUser() {
            return Observable.just(user);
        }
    };
    final Environment env = environment().toBuilder().apiClient(apiClient).build();
    final ProfileViewModel.ViewModel vm = new ProfileViewModel.ViewModel(env);
    final TestSubscriber<Boolean> backedCountTextViewHidden = new TestSubscriber<>();
    vm.outputs.backedCountTextViewHidden().subscribe(backedCountTextViewHidden);
    final TestSubscriber<String> backedCountTextViewText = new TestSubscriber<>();
    vm.outputs.backedCountTextViewText().subscribe(backedCountTextViewText);
    final TestSubscriber<Boolean> backedTextViewHidden = new TestSubscriber<>();
    vm.outputs.backedTextViewHidden().subscribe(backedTextViewHidden);
    final TestSubscriber<Boolean> createdCountTextViewHidden = new TestSubscriber<>();
    vm.outputs.createdCountTextViewHidden().subscribe(createdCountTextViewHidden);
    final TestSubscriber<String> createdCountTextViewText = new TestSubscriber<>();
    vm.outputs.createdCountTextViewText().subscribe(createdCountTextViewText);
    final TestSubscriber<Boolean> createdTextViewHidden = new TestSubscriber<>();
    vm.outputs.createdTextViewHidden().subscribe(createdTextViewHidden);
    final TestSubscriber<Boolean> dividerViewHidden = new TestSubscriber<>();
    vm.outputs.dividerViewHidden().subscribe(dividerViewHidden);
    // Backed text views are displayed.
    backedCountTextViewHidden.assertValues(false);
    backedCountTextViewText.assertValues(NumberUtils.format(user.backedProjectsCount()));
    backedTextViewHidden.assertValues(false);
    // Created text views are hidden.
    createdCountTextViewHidden.assertValues(true);
    createdCountTextViewText.assertNoValues();
    createdTextViewHidden.assertValues(true);
    // Divider view is hidden.
    dividerViewHidden.assertValues(true);
}
Also used : User(com.kickstarter.models.User) MockApiClient(com.kickstarter.services.MockApiClient) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Example 7 with ApiClientType

use of com.kickstarter.services.ApiClientType 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.ViewModel vm = new SignupViewModel.ViewModel(environment);
    final TestSubscriber<Void> signupSuccessTest = new TestSubscriber<>();
    vm.outputs.signupSuccess().subscribe(signupSuccessTest);
    final TestSubscriber<String> signupErrorTest = new TestSubscriber<>();
    vm.outputs.errorString().subscribe(signupErrorTest);
    final TestSubscriber<Boolean> formSubmittingTest = new TestSubscriber<>();
    vm.outputs.formSubmitting().subscribe(formSubmittingTest);
    vm.inputs.name("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);
    this.segmentTrack.assertValues(EventName.PAGE_VIEWED.getEventName(), EventName.CTA_CLICKED.getEventName());
}
Also used : MockApiClient(com.kickstarter.mock.services.MockApiClient) ApiClientType(com.kickstarter.services.ApiClientType) AccessTokenEnvelope(com.kickstarter.services.apiresponses.AccessTokenEnvelope) NonNull(androidx.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) Test(org.junit.Test)

Example 8 with ApiClientType

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

the class UpdateViewModelTest method testUpdateViewModel_UpdateSequence.

@Test
public void testUpdateViewModel_UpdateSequence() {
    final Update initialUpdate = UpdateFactory.update().toBuilder().sequence(1).build();
    final Update anotherUpdate = UpdateFactory.update().toBuilder().sequence(2).build();
    final Request anotherUpdateRequest = new Request.Builder().url("https://kck.str/projects/param/param/posts/id").build();
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<Update> fetchUpdate(@NonNull final String projectParam, @NonNull final String updateParam) {
            return Observable.just(anotherUpdate);
        }
    };
    final Environment environment = environment().toBuilder().apiClient(apiClient).build();
    final UpdateViewModel.ViewModel vm = new UpdateViewModel.ViewModel(environment);
    final TestSubscriber<String> updateSequence = new TestSubscriber<>();
    vm.outputs.updateSequence().subscribe(updateSequence);
    // Start the intent with a project and update.
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, ProjectFactory.project()).putExtra(IntentKey.UPDATE, initialUpdate));
    // Initial update's sequence number emits.
    updateSequence.assertValues(NumberUtils.format(initialUpdate.sequence()));
    vm.inputs.goToUpdateRequest(anotherUpdateRequest);
    // New sequence should emit for new update page.
    updateSequence.assertValues(NumberUtils.format(initialUpdate.sequence()), NumberUtils.format(anotherUpdate.sequence()));
}
Also used : MockApiClient(com.kickstarter.mock.services.MockApiClient) Request(okhttp3.Request) Intent(android.content.Intent) Update(com.kickstarter.models.Update) ApiClientType(com.kickstarter.services.ApiClientType) NonNull(androidx.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) Test(org.junit.Test)

Example 9 with ApiClientType

use of com.kickstarter.services.ApiClientType 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, "");
    this.vm = new TwoFactorViewModel.ViewModel(environment);
    this.vm.intent(intent);
    this.vm.outputs.tfaSuccess().subscribe(this.tfaSuccess);
    this.vm.outputs.formSubmitting().subscribe(this.formSubmitting);
    this.vm.outputs.tfaCodeMismatchError().subscribe(this.tfaCodeMismatchError);
    this.vm.inputs.code("88888");
    this.vm.inputs.loginClick();
    this.formSubmitting.assertValues(true, false);
    this.tfaSuccess.assertNoValues();
    this.tfaCodeMismatchError.assertValueCount(1);
    this.segmentTrack.assertValue(EventName.PAGE_VIEWED.getEventName());
}
Also used : AccessTokenEnvelope(com.kickstarter.services.apiresponses.AccessTokenEnvelope) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Environment(com.kickstarter.libs.Environment) Intent(android.content.Intent) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Example 10 with ApiClientType

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

the class FacebookConfimationViewModelTest method testSignupErrorDisplay.

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

        @Override
        @NonNull
        public Observable<AccessTokenEnvelope> registerWithFacebook(@NonNull final String fbAccessToken, final boolean sendNewsletters) {
            return Observable.error(ApiExceptionFactory.apiError(ErrorEnvelope.builder().httpCode(404).errorMessages(Collections.singletonList("oh no")).build()));
        }
    };
    final Environment environment = environment().toBuilder().apiClient(apiClient).build();
    this.vm = new FacebookConfirmationViewModel.ViewModel(environment);
    this.vm.intent(new Intent().putExtra(IntentKey.FACEBOOK_TOKEN, "token"));
    this.vm.outputs.signupError().subscribe(this.signupError);
    this.vm.inputs.sendNewslettersClick(true);
    this.vm.inputs.createNewAccountClick();
    this.signupError.assertValue("oh no");
}
Also used : AccessTokenEnvelope(com.kickstarter.services.apiresponses.AccessTokenEnvelope) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Environment(com.kickstarter.libs.Environment) Intent(android.content.Intent) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Aggregations

ApiClientType (com.kickstarter.services.ApiClientType)31 Test (org.junit.Test)31 Environment (com.kickstarter.libs.Environment)25 MockApiClient (com.kickstarter.mock.services.MockApiClient)19 TestSubscriber (rx.observers.TestSubscriber)18 Intent (android.content.Intent)16 NonNull (androidx.annotation.NonNull)12 MockApiClient (com.kickstarter.services.MockApiClient)12 User (com.kickstarter.models.User)9 NonNull (android.support.annotation.NonNull)8 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)8 AccessTokenEnvelope (com.kickstarter.services.apiresponses.AccessTokenEnvelope)8 Update (com.kickstarter.models.Update)5 CurrentUserType (com.kickstarter.libs.CurrentUserType)4 Project (com.kickstarter.models.Project)3 Nullable (androidx.annotation.Nullable)2 ProjectNotification (com.kickstarter.models.ProjectNotification)2 MessageThreadsEnvelope (com.kickstarter.services.apiresponses.MessageThreadsEnvelope)2 Mailbox (com.kickstarter.ui.data.Mailbox)2 TestScheduler (rx.schedulers.TestScheduler)2