Search in sources :

Example 11 with MockApiClient

use of com.kickstarter.services.MockApiClient in project android-oss by kickstarter.

the class LoginViewModelTest method testLoginApiError.

@Test
public void testLoginApiError() {
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<AccessTokenEnvelope> login(@NonNull final String email, @NonNull final String password) {
            return Observable.error(ApiExceptionFactory.badRequestException());
        }
    };
    final Environment environment = environment().toBuilder().apiClient(apiClient).build();
    final LoginViewModel vm = new LoginViewModel(environment);
    final TestSubscriber<Void> loginSuccess = new TestSubscriber<>();
    vm.outputs.loginSuccess().subscribe(loginSuccess);
    final TestSubscriber<String> genericLoginError = new TestSubscriber<>();
    vm.errors.genericLoginError().subscribe(genericLoginError);
    vm.inputs.email("incorrect@kickstarter.com");
    vm.inputs.password("danisawesome");
    vm.inputs.loginClick();
    loginSuccess.assertNoValues();
    genericLoginError.assertValueCount(1);
}
Also used : AccessTokenEnvelope(com.kickstarter.services.apiresponses.AccessTokenEnvelope) MockApiClient(com.kickstarter.services.MockApiClient) NonNull(android.support.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Example 12 with MockApiClient

use of com.kickstarter.services.MockApiClient in project android-oss by kickstarter.

the class ProfileViewModelTest method testProfileViewModel_EmitsProjects.

@Test
public void testProfileViewModel_EmitsProjects() {
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<DiscoverEnvelope> fetchProjects(@NonNull final DiscoveryParams params) {
            return Observable.just(DiscoverEnvelopeFactory.discoverEnvelope(Collections.singletonList(ProjectFactory.project())));
        }
    };
    final Environment env = environment().toBuilder().apiClient(apiClient).build();
    final ProfileViewModel.ViewModel vm = new ProfileViewModel.ViewModel(env);
    final TestSubscriber<List<Project>> projects = new TestSubscriber<>();
    vm.outputs.projects().subscribe(projects);
    koalaTest.assertValues(KoalaEvent.PROFILE_VIEW_MY, KoalaEvent.VIEWED_PROFILE);
    projects.assertValueCount(1);
}
Also used : DiscoverEnvelope(com.kickstarter.services.apiresponses.DiscoverEnvelope) MockApiClient(com.kickstarter.services.MockApiClient) NonNull(android.support.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) List(java.util.List) DiscoveryParams(com.kickstarter.services.DiscoveryParams) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Example 13 with MockApiClient

use of com.kickstarter.services.MockApiClient in project android-oss by kickstarter.

the class ProfileViewModelTest method testProfileViewModel_EmitsBackedProjectsData.

