Skip to content

Commit

Permalink
Money values with decimal places are correctly parsed
Browse files Browse the repository at this point in the history
[#178255123]
  • Loading branch information
bencalegari committed May 22, 2021
1 parent 4fb4c67 commit eb5fa43
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/main/java/org/codeforamerica/shiba/Money.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.Serial;
import java.math.BigDecimal;
import java.math.RoundingMode;

public class Money extends BigDecimal {
@Serial
Expand All @@ -10,7 +11,7 @@ public class Money extends BigDecimal {
public static final Money ONE = new Money(BigDecimal.ONE);

private Money(BigDecimal val) {
super(val.unscaledValue(), 0);
super(String.valueOf(new BigDecimal(String.valueOf(val)).setScale(2, RoundingMode.DOWN)));
}

public static Money parse(String s) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ void shouldMapJobIncomeInformationToInputs() {
List<ApplicationInput> applicationInputs = grossMonthlyIncomeMapper.map(application, null, null, scopeTracker);

assertThat(applicationInputs).contains(
new ApplicationInput("employee", "grossMonthlyIncome", List.of("1440"), SINGLE_VALUE, 0),
new ApplicationInput("prefix_employee", "grossMonthlyIncome", List.of("1440"), SINGLE_VALUE, 0),
new ApplicationInput("employee", "grossMonthlyIncome", List.of("1080"), SINGLE_VALUE, 1),
new ApplicationInput("prefix_employee", "grossMonthlyIncome", List.of("1080"), SINGLE_VALUE, 1)
new ApplicationInput("employee", "grossMonthlyIncome", List.of("1440.00"), SINGLE_VALUE, 0),
new ApplicationInput("prefix_employee", "grossMonthlyIncome", List.of("1440.00"), SINGLE_VALUE, 0),
new ApplicationInput("employee", "grossMonthlyIncome", List.of("1080.00"), SINGLE_VALUE, 1),
new ApplicationInput("prefix_employee", "grossMonthlyIncome", List.of("1080.00"), SINGLE_VALUE, 1)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ void shouldCalculateGrossMonthlyIncome() {
HourlyJobIncomeInformation hourlyJobIncomeInformation = new HourlyJobIncomeInformation("2", "5", 0, null);
assertThat(hourlyJobIncomeInformation.grossMonthlyIncome()).isEqualTo(Money.parse("40"));
}

@Test
void shouldCalculateGrossMonthlyIncomeWithNonWholeNumberWages() {
HourlyJobIncomeInformation hourlyJobIncomeInformation = new HourlyJobIncomeInformation("2.5", "5", 0, null);
assertThat(hourlyJobIncomeInformation.grossMonthlyIncome()).isEqualTo(Money.parse("50"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void returnsCalculatedTotalIncome() {
new ApplicationInput(
"totalIncome",
"thirtyDayIncome",
List.of("111"),
List.of("111.00"),
ApplicationInputType.SINGLE_VALUE
)
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ void shouldMapNoForSelfEmployment() {

assertThat(pdAcroForms.get(CCAP).getField("NON_SELF_EMPLOYMENT_EMPLOYERS_NAME_0").getValueAsString()).isEqualTo("someEmployerName");
assertThat(pdAcroForms.get(CCAP).getField("NON_SELF_EMPLOYMENT_PAY_FREQUENCY_0").getValueAsString()).isEqualTo("Every week");
assertThat(pdAcroForms.get(CCAP).getField("NON_SELF_EMPLOYMENT_GROSS_MONTHLY_INCOME_0").getValueAsString()).isEqualTo("4");
assertThat(pdAcroForms.get(CCAP).getField("NON_SELF_EMPLOYMENT_GROSS_MONTHLY_INCOME_0").getValueAsString()).isEqualTo("4.00");
}

@Test
Expand Down Expand Up @@ -898,11 +898,11 @@ void shouldMapJobLastThirtyDayIncome() {
testPage.clickContinue();

Map<Document, PDAcroForm> pdAcroForms = submitAndDownloadReceipt();
assertThat(getPdfFieldText(pdAcroForms.get(CAF), "GROSS_MONTHLY_INCOME_0")).isEqualTo("123");
assertThat(getPdfFieldText(pdAcroForms.get(CAF), "MONEY_MADE_LAST_MONTH")).isEqualTo("123");
assertThat(getPdfFieldText(pdAcroForms.get(CAF), "GROSS_MONTHLY_INCOME_0")).isEqualTo("123.00");
assertThat(getPdfFieldText(pdAcroForms.get(CAF), "MONEY_MADE_LAST_MONTH")).isEqualTo("123.00");
assertThat(getPdfFieldText(pdAcroForms.get(CAF), "SNAP_EXPEDITED_ELIGIBILITY")).isEqualTo("SNAP");

assertThat(getPdfFieldText(pdAcroForms.get(CCAP), "NON_SELF_EMPLOYMENT_GROSS_MONTHLY_INCOME_0")).isEqualTo("123");
assertThat(getPdfFieldText(pdAcroForms.get(CCAP), "NON_SELF_EMPLOYMENT_GROSS_MONTHLY_INCOME_0")).isEqualTo("123.00");
}

@Test
Expand Down Expand Up @@ -937,11 +937,11 @@ void shouldMapJobLastThirtyDayIncomeSomeBlankIsDetermined() {
testPage.clickContinue();

Map<Document, PDAcroForm> pdAcroForms = submitAndDownloadReceipt();
assertThat(getPdfFieldText(pdAcroForms.get(CAF), "GROSS_MONTHLY_INCOME_0")).isEqualTo("123");
assertThat(getPdfFieldText(pdAcroForms.get(CAF), "MONEY_MADE_LAST_MONTH")).isEqualTo("123");
assertThat(getPdfFieldText(pdAcroForms.get(CAF), "GROSS_MONTHLY_INCOME_0")).isEqualTo("123.00");
assertThat(getPdfFieldText(pdAcroForms.get(CAF), "MONEY_MADE_LAST_MONTH")).isEqualTo("123.00");
assertThat(getPdfFieldText(pdAcroForms.get(CAF), "SNAP_EXPEDITED_ELIGIBILITY")).isEqualTo("SNAP");

assertThat(getPdfFieldText(pdAcroForms.get(CCAP), "NON_SELF_EMPLOYMENT_GROSS_MONTHLY_INCOME_0")).isEqualTo("123");
assertThat(getPdfFieldText(pdAcroForms.get(CCAP), "NON_SELF_EMPLOYMENT_GROSS_MONTHLY_INCOME_0")).isEqualTo("123.00");
}

@Test
Expand Down

0 comments on commit eb5fa43

Please sign in to comment.