Search in sources :

Example 46 with Environment

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");
}
Also used : MockApiClient(com.kickstarter.services.MockApiClient) Intent(android.content.Intent) ApiClientType(com.kickstarter.services.ApiClientType) AccessTokenEnvelope(com.kickstarter.services.apiresponses.AccessTokenEnvelope) NonNull(android.support.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) Test(org.junit.Test)

Example 47 with Environment

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);
}
Also used : MockCurrentUser(com.kickstarter.libs.MockCurrentUser) ConfigFactory(com.kickstarter.factories.ConfigFactory) Project(com.kickstarter.models.Project) Intent(android.content.Intent) Test(org.junit.Test) CurrentUserType(com.kickstarter.libs.CurrentUserType) UserFactory(com.kickstarter.factories.UserFactory) KoalaEvent(com.kickstarter.libs.KoalaEvent) KSRobolectricTestCase(com.kickstarter.KSRobolectricTestCase) TestSubscriber(rx.observers.TestSubscriber) Environment(com.kickstarter.libs.Environment) ProjectFactory(com.kickstarter.factories.ProjectFactory) IntentKey(com.kickstarter.ui.IntentKey) Project(com.kickstarter.models.Project) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) Intent(android.content.Intent) Test(org.junit.Test)

Example 48 with Environment

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);
}
Also used : Project(com.kickstarter.models.Project) Config(com.kickstarter.libs.Config) CurrentConfigType(com.kickstarter.libs.CurrentConfigType) Environment(com.kickstarter.libs.Environment) Reward(com.kickstarter.models.Reward) Test(org.junit.Test)

Example 49 with Environment

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);
}
Also used : Project(com.kickstarter.models.Project) Config(com.kickstarter.libs.Config) CurrentConfigType(com.kickstarter.libs.CurrentConfigType) Environment(com.kickstarter.libs.Environment) Reward(com.kickstarter.models.Reward) Test(org.junit.Test)

Example 50 with Environment

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");
}
Also used : Project(com.kickstarter.models.Project) Config(com.kickstarter.libs.Config) Environment(com.kickstarter.libs.Environment) Reward(com.kickstarter.models.Reward) Test(org.junit.Test)

Aggregations

Environment (com.kickstarter.libs.Environment)50 Test (org.junit.Test)49 TestSubscriber (rx.observers.TestSubscriber)43 Intent (android.content.Intent)23 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)22 MockApiClient (com.kickstarter.services.MockApiClient)21 ApiClientType (com.kickstarter.services.ApiClientType)20 CurrentUserType (com.kickstarter.libs.CurrentUserType)19 Project (com.kickstarter.models.Project)19 User (com.kickstarter.models.User)16 NonNull (android.support.annotation.NonNull)14 KSRobolectricTestCase (com.kickstarter.KSRobolectricTestCase)9 MockBooleanPreference (com.kickstarter.libs.preferences.MockBooleanPreference)8 UserFactory (com.kickstarter.factories.UserFactory)7 AccessTokenEnvelope (com.kickstarter.services.apiresponses.AccessTokenEnvelope)7 ProjectFactory (com.kickstarter.factories.ProjectFactory)6 IntentKey (com.kickstarter.ui.IntentKey)6 List (java.util.List)6 KoalaEvent (com.kickstarter.libs.KoalaEvent)5 ConfigFactory (com.kickstarter.factories.ConfigFactory)4