Search in sources :

Example 21 with MockApiClient

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

the class KSRobolectricTestCase method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    final MockTrackingClient testTrackingClient = new MockTrackingClient();
    koalaTest = new TestSubscriber<>();
    testTrackingClient.eventNames.subscribe(koalaTest);
    environment = application().component().environment().toBuilder().apiClient(new MockApiClient()).currentConfig(new MockCurrentConfig()).webClient(new MockWebClient()).koala(new Koala(testTrackingClient)).build();
}
Also used : MockCurrentConfig(com.kickstarter.libs.MockCurrentConfig) MockWebClient(com.kickstarter.services.MockWebClient) MockApiClient(com.kickstarter.services.MockApiClient) Koala(com.kickstarter.libs.Koala) MockTrackingClient(com.kickstarter.libs.MockTrackingClient) Before(org.junit.Before)

Example 22 with MockApiClient

use of com.kickstarter.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()).subscribe(resultTest);
    resultTest.assertValues(DiscoveryParams.builder().build());
}
Also used : MockApiClient(com.kickstarter.services.MockApiClient) Intent(android.content.Intent) DiscoveryParams(com.kickstarter.services.DiscoveryParams) Uri(android.net.Uri) Test(org.junit.Test)

Example 23 with MockApiClient

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

the class ProjectIntentMapperTest method testProject_doesNotEmitFromHttpsProjectUri.

@Test
public void testProject_doesNotEmitFromHttpsProjectUri() {
    final Uri uri = Uri.parse("https://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.assertNoValues();
}
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 24 with MockApiClient

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

the class ProjectIntentMapperTest method testProject_emitsTwiceFromProjectExtra.

@Test
public void testProject_emitsTwiceFromProjectExtra() {
    final Project project = ProjectFactory.project();
    final Intent intent = new Intent().putExtra(IntentKey.PROJECT, project);
    final TestSubscriber<Project> resultTest = TestSubscriber.create();
    ProjectIntentMapper.project(intent, new MockApiClient()).subscribe(resultTest);
    resultTest.assertValueCount(2);
}
Also used : Project(com.kickstarter.models.Project) MockApiClient(com.kickstarter.services.MockApiClient) Intent(android.content.Intent) Test(org.junit.Test)

Example 25 with MockApiClient

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

the class LoginViewModelTest method testLoginTfaChallenge.

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

        @Override
        @NonNull
        public Observable<AccessTokenEnvelope> login(@NonNull final String email, @NonNull final String password) {
            return Observable.error(ApiExceptionFactory.tfaRequired());
        }
    };
    final Environment environment = environment().toBuilder().apiClient(apiClient).build();
    final LoginViewModel vm = new LoginViewModel(environment);
    final TestSubscriber<Void> tfaChallenge = new TestSubscriber<>();
    vm.errors.tfaChallenge().subscribe(tfaChallenge);
    final TestSubscriber<Void> loginSuccess = new TestSubscriber<>();
    vm.outputs.loginSuccess().subscribe(loginSuccess);
    vm.inputs.email("hello@kickstarter.com");
    vm.inputs.password("danisawesome");
    vm.inputs.loginClick();
    loginSuccess.assertNoValues();
    tfaChallenge.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