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

Add more date validation to activities program date #219

Merged
merged 4 commits into from Apr 30, 2024

Conversation

coltborg
Copy link
Contributor

@coltborg coltborg commented Apr 24, 2024

🔗 Jira ticket

CCAP-21

✍️ Description

This PR is to address comments here in regards to date validation.

  • Add validation if letters are provided
  • Add validation if a date is before 01/01/1901
  • Add validation if a date is after today
  • Expand tests to include these new validations
  • activityProgram dates and partnerProgram dates have the same validation

✅ Completion tasks

  • Added relevant tests
  • Meets acceptance criteria

@coltborg coltborg self-assigned this Apr 24, 2024
@coltborg coltborg force-pushed the CCAP-21-fix-date-validation branch from 37f297c to 9f7f796 Compare April 25, 2024 17:15
@coltborg coltborg marked this pull request as ready for review April 25, 2024 21:28
@coltborg coltborg changed the title WIP - Add more date validation to activities program Add more date validation to activities program Apr 25, 2024
@coltborg coltborg changed the title Add more date validation to activities program Add more date validation to activities program date Apr 25, 2024
@@ -91,6 +91,7 @@ errors.required-financial-assistance=Please answer whether you need child care a
errors.invalid-date-format=Make sure the date you entered is in this format: mm/dd/yyyy
errors.invalid-birthdate-format=Make sure the birthdate you entered is in this format: mm/dd/yyyy
errors.invalid-birthdate-range=Make sure the date you entered is between 01/01/1901 and today.
errors.invalid-date-range=Make sure the date you entered is after 01/01/1901 and before today.
Copy link
Contributor

Choose a reason for hiding this comment

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

Feels like the error message is the same as errors.invalid-birthdate-range but is worded weirdly. Should we have the same verbiage as errors.invalid-birthdate-range ? (pending verifying with design)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ya, I can align them.

Comment on lines +170 to +183
void shouldErrorWhenStartDateIsBefore1901() {
Map<String, Object> formData = Map.of(
"activitiesProgramStartMonth", "01",
"activitiesProgramStartDay", "",
"activitiesProgramStartYear", "1700",
"activitiesProgramEndMonth", "01",
"activitiesProgramEndDay", "",
"activitiesProgramEndYear", "2024"
);
FormSubmission submission = new FormSubmission(formData);
Map<String, List<String>> errors = validator.runValidation(submission, new Submission());
assertThat(errors).containsKey("activitiesProgramStart");
assertThat(errors.get("activitiesProgramStart")).contains("Make sure the date you entered is after 01/01/1901 and before today.");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey! (Pardon if this is nitpicky) but I tried

   ....
    "activitiesProgramStartMonth", "01",
    "activitiesProgramStartDay", "",
    "activitiesProgramStartYear", "1901",
   ...

Not sure if this is a bug but this still throws an error (setting date for the date today does not throw an error, so I was assuming that this is an inclusive between)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The logic on 01/1901 being inclusive or not is in the VerifyDate action we're extending.

And seeing Carl's message about this in our stand up zoom, I'm going to keep it the same for now as this work didn't change the existing behavior.

"Let’s not worry about it too much. Not many of our dates will actually be on 1/1/1901"

Copy link
Contributor

@rapicastillo rapicastillo left a comment

Choose a reason for hiding this comment

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

I'll defer to what @enyia21 says but I left some questions and messages. Thanks Cypress!

@coltborg coltborg force-pushed the CCAP-21-fix-date-validation branch from 29cbf76 to 7d8dc7b Compare April 29, 2024 15:53

String endMonth = inputData.get(INPUT_NAME_END_MONTH).toString();
String endYear = inputData.get(INPUT_NAME_END_YEAR).toString();
String endGroup = "activitiesProgramEnd";
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this code be refactored?
... String startMonthField = startGroup.concat("Month"); String startDayField = startGroup.concat("Day"); String startYearField = startGroup.concat("Year"); ...
This pattern appears to be repeated for the start and end date.
String endGroup = "activitiesProgramEnd"; String endMonthField = endGroup.concat("Month"); String endDayField = endGroup.concat("Day"); String endYearField = endGroup.concat("Year");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, looking into this now

@coltborg
Copy link
Contributor Author

@rapicastillo / @enyia21, I've made changes to my PR to address the messaging and DRY up the code

- Remove old activity date tests as the new ones cover them and more
- Invert isBetweenNowAndMinDate because we always invert it when we use it
@coltborg coltborg force-pushed the CCAP-21-fix-date-validation branch from d99664d to 1629fd0 Compare April 30, 2024 16:06
@enyia21 enyia21 merged commit 2e1fc40 into main Apr 30, 2024
5 checks passed
@enyia21 enyia21 deleted the CCAP-21-fix-date-validation branch April 30, 2024 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants