use of com.kickstarter.libs.Environment in project android-oss by kickstarter.
the class TwoFactorViewModelTest method testTwoFactorViewModel_GenericError.
@Test
public void testTwoFactorViewModel_GenericError() {
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.apiError(ErrorEnvelope.builder().httpCode(400).build()));
}
};
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> genericTfaError = new TestSubscriber<>();
vm.errors.genericTfaError().subscribe(genericTfaError);
vm.inputs.code("88888");
vm.inputs.loginClick();
formSubmitting.assertValues(true, false);
tfaSuccess.assertNoValues();
genericTfaError.assertValueCount(1);
koalaTest.assertValues("Two-factor Authentication Confirm View", "Errored User Login");
}
use of com.kickstarter.libs.Environment in project android-oss by kickstarter.
the class ProjectViewModelTest method testProjectViewModel_EmitsProjectWithStandardSetUp.
@Test
public void testProjectViewModel_EmitsProjectWithStandardSetUp() {
final Environment environment = environment();
environment.currentConfig().config(ConfigFactory.config());
final ProjectViewModel.ViewModel vm = new ProjectViewModel.ViewModel(environment);
final TestSubscriber<Project> projectTest = new TestSubscriber<>();
vm.outputs.projectAndUserCountry().map(pc -> pc.first).subscribe(projectTest);
final Project project = ProjectFactory.project();
vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
projectTest.assertValues(project, project);
koalaTest.assertValues(KoalaEvent.PROJECT_PAGE, KoalaEvent.VIEWED_PROJECT_PAGE);
}
use of com.kickstarter.libs.Environment in project android-oss by kickstarter.
the class RewardViewModelTest method testUsdConversionNotShownForUSProject.
@Test
public void testUsdConversionNotShownForUSProject() {
// Set user's country to US.
final Config config = ConfigFactory.configForUSUser();
final Environment environment = environment();
final CurrentConfigType currentConfig = environment.currentConfig();
environment.currentConfig().config(config);
final RewardViewModel vm = new RewardViewModel(environment);
// Set project's country to US.
final Project project = ProjectFactory.project().toBuilder().country("US").build();
final Reward reward = RewardFactory.reward();
final TestSubscriber<String> usdConversionTextViewText = TestSubscriber.create();
vm.outputs.usdConversionTextViewText().subscribe(usdConversionTextViewText);
final TestSubscriber<Boolean> usdConversionSectionIsHidden = TestSubscriber.create();
vm.outputs.usdConversionTextViewIsHidden().subscribe(usdConversionSectionIsHidden);
// USD conversion should not be shown.
vm.inputs.projectAndReward(project, reward);
usdConversionTextViewText.assertNoValues();
usdConversionSectionIsHidden.assertValue(true);
// Set user's country to CA.
currentConfig.config(ConfigFactory.configForCAUser());
// USD conversion should still not be shown (distinct until changed).
usdConversionTextViewText.assertNoValues();
usdConversionSectionIsHidden.assertValues(true);
}
use of com.kickstarter.libs.Environment in project android-oss by kickstarter.
the class RewardViewModelTest method testUsdConversionForNonUSProject.
@Test
public void testUsdConversionForNonUSProject() {
// Set user's country to US.
final Config config = ConfigFactory.configForUSUser();
final Environment environment = environment();
final CurrentConfigType currentConfig = environment.currentConfig();
environment.currentConfig().config(config);
final RewardViewModel vm = new RewardViewModel(environment);
// Set project's country to CA.
final Project project = ProjectFactory.caProject();
final Reward reward = RewardFactory.reward();
final TestSubscriber<String> usdConversionTextViewText = TestSubscriber.create();
vm.outputs.usdConversionTextViewText().subscribe(usdConversionTextViewText);
final TestSubscriber<Boolean> usdConversionSectionIsHidden = TestSubscriber.create();
vm.outputs.usdConversionTextViewIsHidden().subscribe(usdConversionSectionIsHidden);
// USD conversion should be shown.
vm.inputs.projectAndReward(project, reward);
usdConversionTextViewText.assertValueCount(1);
usdConversionSectionIsHidden.assertValue(false);
// Set user's country to CA (any country except the US is fine).
currentConfig.config(ConfigFactory.configForCAUser());
// USD conversion should now be hidden.
usdConversionTextViewText.assertValueCount(1);
usdConversionSectionIsHidden.assertValues(false, true);
}
use of com.kickstarter.libs.Environment in project android-oss by kickstarter.
the class RewardViewModelTest method testUsdConversionTextRoundsUp.
@Test
public void testUsdConversionTextRoundsUp() {
// Set user's country to US.
final Config config = ConfigFactory.configForUSUser();
final Environment environment = environment();
environment.currentConfig().config(config);
final RewardViewModel vm = new RewardViewModel(environment);
// Set project's country to CA and reward minimum to $0.30.
final Project project = ProjectFactory.caProject();
final Reward reward = RewardFactory.reward().toBuilder().minimum(0.3f).build();
final TestSubscriber<String> usdConversionTextViewText = TestSubscriber.create();
vm.outputs.usdConversionTextViewText().subscribe(usdConversionTextViewText);
// USD conversion should be rounded up.
vm.inputs.projectAndReward(project, reward);
usdConversionTextViewText.assertValue("$1");
}
Aggregations