use of com.kickstarter.mock.services.MockApiClient in project android-oss by kickstarter.
the class MessageThreadsViewModelTest method testMessageThreadsEmit_NoProjectIntent.
@Test
public void testMessageThreadsEmit_NoProjectIntent() {
final CurrentUserType currentUser = new MockCurrentUser();
currentUser.login(UserFactory.user().toBuilder().unreadMessagesCount(0).build(), "beefbod5");
final MessageThreadsEnvelope inboxEnvelope = MessageThreadsEnvelopeFactory.messageThreadsEnvelope().toBuilder().messageThreads(Collections.singletonList(MessageThreadFactory.messageThread())).build();
final MessageThreadsEnvelope sentEnvelope = MessageThreadsEnvelopeFactory.messageThreadsEnvelope().toBuilder().messageThreads(Arrays.asList(MessageThreadFactory.messageThread(), MessageThreadFactory.messageThread())).build();
final ApiClientType apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<MessageThreadsEnvelope> fetchMessageThreads(@Nullable final Project project, @NonNull final Mailbox mailbox) {
return Observable.just(mailbox == Mailbox.INBOX ? inboxEnvelope : sentEnvelope);
}
};
setUpEnvironment(environment().toBuilder().apiClient(apiClient).currentUser(currentUser).build());
final Intent intent = new Intent().putExtra(IntentKey.PROJECT, Empty.INSTANCE);
this.vm.intent(intent);
this.messageThreadList.assertValueCount(2);
this.messageThreadListCount.assertValues(0, 1);
// Same message threads should not emit again.
this.vm.inputs.onResume();
this.messageThreadList.assertValueCount(2);
this.messageThreadListCount.assertValues(0, 1);
this.vm.inputs.mailbox(Mailbox.SENT);
this.messageThreadList.assertValueCount(4);
this.messageThreadListCount.assertValues(0, 1, 0, 2);
}
use of com.kickstarter.mock.services.MockApiClient in project android-oss by kickstarter.
the class DiscoveryViewModelTest method testShowSnackBar_whenIntentFromDeepLinkSuccessResponse_showSuccessMessage.
@Test
public void testShowSnackBar_whenIntentFromDeepLinkSuccessResponse_showSuccessMessage() {
final String url = "https://*.kickstarter.com/profile/verify_email";
final Intent intentWithUrl = new Intent().setData(Uri.parse(url));
final MockApiClient mockApiClient = new MockApiClient() {
@NonNull
@Override
public Observable<EmailVerificationEnvelope> verifyEmail(@NonNull final String token) {
return Observable.just(EmailVerificationEnvelope.Companion.builder().code(200).message("Success").build());
}
};
final Environment mockedClientEnvironment = environment().toBuilder().apiClient(mockApiClient).build();
this.vm = new DiscoveryViewModel.ViewModel(mockedClientEnvironment);
this.vm.getOutputs().showSuccessMessage().subscribe(this.showSuccessMessage);
this.vm.getOutputs().showErrorMessage().subscribe(this.showErrorMessage);
this.vm.intent(intentWithUrl);
this.showSuccessMessage.assertValue("Success");
this.showErrorMessage.assertNoValues();
}
use of com.kickstarter.mock.services.MockApiClient in project android-oss by kickstarter.
the class LoginToutViewModelTest method facebookLogin_error.
@Test
public void facebookLogin_error() {
final MockCurrentUser currentUser = new MockCurrentUser();
final Environment environment = environment().toBuilder().currentUser(currentUser).apiClient(new MockApiClient() {
@Override
@NonNull
public Observable<AccessTokenEnvelope> loginWithFacebook(@NonNull final String accessToken) {
return Observable.error(new Throwable("error"));
}
}).build();
setUpEnvironment(environment, LoginReason.DEFAULT);
this.currentUser.assertValuesAndClear(null);
this.vm.inputs.facebookLoginClick(null, Arrays.asList("public_profile", "user_friends", "email"));
this.vm.facebookAccessToken.onNext("token");
this.currentUser.assertNoValues();
this.finishWithSuccessfulResult.assertNoValues();
this.segmentTrack.assertValues(EventName.PAGE_VIEWED.getEventName(), EventName.CTA_CLICKED.getEventName());
}
use of com.kickstarter.mock.services.MockApiClient in project android-oss by kickstarter.
the class SearchViewModelTest method testNoResults.
@Test
public void testNoResults() {
final TestScheduler scheduler = new TestScheduler();
final List<Project> projects = Arrays.asList();
final MockApiClient apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<DiscoverEnvelope> fetchProjects(@NonNull final DiscoveryParams params) {
return Observable.just(DiscoverEnvelopeFactory.discoverEnvelope(projects));
}
};
final Environment env = environment().toBuilder().scheduler(scheduler).apiClient(apiClient).build();
setUpEnvironment(env);
// populate search and overcome debounce
this.vm.inputs.search("__");
scheduler.advanceTimeBy(300, TimeUnit.MILLISECONDS);
this.searchProjects.assertValueCount(2);
}
use of com.kickstarter.mock.services.MockApiClient in project android-oss by kickstarter.
the class SignupViewModelTest method testSignupViewModel_ApiError.
@Test
public void testSignupViewModel_ApiError() {
final ApiClientType apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<AccessTokenEnvelope> signup(@NonNull final String name, @NonNull final String email, @NonNull final String password, @NonNull final String passwordConfirmation, final boolean sendNewsletters) {
return Observable.error(ApiExceptionFactory.badRequestException());
}
};
final Environment environment = environment().toBuilder().apiClient(apiClient).build();
final SignupViewModel.ViewModel vm = new SignupViewModel.ViewModel(environment);
final TestSubscriber<Void> signupSuccessTest = new TestSubscriber<>();
vm.outputs.signupSuccess().subscribe(signupSuccessTest);
final TestSubscriber<String> signupErrorTest = new TestSubscriber<>();
vm.outputs.errorString().subscribe(signupErrorTest);
final TestSubscriber<Boolean> formSubmittingTest = new TestSubscriber<>();
vm.outputs.formSubmitting().subscribe(formSubmittingTest);
vm.inputs.name("brandon");
vm.inputs.email("hello@kickstarter.com");
vm.inputs.email("incorrect@kickstarter");
vm.inputs.password("danisawesome");
vm.inputs.sendNewslettersClick(true);
vm.inputs.signupClick();
formSubmittingTest.assertValues(true, false);
signupSuccessTest.assertValueCount(0);
signupErrorTest.assertValueCount(1);
this.segmentTrack.assertValues(EventName.PAGE_VIEWED.getEventName(), EventName.CTA_CLICKED.getEventName());
}
Aggregations