use of com.kickstarter.services.MockApiClient in project android-oss by kickstarter.
the class LoginViewModelTest method testLoginApiError.
@Test
public void testLoginApiError() {
final ApiClientType apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<AccessTokenEnvelope> login(@NonNull final String email, @NonNull final String password) {
return Observable.error(ApiExceptionFactory.badRequestException());
}
};
final Environment environment = environment().toBuilder().apiClient(apiClient).build();
final LoginViewModel vm = new LoginViewModel(environment);
final TestSubscriber<Void> loginSuccess = new TestSubscriber<>();
vm.outputs.loginSuccess().subscribe(loginSuccess);
final TestSubscriber<String> genericLoginError = new TestSubscriber<>();
vm.errors.genericLoginError().subscribe(genericLoginError);
vm.inputs.email("incorrect@kickstarter.com");
vm.inputs.password("danisawesome");
vm.inputs.loginClick();
loginSuccess.assertNoValues();
genericLoginError.assertValueCount(1);
}
use of com.kickstarter.services.MockApiClient in project android-oss by kickstarter.
the class ProfileViewModelTest method testProfileViewModel_EmitsProjects.
@Test
public void testProfileViewModel_EmitsProjects() {
final ApiClientType apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<DiscoverEnvelope> fetchProjects(@NonNull final DiscoveryParams params) {
return Observable.just(DiscoverEnvelopeFactory.discoverEnvelope(Collections.singletonList(ProjectFactory.project())));
}
};
final Environment env = environment().toBuilder().apiClient(apiClient).build();
final ProfileViewModel.ViewModel vm = new ProfileViewModel.ViewModel(env);
final TestSubscriber<List<Project>> projects = new TestSubscriber<>();
vm.outputs.projects().subscribe(projects);
koalaTest.assertValues(KoalaEvent.PROFILE_VIEW_MY, KoalaEvent.VIEWED_PROFILE);
projects.assertValueCount(1);
}
use of com.kickstarter.services.MockApiClient in project android-oss by kickstarter.
the class ProfileViewModelTest method testProfileViewModel_EmitsBackedProjectsData.
@Test
public void testProfileViewModel_EmitsBackedProjectsData() {
final User user = UserFactory.user().toBuilder().backedProjectsCount(5).createdProjectsCount(0).build();
final ApiClientType apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<User> fetchCurrentUser() {
return Observable.just(user);
}
};
final Environment env = environment().toBuilder().apiClient(apiClient).build();
final ProfileViewModel.ViewModel vm = new ProfileViewModel.ViewModel(env);
final TestSubscriber<Boolean> backedCountTextViewHidden = new TestSubscriber<>();
vm.outputs.backedCountTextViewHidden().subscribe(backedCountTextViewHidden);
final TestSubscriber<String> backedCountTextViewText = new TestSubscriber<>();
vm.outputs.backedCountTextViewText().subscribe(backedCountTextViewText);
final TestSubscriber<Boolean> backedTextViewHidden = new TestSubscriber<>();
vm.outputs.backedTextViewHidden().subscribe(backedTextViewHidden);
final TestSubscriber<Boolean> createdCountTextViewHidden = new TestSubscriber<>();
vm.outputs.createdCountTextViewHidden().subscribe(createdCountTextViewHidden);
final TestSubscriber<String> createdCountTextViewText = new TestSubscriber<>();
vm.outputs.createdCountTextViewText().subscribe(createdCountTextViewText);
final TestSubscriber<Boolean> createdTextViewHidden = new TestSubscriber<>();
vm.outputs.createdTextViewHidden().subscribe(createdTextViewHidden);
final TestSubscriber<Boolean> dividerViewHidden = new TestSubscriber<>();
vm.outputs.dividerViewHidden().subscribe(dividerViewHidden);
// Backed text views are displayed.
backedCountTextViewHidden.assertValues(false);
backedCountTextViewText.assertValues(NumberUtils.format(user.backedProjectsCount()));
backedTextViewHidden.assertValues(false);
// Created text views are hidden.
createdCountTextViewHidden.assertValues(true);
createdCountTextViewText.assertNoValues();
createdTextViewHidden.assertValues(true);
// Divider view is hidden.
dividerViewHidden.assertValues(true);
}
use of com.kickstarter.services.MockApiClient in project android-oss by kickstarter.
the class DiscoveryIntentMapperTest method emitsFromDiscoveryCategoryUri.
@Test
public void emitsFromDiscoveryCategoryUri() {
final Uri uri = Uri.parse("https://www.kickstarter.com/discover/categories/music");
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
final TestSubscriber<DiscoveryParams> resultTest = TestSubscriber.create();
DiscoveryIntentMapper.params(intent, new MockApiClient()).subscribe(resultTest);
resultTest.assertValueCount(1);
}
use of com.kickstarter.services.MockApiClient in project android-oss by kickstarter.
the class DiscoveryIntentMapperTest method emitsFromDiscoveryLocationUri.
@Test
public void emitsFromDiscoveryLocationUri() {
final Uri uri = Uri.parse("https://www.kickstarter.com/discover/places/sydney-au");
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
final TestSubscriber<DiscoveryParams> resultTest = TestSubscriber.create();
DiscoveryIntentMapper.params(intent, new MockApiClient()).subscribe(resultTest);
resultTest.assertValueCount(1);
}
Aggregations