Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@

public class SelectTransferMethodPresenter implements SelectTransferMethodContract.Presenter {

private static final String DEFAULT_COUNTRY_CODE = "US";

private final TransferMethodConfigurationRepository mTransferMethodConfigurationRepository;
private final UserRepository mUserRepository;
private final SelectTransferMethodContract.View mView;
Expand Down Expand Up @@ -82,7 +80,7 @@ public void onKeysLoaded(@Nullable final HyperwalletTransferMethodConfigurationK
: key.getCountry(countryCode);

if (country == null) { // param and user country is null
country = key.getCountry(DEFAULT_COUNTRY_CODE);
country = key.getCountries().iterator().next();
}

String currencyCodeString = currencyCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.hyperwallet.android.ui.user.repository.UserRepositoryImpl;

import org.hamcrest.Matchers;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -1073,4 +1074,58 @@ public Object answer(InvocationOnMock invocation) {
selectTransferMethodPresenter.loadTransferMethodTypes(false, "CA", "CAD");
verify(view).showErrorLoadTransferMethodTypes(ArgumentMatchers.<Error>anyList());
}

@Test
public void loadTransferMethodConfigurationKeys_userWithCountryNotPresentInProgramCountries() throws JSONException {
// User's country is Albania which is not present in mResult successful_tmc_keys_response.json
String userResponseBody = externalResourceManager.getResourceContent("user_al_response.json");
final JSONObject userJsonObject = new JSONObject(userResponseBody);
final User user = new User(userJsonObject);

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.onKeysLoaded(mFeeAndProcessingTimeResult);
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(user);
return userCallback;
}
}).when(mUserRepository).loadUser(any(
UserRepository.LoadUserCallback.class));

selectTransferMethodPresenter.loadTransferMethodConfigurationKeys(true, null, null);

// Canada is first country in successful_tmc_keys_response.json
verify(view).showTransferMethodCountry("CA");
verify(view).showTransferMethodCurrency("CAD");
verify(view).showTransferMethodTypes(ArgumentMatchers.<TransferMethodSelectionItem>anyList());
verify(view, never()).showErrorLoadTransferMethodConfigurationKeys(
ArgumentMatchers.<Error>anyList());
verify(view, never()).showErrorLoadCurrency(ArgumentMatchers.<Error>anyList());
verify(view, never()).showErrorLoadTransferMethodTypes(ArgumentMatchers.<Error>anyList());
verify(view, never()).showErrorLoadCountrySelection(ArgumentMatchers.<Error>anyList());
verify(view, never()).showErrorLoadCurrencySelection(ArgumentMatchers.<Error>anyList());
verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString(), anyString());
}
}
26 changes: 26 additions & 0 deletions transfermethodui/src/test/resources/user_al_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"token": "usr-token-5",
"status": "PRE_ACTIVATED",
"createdOn": "2017-10-30T22:15:45",
"clientUserId": "123456",
"profileType": "INDIVIDUAL",
"firstName": "Person",
"lastName": "FromAlbania",
"dateOfBirth": "1991-01-01",
"email": "user+5satF1xV@hyperwallet.com",
"addressLine1": "950 Granville",
"city": "Gjirokaster",
"stateProvince": "Gjirokaster",
"country": "AL",
"postalCode": "443001",
"language": "en",
"programToken": "prg-token-2",
"links": [
{
"params": {
"rel": "self"
},
"href": "https://localhost/rest/v3/users/usr-token-5"
}
]
}