Search in sources :

Example 61 with MockApiClient

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

the class DiscoveryIntentMapperTest method emitsFromDiscoveryUri.

@Test
public void emitsFromDiscoveryUri() {
    final Uri uri = Uri.parse("https://www.kickstarter.com/discover");
    final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    final TestSubscriber<DiscoveryParams> resultTest = TestSubscriber.create();
    DiscoveryIntentMapper.params(intent, new MockApiClient(), new MockApolloClient()).subscribe(resultTest);
    resultTest.assertValues(DiscoveryParams.builder().build());
}
Also used : MockApolloClient(com.kickstarter.mock.services.MockApolloClient) MockApiClient(com.kickstarter.mock.services.MockApiClient) Intent(android.content.Intent) DiscoveryParams(com.kickstarter.services.DiscoveryParams) Uri(android.net.Uri) Test(org.junit.Test)

Example 62 with MockApiClient

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

the class ActivityFeedViewModelTest method testUser_LoggedIn_SwipeRefreshed.

@Test
public void testUser_LoggedIn_SwipeRefreshed() {
    final CurrentUserType currentUser = new MockCurrentUser();
    final User initialUser = UserFactory.user().toBuilder().unseenActivityCount(3).build();
    currentUser.login(initialUser, "deadbeef");
    final User updatedUser = UserFactory.user();
    final Environment environment = this.environment().toBuilder().apiClient(new MockApiClient() {

        @NonNull
        @Override
        public Observable<User> fetchCurrentUser() {
            return Observable.just(updatedUser);
        }
    }).currentUser(currentUser).build();
    environment.currentUser().loggedInUser().subscribe(this.user);
    setUpEnvironment(environment);
    this.surveys.assertValueCount(1);
    this.user.assertValues(initialUser, updatedUser);
    this.vm.inputs.refresh();
    this.surveys.assertValueCount(2);
    this.user.assertValues(initialUser, updatedUser);
}
Also used : User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Environment(com.kickstarter.libs.Environment) CurrentUserType(com.kickstarter.libs.CurrentUserType) Observable(rx.Observable) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 63 with MockApiClient

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

the class ActivityFeedViewModelTest method testUser_whenLoggedInAndResumedWithErroredBackings.

@Test
public void testUser_whenLoggedInAndResumedWithErroredBackings() {
    final CurrentUserType currentUser = new MockCurrentUser();
    final User initialUser = UserFactory.user().toBuilder().erroredBackingsCount(3).build();
    currentUser.login(initialUser, "token");
    final User updatedUser = UserFactory.user();
    final Environment environment = this.environment().toBuilder().apiClient(new MockApiClient() {

        @Override
        @NonNull
        public Observable<User> fetchCurrentUser() {
            return Observable.just(updatedUser);
        }
    }).currentUser(currentUser).build();
    environment.currentUser().loggedInUser().subscribe(this.user);
    setUpEnvironment(environment);
    this.user.assertValues(initialUser, updatedUser);
    this.vm.inputs.resume();
    this.user.assertValues(initialUser, updatedUser);
}
Also used : User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Environment(com.kickstarter.libs.Environment) CurrentUserType(com.kickstarter.libs.CurrentUserType) Observable(rx.Observable) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 64 with MockApiClient

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

the class ActivityFeedViewModelTest method testLoginFlow.

@Test
public void testLoginFlow() {
    final ApiClientType apiClient = new MockApiClient();
    final CurrentUserType currentUser = new MockCurrentUser();
    final Environment environment = this.environment().toBuilder().apiClient(apiClient).currentUser(currentUser).build();
    setUpEnvironment(environment);
    // Empty activity feed with login button should be shown.
    this.loggedOutEmptyStateIsVisible.assertValue(true);
    // Login.
    this.vm.inputs.emptyActivityFeedLoginClicked(null);
    this.goToLogin.assertValueCount(1);
    currentUser.refresh(UserFactory.user());
    // Empty states are not shown when activities emit on successful login.
    this.activityList.assertValueCount(1);
    this.loggedOutEmptyStateIsVisible.assertValues(true, false);
    this.loggedInEmptyStateIsVisible.assertValue(false);
}
Also used : MockApiClient(com.kickstarter.mock.services.MockApiClient) Environment(com.kickstarter.libs.Environment) CurrentUserType(com.kickstarter.libs.CurrentUserType) ApiClientType(com.kickstarter.services.ApiClientType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 65 with MockApiClient

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

the class ActivityFeedViewModelTest method testErroredBackings_whenLoggedIn.

@Test
public void testErroredBackings_whenLoggedIn() {
    final CurrentUserType currentUser = new MockCurrentUser();
    final User initialUser = UserFactory.user();
    currentUser.login(initialUser, "deadbeef");
    final User updatedUser = UserFactory.user();
    final Environment environment = this.environment().toBuilder().apiClient(new MockApiClient() {

        @NonNull
        @Override
        public Observable<User> fetchCurrentUser() {
            return Observable.just(updatedUser);
        }
    }).currentUser(currentUser).build();
    setUpEnvironment(environment);
    this.erroredBackings.assertValueCount(1);
    this.vm.inputs.refresh();
    this.erroredBackings.assertValueCount(2);
    this.segmentTrack.assertValue(EventName.PAGE_VIEWED.getEventName());
}
Also used : User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Environment(com.kickstarter.libs.Environment) CurrentUserType(com.kickstarter.libs.CurrentUserType) Observable(rx.Observable) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Aggregations

MockApiClient (com.kickstarter.mock.services.MockApiClient)66 Test (org.junit.Test)64 NonNull (androidx.annotation.NonNull)47 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)33 Environment (com.kickstarter.libs.Environment)29 Intent (android.content.Intent)28 Project (com.kickstarter.models.Project)25 ApiClientType (com.kickstarter.services.ApiClientType)19 User (com.kickstarter.models.User)14 CurrentUserType (com.kickstarter.libs.CurrentUserType)12 DiscoveryParams (com.kickstarter.services.DiscoveryParams)12 MessageThreadEnvelope (com.kickstarter.services.apiresponses.MessageThreadEnvelope)12 Backing (com.kickstarter.models.Backing)9 MessageThread (com.kickstarter.models.MessageThread)9 TestScheduler (rx.schedulers.TestScheduler)8 TestSubscriber (rx.observers.TestSubscriber)7 Update (com.kickstarter.models.Update)6 AccessTokenEnvelope (com.kickstarter.services.apiresponses.AccessTokenEnvelope)6 DiscoverEnvelope (com.kickstarter.services.apiresponses.DiscoverEnvelope)6 ProjectsEnvelope (com.kickstarter.services.apiresponses.ProjectsEnvelope)6