Skip to content

Commit

Permalink
Merge pull request #200 from codeforamerica/pdf-tca-signature-187366326
Browse files Browse the repository at this point in the history
Write tca signature only if tca application
  • Loading branch information
analoo authored Apr 10, 2024
2 parents b73249f + 8da320b commit ae65d3b
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import formflow.library.pdf.SingleField;
import formflow.library.pdf.SubmissionField;
import formflow.library.pdf.SubmissionFieldPreparer;
import java.time.format.DateTimeFormatter;
import java.util.List;
import org.springframework.stereotype.Component;

Expand All @@ -28,11 +29,16 @@ public Map<String, SubmissionField> prepareSubmissionFields(Submission submissio
results.put("needsSNAP",
new SingleField("needsSNAP", String.valueOf(programs.contains("SNAP")), null));

boolean needsCash = programs.contains("TDAP") || programs.contains("TCA") || programs.contains("RCA");
boolean needsCash = programs.contains("TDAP") || programs.contains("RCA") || programs.contains("TCA");

results.put("needsCashAssistance",
new SingleField("needsCashAssistance", String.valueOf(needsCash), null));

if(needsCash){
results.put("tcaSignature", new SingleField("tcaSignature", inputData.getOrDefault("signature", "").toString(), null));
results.put("tcaSubmissionDate", new SingleField("tcaSubmissionDate", submission.getSubmittedAt().format(DateTimeFormatter.ofPattern("MM/dd/yyyy")), null));
}

return results;
}
}
2 changes: 2 additions & 0 deletions src/main/resources/pdf-map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ inputFields:
needsCashAssistance: applicant_needs_cash_assistance
needsSNAP: applicant_needs_snap
signature: applicant_signature
tcaSignature: tca_applicant_signature
tcaSubmissionDate: tca_date_submitted
householdHasDisability: household_disability_bool
householdHasDisabilitySeeCover: hhmember_disability_see_cover
householdHasPregnancy: household_pregnancy_bool
Expand Down
Binary file modified src/main/resources/pdfs/9701.pdf
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package org.mdbenefits.app.preparers;

import static org.assertj.core.api.Assertions.assertThat;
import formflow.library.data.Submission;
import formflow.library.pdf.SingleField;
import formflow.library.pdf.SubmissionField;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.mdbenefits.app.data.SubmissionTestBuilder;
import org.mdbenefits.app.testutils.TestUtils;

class ApplicantNeedsPreparerTest {
private final ApplicantNeedsPreparer preparer = new ApplicantNeedsPreparer();

private final OffsetDateTime NovTwelve = TestUtils.makeOffsetDateTime("2024-11-12");

@Test
public void tdapProgramSelectionGeneratesNeedsCashAssistance() {
Submission submission = new SubmissionTestBuilder()
.withPersonalInfo("John", "Doe", "10", "12", "1999",
"", "", "", "", "")
.with("programs[]", List.of("TDAP"))
.with("signature", "My Signature")
.build();

submission.setSubmittedAt(NovTwelve);

Map<String, SubmissionField> result = preparer.prepareSubmissionFields(submission, null);
assertThat(result.get("needsSNAP"))
.isEqualTo(new SingleField("needsSNAP", "false", null));
assertThat(result.get("needsCashAssistance"))
.isEqualTo(new SingleField("needsCashAssistance", "true", null));
assertThat(result.get("tcaSignature"))
.isEqualTo(new SingleField("tcaSignature", "My Signature", null));
assertThat(result.get("tcaSubmissionDate")).isEqualTo(new SingleField("tcaSubmissionDate", "11/12/2024", null));
}

@Test
public void rcaProgramSelectionGeneratesNeedsCashAssistance() {
Submission submission = new SubmissionTestBuilder()
.withPersonalInfo("John", "Doe", "10", "12", "1999",
"", "", "", "", "")
.with("programs[]", List.of("RCA"))
.with("signature", "My Signature")
.build();

submission.setSubmittedAt(NovTwelve);

Map<String, SubmissionField> result = preparer.prepareSubmissionFields(submission, null);
assertThat(result.get("needsSNAP"))
.isEqualTo(new SingleField("needsSNAP", "false", null));
assertThat(result.get("needsCashAssistance"))
.isEqualTo(new SingleField("needsCashAssistance", "true", null));
assertThat(result.get("tcaSignature"))
.isEqualTo(new SingleField("tcaSignature", "My Signature", null));
assertThat(result.get("tcaSubmissionDate")).isEqualTo(new SingleField("tcaSubmissionDate", "11/12/2024", null));
}

@Test
public void snapProgramSelectionGeneratesNeedsCashAssistance() {
Submission submission = new SubmissionTestBuilder()
.withPersonalInfo("John", "Doe", "10", "12", "1999",
"", "", "", "", "")
.with("programs[]", List.of("SNAP"))
.with("signature", "My Signature")
.build();

submission.setSubmittedAt(NovTwelve);

Map<String, SubmissionField> result = preparer.prepareSubmissionFields(submission, null);
assertThat(result.get("needsSNAP"))
.isEqualTo(new SingleField("needsSNAP", "true", null));
assertThat(result.get("needsCashAssistance"))
.isEqualTo(new SingleField("needsCashAssistance", "false", null));
assertThat(result.get("tcaSignature"))
.isEqualTo(null);
assertThat(result.get("tcaSubmissionDate")).isEqualTo(null);
}

@Test
public void tcaProgramSelectionGeneratesNeedsCashAssistance() {
Submission submission = new SubmissionTestBuilder()
.withPersonalInfo("John", "Doe", "10", "12", "1999",
"", "", "", "", "")
.with("programs[]", List.of("TCA"))
.with("signature", "My Signature")
.build();

submission.setSubmittedAt(NovTwelve);

Map<String, SubmissionField> result = preparer.prepareSubmissionFields(submission, null);
assertThat(result.get("needsSNAP"))
.isEqualTo(new SingleField("needsSNAP", "false", null));
assertThat(result.get("needsCashAssistance"))
.isEqualTo(new SingleField("needsCashAssistance", "true", null));
assertThat(result.get("tcaSignature"))
.isEqualTo(new SingleField("tcaSignature", "My Signature", null));
assertThat(result.get("tcaSubmissionDate")).isEqualTo(new SingleField("tcaSubmissionDate", "11/12/2024", null));
}
}

0 comments on commit ae65d3b

Please sign in to comment.