Search in sources :

Example 26 with MockApiClient

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

the class MessagesViewModelTest method testCreatorViewingProjectMessages.

@Test
public void testCreatorViewingProjectMessages() {
    final User creator = UserFactory.creator().toBuilder().name("Sharon").build();
    final User participant = UserFactory.user().toBuilder().name("Timothy").build();
    final CurrentUserType currentUser = new MockCurrentUser(creator);
    final MessageThread messageThread = MessageThreadFactory.messageThread().toBuilder().project(ProjectFactory.project().toBuilder().creator(creator).build()).participant(participant).build();
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<MessageThreadEnvelope> fetchMessagesForThread(@NonNull final MessageThread thread) {
            return Observable.just(MessageThreadEnvelopeFactory.messageThreadEnvelope().toBuilder().messageThread(messageThread).build());
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).currentUser(currentUser).build());
    // Start the view model with a message thread.
    this.vm.intent(messagesContextIntent(messageThread));
    // Creator name is the project creator, edit text hint is always the participant.
    this.creatorNameTextViewText.assertValues(creator.name());
    this.messageEditTextHint.assertValues(participant.name());
}
Also used : 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) CurrentUserType(com.kickstarter.libs.CurrentUserType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) MessageThreadEnvelope(com.kickstarter.services.apiresponses.MessageThreadEnvelope) Test(org.junit.Test)

Example 27 with MockApiClient

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

the class FacebookConfimationViewModelTest method testSignupErrorDisplay.

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

        @Override
        @NonNull
        public Observable<AccessTokenEnvelope> registerWithFacebook(@NonNull final String fbAccessToken, final boolean sendNewsletters) {
            return Observable.error(ApiExceptionFactory.apiError(ErrorEnvelope.builder().httpCode(404).errorMessages(Collections.singletonList("oh no")).build()));
        }
    };
    final Environment environment = environment().toBuilder().apiClient(apiClient).build();
    this.vm = new FacebookConfirmationViewModel.ViewModel(environment);
    this.vm.intent(new Intent().putExtra(IntentKey.FACEBOOK_TOKEN, "token"));
    this.vm.outputs.signupError().subscribe(this.signupError);
    this.vm.inputs.sendNewslettersClick(true);
    this.vm.inputs.createNewAccountClick();
    this.signupError.assertValue("oh no");
}
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 28 with MockApiClient

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

the class FacebookConfimationViewModelTest method testSuccessfulUserCreation.

@Test
public void testSuccessfulUserCreation() {
    final ApiClientType apiClient = new MockApiClient();
    final Environment environment = environment().toBuilder().apiClient(apiClient).build();
    this.vm = new FacebookConfirmationViewModel.ViewModel(environment);
    this.vm.intent(new Intent().putExtra(IntentKey.FACEBOOK_TOKEN, "token"));
    this.vm.outputs.signupSuccess().subscribe(this.signupSuccess);
    this.vm.inputs.sendNewslettersClick(true);
    this.vm.inputs.createNewAccountClick();
    this.signupSuccess.assertValueCount(1);
}
Also used : MockApiClient(com.kickstarter.mock.services.MockApiClient) Environment(com.kickstarter.libs.Environment) Intent(android.content.Intent) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Example 29 with MockApiClient

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

the class MessageThreadsViewModelTest method testHasUnreadMessages.

@Test
public void testHasUnreadMessages() {
    final User user = UserFactory.user().toBuilder().unreadMessagesCount(3).build();
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<User> fetchCurrentUser() {
            return Observable.just(user);
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).build());
    this.vm.intent(new Intent());
    this.vm.inputs.onResume();
    // Unread count text view is shown.
    this.unreadMessagesCount.assertValues(user.unreadMessagesCount());
    this.unreadMessagesCountIsGone.assertValues(false);
    this.hasNoUnreadMessages.assertValues(false);
    this.unreadCountTextViewColorInt.assertValues(R.color.accent);
    this.unreadCountTextViewTypefaceInt.assertValues(Typeface.BOLD);
    this.unreadCountToolbarTextViewIsGone.assertValues(false);
    this.vm.inputs.mailbox(Mailbox.SENT);
    this.unreadMessagesCountIsGone.assertValues(false, true);
}
Also used : User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) MockApiClient(com.kickstarter.mock.services.MockApiClient) Intent(android.content.Intent) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Example 30 with MockApiClient

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

the class MessageThreadsViewModelTest method testNoMessages.

@Test
public void testNoMessages() {
    final User user = UserFactory.user().toBuilder().unreadMessagesCount(null).build();
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<User> fetchCurrentUser() {
            return Observable.just(user);
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).build());
    this.vm.intent(new Intent());
    this.vm.inputs.onResume();
    this.hasNoMessages.assertValues(true);
    this.unreadMessagesCount.assertNoValues();
    this.unreadMessagesCountIsGone.assertValue(false);
    this.unreadCountTextViewColorInt.assertValues(R.color.kds_support_400);
    this.unreadCountTextViewTypefaceInt.assertValues(Typeface.NORMAL);
    this.unreadCountToolbarTextViewIsGone.assertValues(true);
    this.vm.inputs.mailbox(Mailbox.SENT);
    this.unreadMessagesCountIsGone.assertValues(false, true);
}
Also used : User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) MockApiClient(com.kickstarter.mock.services.MockApiClient) Intent(android.content.Intent) ApiClientType(com.kickstarter.services.ApiClientType) 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