Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix money on hand boolean PDF mapping #286

Merged
merged 5 commits into from
Jun 18, 2024
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
3 changes: 0 additions & 3 deletions src/main/java/org/mdbenefits/app/inputs/MdBenefitsFlow.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,6 @@ public class MdBenefitsFlow extends FlowInputs {
@Money(message = "{error.invalid-money}")
private String additionalIncomeOther;

@NotEmpty
private List<String> moneyOnHandTypes;

@Money(message = "{error.invalid-money}")
@NotBlank(message = "{error.missing-dollar-amount}")
private String monthlyHouseholdIncome;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

results.putAll(prepareIncome(submission));
results.putAll(prepareAdditionIncome(submission));
results.putAll(prepareMoneyOnHandResources(submission));
results.putAll(prepareHasMoreThanHundredOnHand(submission));
return results;
}

Expand Down Expand Up @@ -144,30 +144,13 @@
null
));
}

private Map<String, SubmissionField> prepareMoneyOnHandResources(Submission submission) {
private Map<String, SubmissionField> prepareHasMoreThanHundredOnHand(Submission submission) {
Map<String, SubmissionField> fields = new HashMap<>();
var moneyOnHandSelected = (List<String>) submission.getInputData().getOrDefault("moneyOnHandTypes[]", emptyList());

if (moneyOnHandSelected.isEmpty()) {
return fields;
}
if (isNoneOfAboveSelection(moneyOnHandSelected)) {
fields.put("householdHasResourcesOrAssets", new SingleField("householdHasResourcesOrAssets", "false", null
));
return fields;
} else {
int i = 1;
for (var type : MoneyOnHandType.values()) {
if (moneyOnHandSelected.contains(type.name())) {
fields.put("householdHasResourcesOrAssets", new SingleField("householdHasResourcesOrAssets", "true", null
));
fields.put("resourcesOrAssetsType" + i,
new SingleField("resourcesOrAssetsType" + i, messagesSource.getMessage(
type.getLabelSrc(), null, Locale.ENGLISH), null));
i++;
}
}
Map<String, Object> inputData = submission.getInputData();
if (inputData.containsKey("expeditedMoneyOnHandAmount")) {
double expeditedMoneyOnHandAmount = Double.parseDouble(inputData.get("expeditedMoneyOnHandAmount").toString());

Check notice

Code scanning / CodeQL

Missing catch of NumberFormatException Note

Potential uncaught 'java.lang.NumberFormatException'.
Copy link
Contributor

@bseeger bseeger Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expeditedMoneyOnHandAmount may be set to "". We need to account for that here. This is what I did in one of the actions that uses it:

String moneyOnHandStr = (String) submission.getInputData().get("expeditedMoneyOnHandAmount");

Funny, though, I was just looking at the MdBenefitsFlow.java file and I see that it is required, so now I'm wondering what I was thinking about with that logic I linked to above. I wonder if people can enter " " and move forward.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I sorted this out and it was unrelated to this. I think you're change is fine. The field is required and and you check to see that it is set before grabbing it. I think we will not see NumberFormatExceptions as a result of this code.

fields.put("householdHasResourcesOrAssets", new SingleField("householdHasResourcesOrAssets", expeditedMoneyOnHandAmount > 0 ? "true" : "false", null));
}
return fields;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -105,41 +105,6 @@ public void testAdditionalIncome() {
assertThat(yesRow.getValue()).isEqualToIgnoringCase("Yes");
}


@Test
public void testPrepareMoneyOnHandResourcesDoesNotAddWhenNONEisPresent() {
Submission submission = new SubmissionTestBuilder()
.withPersonalInfo("Person", "One", "", "", "", "", "", "", "", "")
.with("moneyOnHandTypes[]", List.of(NONE_OF_ABOVE_SELECTION_VALUE))
.build();

Map<String, SubmissionField> result = incomePreparer.prepareSubmissionFields(submission, null);
assertThat(result.get("householdHasResourcesOrAssets"))
.isEqualTo(new SingleField("householdHasResourcesOrAssets", "false", null));
}

@Test
public void testPrepareMoneyOnHandResourcesAddsRelevantItems() {
Submission submission = new SubmissionTestBuilder()
.withPersonalInfo("Person", "One", "", "", "", "", "", "", "", "")
.with("moneyOnHandTypes[]", List.of("CHECKING", "SAVINGS", "BONDS"))
.build();

Map<String, SubmissionField> result = incomePreparer.prepareSubmissionFields(submission, null);

assertThat(withNoJobIncome(result).size()).isEqualTo(4);
assertThat(result.get("householdHasResourcesOrAssets"))
.isEqualTo(new SingleField("householdHasResourcesOrAssets", "true", null));
assertThat(result.get("resourcesOrAssetsType1"))
.isEqualTo(new SingleField("resourcesOrAssetsType1", "Checking account", null));

assertThat(result.get("resourcesOrAssetsType2"))
.isEqualTo(new SingleField("resourcesOrAssetsType2", "Savings account", null));

assertThat(result.get("resourcesOrAssetsType3"))
.isEqualTo(new SingleField("resourcesOrAssetsType3", "Bonds", null));
}

private void assertJobIncome(Map<String, SubmissionField> results, String expected) {
assertThat(results).containsKey("householdHasEarnedIncome");
var hasIncomeField = (SingleField) results.get("householdHasEarnedIncome");
Expand Down
Loading