Search in sources :

Example 21 with ApiClientType

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

Example 22 with ApiClientType

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

the class UpdateViewModelTest method testUpdateViewModel_DeepLinkPost.

@Test
public void testUpdateViewModel_DeepLinkPost() {
    final String postId = "3254626";
    final Update update = UpdateFactory.update().toBuilder().sequence(2).build();
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<Update> fetchUpdate(@NonNull final String projectParam, @NonNull final String updateParam) {
            return Observable.just(update);
        }
    };
    final Environment environment = environment().toBuilder().apiClient(apiClient).build();
    final UpdateViewModel.ViewModel vm = new UpdateViewModel.ViewModel(environment);
    final TestSubscriber<String> webViewUrl = new TestSubscriber<>();
    vm.outputs.webViewUrl().subscribe(webViewUrl);
    // Start the intent with a project and update.
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, ProjectFactory.project()).putExtra(IntentKey.UPDATE_POST_ID, postId));
    // Initial update index url emits.
    webViewUrl.assertValues(update.urls().web().update());
}
Also used : MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.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 23 with ApiClientType

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

the class UpdateViewModelTest method testUpdateViewModel_DeepLinkCommentThread.

@Test
public void testUpdateViewModel_DeepLinkCommentThread() {
    final String postId = "3254626";
    final String commentableId = "Q29tbWVudC0zMzU2MTY4Ng";
    final Update update = UpdateFactory.update();
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<Update> fetchUpdate(@NonNull final String projectParam, @NonNull final String updateParam) {
            return Observable.just(update);
        }
    };
    final TestScheduler testScheduler = new TestScheduler();
    final Environment environment = environment().toBuilder().apiClient(apiClient).scheduler(testScheduler).build();
    final UpdateViewModel.ViewModel vm = new UpdateViewModel.ViewModel(environment);
    final TestSubscriber<Pair<String, Update>> startRootCommentsActivityToDeepLinkThreadActivity = new TestSubscriber<>();
    vm.outputs.startRootCommentsActivityToDeepLinkThreadActivity().subscribe(startRootCommentsActivityToDeepLinkThreadActivity);
    final TestSubscriber<String> webViewUrl = new TestSubscriber<>();
    vm.outputs.webViewUrl().subscribe(webViewUrl);
    final TestSubscriber<Pair<String, Boolean>> deepLinkToThreadActivity = new TestSubscriber<>();
    vm.deepLinkToThreadActivity().subscribe(deepLinkToThreadActivity);
    // Start the intent with a project and update.
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, ProjectFactory.project()).putExtra(IntentKey.UPDATE_POST_ID, postId).putExtra(IntentKey.IS_UPDATE_COMMENT, true).putExtra(IntentKey.COMMENT, commentableId));
    // Initial update index url emits.
    webViewUrl.assertValues(update.urls().web().update());
    deepLinkToThreadActivity.assertValue(Pair.create(commentableId, true));
    vm.inputs.goToCommentsActivityToDeepLinkThreadActivity(commentableId);
    testScheduler.advanceTimeBy(2, TimeUnit.SECONDS);
    startRootCommentsActivityToDeepLinkThreadActivity.assertValue(Pair.create(commentableId, update));
    startRootCommentsActivityToDeepLinkThreadActivity.assertValueCount(1);
}
Also used : MockApiClient(com.kickstarter.mock.services.MockApiClient) Intent(android.content.Intent) Update(com.kickstarter.models.Update) ApiClientType(com.kickstarter.services.ApiClientType) NonNull(androidx.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) TestScheduler(rx.schedulers.TestScheduler) Pair(android.util.Pair) Test(org.junit.Test)

Example 24 with ApiClientType

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

the class UpdateViewModelTest method testUpdateViewModel_DeepLinkComment.

@Test
public void testUpdateViewModel_DeepLinkComment() {
    final String postId = "3254626";
    final Update update = UpdateFactory.update();
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<Update> fetchUpdate(@NonNull final String projectParam, @NonNull final String updateParam) {
            return Observable.just(update);
        }
    };
    final TestScheduler testScheduler = new TestScheduler();
    final Environment environment = environment().toBuilder().apiClient(apiClient).scheduler(testScheduler).build();
    final UpdateViewModel.ViewModel vm = new UpdateViewModel.ViewModel(environment);
    final TestSubscriber<Update> startRootCommentsActivity = new TestSubscriber<>();
    vm.outputs.startRootCommentsActivity().subscribe(startRootCommentsActivity);
    final TestSubscriber<String> webViewUrl = new TestSubscriber<>();
    vm.outputs.webViewUrl().subscribe(webViewUrl);
    final TestSubscriber<Boolean> deepLinkToRootComment = new TestSubscriber<>();
    vm.hasCommentsDeepLinks().subscribe(deepLinkToRootComment);
    // Start the intent with a project and update.
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, ProjectFactory.project()).putExtra(IntentKey.UPDATE_POST_ID, postId).putExtra(IntentKey.IS_UPDATE_COMMENT, true));
    // Initial update index url emits.
    webViewUrl.assertValues(update.urls().web().update());
    deepLinkToRootComment.assertValue(true);
    vm.inputs.goToCommentsActivity();
    testScheduler.advanceTimeBy(2, TimeUnit.SECONDS);
    startRootCommentsActivity.assertValue(update);
    startRootCommentsActivity.assertValueCount(1);
}
Also used : MockApiClient(com.kickstarter.mock.services.MockApiClient) Intent(android.content.Intent) Update(com.kickstarter.models.Update) ApiClientType(com.kickstarter.services.ApiClientType) NonNull(androidx.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) TestScheduler(rx.schedulers.TestScheduler) Test(org.junit.Test)

Example 25 with ApiClientType

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

the class TwoFactorViewModelTest method testTwoFactorViewModel_GenericError.

@Test
public void testTwoFactorViewModel_GenericError() {
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<AccessTokenEnvelope> login(@NonNull final String email, @NonNull final String password, @NonNull final String code) {
            return Observable.error(ApiExceptionFactory.apiError(ErrorEnvelope.builder().httpCode(400).build()));
        }
    };
    final Environment environment = environment().toBuilder().apiClient(apiClient).build();
    final Intent intent = new Intent();
    intent.putExtra(IntentKey.EMAIL, "gina@kickstarter.com");
    intent.putExtra(IntentKey.PASSWORD, "hello");
    intent.putExtra(IntentKey.FACEBOOK_LOGIN, false);
    intent.putExtra(IntentKey.FACEBOOK_TOKEN, "");
    this.vm = new TwoFactorViewModel.ViewModel(environment);
    this.vm.intent(intent);
    this.vm.outputs.tfaSuccess().subscribe(this.tfaSuccess);
    this.vm.outputs.formSubmitting().subscribe(this.formSubmitting);
    this.vm.outputs.genericTfaError().subscribe(this.genericTfaError);
    this.vm.inputs.code("88888");
    this.vm.inputs.loginClick();
    this.formSubmitting.assertValues(true, false);
    this.tfaSuccess.assertNoValues();
    this.genericTfaError.assertValueCount(1);
    this.segmentTrack.assertValue(EventName.PAGE_VIEWED.getEventName());
}
Also used : AccessTokenEnvelope(com.kickstarter.services.apiresponses.AccessTokenEnvelope) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Environment(com.kickstarter.libs.Environment) Intent(android.content.Intent) 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