Skip to content

Commit 49f90dd

Browse files
committed
DTSERWFOUR-553 fixed mixed fee.
1 parent 6667b3f commit 49f90dd

File tree

4 files changed

+142
-11
lines changed

4 files changed

+142
-11
lines changed

transfermethodui/src/androidTest/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public void testSelectTransferMethod_verifyCountrySelectionList() {
126126
onView(allOf(instanceOf(TextView.class), withParent(withId(R.id.country_selection_toolbar)))).check(
127127
matches(withText(R.string.mobileCountryRegion)));
128128
onView(withId(R.id.search_button)).check(doesNotExist());
129-
onView(withId(R.id.country_selection_list)).check(new RecyclerViewCountAssertion(5));
129+
onView(withId(R.id.country_selection_list)).check(new RecyclerViewCountAssertion(6));
130130
onView(allOf(withId(R.id.country_name), withText("Canada"))).check(matches(isDisplayed()));
131131
onView(allOf(withId(R.id.country_name), withText("Croatia"))).check(matches(isDisplayed()));
132132
onView(allOf(withId(R.id.country_name), withText("Mexico"))).check(matches(isDisplayed()));
@@ -277,7 +277,7 @@ public void testSelectTransferMethod_verifyTransferMethodsListEmptyFee() {
277277
onView(withId(R.id.select_transfer_method_types_list)).check(
278278
matches(atPosition(0, hasDescendant(withText(R.string.bank_account)))));
279279
onView(withId(R.id.select_transfer_method_types_list)).check(
280-
matches(atPosition(0, hasDescendant(withText("1-2 Business days")))));
280+
matches(atPosition(0, hasDescendant(withText("No fee \u2022 1-2 Business days")))));
281281
}
282282

283283
@Test

