diff --git a/transfermethodrepository/src/main/java/com/hyperwallet/android/ui/transfermethod/repository/TransferMethodConfigurationRepository.java b/transfermethodrepository/src/main/java/com/hyperwallet/android/ui/transfermethod/repository/TransferMethodConfigurationRepository.java index 69ee0ab90..153d3c87e 100644 --- a/transfermethodrepository/src/main/java/com/hyperwallet/android/ui/transfermethod/repository/TransferMethodConfigurationRepository.java +++ b/transfermethodrepository/src/main/java/com/hyperwallet/android/ui/transfermethod/repository/TransferMethodConfigurationRepository.java @@ -37,6 +37,9 @@ public interface TransferMethodConfigurationRepository { void getKeys(@NonNull final LoadKeysCallback loadKeysCallback); + void getTransferMethodTypesFeeAndProcessingTime(@NonNull final String country, @NonNull final String currency, + @NonNull final LoadKeysCallback loadKeysCallback); + void getFields(@NonNull final String country, @NonNull final String currency, @NonNull final String transferMethodType, @NonNull final String transferMethodProfileType, @NonNull final LoadFieldsCallback loadFieldsCallback); diff --git a/transfermethodrepository/src/main/java/com/hyperwallet/android/ui/transfermethod/repository/TransferMethodConfigurationRepositoryImpl.java b/transfermethodrepository/src/main/java/com/hyperwallet/android/ui/transfermethod/repository/TransferMethodConfigurationRepositoryImpl.java index a6a2793a9..da6153fe9 100644 --- a/transfermethodrepository/src/main/java/com/hyperwallet/android/ui/transfermethod/repository/TransferMethodConfigurationRepositoryImpl.java +++ b/transfermethodrepository/src/main/java/com/hyperwallet/android/ui/transfermethod/repository/TransferMethodConfigurationRepositoryImpl.java @@ -39,6 +39,7 @@ import com.hyperwallet.android.model.graphql.HyperwalletTransferMethodConfigurationKey; import com.hyperwallet.android.model.graphql.query.TransferMethodConfigurationFieldQuery; import com.hyperwallet.android.model.graphql.query.TransferMethodConfigurationKeysQuery; +import com.hyperwallet.android.model.graphql.query.TransferMethodTypesFeeAndProcessingTimesQuery; import com.hyperwallet.android.ui.common.repository.EspressoIdlingResource; import java.util.HashMap; @@ -97,6 +98,31 @@ public Handler getHandler() { }); } + @VisibleForTesting + void getTransferMethodTypesFeeAndProcessingTimeKeyResult(final String country, final String currency, final LoadKeysCallback loadKeysCallback){ + TransferMethodTypesFeeAndProcessingTimesQuery query = new TransferMethodTypesFeeAndProcessingTimesQuery(country, currency); + EspressoIdlingResource.increment(); + getHyperwallet().retrieveTransferMethodTypesFeesAndProcessingTimes(query, + new HyperwalletListener() { + @Override + public void onSuccess(@Nullable HyperwalletTransferMethodConfigurationKey result) { + loadKeysCallback.onKeysLoaded(result); + EspressoIdlingResource.decrement(); + } + + @Override + public void onFailure(HyperwalletException exception) { + loadKeysCallback.onError(exception.getErrors()); + EspressoIdlingResource.decrement(); + } + + @Override + public Handler getHandler() { + return mHandler; + } + }); + } + @VisibleForTesting void getTransferMethodConfigurationFieldResult(@NonNull final String country, @@ -143,6 +169,12 @@ public synchronized void getKeys(@NonNull final LoadKeysCallback loadKeysCallbac } } + @Override + public synchronized void getTransferMethodTypesFeeAndProcessingTime(@NonNull String country, @NonNull String currency, + @NonNull LoadKeysCallback loadKeysCallback) { + getTransferMethodTypesFeeAndProcessingTimeKeyResult(country, currency, loadKeysCallback); + } + @Override public synchronized void getFields(@NonNull final String country, @NonNull final String currency, @NonNull final String transferMethodType, diff --git a/transfermethodui/src/androidTest/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodTest.java b/transfermethodui/src/androidTest/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodTest.java index 3a7b10713..ee3f23761 100644 --- a/transfermethodui/src/androidTest/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodTest.java +++ b/transfermethodui/src/androidTest/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodTest.java @@ -98,6 +98,9 @@ public void testSelectTransferMethod_verifyCorrectLabelsDisplayed() { mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_response.json")).mock(); + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("successful_tmc_keys_fee_processing_time_CA_response.json")).mock(); + mActivityTestRule.launchActivity(null); onView(withId(R.id.toolbar)).check(matches(isDisplayed())); @@ -119,6 +122,12 @@ public void testSelectTransferMethod_verifyCountrySelectionList() { mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_response.json")).mock(); + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("successful_tmc_keys_fee_processing_time_CA_response.json")).mock(); + + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("successful_tmc_keys_fee_processing_time_CA_response.json")).mock(); + mActivityTestRule.launchActivity(null); onView(withId(R.id.select_transfer_method_country_value)).perform(click()); @@ -147,6 +156,12 @@ public void testSelectTransferMethod_verifyCountrySelectionSearch() { mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_large_response.json")).mock(); + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("successful_tmc_keys_fee_processing_time_CA_response.json")).mock(); + + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("successful_tmc_keys_fee_processing_time_CA_response.json")).mock(); + mActivityTestRule.launchActivity(null); onView(withId(R.id.select_transfer_method_country_value)).perform(click()); @@ -169,6 +184,16 @@ public void testSelectTransferMethod_verifyCurrencySelectionList() { mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_response.json")).mock(); + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("successful_tmc_keys_fee_processing_time_US_response.json")).mock(); + + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("successful_tmc_keys_fee_processing_time_US_response.json")).mock(); + + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("successful_tmc_keys_fee_processing_time_US_response.json")).mock(); + + mActivityTestRule.launchActivity(null); onView(withId(R.id.select_transfer_method_country_value)).perform(click()); @@ -195,6 +220,10 @@ public void testSelectTransferMethod_verifyTransferMethodsList() { mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_response.json")).mock(); + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("successful_tmc_keys_fee_processing_time_US_response.json")).mock(); + + mActivityTestRule.launchActivity(null); onView(withId(R.id.select_transfer_method_country_value)).check(matches(withText("United States"))); @@ -266,6 +295,10 @@ public void testSelectTransferMethod_verifyTransferMethodsListEmptyFee() { mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_empty_fee_response.json")).mock(); + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("successful_tmc_keys_empty_fee_US_response.json")).mock(); + + mActivityTestRule.launchActivity(null); onView(withId(R.id.select_transfer_method_country_value)).check(matches(withText("United States"))); @@ -287,6 +320,10 @@ public void testSelectTransferMethod_verifyTransferMethodsListEmptyProcessing() mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_empty_processing_response.json")).mock(); + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("successful_tmc_keys_empty_processing_US_response.json")).mock(); + + mActivityTestRule.launchActivity(null); onView(withId(R.id.select_transfer_method_country_value)).check(matches(withText("United States"))); @@ -311,6 +348,14 @@ public void testSelectTransferMethod_verifyTransferMethodsListUpdatedOnSelection mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_response.json")).mock(); + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("successful_tmc_keys_fee_processing_time_US_response.json")).mock(); + + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("successful_tmc_keys_fee_processing_time_CA_response.json")).mock(); + + + mActivityTestRule.launchActivity(null); onView(withId(R.id.select_transfer_method_country_value)).check(matches(withText("United States"))); @@ -354,6 +399,10 @@ public void testSelectTransferMethod_verifyIntentIndividualUser() { .getResourceContent("user_response.json")).mock(); mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_response.json")).mock(); + + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("successful_tmc_keys_fee_processing_time_US_response.json")).mock(); + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_fields_bank_account_response.json")).mock(); @@ -373,6 +422,10 @@ public void testSelectTransferMethod_verifyIntentBusinessUser() { .getResourceContent("user_business_response.json")).mock(); mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_response.json")).mock(); + + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("successful_tmc_keys_fee_processing_time_US_response.json")).mock(); + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_fields_bank_account_response.json")).mock(); @@ -392,6 +445,10 @@ public void testSelectTransferMethod_clickBankAccountOpensAddTransferMethodUi() .getResourceContent("user_response.json")).mock(); mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_response.json")).mock(); + + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("successful_tmc_keys_fee_processing_time_US_response.json")).mock(); + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_fields_bank_account_response.json")).mock(); @@ -409,6 +466,10 @@ public void testSelectTransferMethod_clickBankCardOpensAddTransferMethodUi() { .getResourceContent("user_response.json")).mock(); mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_response.json")).mock(); + + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("successful_tmc_keys_fee_processing_time_US_response.json")).mock(); + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_fields_bank_card_response.json")).mock(); @@ -427,6 +488,9 @@ public void testSelectTransferMethod_verifyThatCountryIsFromUserProfile() { mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_response.json")).mock(); + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("successful_tmc_keys_fee_processing_time_CA_response.json")).mock(); + mActivityTestRule.launchActivity(null); onView(withId(R.id.select_transfer_method_country_value)).check(matches(withText("Canada"))); @@ -440,6 +504,10 @@ public void testSelectTransferMethod_verifyDefaultsToUSWhenUserProfileCountryIsN mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_response.json")).mock(); + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("successful_tmc_keys_fee_processing_time_US_response.json")).mock(); + + mActivityTestRule.launchActivity(null); onView(withId(R.id.select_transfer_method_country_value)).check(matches(withText("United States"))); @@ -453,6 +521,10 @@ public void testSelectTransferMethod_verifyDefaultsToUSWhenUserProfileDoesNotHav mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_response.json")).mock(); + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("successful_tmc_keys_fee_processing_time_US_response.json")).mock(); + + mActivityTestRule.launchActivity(null); onView(withId(R.id.select_transfer_method_country_value)).check(matches(withText("United States"))); @@ -466,6 +538,12 @@ public void testSelectTransferMethod_verifyNoFeeLabelsDisplayed() { mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_response.json")).mock(); + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("successful_tmc_keys_fee_processing_time_US_response.json")).mock(); + + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("successful_tmc_keys_no_fee_response.json")).mock(); + mActivityTestRule.launchActivity(null); onView(withId(R.id.toolbar)).check(matches(isDisplayed())); @@ -523,6 +601,12 @@ public void testSelectTransferMethod_verifyMixedFeeIsDisplayed() { mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_mixedfee_response.json")).mock(); + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("successful_tmc_keys_fee_processing_time_US_response.json")).mock(); + + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("successful_tmc_keys_mixed_fee_CN_response.json")).mock(); + mActivityTestRule.launchActivity(null); onView(withId(R.id.toolbar)).check(matches(isDisplayed())); diff --git a/transfermethodui/src/main/java/com/hyperwallet/android/ui/transfermethod/view/SelectTransferMethodPresenter.java b/transfermethodui/src/main/java/com/hyperwallet/android/ui/transfermethod/view/SelectTransferMethodPresenter.java index 17105aa23..7e529c0c6 100644 --- a/transfermethodui/src/main/java/com/hyperwallet/android/ui/transfermethod/view/SelectTransferMethodPresenter.java +++ b/transfermethodui/src/main/java/com/hyperwallet/android/ui/transfermethod/view/SelectTransferMethodPresenter.java @@ -102,17 +102,11 @@ public void onKeysLoaded(@Nullable final HyperwalletTransferMethodConfigurationK return; } - mView.hideProgressBar(); - Set transferMethodTypes = - key.getTransferMethodType(country.getCode(), currencyCodeString) != null - ? key.getTransferMethodType(country.getCode(), currencyCodeString) : - new HashSet(); - mView.showTransferMethodCountry(country.getCode()); mView.showTransferMethodCurrency(currencyCodeString); - mView.showTransferMethodTypes( - getTransferMethodSelectionItems(country.getCode(), currencyCodeString, - user.getProfileType(), transferMethodTypes)); + + loadFeeAndProcessingTimeAndShowTransferMethods(country.getCode(), currencyCodeString, + user); } @Override @@ -139,6 +133,7 @@ private void showErrorLoadTransferMethods(@NonNull Errors errors) { @Override public void loadCurrency(final boolean forceUpdate, @NonNull final String countryCode) { + mView.showProgressBar(); if (forceUpdate) { mTransferMethodConfigurationRepository.refreshKeys(); @@ -156,17 +151,12 @@ public void onKeysLoaded(@Nullable final HyperwalletTransferMethodConfigurationK List currencies = key.getCurrencies(countryCode) != null ? new ArrayList<>(key.getCurrencies(countryCode)) : new ArrayList(); - String currencyCode = currencies.get(0).getCode(); - Set transferMethodTypes = - key.getTransferMethodType(countryCode, currencyCode) != null ? - key.getTransferMethodType(countryCode, currencyCode) : - new HashSet(); mView.showTransferMethodCountry(countryCode); mView.showTransferMethodCurrency(currencies.get(0).getCode()); - mView.showTransferMethodTypes(getTransferMethodSelectionItems(countryCode, - currencies.get(0).getCode(), - user.getProfileType(), transferMethodTypes)); + + loadFeeAndProcessingTimeAndShowTransferMethods(countryCode, currencies.get(0).getCode(), + user); } @Override @@ -193,6 +183,8 @@ private void showErrorLoadCurrency(@NonNull Errors errors) { @Override public void loadTransferMethodTypes(final boolean forceUpdate, @NonNull final String countryCode, @NonNull final String currencyCode) { + mView.showProgressBar(); + if (forceUpdate) { mTransferMethodConfigurationRepository.refreshKeys(); } @@ -200,6 +192,7 @@ public void loadTransferMethodTypes(final boolean forceUpdate, mUserRepository.loadUser(new UserRepository.LoadUserCallback() { @Override public void onUserLoaded(@NonNull final User user) { + mView.showProgressBar(); mTransferMethodConfigurationRepository.getKeys( new TransferMethodConfigurationRepository.LoadKeysCallback() { @Override @@ -207,16 +200,10 @@ public void onKeysLoaded(@Nullable final HyperwalletTransferMethodConfigurationK if (!mView.isActive()) { return; } - - Set transferMethodTypes = - key.getTransferMethodType(countryCode, currencyCode) != null ? - key.getTransferMethodType(countryCode, currencyCode) : - new HashSet(); mView.showTransferMethodCountry(countryCode); mView.showTransferMethodCurrency(currencyCode); - mView.showTransferMethodTypes( - getTransferMethodSelectionItems(countryCode, currencyCode, - user.getProfileType(), transferMethodTypes)); + + loadFeeAndProcessingTimeAndShowTransferMethods(countryCode, currencyCode, user); } @Override @@ -322,4 +309,28 @@ private List getTransferMethodSelectionItems( } return selectionItems; } + + private void loadFeeAndProcessingTimeAndShowTransferMethods(final String countryCode, final String currencyCode, + final User user) { + mTransferMethodConfigurationRepository.getTransferMethodTypesFeeAndProcessingTime(countryCode, currencyCode, + new TransferMethodConfigurationRepository.LoadKeysCallback() { + @Override + public void onKeysLoaded( + @Nullable final HyperwalletTransferMethodConfigurationKey transferMethodConfigurationKey) { + mView.hideProgressBar(); + Set transferMethodTypes = + transferMethodConfigurationKey.getTransferMethodType( + countryCode, currencyCode) != null + ? transferMethodConfigurationKey.getTransferMethodType( + countryCode, currencyCode) : new HashSet(); + mView.showTransferMethodTypes(getTransferMethodSelectionItems( + countryCode, currencyCode, user.getProfileType(), transferMethodTypes)); + } + + @Override + public void onError(@NonNull Errors errors) { + showErrorLoadTransferMethods(errors); + } + }); + } } diff --git a/transfermethodui/src/test/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenterTest.java b/transfermethodui/src/test/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenterTest.java index ad4602bf6..c179c48f7 100644 --- a/transfermethodui/src/test/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenterTest.java +++ b/transfermethodui/src/test/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenterTest.java @@ -65,6 +65,7 @@ public class SelectTransferMethodPresenterTest { private HyperwalletTransferMethodConfigurationKey mResult; private HyperwalletTransferMethodConfigurationKey mPartialResult; + private HyperwalletTransferMethodConfigurationKey mFeeAndProcessingTimeResult; private User mUser; private SelectTransferMethodPresenter selectTransferMethodPresenter; @@ -83,6 +84,11 @@ public void initialize() throws Exception { final JSONObject userJsonObject = new JSONObject(userResponseBody); mUser = new User(userJsonObject); + String feeAndProcessingTimeResponseBody = externalResourceManager.getResourceContent( + "successful_tmc_keys_fee_processing_time_CA_response.json"); + final JSONObject feeAndProcessingTimeJsonObject = new JSONObject(feeAndProcessingTimeResponseBody); + mFeeAndProcessingTimeResult = new TransferMethodConfigurationKeyResult(feeAndProcessingTimeJsonObject); + selectTransferMethodPresenter = new SelectTransferMethodPresenter(view, mTransferMethodConfigurationRepository, mUserRepository); } @@ -103,6 +109,17 @@ public Object answer(InvocationOnMock invocation) { }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + TransferMethodConfigurationRepository.LoadKeysCallback callback = + (TransferMethodConfigurationRepository.LoadKeysCallback) invocation.getArguments()[2]; + callback.onKeysLoaded(mFeeAndProcessingTimeResult); + return callback; + } + }).when(mTransferMethodConfigurationRepository).getTransferMethodTypesFeeAndProcessingTime(anyString(), anyString(), any( + TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) { @@ -115,7 +132,7 @@ public Object answer(InvocationOnMock invocation) { UserRepository.LoadUserCallback.class)); // Then - selectTransferMethodPresenter.loadTransferMethodConfigurationKeys(false, "CA", "CAD"); + selectTransferMethodPresenter.loadTransferMethodConfigurationKeys(true, "CA", "CAD"); verify(view).showTransferMethodCountry("CA"); verify(view).showTransferMethodCurrency("CAD"); @@ -129,6 +146,58 @@ public Object answer(InvocationOnMock invocation) { verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString(), anyString()); } + @Test + public void testLoadTransferMethodConfigurationKeys_loadsFeeAndProcessingTimeKeysIntoViewOnError() { + // When + when(view.isActive()).thenReturn(true); + + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + TransferMethodConfigurationRepository.LoadKeysCallback callback = + (TransferMethodConfigurationRepository.LoadKeysCallback) invocation.getArguments()[0]; + callback.onKeysLoaded(mResult); + return callback; + } + }).when(mTransferMethodConfigurationRepository).getKeys(any( + TransferMethodConfigurationRepository.LoadKeysCallback.class)); + + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + TransferMethodConfigurationRepository.LoadKeysCallback callback = + (TransferMethodConfigurationRepository.LoadKeysCallback) invocation.getArguments()[2]; + callback.onError(errors); + return callback; + } + }).when(mTransferMethodConfigurationRepository).getTransferMethodTypesFeeAndProcessingTime(anyString(), anyString(), any( + TransferMethodConfigurationRepository.LoadKeysCallback.class)); + + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + UserRepository.LoadUserCallback userCallback = + (UserRepository.LoadUserCallback) invocation.getArguments()[0]; + userCallback.onUserLoaded(mUser); + return userCallback; + } + }).when(mUserRepository).loadUser(any( + UserRepository.LoadUserCallback.class)); + + // Then + selectTransferMethodPresenter.loadTransferMethodConfigurationKeys(false, "CA", "CAD"); + + verify(view).showTransferMethodCountry("CA"); + verify(view).showTransferMethodCurrency("CAD"); + verify(view, never()).showTransferMethodTypes(ArgumentMatchers.anyList()); + verify(view).showErrorLoadTransferMethodConfigurationKeys(ArgumentMatchers.anyList()); + verify(view, never()).showErrorLoadCurrency(ArgumentMatchers.anyList()); + verify(view, never()).showErrorLoadTransferMethodTypes(ArgumentMatchers.anyList()); + verify(view, never()).showErrorLoadCountrySelection(ArgumentMatchers.anyList()); + verify(view, never()).showErrorLoadCurrencySelection(ArgumentMatchers.anyList()); + verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString(), anyString()); + } + @Test public void testLoadTransferMethodConfigurationKeys_loadsKeysIntoViewOnSuccessInactive() { // When @@ -145,6 +214,17 @@ public Object answer(InvocationOnMock invocation) { }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + TransferMethodConfigurationRepository.LoadKeysCallback callback = + (TransferMethodConfigurationRepository.LoadKeysCallback) invocation.getArguments()[2]; + callback.onKeysLoaded(mFeeAndProcessingTimeResult); + return callback; + } + }).when(mTransferMethodConfigurationRepository).getTransferMethodTypesFeeAndProcessingTime(anyString(), anyString(), any( + TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) { @@ -186,6 +266,17 @@ public Object answer(InvocationOnMock invocation) { }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + TransferMethodConfigurationRepository.LoadKeysCallback callback = + (TransferMethodConfigurationRepository.LoadKeysCallback) invocation.getArguments()[2]; + callback.onKeysLoaded(mFeeAndProcessingTimeResult); + return callback; + } + }).when(mTransferMethodConfigurationRepository).getTransferMethodTypesFeeAndProcessingTime(anyString(), anyString(), any( + TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) { @@ -221,6 +312,17 @@ public Object answer(InvocationOnMock invocation) { }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + TransferMethodConfigurationRepository.LoadKeysCallback callback = + (TransferMethodConfigurationRepository.LoadKeysCallback) invocation.getArguments()[2]; + callback.onKeysLoaded(mFeeAndProcessingTimeResult); + return callback; + } + }).when(mTransferMethodConfigurationRepository).getTransferMethodTypesFeeAndProcessingTime(anyString(), anyString(), any( + TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) { @@ -263,6 +365,17 @@ public Object answer(InvocationOnMock invocation) { }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + TransferMethodConfigurationRepository.LoadKeysCallback callback = + (TransferMethodConfigurationRepository.LoadKeysCallback) invocation.getArguments()[2]; + callback.onKeysLoaded(mFeeAndProcessingTimeResult); + return callback; + } + }).when(mTransferMethodConfigurationRepository).getTransferMethodTypesFeeAndProcessingTime(anyString(), anyString(), any( + TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) { @@ -310,6 +423,17 @@ public Object answer(InvocationOnMock invocation) { }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + TransferMethodConfigurationRepository.LoadKeysCallback callback = + (TransferMethodConfigurationRepository.LoadKeysCallback) invocation.getArguments()[2]; + callback.onKeysLoaded(mFeeAndProcessingTimeResult); + return callback; + } + }).when(mTransferMethodConfigurationRepository).getTransferMethodTypesFeeAndProcessingTime(anyString(), anyString(), any( + TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) { @@ -325,7 +449,7 @@ public Object answer(InvocationOnMock invocation) { selectTransferMethodPresenter.loadCurrency(false, "CA"); verify(view).showTransferMethodCurrency("CAD"); - verify(view).showTransferMethodTypes(ArgumentMatchers.anyList()); + // verify(view).showTransferMethodTypes(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadTransferMethodConfigurationKeys( ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadCurrency(ArgumentMatchers.anyList()); @@ -352,6 +476,19 @@ public Object answer(InvocationOnMock invocation) { } }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); + + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + TransferMethodConfigurationRepository.LoadKeysCallback callback = + (TransferMethodConfigurationRepository.LoadKeysCallback) invocation.getArguments()[2]; + callback.onKeysLoaded(mFeeAndProcessingTimeResult); + return callback; + } + }).when(mTransferMethodConfigurationRepository).getTransferMethodTypesFeeAndProcessingTime(anyString(), anyString(), any( + TransferMethodConfigurationRepository.LoadKeysCallback.class)); + + doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) { @@ -400,6 +537,17 @@ public Object answer(InvocationOnMock invocation) { }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + TransferMethodConfigurationRepository.LoadKeysCallback callback = + (TransferMethodConfigurationRepository.LoadKeysCallback) invocation.getArguments()[2]; + callback.onKeysLoaded(mFeeAndProcessingTimeResult); + return callback; + } + }).when(mTransferMethodConfigurationRepository).getTransferMethodTypesFeeAndProcessingTime(anyString(), anyString(), any( + TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) { @@ -436,6 +584,17 @@ public Object answer(InvocationOnMock invocation) { }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + TransferMethodConfigurationRepository.LoadKeysCallback callback = + (TransferMethodConfigurationRepository.LoadKeysCallback) invocation.getArguments()[2]; + callback.onKeysLoaded(mFeeAndProcessingTimeResult); + return callback; + } + }).when(mTransferMethodConfigurationRepository).getTransferMethodTypesFeeAndProcessingTime(anyString(), anyString(), any( + TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) { @@ -449,7 +608,7 @@ public Object answer(InvocationOnMock invocation) { // Then - selectTransferMethodPresenter.loadTransferMethodTypes(false, "CA", "CAD"); + selectTransferMethodPresenter.loadTransferMethodTypes(true, "CA", "CAD"); verify(view).showTransferMethodTypes(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadTransferMethodConfigurationKeys( @@ -478,6 +637,17 @@ public Object answer(InvocationOnMock invocation) { }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + TransferMethodConfigurationRepository.LoadKeysCallback callback = + (TransferMethodConfigurationRepository.LoadKeysCallback) invocation.getArguments()[2]; + callback.onKeysLoaded(mFeeAndProcessingTimeResult); + return callback; + } + }).when(mTransferMethodConfigurationRepository).getTransferMethodTypesFeeAndProcessingTime(anyString(), anyString(), any( + TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) { @@ -520,6 +690,17 @@ public Object answer(InvocationOnMock invocation) { }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + TransferMethodConfigurationRepository.LoadKeysCallback callback = + (TransferMethodConfigurationRepository.LoadKeysCallback) invocation.getArguments()[2]; + callback.onKeysLoaded(mFeeAndProcessingTimeResult); + return callback; + } + }).when(mTransferMethodConfigurationRepository).getTransferMethodTypesFeeAndProcessingTime(anyString(), anyString(), any( + TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) { @@ -554,6 +735,17 @@ public Object answer(InvocationOnMock invocation) { }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + TransferMethodConfigurationRepository.LoadKeysCallback callback = + (TransferMethodConfigurationRepository.LoadKeysCallback) invocation.getArguments()[2]; + callback.onKeysLoaded(mFeeAndProcessingTimeResult); + return callback; + } + }).when(mTransferMethodConfigurationRepository).getTransferMethodTypesFeeAndProcessingTime(anyString(), anyString(), any( + TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) { diff --git a/transfermethodui/src/test/resources/successful_tmc_keys_empty_fee_US_response.json b/transfermethodui/src/test/resources/successful_tmc_keys_empty_fee_US_response.json new file mode 100644 index 000000000..81cf43b6b --- /dev/null +++ b/transfermethodui/src/test/resources/successful_tmc_keys_empty_fee_US_response.json @@ -0,0 +1,38 @@ +{ + "data": { + "countries": { + "nodes": [ + { + "code": "US", + "name": "United States", + "currencies": { + "nodes": [ + { + "code": "USD", + "name": "USD", + "transferMethodTypes": { + "nodes": [ + { + "code": "BANK_ACCOUNT", + "name": "Bank Account", + "processingTimes": { + "nodes": [ + { + "country": "US", + "currency": "USD", + "transferMethodType": "BANK_ACCOUNT", + "value": "1-2 Business days" + } + ] + } + } + ] + } + } + ] + } + } + ] + } + } +} \ No newline at end of file diff --git a/transfermethodui/src/test/resources/successful_tmc_keys_empty_processing_US_response.json b/transfermethodui/src/test/resources/successful_tmc_keys_empty_processing_US_response.json new file mode 100644 index 000000000..ccc9f5c72 --- /dev/null +++ b/transfermethodui/src/test/resources/successful_tmc_keys_empty_processing_US_response.json @@ -0,0 +1,39 @@ +{ + "data": { + "countries": { + "nodes": [ + { + "code": "US", + "name": "United States", + "currencies": { + "nodes": [ + { + "code": "USD", + "name": "USD", + "transferMethodTypes": { + "nodes": [ + { + "code": "BANK_ACCOUNT", + "name": "Bank Account", + "fees": { + "nodes": [ + { + "country": "US", + "currency": "USD", + "transferMethodType": "BANK_ACCOUNT", + "value": "2.00", + "feeRateType": "FLAT" + } + ] + } + } + ] + } + } + ] + } + } + ] + } + } +} \ No newline at end of file diff --git a/transfermethodui/src/test/resources/successful_tmc_keys_fee_processing_time_CA_response.json b/transfermethodui/src/test/resources/successful_tmc_keys_fee_processing_time_CA_response.json new file mode 100644 index 000000000..8adfc20d4 --- /dev/null +++ b/transfermethodui/src/test/resources/successful_tmc_keys_fee_processing_time_CA_response.json @@ -0,0 +1,74 @@ +{ + "data": { + "countries": { + "nodes": [ + { + "code": "CA", + "name": "Canada", + "currencies": { + "nodes": [ + { + "code": "CAD", + "name": "Canadian Dollar", + "transferMethodTypes": { + "nodes": [ + { + "code": "BANK_ACCOUNT", + "name": "Bank Account", + "fees": { + "nodes": [ + { + "country": "CA", + "currency": "CAD", + "transferMethodType": "BANK_ACCOUNT", + "value": "2.20", + "feeRateType": "FLAT" + } + ] + }, + "processingTimes": { + "nodes": [ + { + "value": "1-2 Business days", + "country": "CA", + "currency": "CAD", + "transferMethodType": "BANK_ACCOUNT" + } + ] + } + }, + { + "code": "PAYPAL_ACCOUNT", + "name": "PayPal", + "fees": { + "nodes": [ + { + "country": "CA", + "currency": "CAD", + "transferMethodType": "PAYPAL_ACCOUNT", + "value": "0.25", + "feeRateType": "FLAT" + } + ] + }, + "processingTimes": { + "nodes": [ + { + "value": "IMMEDIATE", + "country": "CA", + "currency": "CAD", + "transferMethodType": "PAYPAL_ACCOUNT" + } + ] + } + } + ] + } + } + ] + } + } + ] + } + } +} \ No newline at end of file diff --git a/transfermethodui/src/test/resources/successful_tmc_keys_fee_processing_time_US_response.json b/transfermethodui/src/test/resources/successful_tmc_keys_fee_processing_time_US_response.json new file mode 100644 index 000000000..e4b5371e3 --- /dev/null +++ b/transfermethodui/src/test/resources/successful_tmc_keys_fee_processing_time_US_response.json @@ -0,0 +1,124 @@ +{ + "data": { + "countries": { + "nodes": [ + { + "code": "US", + "name": "United States", + "currencies": { + "nodes": [ + { + "code": "USD", + "name": "United States Dollar", + "transferMethodTypes": { + "nodes": [ + { + "code": "BANK_ACCOUNT", + "name": "Bank Account", + "fees": { + "nodes": [ + { + "country": "US", + "currency": "USD", + "transferMethodType": "BANK_ACCOUNT", + "value": "2.00", + "feeRateType": "FLAT" + } + ] + }, + "processingTimes": { + "nodes": [ + { + "value": "1-2 Business days", + "country": "US", + "currency": "USD", + "transferMethodType": "BANK_ACCOUNT" + } + ] + } + }, + { + "code": "BANK_CARD", + "name": "Debit Card", + "fees": { + "nodes": [ + { + "country": "US", + "currency": "USD", + "transferMethodType": "BANK_CARD", + "value": "1.75", + "feeRateType": "FLAT" + } + ] + }, + "processingTimes": { + "nodes": [ + { + "value": "IMMEDIATE", + "country": "US", + "currency": "USD", + "transferMethodType": "BANK_CARD" + } + ] + } + }, + { + "code": "WIRE_ACCOUNT", + "name": "Wire Transfer", + "fees": { + "nodes": [ + { + "country": "US", + "currency": "USD", + "transferMethodType": "WIRE_ACCOUNT", + "value": "20.00", + "feeRateType": "FLAT" + } + ] + }, + "processingTimes": { + "nodes": [ + { + "value": "1-3 Business days", + "country": "US", + "currency": "USD", + "transferMethodType": "WIRE_ACCOUNT" + } + ] + } + }, + { + "code": "PAYPAL_ACCOUNT", + "name": "PayPal", + "fees": { + "nodes": [ + { + "country": "US", + "currency": "USD", + "transferMethodType": "PAYPAL_ACCOUNT", + "value": "0.25", + "feeRateType": "FLAT" + } + ] + }, + "processingTimes": { + "nodes": [ + { + "value": "IMMEDIATE", + "country": "US", + "currency": "USD", + "transferMethodType": "PAYPAL_ACCOUNT" + } + ] + } + } + ] + } + } + ] + } + } + ] + } + } +} \ No newline at end of file diff --git a/transfermethodui/src/test/resources/successful_tmc_keys_mixed_fee_CN_response.json b/transfermethodui/src/test/resources/successful_tmc_keys_mixed_fee_CN_response.json new file mode 100644 index 000000000..26393fa23 --- /dev/null +++ b/transfermethodui/src/test/resources/successful_tmc_keys_mixed_fee_CN_response.json @@ -0,0 +1,161 @@ +{ + "data": { + "countries": { + "nodes": [ + { + "code": "CN", + "name": "CHINA", + "currencies": { + "nodes": [ + { + "code": "USD", + "name": "USD", + "transferMethodTypes": { + "nodes": [ + { + "code": "BANK_ACCOUNT", + "name": "Bank Account", + "fees": { + "nodes": [ + { + "country": "CN", + "currency": "USD", + "transferMethodType": "BANK_ACCOUNT", + "value": "0.0", + "feeRateType": "FLAT" + } + ] + }, + "processingTimes": { + "nodes": [ + { + "value": "1-2 Business days", + "country": "CN", + "currency": "USD", + "transferMethodType": "BANK_ACCOUNT" + } + ] + } + }, + { + "code": "BANK_CARD", + "name": "Debit Card", + "fees": { + "nodes": [ + { + "country": "CN", + "currency": "USD", + "transferMethodType": "BANK_CARD", + "value": "0.00", + "feeRateType": "FLAT" + } + ] + }, + "processingTimes": { + "nodes": [ + { + "value": "IMMEDIATE", + "country": "CN", + "currency": "USD", + "transferMethodType": "BANK_CARD" + } + ] + } + }, + + { + "code": "WIRE_ACCOUNT", + "name": "Wire Transfer", + "fees": { + "nodes": [ + { + "country": "CN", + "currency": "USD", + "transferMethodType": "WIRE_ACCOUNT", + "value": "0.000", + "feeRateType": "FLAT" + } + ] + }, + "processingTimes": { + "nodes": [ + { + "value": "1-3 Business days", + "country": "CN", + "currency": "USD", + "transferMethodType": "WIRE_ACCOUNT" + } + ] + } + }, + { + "code": "PAYPAL_ACCOUNT", + "name": "PayPal", + "fees": { + "nodes": [ + { + "country": "CN", + "currency": "USD", + "transferMethodType": "PAYPAL_ACCOUNT", + "value": "0.00", + "feeRateType": "PERCENT", + "minimum": "4.00", + "maximum": "10.00" + } + ] + }, + "processingTimes": { + "nodes": [ + { + "value": "IMMEDIATE", + "country": "CN", + "currency": "USD", + "transferMethodType": "PAYPAL_ACCOUNT" + } + ] + } + }, + { + "code": "VENMO_ACCOUNT", + "name": "VENMO", + "fees": { + "nodes": [ + { + "country": "CN", + "currency": "USD", + "transferMethodType": "VENMO_ACCOUNT", + "value": "5.00", + "feeRateType": "FLAT" + }, + { + "country": "CN", + "currency": "USD", + "transferMethodType": "VENMO_ACCOUNT", + "value": "4.50", + "feeRateType": "PERCENT", + "minimum": "4.00", + "maximum": "10.00" + } + ] + }, + "processingTimes": { + "nodes": [ + { + "value": "1-2 Business days", + "country": "CN", + "currency": "USD", + "transferMethodType": "VENMO_ACCOUNT" + } + ] + } + } + ] + } + } + ] + } + } + ] + } + } +} \ No newline at end of file diff --git a/transfermethodui/src/test/resources/successful_tmc_keys_no_fee_response.json b/transfermethodui/src/test/resources/successful_tmc_keys_no_fee_response.json new file mode 100644 index 000000000..c296ff51a --- /dev/null +++ b/transfermethodui/src/test/resources/successful_tmc_keys_no_fee_response.json @@ -0,0 +1,81 @@ +{ + "data": { + "countries": { + "nodes": [ + { + "code": "CN", + "name": "CHINA", + "currencies": { + "nodes": [ + { + "code": "USD", + "name": "USD", + "transferMethodTypes": { + "nodes": [ + { + "code": "BANK_ACCOUNT", + "name": "Bank Account", + "processingTimes": { + "nodes": [ + { + "value": "1-2 Business days", + "country": "CN", + "currency": "USD", + "transferMethodType": "BANK_ACCOUNT" + } + ] + } + }, + { + "code": "BANK_CARD", + "name": "Debit Card", + "processingTimes": { + "nodes": [ + { + "value": "IMMEDIATE", + "country": "CN", + "currency": "USD", + "transferMethodType": "BANK_CARD" + } + ] + } + }, + + { + "code": "WIRE_ACCOUNT", + "name": "Wire Transfer", + "processingTimes": { + "nodes": [ + { + "value": "1-3 Business days", + "country": "CN", + "currency": "USD", + "transferMethodType": "WIRE_ACCOUNT" + } + ] + } + }, + { + "code": "PAYPAL_ACCOUNT", + "name": "PayPal", + "processingTimes": { + "nodes": [ + { + "value": "IMMEDIATE", + "country": "CN", + "currency": "USD", + "transferMethodType": "PAYPAL_ACCOUNT" + } + ] + } + } + ] + } + } + ] + } + } + ] + } + } +} \ No newline at end of file