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);
}
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());
}
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()));
}
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());
}
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");
}
Aggregations