use of com.kickstarter.libs.Environment 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");
}
use of com.kickstarter.libs.Environment in project android-oss by kickstarter.
the class ThanksViewModelTest method testThanksViewModel_dontShowGamesNewsletterDialogIfUserHasAlreadySeen.
@Test
public void testThanksViewModel_dontShowGamesNewsletterDialogIfUserHasAlreadySeen() {
final MockBooleanPreference hasSeenGamesNewsletterPreference = new MockBooleanPreference(true);
final User user = UserFactory.user().toBuilder().gamesNewsletter(false).build();
final CurrentUserType currentUser = new MockCurrentUser(user);
final Environment environment = environment().toBuilder().currentUser(currentUser).hasSeenGamesNewsletterPreference(hasSeenGamesNewsletterPreference).build();
final ThanksViewModel vm = new ThanksViewModel(environment);
final TestSubscriber<Void> showGamesNewsletterDialogTest = new TestSubscriber<>();
vm.outputs.showGamesNewsletterDialog().subscribe(showGamesNewsletterDialogTest);
final Project project = ProjectFactory.project().toBuilder().category(CategoryFactory.tabletopGamesCategory()).build();
vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
showGamesNewsletterDialogTest.assertValueCount(0);
}
use of com.kickstarter.libs.Environment in project android-oss by kickstarter.
the class ProjectViewModelTest method testProjectViewModel_LoggedOutStarProjectFlow.
@Test
public void testProjectViewModel_LoggedOutStarProjectFlow() {
final CurrentUserType currentUser = new MockCurrentUser();
final Environment environment = environment().toBuilder().currentUser(currentUser).build();
environment.currentConfig().config(ConfigFactory.config());
final ProjectViewModel.ViewModel vm = new ProjectViewModel.ViewModel(environment);
final TestSubscriber<Void> loginToutTest = new TestSubscriber<>();
vm.outputs.startLoginToutActivity().subscribe(loginToutTest);
final TestSubscriber<Void> showStarredPromptTest = new TestSubscriber<>();
vm.outputs.showStarredPrompt().subscribe(showStarredPromptTest);
final TestSubscriber<Boolean> starredTest = new TestSubscriber<>();
vm.outputs.projectAndUserCountry().map(pc -> pc.first.isStarred()).subscribe(starredTest);
// Start the view model with a project
vm.intent(new Intent().putExtra(IntentKey.PROJECT, ProjectFactory.halfWayProject()));
starredTest.assertValues(false, false);
// Try starring while logged out
vm.inputs.starButtonClicked();
// The project shouldn't be starred, and a login prompt should be shown.
starredTest.assertValues(false, false);
showStarredPromptTest.assertValueCount(0);
loginToutTest.assertValueCount(1);
// A koala event for starring should NOT be tracked
koalaTest.assertValues(KoalaEvent.PROJECT_PAGE, KoalaEvent.VIEWED_PROJECT_PAGE);
// Login
currentUser.refresh(UserFactory.user());
// The project should be starred, and a star prompt should be shown.
starredTest.assertValues(false, false, true);
showStarredPromptTest.assertValueCount(1);
// A koala event for starring should be tracked
koalaTest.assertValues(KoalaEvent.PROJECT_PAGE, KoalaEvent.VIEWED_PROJECT_PAGE, KoalaEvent.PROJECT_STAR, KoalaEvent.STARRED_PROJECT);
}
use of com.kickstarter.libs.Environment in project android-oss by kickstarter.
the class ProjectViewModelTest method testProjectViewModel_StarProjectThatIsSuccessful.
@Test
public void testProjectViewModel_StarProjectThatIsSuccessful() {
final CurrentUserType currentUser = new MockCurrentUser();
final Environment environment = environment().toBuilder().currentUser(currentUser).build();
environment.currentConfig().config(ConfigFactory.config());
final ProjectViewModel.ViewModel vm = new ProjectViewModel.ViewModel(environment);
final TestSubscriber<Void> showStarredPromptTest = new TestSubscriber<>();
vm.outputs.showStarredPrompt().subscribe(showStarredPromptTest);
final TestSubscriber<Boolean> starredTest = new TestSubscriber<>();
vm.outputs.projectAndUserCountry().map(pc -> pc.first.isStarred()).subscribe(starredTest);
// Start the view model with a successful project
vm.intent(new Intent().putExtra(IntentKey.PROJECT, ProjectFactory.successfulProject()));
// Login
currentUser.refresh(UserFactory.user());
// Star the project
vm.inputs.starButtonClicked();
// The project should be starred, and a star prompt should NOT be shown.
starredTest.assertValues(false, false, true);
showStarredPromptTest.assertValueCount(0);
}
use of com.kickstarter.libs.Environment in project android-oss by kickstarter.
the class ProjectViewModelTest method testProjectViewModel_StarProjectThatIsAlmostCompleted.
@Test
public void testProjectViewModel_StarProjectThatIsAlmostCompleted() {
final Project project = ProjectFactory.almostCompletedProject();
final CurrentUserType currentUser = new MockCurrentUser();
final Environment environment = environment().toBuilder().currentUser(currentUser).build();
environment.currentConfig().config(ConfigFactory.config());
final ProjectViewModel.ViewModel vm = new ProjectViewModel.ViewModel(environment);
final TestSubscriber<Void> showStarredPromptTest = new TestSubscriber<>();
vm.outputs.showStarredPrompt().subscribe(showStarredPromptTest);
final TestSubscriber<Boolean> starredTest = new TestSubscriber<>();
vm.outputs.projectAndUserCountry().map(pc -> pc.first.isStarred()).subscribe(starredTest);
// Start the view model with an almost completed project
vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
// Login
currentUser.refresh(UserFactory.user());
// Star the project
vm.inputs.starButtonClicked();
// The project should be starred, and a star prompt should NOT be shown.
starredTest.assertValues(false, false, true);
showStarredPromptTest.assertValueCount(0);
}
Aggregations