Search in sources :

Example 6 with MessageThread

use of com.kickstarter.models.MessageThread 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 7 with MessageThread

use of com.kickstarter.models.MessageThread 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 8 with MessageThread

use of com.kickstarter.models.MessageThread 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)

Example 9 with MessageThread

use of com.kickstarter.models.MessageThread in project android-oss by kickstarter.

the class MessagesViewModelTest method testStartBackingActivity_AsBacker.

@Test
public void testStartBackingActivity_AsBacker() {
    final User user = UserFactory.user();
    final Project project = ProjectFactory.project().toBuilder().isBacking(true).build();
    final Backing backing = BackingFactory.backing();
    final MessageThread messageThread = MessageThreadFactory.messageThread().toBuilder().project(project).build();
    final MessageThreadEnvelope messageThreadEnvelope = MessageThreadEnvelopeFactory.messageThreadEnvelope().toBuilder().messageThread(messageThread).build();
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<MessageThreadEnvelope> fetchMessagesForBacking(@NonNull final Backing backing) {
            return Observable.just(messageThreadEnvelope);
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).currentUser(new MockCurrentUser(user)).build());
    this.vm.intent(backerModalContextIntent(backing, project));
    this.vm.inputs.viewPledgeButtonClicked();
    this.startBackingActivity.assertValues(new BackingWrapper(backing, user, project));
}
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) BackingWrapper(com.kickstarter.models.BackingWrapper) 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)

Example 10 with MessageThread

use of com.kickstarter.models.MessageThread in project android-oss by kickstarter.

the class MessagesViewModelTest method testStartBackingActivity_AsCreator.

@Test
public void testStartBackingActivity_AsCreator() {
    final User backer = UserFactory.user().toBuilder().name("Vanessa").build();
    final User creator = UserFactory.user().toBuilder().name("Jessica").build();
    final Backing backing = BackingFactory.backing();
    final Project project = ProjectFactory.project().toBuilder().creator(creator).build();
    final MessageThread messageThread = MessageThreadFactory.messageThread().toBuilder().backing(backing).participant(backer).project(project).build();
    final MessageThreadEnvelope messageThreadEnvelope = MessageThreadEnvelopeFactory.messageThreadEnvelope().toBuilder().messageThread(messageThread).build();
    final MockApiClient apiClient = new MockApiClient() {

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

        @NonNull
        @Override
        public Observable<Backing> fetchProjectBacking(@NonNull final Project project, @NonNull final User user) {
            return Observable.just(backing);
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).currentUser(new MockCurrentUser(creator)).build());
    this.vm.intent(messagesContextIntent(messageThread));
    this.vm.inputs.viewPledgeButtonClicked();
    this.startBackingActivity.assertValues(new BackingWrapper(messageThread.backing(), backer, project));
}
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) BackingWrapper(com.kickstarter.models.BackingWrapper) 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

MessageThread (com.kickstarter.models.MessageThread)17 Test (org.junit.Test)17 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)10 NonNull (androidx.annotation.NonNull)9 MockApiClient (com.kickstarter.mock.services.MockApiClient)9 MessageThreadEnvelope (com.kickstarter.services.apiresponses.MessageThreadEnvelope)7 User (com.kickstarter.models.User)5 Backing (com.kickstarter.models.Backing)4 Project (com.kickstarter.models.Project)4 BackingWrapper (com.kickstarter.models.BackingWrapper)2 CurrentUserType (com.kickstarter.libs.CurrentUserType)1