Search in sources :

Example 51 with MockApiClient

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

the class CreatorDashboardViewModelTest method testProjectsForBottomSheet_With1Project.

@Test
public void testProjectsForBottomSheet_With1Project() {
    final List<Project> projects = Collections.singletonList(ProjectFactory.project());
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<ProjectsEnvelope> fetchProjects(final boolean member) {
            return Observable.just(ProjectsEnvelopeFactory.projectsEnvelope(projects));
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).build());
    this.projectsForBottomSheet.assertNoValues();
}
Also used : Project(com.kickstarter.models.Project) ProjectsEnvelope(com.kickstarter.services.apiresponses.ProjectsEnvelope) MockApiClient(com.kickstarter.mock.services.MockApiClient) Test(org.junit.Test)

Example 52 with MockApiClient

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

the class CreatorDashboardViewModelTest method testProjectsForBottomSheet_WithManyProjects.

@Test
public void testProjectsForBottomSheet_WithManyProjects() {
    final Project project1 = ProjectFactory.project();
    final Project project2 = ProjectFactory.project();
    final List<Project> projects = Arrays.asList(project1, project2);
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<ProjectsEnvelope> fetchProjects(final boolean member) {
            return Observable.just(ProjectsEnvelopeFactory.projectsEnvelope(projects));
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).build());
    this.vm.intent(new Intent());
    this.projectsForBottomSheet.assertValue(Collections.singletonList(project2));
}
Also used : Project(com.kickstarter.models.Project) ProjectsEnvelope(com.kickstarter.services.apiresponses.ProjectsEnvelope) MockApiClient(com.kickstarter.mock.services.MockApiClient) Intent(android.content.Intent) Test(org.junit.Test)

Example 53 with MockApiClient

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

the class CreatorDashboardViewModelTest method testProjectName_whenSingleProject.

@Test
public void testProjectName_whenSingleProject() {
    final Project project = ProjectFactory.project().toBuilder().name("Best Project 2K19").build();
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<ProjectsEnvelope> fetchProjects(final boolean member) {
            return Observable.just(ProjectsEnvelopeFactory.projectsEnvelope(Collections.singletonList(project)));
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).build());
    this.vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
    this.projectName.assertValue("Best Project 2K19");
}
Also used : Project(com.kickstarter.models.Project) ProjectsEnvelope(com.kickstarter.services.apiresponses.ProjectsEnvelope) MockApiClient(com.kickstarter.mock.services.MockApiClient) Intent(android.content.Intent) Test(org.junit.Test)

Example 54 with MockApiClient

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

the class DiscoveryFragmentViewModelTest method testShowHeaderViews.

@Test
public void testShowHeaderViews() {
    final CurrentUserType currentUser = new MockCurrentUser();
    final Activity activity = ActivityFactory.activity();
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<ActivityEnvelope> fetchActivities() {
            return Observable.just(ActivityEnvelopeFactory.activityEnvelope(Collections.singletonList(activity)));
        }
    };
    final MockIntPreference activitySamplePreference = new MockIntPreference(987654321);
    final Environment environment = environment().toBuilder().activitySamplePreference(activitySamplePreference).apiClient(apiClient).currentUser(currentUser).build();
    setUpEnvironment(environment);
    // Initial home all projects params.
    setUpInitialHomeAllProjectsParams();
    // Should show onboarding view.
    this.shouldShowOnboardingViewTest.assertValues(true);
    this.activityTest.assertNoValues();
    // Change params. Onboarding view should not be shown.
    this.vm.inputs.paramsFromActivity(DiscoveryParams.builder().sort(DiscoveryParams.Sort.NEWEST).build());
    this.shouldShowOnboardingViewTest.assertValues(true, false);
    this.activityTest.assertNoValues();
    // Login.
    logUserIn(currentUser);
    // Activity sampler should be shown rather than onboarding view.
    this.shouldShowOnboardingViewTest.assertValues(true, false, false, false);
    this.activityTest.assertValues(null, activity);
    // Change params. Activity sampler should not be shown.
    this.vm.inputs.paramsFromActivity(DiscoveryParams.builder().build());
    this.activityTest.assertValues(null, activity, null);
}
Also used : ActivityEnvelope(com.kickstarter.services.apiresponses.ActivityEnvelope) MockIntPreference(com.kickstarter.libs.preferences.MockIntPreference) MockApiClient(com.kickstarter.mock.services.MockApiClient) Activity(com.kickstarter.models.Activity) Environment(com.kickstarter.libs.Environment) CurrentUserType(com.kickstarter.libs.CurrentUserType) ApiClientType(com.kickstarter.services.ApiClientType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 55 with MockApiClient

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

the class DiscoveryFragmentViewModelTest method testErroredResponseForFetchActivitiesWithCount.

@Test
public void testErroredResponseForFetchActivitiesWithCount() {
    final CurrentUserType currentUser = new MockCurrentUser();
    final Throwable throwableError = new Throwable();
    final MockApiClient apiClient = new MockApiClient() {

        @NonNull
        @Override
        public Observable<ActivityEnvelope> fetchActivities(@Nullable final Integer count) {
            return Observable.error(throwableError);
        }
    };
    final Environment env = environment().toBuilder().currentUser(currentUser).apiClient(apiClient).build();
    setUpEnvironment(env);
    // Load initial params and root categories from activity.
    setUpInitialHomeAllProjectsParams();
    // Log in.
    logUserIn(currentUser);
    this.activityTest.assertValueCount(1);
    this.activityTest.assertError(throwableError);
    this.activityTest.assertValue(null);
}
Also used : ActivityEnvelope(com.kickstarter.services.apiresponses.ActivityEnvelope) MockApiClient(com.kickstarter.mock.services.MockApiClient) Environment(com.kickstarter.libs.Environment) CurrentUserType(com.kickstarter.libs.CurrentUserType) Nullable(androidx.annotation.Nullable) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Aggregations

MockApiClient (com.kickstarter.mock.services.MockApiClient)66 Test (org.junit.Test)64 NonNull (androidx.annotation.NonNull)47 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)33 Environment (com.kickstarter.libs.Environment)29 Intent (android.content.Intent)28 Project (com.kickstarter.models.Project)25 ApiClientType (com.kickstarter.services.ApiClientType)19 User (com.kickstarter.models.User)14 CurrentUserType (com.kickstarter.libs.CurrentUserType)12 DiscoveryParams (com.kickstarter.services.DiscoveryParams)12 MessageThreadEnvelope (com.kickstarter.services.apiresponses.MessageThreadEnvelope)12 Backing (com.kickstarter.models.Backing)9 MessageThread (com.kickstarter.models.MessageThread)9 TestScheduler (rx.schedulers.TestScheduler)8 TestSubscriber (rx.observers.TestSubscriber)7 Update (com.kickstarter.models.Update)6 AccessTokenEnvelope (com.kickstarter.services.apiresponses.AccessTokenEnvelope)6 DiscoverEnvelope (com.kickstarter.services.apiresponses.DiscoverEnvelope)6 ProjectsEnvelope (com.kickstarter.services.apiresponses.ProjectsEnvelope)6