Search in sources :

Example 21 with MockApiClient

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

the class MessagesViewModelTest method testSendMessage_Error.

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

        @Override
        @NonNull
        public Observable<Message> sendMessage(@NonNull final MessageSubject messageSubject, @NonNull final String body) {
            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(MessageThreadFactory.messageThread()));
    // Send a message unsuccessfully.
    this.vm.inputs.messageEditTextChanged("Hello there");
    this.vm.inputs.sendMessageButtonClicked();
    // Error toast is displayed, errored message body remains in edit text, no new message is emitted.
    this.showMessageErrorToast.assertValueCount(1);
    this.setMessageEditText.assertNoValues();
}
Also used : MessageSubject(com.kickstarter.ui.data.MessageSubject) Message(com.kickstarter.models.Message) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 22 with MockApiClient

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

the class MessagesViewModelTest method testSendMessage_Success.

@Test
public void testSendMessage_Success() {
    final Message sentMessage = MessageFactory.message();
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<Message> sendMessage(@NonNull final MessageSubject messageSubject, @NonNull final String body) {
            return Observable.just(sentMessage);
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).currentUser(new MockCurrentUser(UserFactory.user())).build());
    // Start the view model with a message thread.
    this.vm.intent(messagesContextIntent(MessageThreadFactory.messageThread()));
    // Initial messages emit.
    this.messageList.assertValueCount(1);
    // Send a message successfully.
    this.vm.inputs.messageEditTextChanged("Salutations friend!");
    this.vm.inputs.sendMessageButtonClicked();
    // New message list emits.
    this.messageList.assertValueCount(2);
    // Reply edit text should be cleared and view should be scrolled to new message.
    this.setMessageEditText.assertValues("");
    this.scrollRecyclerViewToBottom.assertValueCount(1);
}
Also used : MessageSubject(com.kickstarter.ui.data.MessageSubject) Message(com.kickstarter.models.Message) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 23 with MockApiClient

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

the class MessagesViewModelTest method testStartBackingActivity_AsBacker_EmptyThread.

@Test
public void testStartBackingActivity_AsBacker_EmptyThread() {
    final User user = UserFactory.user();
    final Project project = ProjectFactory.project().toBuilder().isBacking(true).build();
    final Backing backing = BackingFactory.backing();
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<MessageThreadEnvelope> fetchMessagesForBacking(@NonNull final Backing backing) {
            return Observable.just(MessageThreadEnvelopeFactory.empty());
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).currentUser(new MockCurrentUser(user)).build());
    this.vm.intent(creatorBioModalContextIntent(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) Backing(com.kickstarter.models.Backing) MessageThreadEnvelope(com.kickstarter.services.apiresponses.MessageThreadEnvelope) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 24 with MockApiClient

use of com.kickstarter.mock.services.MockApiClient 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 25 with MockApiClient

use of com.kickstarter.mock.services.MockApiClient 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

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