use of com.kickstarter.services.ApiClientType in project android-oss by kickstarter.
the class ResetPasswordViewModelTest method testResetPasswordViewModel_resetFailure.
@Test
public void testResetPasswordViewModel_resetFailure() {
final ApiClientType apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<User> resetPassword(@NonNull final String email) {
return Observable.error(ApiExceptionFactory.badRequestException());
}
};
final Environment environment = environment().toBuilder().apiClient(apiClient).build();
final ResetPasswordViewModel vm = new ResetPasswordViewModel(environment);
final TestSubscriber<String> errorTest = new TestSubscriber<>();
koalaTest.assertValues("Forgot Password View");
vm.errors.resetError().subscribe(errorTest);
vm.inputs.email("hello@kickstarter.com");
vm.inputs.resetPasswordClick();
errorTest.assertValue("bad request");
koalaTest.assertValues("Forgot Password View", "Forgot Password Errored");
}
use of com.kickstarter.services.ApiClientType in project android-oss by kickstarter.
the class CommentsViewModelTest method testCommentsViewModel_EmptyState.
@Test
public void testCommentsViewModel_EmptyState() {
final ApiClientType apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<CommentsEnvelope> fetchComments(@NonNull final Update update) {
return Observable.empty();
}
};
final Environment env = environment().toBuilder().apiClient(apiClient).build();
final CommentsViewModel vm = new CommentsViewModel(env);
final TestSubscriber<CommentsData> commentsData = new TestSubscriber<>();
vm.outputs.commentsData().subscribe(commentsData);
// Start the view model with an update.
vm.intent(new Intent().putExtra(IntentKey.UPDATE, UpdateFactory.update()));
// Only Viewed Comments event should fire.
koalaTest.assertValues(KoalaEvent.VIEWED_COMMENTS);
commentsData.assertNoValues();
}
use of com.kickstarter.services.ApiClientType in project android-oss by kickstarter.
the class LoginViewModelTest method testLoginApiValidationError.
@Test
public void testLoginApiValidationError() {
final ApiClientType apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<AccessTokenEnvelope> login(@NonNull final String email, @NonNull final String password) {
return Observable.error(ApiExceptionFactory.invalidLoginException());
}
};
final Environment environment = environment().toBuilder().apiClient(apiClient).build();
final LoginViewModel vm = new LoginViewModel(environment);
final TestSubscriber<String> invalidLoginError = new TestSubscriber<>();
vm.errors.invalidLoginError().subscribe(invalidLoginError);
final TestSubscriber<Void> loginSuccess = new TestSubscriber<>();
vm.outputs.loginSuccess().subscribe(loginSuccess);
vm.inputs.email("typo@kickstartr.com");
vm.inputs.password("danisawesome");
vm.inputs.loginClick();
loginSuccess.assertNoValues();
invalidLoginError.assertValueCount(1);
}
use of com.kickstarter.services.ApiClientType 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.ApiClientType 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);
}
Aggregations