Search in sources :

Example 1 with ApiClientType

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");
}
Also used : User(com.kickstarter.models.User) MockApiClient(com.kickstarter.services.MockApiClient) NonNull(android.support.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Example 2 with ApiClientType

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();
}
Also used : CommentsEnvelope(com.kickstarter.services.apiresponses.CommentsEnvelope) CommentsData(com.kickstarter.ui.adapters.data.CommentsData) MockApiClient(com.kickstarter.services.MockApiClient) NonNull(android.support.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) Intent(android.content.Intent) Update(com.kickstarter.models.Update) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Example 3 with ApiClientType

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);
}
Also used : AccessTokenEnvelope(com.kickstarter.services.apiresponses.AccessTokenEnvelope) MockApiClient(com.kickstarter.services.MockApiClient) NonNull(android.support.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Example 4 with ApiClientType

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);
}
Also used : AccessTokenEnvelope(com.kickstarter.services.apiresponses.AccessTokenEnvelope) MockApiClient(com.kickstarter.services.MockApiClient) NonNull(android.support.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Example 5 with ApiClientType

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);
}
Also used : DiscoverEnvelope(com.kickstarter.services.apiresponses.DiscoverEnvelope) MockApiClient(com.kickstarter.services.MockApiClient) NonNull(android.support.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) List(java.util.List) DiscoveryParams(com.kickstarter.services.DiscoveryParams) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Aggregations

ApiClientType (com.kickstarter.services.ApiClientType)31 Test (org.junit.Test)31 Environment (com.kickstarter.libs.Environment)25 MockApiClient (com.kickstarter.mock.services.MockApiClient)19 TestSubscriber (rx.observers.TestSubscriber)18 Intent (android.content.Intent)16 NonNull (androidx.annotation.NonNull)12 MockApiClient (com.kickstarter.services.MockApiClient)12 User (com.kickstarter.models.User)9 NonNull (android.support.annotation.NonNull)8 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)8 AccessTokenEnvelope (com.kickstarter.services.apiresponses.AccessTokenEnvelope)8 Update (com.kickstarter.models.Update)5 CurrentUserType (com.kickstarter.libs.CurrentUserType)4 Project (com.kickstarter.models.Project)3 Nullable (androidx.annotation.Nullable)2 ProjectNotification (com.kickstarter.models.ProjectNotification)2 MessageThreadsEnvelope (com.kickstarter.services.apiresponses.MessageThreadsEnvelope)2 Mailbox (com.kickstarter.ui.data.Mailbox)2 TestScheduler (rx.schedulers.TestScheduler)2