Search in sources :

Example 11 with MockApiClient

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

the class DiscoveryIntentMapperTest method emitsFromParamsExtra.

@Test
public void emitsFromParamsExtra() {
    final DiscoveryParams params = DiscoveryParams.builder().build();
    final Intent intent = new Intent().putExtra(IntentKey.DISCOVERY_PARAMS, params);
    final TestSubscriber<DiscoveryParams> resultTest = TestSubscriber.create();
    DiscoveryIntentMapper.params(intent, new MockApiClient(), new MockApolloClient()).subscribe(resultTest);
    resultTest.assertValues(params);
}
Also used : MockApolloClient(com.kickstarter.mock.services.MockApolloClient) MockApiClient(com.kickstarter.mock.services.MockApiClient) Intent(android.content.Intent) DiscoveryParams(com.kickstarter.services.DiscoveryParams) Test(org.junit.Test)

Example 12 with MockApiClient

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

the class DiscoveryIntentMapperTest method emitsFromDiscoveryCategoryUri.

@Test
public void emitsFromDiscoveryCategoryUri() {
    final Uri uri = Uri.parse("https://www.kickstarter.com/discover/categories/music");
    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.assertValueCount(1);
}
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 13 with MockApiClient

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

the class DiscoveryIntentMapperTest method emitsFromDiscoveryLocationUri.

@Test
public void emitsFromDiscoveryLocationUri() {
    final Uri uri = Uri.parse("https://www.kickstarter.com/discover/places/sydney-au");
    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.assertValueCount(1);
}
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 14 with MockApiClient

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

the class DiscoveryIntentMapperTest method emitsFromAdvancedCategoryIdAndLocationIdUri.

@Test
public void emitsFromAdvancedCategoryIdAndLocationIdUri() {
    final Uri uri = Uri.parse("https://www.kickstarter.com/discover/advanced?category_id=1&location_id=1");
    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.assertValueCount(1);
}
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 15 with MockApiClient

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

the class DiscoveryViewModelTest method testShowSnackBar_whenIntentFromDeepLinkSuccessResponse_showErrorMessage.

@Test
public void testShowSnackBar_whenIntentFromDeepLinkSuccessResponse_showErrorMessage() {
    final String url = "https://*.kickstarter.com/profile/verify_email";
    final Intent intentWithUrl = new Intent().setData(Uri.parse(url));
    final ErrorEnvelope errorEnvelope = ErrorEnvelope.builder().httpCode(403).errorMessages(Collections.singletonList("expired")).build();
    final ApiException apiException = ApiExceptionFactory.apiError(errorEnvelope);
    final MockApiClient mockApiClient = new MockApiClient() {

        @NonNull
        @Override
        public Observable<EmailVerificationEnvelope> verifyEmail(@NonNull final String token) {
            return Observable.error(apiException);
        }
    };
    final Environment mockedClientEnvironment = environment().toBuilder().apiClient(mockApiClient).build();
    this.vm = new DiscoveryViewModel.ViewModel(mockedClientEnvironment);
    this.vm.getOutputs().showSuccessMessage().subscribe(this.showSuccessMessage);
    this.vm.getOutputs().showErrorMessage().subscribe(this.showErrorMessage);
    this.vm.intent(intentWithUrl);
    this.showSuccessMessage.assertNoValues();
    this.showErrorMessage.assertValue("expired");
}
Also used : EmailVerificationEnvelope(com.kickstarter.services.apiresponses.EmailVerificationEnvelope) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) ErrorEnvelope(com.kickstarter.services.apiresponses.ErrorEnvelope) Environment(com.kickstarter.libs.Environment) Intent(android.content.Intent) ApiException(com.kickstarter.services.ApiException) 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