use of com.kickstarter.mock.services.MockApiClient in project android-oss by kickstarter.
the class MessagesViewModelTest method testProjectData_ExistingMessages.
@Test
public void testProjectData_ExistingMessages() {
final MessageThread messageThread = MessageThreadFactory.messageThread();
final MockApiClient apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<MessageThreadEnvelope> fetchMessagesForThread(@NonNull final MessageThread thread) {
return Observable.just(MessageThreadEnvelopeFactory.messageThreadEnvelope());
}
};
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.creatorNameTextViewText.assertValues(messageThread.project().creator().name());
this.projectNameTextViewText.assertValues(messageThread.project().name());
this.projectNameToolbarTextViewText.assertValues(messageThread.project().name());
}
use of com.kickstarter.mock.services.MockApiClient in project android-oss by kickstarter.
the class MessagesViewModelTest method testNoMessages.
@Test
public void testNoMessages() {
final Backing backing = BackingFactory.backing();
final Project project = ProjectFactory.project();
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(UserFactory.user())).build());
// Start the view model with a backing and a project.
this.vm.intent(backerModalContextIntent(backing, project));
// All data except for messages should emit.
this.messageList.assertNoValues();
this.creatorNameTextViewText.assertValues(project.creator().name());
this.backingAndProject.assertValues(Pair.create(backing, project));
}
use of com.kickstarter.mock.services.MockApiClient in project android-oss by kickstarter.
the class MessagesViewModelTest method testMessageEditTextHint.
@Test
public void testMessageEditTextHint() {
final MessageThread messageThread = MessageThreadFactory.messageThread();
final MockApiClient apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<MessageThreadEnvelope> fetchMessagesForThread(@NonNull final MessageThread thread) {
return Observable.just(MessageThreadEnvelopeFactory.messageThreadEnvelope());
}
};
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.messageEditTextHint.assertValues(messageThread.project().creator().name());
}
use of com.kickstarter.mock.services.MockApiClient in project android-oss by kickstarter.
the class TwoFactorViewModelTest method testTwoFactorViewModel_GenericError.
@Test
public void testTwoFactorViewModel_GenericError() {
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.apiError(ErrorEnvelope.builder().httpCode(400).build()));
}
};
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.genericTfaError().subscribe(this.genericTfaError);
this.vm.inputs.code("88888");
this.vm.inputs.loginClick();
this.formSubmitting.assertValues(true, false);
this.tfaSuccess.assertNoValues();
this.genericTfaError.assertValueCount(1);
this.segmentTrack.assertValue(EventName.PAGE_VIEWED.getEventName());
}
use of com.kickstarter.mock.services.MockApiClient in project android-oss by kickstarter.
the class CreatorDashboardViewModelTest method testProjectDashboardData_whenViewingAllProjects.
public void testProjectDashboardData_whenViewingAllProjects() {
final List<Project> projects = Collections.singletonList(ProjectFactory.project());
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.projectDashboardData.assertValue(new ProjectDashboardData(Objects.requireNonNull(ListUtils.first(projects)), projectStatsEnvelope, false));
}
Aggregations