use of com.kickstarter.mock.services.MockApiClient in project android-oss by kickstarter.
the class SearchViewModelTest method testFeaturedPopularRefTags.
@Test
public void testFeaturedPopularRefTags() {
final TestScheduler scheduler = new TestScheduler();
final List<Project> projects = Arrays.asList(ProjectFactory.allTheWayProject(), ProjectFactory.almostCompletedProject(), ProjectFactory.backedProject());
final MockApiClient apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<DiscoverEnvelope> fetchProjects(@NonNull final DiscoveryParams params) {
return Observable.just(DiscoverEnvelopeFactory.discoverEnvelope(projects));
}
};
final Environment env = environment().toBuilder().scheduler(scheduler).apiClient(apiClient).build();
setUpEnvironment(env);
// populate search and overcome debounce
this.vm.inputs.search("");
scheduler.advanceTimeBy(300, TimeUnit.MILLISECONDS);
this.vm.inputs.projectClicked(projects.get(0));
this.goToRefTag.assertValues(RefTag.searchPopularFeatured());
this.goToProject.assertValues(projects.get(0));
}
use of com.kickstarter.mock.services.MockApiClient in project android-oss by kickstarter.
the class SearchViewModelTest method testProjectPage_whenFeatureFlagOn_shouldEmitProjectPage.
@Test
public void testProjectPage_whenFeatureFlagOn_shouldEmitProjectPage() {
final MockCurrentUser user = new MockCurrentUser();
final MockExperimentsClientType mockExperimentsClientType = new MockExperimentsClientType() {
@Override
public boolean isFeatureEnabled(@NotNull final OptimizelyFeature.Key feature) {
return true;
}
};
final TestScheduler scheduler = new TestScheduler();
final List<Project> projects = Arrays.asList(ProjectFactory.allTheWayProject(), ProjectFactory.almostCompletedProject(), ProjectFactory.backedProject());
final MockApiClient apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<DiscoverEnvelope> fetchProjects(@NonNull final DiscoveryParams params) {
return Observable.just(DiscoverEnvelopeFactory.discoverEnvelope(projects));
}
};
final Environment env = environment().toBuilder().currentUser(user).optimizely(mockExperimentsClientType).scheduler(scheduler).apiClient(apiClient).build();
setUpEnvironment(env);
// populate search and overcome debounce
this.vm.inputs.search("");
scheduler.advanceTimeBy(300, TimeUnit.MILLISECONDS);
this.vm.inputs.projectClicked(projects.get(2));
this.goToProject.assertValues(projects.get(2));
}
use of com.kickstarter.mock.services.MockApiClient 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.mock.services.MockApiClient in project android-oss by kickstarter.
the class ThanksViewModelTest method testThanksViewModel_signupToGamesNewsletterOnClick.
@Test
public void testThanksViewModel_signupToGamesNewsletterOnClick() {
final User user = UserFactory.user().toBuilder().gamesNewsletter(false).build();
final CurrentUserType currentUser = new MockCurrentUser(user);
final Environment environment = environment().toBuilder().currentUser(currentUser).build();
setUpEnvironment(environment);
final TestSubscriber<User> updateUserSettingsTest = new TestSubscriber<>();
((MockApiClient) environment.apiClient()).observable().filter(e -> "update_user_settings".equals(e.getFirst())).map(e -> (User) e.getSecond().get("user")).subscribe(updateUserSettingsTest);
final Project project = ProjectFactory.project().toBuilder().category(CategoryFactory.tabletopGamesCategory()).build();
this.vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
this.vm.signupToGamesNewsletterClick();
updateUserSettingsTest.assertValues(user.toBuilder().gamesNewsletter(true).build());
this.showConfirmGamesNewsletterDialogTest.assertValueCount(0);
}
use of com.kickstarter.mock.services.MockApiClient 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()));
}
Aggregations