@Test
public void testProfileViewModel_EmitsBackedProjectsData() {
    final User user = UserFactory.user().toBuilder().backedProjectsCount(5).createdProjectsCount(0).build();
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<User> fetchCurrentUser() {
            return Observable.just(user);
        }
    };
    final Environment env = environment().toBuilder().apiClient(apiClient).build();
    final ProfileViewModel.ViewModel vm = new ProfileViewModel.ViewModel(env);
    final TestSubscriber<Boolean> backedCountTextViewHidden = new TestSubscriber<>();
    vm.outputs.backedCountTextViewHidden().subscribe(backedCountTextViewHidden);
    final TestSubscriber<String> backedCountTextViewText = new TestSubscriber<>();
    vm.outputs.backedCountTextViewText().subscribe(backedCountTextViewText);
    final TestSubscriber<Boolean> backedTextViewHidden = new TestSubscriber<>();
    vm.outputs.backedTextViewHidden().subscribe(backedTextViewHidden);
    final TestSubscriber<Boolean> createdCountTextViewHidden = new TestSubscriber<>();
    vm.outputs.createdCountTextViewHidden().subscribe(createdCountTextViewHidden);
    final TestSubscriber<String> createdCountTextViewText = new TestSubscriber<>();
    vm.outputs.createdCountTextViewText().subscribe(createdCountTextViewText);
    final TestSubscriber<Boolean> createdTextViewHidden = new TestSubscriber<>();
    vm.outputs.createdTextViewHidden().subscribe(createdTextViewHidden);
    final TestSubscriber<Boolean> dividerViewHidden = new TestSubscriber<>();
    vm.outputs.dividerViewHidden().subscribe(dividerViewHidden);
    // Backed text views are displayed.
    backedCountTextViewHidden.assertValues(false);
    backedCountTextViewText.assertValues(NumberUtils.format(user.backedProjectsCount()));
    backedTextViewHidden.assertValues(false);
    // Created text views are hidden.
    createdCountTextViewHidden.assertValues(true);
    createdCountTextViewText.assertNoValues();
    createdTextViewHidden.assertValues(true);
    // Divider view is hidden.
    dividerViewHidden.assertValues(true);
}
Also used : User(com.kickstarter.models.User) MockApiClient(com.kickstarter.services.MockApiClient) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Example 14 with MockApiClient

use of com.kickstarter.services.MockApiClient in project android-oss by kickstarter.

the class DiscoveryIntentMapperTest method emitsFromDiscoveryCategoryUri.

@Test
public void emitsFromDiscoveryCategoryUri() {
    final Uri uri = Uri.parse("https://www.kickstarter.com/discover/categories/music");
    final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    final TestSubscriber<DiscoveryParams> resultTest = TestSubscriber.create();
    DiscoveryIntentMapper.params(intent, new MockApiClient()).subscribe(resultTest);
    resultTest.assertValueCount(1);
}
Also used : MockApiClient(com.kickstarter.services.MockApiClient) Intent(android.content.Intent) DiscoveryParams(com.kickstarter.services.DiscoveryParams) Uri(android.net.Uri) Test(org.junit.Test)

Example 15 with MockApiClient

use of com.kickstarter.services.MockApiClient in project android-oss by kickstarter.

the class DiscoveryIntentMapperTest method emitsFromDiscoveryLocationUri.

@Test
public void emitsFromDiscoveryLocationUri() {
    final Uri uri = Uri.parse("https://www.kickstarter.com/discover/places/sydney-au");
    final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    final TestSubscriber<DiscoveryParams> resultTest = TestSubscriber.create();
    DiscoveryIntentMapper.params(intent, new MockApiClient()).subscribe(resultTest);
    resultTest.assertValueCount(1);
}
Also used : MockApiClient(com.kickstarter.services.MockApiClient) Intent(android.content.Intent) DiscoveryParams(com.kickstarter.services.DiscoveryParams) Uri(android.net.Uri) Test(org.junit.Test)

Aggregations

MockApiClient (com.kickstarter.services.MockApiClient)31 Test (org.junit.Test)30 Environment (com.kickstarter.libs.Environment)21 TestSubscriber (rx.observers.TestSubscriber)21 ApiClientType (com.kickstarter.services.ApiClientType)20 Intent (android.content.Intent)16 NonNull (android.support.annotation.NonNull)14 Project (com.kickstarter.models.Project)7 DiscoveryParams (com.kickstarter.services.DiscoveryParams)7 AccessTokenEnvelope (com.kickstarter.services.apiresponses.AccessTokenEnvelope)7 Uri (android.net.Uri)6 User (com.kickstarter.models.User)6 CurrentUserType (com.kickstarter.libs.CurrentUserType)3 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)3 Update (com.kickstarter.models.Update)3 List (java.util.List)3 KSRobolectricTestCase (com.kickstarter.KSRobolectricTestCase)2 ProjectFactory (com.kickstarter.factories.ProjectFactory)2 IntentKey (com.kickstarter.ui.IntentKey)2 Request (okhttp3.Request)2