transfermethodui/src/main/java/com/hyperwallet/android/ui/transfermethod/view/FeeFormatter.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public class FeeFormatter {
3636

3737
public static String getFormattedFee(@NonNull final Context context, @NonNull final List<Fee> fees) {
3838
String formattedString = context.getResources().getString(R.string.noFee);
39-
System.out.println(" fees size " + fees.size());
4039
if (fees.size() == 1) {
4140
formattedString = getSingleFormattedFee(context, fees, formattedString);
4241
} else {
@@ -49,17 +48,14 @@ private static String getSingleFormattedFee(@NonNull Context context, @NonNull L
4948
String formattedString) {
5049
Fee fee = fees.get(0);
5150
if (Fee.FeeRate.FLAT.equals(fee.getFeeRateType())) {
52-
System.out.println("Flat fee value " + fee.getValue());
5351
if (!isValidFee(fee.getValue())) {
5452
return formattedString;
5553
}
5654
formattedString = context.getResources().getString(R.string.fee_flat_formatter,
5755
Currency.getInstance(fee.getCurrency()).getSymbol(Locale.getDefault()), fee.getValue());
5856
} else if (Fee.FeeRate.PERCENT.equals(fee.getFeeRateType())) {
59-
System.out.println("Percentage fee value " + fee.getValue());
6057
formattedString = getPercentFormattedFee(context, fee, formattedString);
6158
}
62-
System.out.println("result in single" + formattedString);
6359
return formattedString;
6460
}
6561

@@ -77,7 +73,6 @@ private static String getMixFormattedFee(@NonNull Context context, @NonNull List
7773
}
7874
}
7975
if (flatFee != null && percentFee != null) {
80-
System.out.println("mixed formatted value flatFee " + flatFee.getValue() + " percent fee " + percentFee.getValue());
8176
String minimumAmount = percentFee.getMin();
8277
String maximumAmount = percentFee.getMax();
8378

@@ -97,9 +92,9 @@ private static String getMixFormattedFee(@NonNull Context context, @NonNull List
9792
formattedString = context.getResources().getString(R.string.fee_flat_formatter,
9893
Currency.getInstance(flatFee.getCurrency()).getSymbol(Locale.getDefault()), flatFee.getValue());
9994
} else if (maximumAmount.isEmpty() && !isValidFee(flatFee.getValue())) {
100-
formattedString = context.getResources().getString(R.string.fee_percent_only_max_formatter,
95+
formattedString = context.getResources().getString(R.string.fee_percent_only_min_formatter,
10196
percentFee.getValue(),
102-
percentFee.getCurrency(), maximumAmount);
97+
percentFee.getCurrency(), minimumAmount);
10398
} else if (maximumAmount.isEmpty()) {
10499
formattedString = context.getResources().getString(R.string.fee_mix_only_min_formatter,
105100
Currency.getInstance(flatFee.getCurrency()).getSymbol(Locale.getDefault()),
@@ -115,13 +110,19 @@ private static String getMixFormattedFee(@NonNull Context context, @NonNull List
115110
formattedString = context.getResources().getString(R.string.fee_mix_only_max_formatter,
116111
Currency.getInstance(flatFee.getCurrency()).getSymbol(Locale.getDefault()),
117112
flatFee.getValue(), percentFee.getValue(), maximumAmount);
113+
} else if (isValidFee(percentFee.getValue()) && !isValidFee(flatFee.getValue())) {
114+
formattedString = context.getResources().getString(R.string.fee_percent_formatter,
115+
percentFee.getValue(),
116+
percentFee.getCurrency(), minimumAmount, maximumAmount);
117+
} else if (isValidFee(flatFee.getValue()) && !isValidFee(percentFee.getValue())) {
118+
formattedString = context.getResources().getString(R.string.fee_flat_formatter,
119+
Currency.getInstance(flatFee.getCurrency()).getSymbol(Locale.getDefault()), flatFee.getValue());
118120
} else {
119121
formattedString = context.getResources().getString(R.string.fee_mix_formatter,
120122
Currency.getInstance(flatFee.getCurrency()).getSymbol(Locale.getDefault()),
121123
flatFee.getValue(), percentFee.getValue(), minimumAmount, maximumAmount);
122124
}
123125
}
124-
System.out.println("result in mixed " + formattedString);
125126
return formattedString;
126127
}
127128

transfermethodui/src/test/java/com/hyperwallet/android/ui/transfermethod/FeeFormatterTest.java

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,102 @@ public void testGetFormattedFee_returnsPercentNoFee() {
166166
int resourceIdCaptorValue = resourceIdCaptor.getValue();
167167
assertThat(resourceIdCaptorValue, is(R.string.noFee));
168168
}
169+
170+
@Test
171+
public void testGetFormattedFee_returnsMixedNoFee() {
172+
Fee flatFee = new Fee(mJSONObject.optJSONObject("FEE_EIGHT").optJSONArray("nodes").optJSONObject(0));
173+
Fee percentFee = new Fee(mJSONObject.optJSONObject("FEE_NINE").optJSONArray("nodes").optJSONObject(0));
174+
175+
FeeFormatter.getFormattedFee(context, Arrays.asList(flatFee,percentFee));
176+
verify(resources).getString(resourceIdCaptor.capture());
177+
int resourceIdCaptorValue = resourceIdCaptor.getValue();
178+
assertThat(resourceIdCaptorValue, is(R.string.noFee));
179+
}
180+
181+
@Test
182+
public void testGetFormattedFee_returnsFlatFee() {
183+
Fee percentFee = new Fee(mJSONObject.optJSONObject("FEE_EIGHT").optJSONArray("nodes").optJSONObject(0));
184+
FeeFormatter.getFormattedFee(context, Arrays.asList(mFlatFee,percentFee));
185+
186+
verify(resources).getString(resourceIdCaptor.capture(), formatterArgumentCapture.capture());
187+
int resourceIdCaptorValue = resourceIdCaptor.getValue();
188+
List<Object> argumentList = formatterArgumentCapture.getAllValues();
189+
assertThat(resourceIdCaptorValue, is(R.string.fee_flat_formatter));
190+
assertThat(argumentList.size(), is(2));
191+
}
192+
193+
@Test
194+
public void testGetFormattedFee_returnsFlatFeeWithMinAndMax() {
195+
Fee percentFee = new Fee(mJSONObject.optJSONObject("FEE_TEN").optJSONArray("nodes").optJSONObject(0));
196+
FeeFormatter.getFormattedFee(context, Arrays.asList(mFlatFee,percentFee));
197+
198+
verify(resources).getString(resourceIdCaptor.capture(), formatterArgumentCapture.capture());
199+
int resourceIdCaptorValue = resourceIdCaptor.getValue();
200+
List<Object> argumentList = formatterArgumentCapture.getAllValues();
201+
assertThat(resourceIdCaptorValue, is(R.string.fee_flat_formatter));
202+
assertThat(argumentList.size(), is(2));
203+
}
204+
205+
@Test
206+
public void testGetFormattedFee_returnsFlatFeeWithMaxOnly() {
207+
Fee percentFee = new Fee(mJSONObject.optJSONObject("FEE_TWELVE").optJSONArray("nodes").optJSONObject(0));
208+
FeeFormatter.getFormattedFee(context, Arrays.asList(mFlatFee,percentFee));
209+
210+
verify(resources).getString(resourceIdCaptor.capture(), formatterArgumentCapture.capture());
211+
int resourceIdCaptorValue = resourceIdCaptor.getValue();
212+
List<Object> argumentList = formatterArgumentCapture.getAllValues();
213+
assertThat(resourceIdCaptorValue, is(R.string.fee_flat_formatter));
214+
assertThat(argumentList.size(), is(2));
215+
}
216+
217+
@Test
218+
public void testGetFormattedFee_returnsFlatFeeWithMinOnly() {
219+
Fee percentFee = new Fee(mJSONObject.optJSONObject("FEE_ELEVEN").optJSONArray("nodes").optJSONObject(0));
220+
FeeFormatter.getFormattedFee(context, Arrays.asList(mFlatFee,percentFee));
221+
222+
verify(resources).getString(resourceIdCaptor.capture(), formatterArgumentCapture.capture());
223+
int resourceIdCaptorValue = resourceIdCaptor.getValue();
224+
List<Object> argumentList = formatterArgumentCapture.getAllValues();
225+
assertThat(resourceIdCaptorValue, is(R.string.fee_flat_formatter));
226+
assertThat(argumentList.size(), is(2));
227+
}
228+
229+
@Test
230+
public void testGetFormattedFee_returnsPercentFeeWithMinAndMax() {
231+
Fee flatFee = new Fee(mJSONObject.optJSONObject("FEE_NINE").optJSONArray("nodes").optJSONObject(0));
232+
Fee percentFee = new Fee(mJSONObject.optJSONObject("FEE_TWO").optJSONArray("nodes").optJSONObject(0));
233+
FeeFormatter.getFormattedFee(context, Arrays.asList(flatFee,percentFee));
234+
235+
verify(resources).getString(resourceIdCaptor.capture(), formatterArgumentCapture.capture());
236+
int resourceIdCaptorValue = resourceIdCaptor.getValue();
237+
List<Object> argumentList = formatterArgumentCapture.getAllValues();
238+
assertThat(resourceIdCaptorValue, is(R.string.fee_percent_formatter));
239+
assertThat(argumentList.size(), is(4));
240+
}
241+
242+
@Test
243+
public void testGetFormattedFee_returnsPercentFeeWithMinOnly() {
244+
Fee flatFee = new Fee(mJSONObject.optJSONObject("FEE_NINE").optJSONArray("nodes").optJSONObject(0));
245+
Fee percentFee = new Fee(mJSONObject.optJSONObject("FEE_THREE").optJSONArray("nodes").optJSONObject(0));
246+
FeeFormatter.getFormattedFee(context, Arrays.asList(flatFee,percentFee));
247+
248+
verify(resources).getString(resourceIdCaptor.capture(), formatterArgumentCapture.capture());
249+
int resourceIdCaptorValue = resourceIdCaptor.getValue();
250+
List<Object> argumentList = formatterArgumentCapture.getAllValues();
251+
assertThat(resourceIdCaptorValue, is(R.string.fee_percent_only_min_formatter));
252+
assertThat(argumentList.size(), is(3));
253+
}
254+
255+
@Test
256+
public void testGetFormattedFee_returnsPercentFeeWithMaxOnly() {
257+
Fee flatFee = new Fee(mJSONObject.optJSONObject("FEE_NINE").optJSONArray("nodes").optJSONObject(0));
258+
Fee percentFee = new Fee(mJSONObject.optJSONObject("FEE_FOUR").optJSONArray("nodes").optJSONObject(0));
259+
FeeFormatter.getFormattedFee(context, Arrays.asList(flatFee,percentFee));
260+
261+
verify(resources).getString(resourceIdCaptor.capture(), formatterArgumentCapture.capture());
262+
int resourceIdCaptorValue = resourceIdCaptor.getValue();
263+
List<Object> argumentList = formatterArgumentCapture.getAllValues();
264+
assertThat(resourceIdCaptorValue, is(R.string.fee_percent_only_max_formatter));
265+
assertThat(argumentList.size(), is(3));
266+
}
169267
}

transfermethodui/src/test/resources/fee_information.json

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,38 @@
9393
"feeRateType": "FLAT"
9494
}
9595
]
96+
},
97+
"FEE_TEN": {
98+
"nodes": [
99+
{
100+
"currency": "USD",
101+
"feeRateType": "PERCENT",
102+
"value": "0.00",
103+
"minimum": "10.00",
104+
"maximum": "20.00"
105+
}
106+
]
107+
},
108+
"FEE_ELEVEN": {
109+
"nodes": [
110+
{
111+
"currency": "USD",
112+
"feeRateType": "PERCENT",
113+
"value": "0.00",
114+
"minimum": "10.00",
115+
"maximum": ""
116+
}
117+
]
118+
},
119+
"FEE_TWELVE": {
120+
"nodes": [
121+
{
122+
"currency": "USD",
123+
"feeRateType": "PERCENT",
124+
"value": "0.00",
125+
"minimum": "",
126+
"maximum": "20.00"
127+
}
128+
]
96129
}
97-
98130
}

0 commit comments

Comments
 (0)