Search in sources :

Example 6 with MockApiClient

use of com.kickstarter.services.MockApiClient 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 7 with MockApiClient

use of com.kickstarter.services.MockApiClient in project android-oss by kickstarter.

the class ProjectIntentMapperTest method testProject_emitsFromKsrProjectUri.

@Test
public void testProject_emitsFromKsrProjectUri() {
    final Uri uri = Uri.parse("ksr://www.kickstarter.com/projects/1186238668/skull-graphic-tee");
    final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    final TestSubscriber<Project> resultTest = TestSubscriber.create();
    ProjectIntentMapper.project(intent, new MockApiClient()).subscribe(resultTest);
    resultTest.assertValueCount(1);
}
Also used : Project(com.kickstarter.models.Project) MockApiClient(com.kickstarter.services.MockApiClient) Intent(android.content.Intent) Uri(android.net.Uri) Test(org.junit.Test)

Example 8 with MockApiClient

use of com.kickstarter.services.MockApiClient in project android-oss by kickstarter.

the class ProjectIntentMapperTest method testProject_emitsFromProjectParamExtra.

@Test
public void testProject_emitsFromProjectParamExtra() {
    final Intent intent = new Intent().putExtra(IntentKey.PROJECT_PARAM, "skull-graphic-tee");
    final TestSubscriber<Project> resultTest = TestSubscriber.create();
    ProjectIntentMapper.project(intent, new MockApiClient()).subscribe(resultTest);
    resultTest.assertValueCount(1);
}
Also used : Project(com.kickstarter.models.Project) MockApiClient(com.kickstarter.services.MockApiClient) Intent(android.content.Intent) Test(org.junit.Test)

Example 9 with MockApiClient

use of com.kickstarter.services.MockApiClient 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 10 with MockApiClient

use of com.kickstarter.services.MockApiClient 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)

Aggregations

MockApiClient (com.kickstarter.services.MockApiClient)31 Test (org.junit.Test)30 Environment (com.kickstarter.libs.Environment)21 TestSubscriber (rx.observers.TestSubscriber)21 ApiClientType (com.kickstarter.services.ApiClientType)20 Intent (android.content.Intent)16 NonNull (android.support.annotation.NonNull)14 Project (com.kickstarter.models.Project)7 DiscoveryParams (com.kickstarter.services.DiscoveryParams)7 AccessTokenEnvelope (com.kickstarter.services.apiresponses.AccessTokenEnvelope)7 Uri (android.net.Uri)6 User (com.kickstarter.models.User)6 CurrentUserType (com.kickstarter.libs.CurrentUserType)3 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)3 Update (com.kickstarter.models.Update)3 List (java.util.List)3 KSRobolectricTestCase (com.kickstarter.KSRobolectricTestCase)2 ProjectFactory (com.kickstarter.factories.ProjectFactory)2 IntentKey (com.kickstarter.ui.IntentKey)2 Request (okhttp3.Request)2