Search in sources :

Example 6 with MockApiClient

use of com.kickstarter.mock.services.MockApiClient 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, "");
    this.vm = new TwoFactorViewModel.ViewModel(environment);
    this.vm.intent(intent);
    this.vm.outputs.tfaSuccess().subscribe(this.tfaSuccess);
    this.vm.outputs.formSubmitting().subscribe(this.formSubmitting);
    this.vm.outputs.tfaCodeMismatchError().subscribe(this.tfaCodeMismatchError);
    this.vm.inputs.code("88888");
    this.vm.inputs.loginClick();
    this.formSubmitting.assertValues(true, false);
    this.tfaSuccess.assertNoValues();
    this.tfaCodeMismatchError.assertValueCount(1);
    this.segmentTrack.assertValue(EventName.PAGE_VIEWED.getEventName());
}
Also used : AccessTokenEnvelope(com.kickstarter.services.apiresponses.AccessTokenEnvelope) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Environment(com.kickstarter.libs.Environment) Intent(android.content.Intent) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Example 7 with MockApiClient

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

the class CreatorDashboardViewModelTest method testProjectName_whenMultipleProjects.

@Test
public void testProjectName_whenMultipleProjects() {
    final Project project1 = ProjectFactory.project().toBuilder().name("Best Project 2K19").build();
    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.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 8 with MockApiClient

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

the class CreatorDashboardViewModelTest method testProjectSwitcherProjectClickOutput.

@Test
public void testProjectSwitcherProjectClickOutput() {
    DateTimeUtils.setCurrentMillisFixed(new DateTime().getMillis());
    final Project project1 = ProjectFactory.project();
    final Project project2 = ProjectFactory.project();
    final List<Project> projects = Arrays.asList(project1, project2);
    final ProjectStatsEnvelope projectStatsEnvelope = ProjectStatsEnvelopeFactory.projectStatsEnvelope();
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<ProjectsEnvelope> fetchProjects(final boolean member) {
            return Observable.just(ProjectsEnvelopeFactory.projectsEnvelope(projects));
        }

        @Override
        @NonNull
        public Observable<ProjectStatsEnvelope> fetchProjectStats(@NonNull final Project project) {
            return Observable.just(projectStatsEnvelope);
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).build());
    this.vm.intent(new Intent());
    this.vm.inputs.projectSelectionInput(project2);
    this.projectDashboardData.assertValues(new ProjectDashboardData(project1, ProjectStatsEnvelopeFactory.projectStatsEnvelope(), false), new ProjectDashboardData(project2, ProjectStatsEnvelopeFactory.projectStatsEnvelope(), false));
}
Also used : Project(com.kickstarter.models.Project) ProjectStatsEnvelope(com.kickstarter.services.apiresponses.ProjectStatsEnvelope) ProjectsEnvelope(com.kickstarter.services.apiresponses.ProjectsEnvelope) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Intent(android.content.Intent) DateTime(org.joda.time.DateTime) ProjectDashboardData(com.kickstarter.ui.adapters.data.ProjectDashboardData) Test(org.junit.Test)

Example 9 with MockApiClient

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

the class CreatorDashboardViewModelTest method testProjectDashboardData_whenViewingSingleProjects.

public void testProjectDashboardData_whenViewingSingleProjects() {
    final Project project = ProjectFactory.project();
    final ProjectStatsEnvelope projectStatsEnvelope = ProjectStatsEnvelopeFactory.projectStatsEnvelope();
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<ProjectStatsEnvelope> fetchProjectStats(@NonNull final Project project) {
            return Observable.just(projectStatsEnvelope);
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).build());
    this.vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
    this.projectDashboardData.assertValue(new ProjectDashboardData(project, projectStatsEnvelope, true));
}
Also used : Project(com.kickstarter.models.Project) ProjectStatsEnvelope(com.kickstarter.services.apiresponses.ProjectStatsEnvelope) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Intent(android.content.Intent) ProjectDashboardData(com.kickstarter.ui.adapters.data.ProjectDashboardData)

Example 10 with MockApiClient

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

the class DiscoveryFragmentViewModelTest method testSuccessResponseForFetchActivitiesWithCount.

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

        @NonNull
        @Override
        public Observable<ActivityEnvelope> fetchActivities(@Nullable final Integer count) {
            return Observable.just(ActivityEnvelopeFactory.activityEnvelope(Collections.singletonList(activity)));
        }
    };
    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(2);
    this.activityTest.assertValues(null, activity);
}
Also used : ActivityEnvelope(com.kickstarter.services.apiresponses.ActivityEnvelope) MockApiClient(com.kickstarter.mock.services.MockApiClient) Activity(com.kickstarter.models.Activity) 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