use of com.kickstarter.libs.Environment in project android-oss by kickstarter.
the class SignupViewModelTest method testSignupViewModel_ApiError.
@Test
public void testSignupViewModel_ApiError() {
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.badRequestException());
}
};
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_dontShowGamesNewsletterDialogIfUserHasAlreadySignedUp.
@Test
public void testThanksViewModel_dontShowGamesNewsletterDialogIfUserHasAlreadySignedUp() {
final MockBooleanPreference hasSeenGamesNewsletterPreference = new MockBooleanPreference(false);
final User user = UserFactory.user().toBuilder().gamesNewsletter(true).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 ThanksViewModelTest method testThanksViewModel_dontShowGamesNewsletterDialogIfRootCategoryIsNotGames.
@Test
public void testThanksViewModel_dontShowGamesNewsletterDialogIfRootCategoryIsNotGames() {
final MockBooleanPreference hasSeenGamesNewsletterPreference = new MockBooleanPreference(false);
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.ceramicsCategory()).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 ThanksViewModelTest method testThanksViewModel_dontShowRatingDialogIfGamesNewsletterWillDisplay.
@Test
public void testThanksViewModel_dontShowRatingDialogIfGamesNewsletterWillDisplay() {
final MockBooleanPreference hasSeenAppRatingPreference = new MockBooleanPreference(false);
final MockBooleanPreference hasSeenGamesNewsletterPreference = new MockBooleanPreference(false);
final User user = UserFactory.user().toBuilder().gamesNewsletter(false).build();
final CurrentUserType currentUser = new MockCurrentUser(user);
final Environment environment = environment().toBuilder().currentUser(currentUser).hasSeenAppRatingPreference(hasSeenAppRatingPreference).hasSeenGamesNewsletterPreference(hasSeenGamesNewsletterPreference).build();
final ThanksViewModel vm = new ThanksViewModel(environment);
final TestSubscriber<Void> showRatingDialogTest = new TestSubscriber<>();
vm.outputs.showRatingDialog().subscribe(showRatingDialogTest);
final Project project = ProjectFactory.project().toBuilder().category(CategoryFactory.tabletopGamesCategory()).build();
vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
showRatingDialogTest.assertValueCount(0);
}
use of com.kickstarter.libs.Environment in project android-oss by kickstarter.
the class ThanksViewModelTest method testThanksViewModel_showRatingDialog.
@Test
public void testThanksViewModel_showRatingDialog() {
final MockBooleanPreference hasSeenAppRatingPreference = new MockBooleanPreference(false);
final MockBooleanPreference hasSeenGamesNewsletterPreference = new MockBooleanPreference(true);
final Environment environment = environment().toBuilder().hasSeenAppRatingPreference(hasSeenAppRatingPreference).hasSeenGamesNewsletterPreference(hasSeenGamesNewsletterPreference).build();
final ThanksViewModel vm = new ThanksViewModel(environment);
final TestSubscriber<Void> showRatingDialogTest = new TestSubscriber<>();
vm.outputs.showRatingDialog().subscribe(showRatingDialogTest);
final Project project = ProjectFactory.project();
vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
showRatingDialogTest.assertValueCount(1);
}
Aggregations