Search in sources :

Example 16 with MockApiClient

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

the class ProjectUpdatesViewModelTest method testStartUpdateActivity.

@Test
public void testStartUpdateActivity() {
    final Update update = UpdateFactory.update();
    final List<Update> updates = Collections.singletonList(update);
    final Project project = ProjectFactory.project();
    setUpEnvironment(environment().toBuilder().apiClient(new MockApiClient() {

        @NonNull
        @Override
        public Observable<UpdatesEnvelope> fetchUpdates(@NonNull final Project project) {
            return Observable.just(UpdatesEnvelope.builder().updates(updates).urls(urlsEnvelope()).build());
        }
    }).build(), project, ProjectDataFactory.Companion.project(project));
    this.vm.inputs.updateClicked(update);
    this.startUpdateActivity.assertValues(Pair.create(project, update));
}
Also used : Project(com.kickstarter.models.Project) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Update(com.kickstarter.models.Update) Observable(rx.Observable) Test(org.junit.Test)

Example 17 with MockApiClient

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

the class ProjectUpdatesViewModelTest method test_projectAndUpdates_whenUpdatesListIsEmpty.

@Test
public void test_projectAndUpdates_whenUpdatesListIsEmpty() {
    final Project project = ProjectFactory.project();
    setUpEnvironment(environment().toBuilder().apiClient(new MockApiClient() {

        @NonNull
        @Override
        public Observable<UpdatesEnvelope> fetchUpdates(@NonNull final Project project) {
            return Observable.just(UpdatesEnvelope.builder().updates(Collections.emptyList()).urls(urlsEnvelope()).build());
        }
    }).build(), project, ProjectDataFactory.Companion.project(project));
    this.projectAndUpdates.assertValues(Pair.create(project, Collections.emptyList()));
    this.isFetchingUpdates.assertValues(true, false);
    this.horizontalProgressBarIsGone.assertValues(false, true);
}
Also used : Project(com.kickstarter.models.Project) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Observable(rx.Observable) Test(org.junit.Test)

Example 18 with MockApiClient

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

the class MessagesViewModelTest method testBackingInfo_NoBacking.

@Test
public void testBackingInfo_NoBacking() {
    final Project project = ProjectFactory.project().toBuilder().isBacking(false).build();
    final MessageThread messageThread = MessageThreadFactory.messageThread().toBuilder().project(project).backing(null).build();
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<Backing> fetchProjectBacking(@NonNull final Project project, @NonNull final User user) {
            return Observable.error(ApiExceptionFactory.badRequestException());
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).currentUser(new MockCurrentUser(UserFactory.user())).build());
    // Start the view model with a message thread.
    this.vm.intent(messagesContextIntent(messageThread));
    this.backingAndProject.assertNoValues();
    this.backingInfoViewIsGone.assertValues(true);
}
Also used : Project(com.kickstarter.models.Project) User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) MessageThread(com.kickstarter.models.MessageThread) Backing(com.kickstarter.models.Backing) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 19 with MockApiClient

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

the class MessagesViewModelTest method testSuccessfullyMarkedAsRead.

@Test
public void testSuccessfullyMarkedAsRead() {
    final MessageThread messageThread = MessageThreadFactory.messageThread();
    final MockApiClient apiClient = new MockApiClient() {

        @NonNull
        @Override
        public Observable<MessageThread> markAsRead(@NonNull final MessageThread thread) {
            return Observable.just(messageThread);
        }
    };
    setUpEnvironment(environment().toBuilder().currentUser(new MockCurrentUser(UserFactory.user())).apiClient(apiClient).build());
    this.vm.intent(messagesContextIntent(messageThread));
    this.successfullyMarkedAsRead.assertValueCount(1);
}
Also used : MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) MessageThread(com.kickstarter.models.MessageThread) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 20 with MockApiClient

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

the class MessagesViewModelTest method testBackingAndProject_Participant.

@Test
public void testBackingAndProject_Participant() {
    final Project project = ProjectFactory.project().toBuilder().isBacking(false).build();
    final Backing backing = BackingFactory.backing().toBuilder().project(project).build();
    final MessageThread messageThread = MessageThreadFactory.messageThread().toBuilder().project(project).backing(backing).build();
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<MessageThreadEnvelope> fetchMessagesForThread(@NonNull final MessageThread messageThread) {
            return Observable.just(MessageThreadEnvelopeFactory.messageThreadEnvelope());
        }

        @Override
        @NonNull
        public Observable<Backing> fetchProjectBacking(@NonNull final Project project, @NonNull final User user) {
            return Observable.just(backing);
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).currentUser(new MockCurrentUser(UserFactory.user())).build());
    // Start the view model with a message thread.
    this.vm.intent(messagesContextIntent(messageThread));
    this.backingAndProject.assertValues(Pair.create(backing, backing.project()));
    this.backingInfoViewIsGone.assertValues(false);
}
Also used : Project(com.kickstarter.models.Project) User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) MessageThread(com.kickstarter.models.MessageThread) Backing(com.kickstarter.models.Backing) MessageThreadEnvelope(com.kickstarter.services.apiresponses.MessageThreadEnvelope) 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