use of com.kickstarter.libs.Environment 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();
final ThanksViewModel vm = new ThanksViewModel(environment);
final TestSubscriber<User> updateUserSettingsTest = new TestSubscriber<>();
((MockApiClient) environment.apiClient()).observable().filter(e -> "update_user_settings".equals(e.first)).map(e -> (User) e.second.get("user")).subscribe(updateUserSettingsTest);
final TestSubscriber<Void> showConfirmGamesNewsletterDialogTest = TestSubscriber.create();
vm.outputs.showConfirmGamesNewsletterDialog().subscribe(showConfirmGamesNewsletterDialogTest);
final Project project = ProjectFactory.project().toBuilder().category(CategoryFactory.tabletopGamesCategory()).build();
vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
vm.signupToGamesNewsletterClick();
updateUserSettingsTest.assertValues(user.toBuilder().gamesNewsletter(true).build());
showConfirmGamesNewsletterDialogTest.assertValueCount(0);
koalaTest.assertValues("Newsletter Subscribe");
}
use of com.kickstarter.libs.Environment in project android-oss by kickstarter.
the class ThanksViewModelTest method testThanksViewModel_showGamesNewsletterDialog.
@Test
public void testThanksViewModel_showGamesNewsletterDialog() {
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.tabletopGamesCategory()).build();
vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
showGamesNewsletterDialogTest.assertValueCount(1);
assertEquals(Arrays.asList(false, true), hasSeenGamesNewsletterPreference.values());
koalaTest.assertValueCount(0);
}
use of com.kickstarter.libs.Environment in project android-oss by kickstarter.
the class ThanksViewModelTest method testThanksViewModel_showNewsletterConfirmationPromptAfterSignupForGermanUser.
@Test
public void testThanksViewModel_showNewsletterConfirmationPromptAfterSignupForGermanUser() {
final User user = UserFactory.user().toBuilder().gamesNewsletter(false).location(LocationFactory.germany()).build();
final CurrentUserType currentUser = new MockCurrentUser(user);
final Environment environment = environment().toBuilder().currentUser(currentUser).build();
final ThanksViewModel vm = new ThanksViewModel(environment);
final TestSubscriber<Void> showConfirmGamesNewsletterDialogTest = TestSubscriber.create();
vm.outputs.showConfirmGamesNewsletterDialog().subscribe(showConfirmGamesNewsletterDialogTest);
final Project project = ProjectFactory.project().toBuilder().category(CategoryFactory.tabletopGamesCategory()).build();
vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
vm.signupToGamesNewsletterClick();
showConfirmGamesNewsletterDialogTest.assertValueCount(1);
koalaTest.assertValues("Newsletter Subscribe");
}
use of com.kickstarter.libs.Environment in project android-oss by kickstarter.
the class ThanksViewModelTest method testThanksViewModel_dontShowRatingDialogIfAlreadySeen.
@Test
public void testThanksViewModel_dontShowRatingDialogIfAlreadySeen() {
final MockBooleanPreference hasSeenAppRatingPreference = new MockBooleanPreference(true);
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(0);
}
use of com.kickstarter.libs.Environment 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, "");
final TwoFactorViewModel vm = new TwoFactorViewModel(environment);
vm.intent(intent);
final TestSubscriber<Void> tfaSuccess = new TestSubscriber<>();
vm.outputs.tfaSuccess().subscribe(tfaSuccess);
final TestSubscriber<Boolean> formSubmitting = new TestSubscriber<>();
vm.outputs.formSubmitting().subscribe(formSubmitting);
final TestSubscriber<Void> tfaCodeMismatchError = new TestSubscriber<>();
vm.errors.tfaCodeMismatchError().subscribe(tfaCodeMismatchError);
vm.inputs.code("88888");
vm.inputs.loginClick();
formSubmitting.assertValues(true, false);
tfaSuccess.assertNoValues();
tfaCodeMismatchError.assertValueCount(1);
koalaTest.assertValues("Two-factor Authentication Confirm View", "Errored User Login");
}
Aggregations