Search in sources :

Example 1 with EmailVerificationEnvelope

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

Example 2 with EmailVerificationEnvelope

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

the class DiscoveryViewModelTest method testShowSnackBar_whenIntentFromDeepLinkSuccessResponse_showSuccessMessage.

@Test
public void testShowSnackBar_whenIntentFromDeepLinkSuccessResponse_showSuccessMessage() {
    final String url = "https://*.kickstarter.com/profile/verify_email";
    final Intent intentWithUrl = new Intent().setData(Uri.parse(url));
    final MockApiClient mockApiClient = new MockApiClient() {

        @NonNull
        @Override
        public Observable<EmailVerificationEnvelope> verifyEmail(@NonNull final String token) {
            return Observable.just(EmailVerificationEnvelope.Companion.builder().code(200).message("Success").build());
        }
    };
    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.assertValue("Success");
    this.showErrorMessage.assertNoValues();
}
Also used : EmailVerificationEnvelope(com.kickstarter.services.apiresponses.EmailVerificationEnvelope) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Environment(com.kickstarter.libs.Environment) Intent(android.content.Intent) Test(org.junit.Test)

Aggregations

Intent (android.content.Intent)2 NonNull (androidx.annotation.NonNull)2 Environment (com.kickstarter.libs.Environment)2 MockApiClient (com.kickstarter.mock.services.MockApiClient)2 EmailVerificationEnvelope (com.kickstarter.services.apiresponses.EmailVerificationEnvelope)2 Test (org.junit.Test)2 ApiException (com.kickstarter.services.ApiException)1 ErrorEnvelope (com.kickstarter.services.apiresponses.ErrorEnvelope)1