-
Notifications
You must be signed in to change notification settings - Fork 87
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(mrf be val): skip validation for unchanged mrf responses #7894
fix(mrf be val): skip validation for unchanged mrf responses #7894
Conversation
Datadog ReportBranch report: ✅ 0 Failed, 1285 Passed, 1 Skipped, 2m 16.27s Total duration (4m 30.22s time saved) |
@@ -191,7 +191,9 @@ const pastOnlyValidatorV3: ResponseValidator<DateResponseV3> = (response) => { | |||
const answerDate = createMomentFromDateStringV3(answer) | |||
|
|||
return answerDate.isAfter(todayMax) | |||
? left(`DateValidatorV3:\t answer does not pass date logic validation`) | |||
? left( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes in this file are added to make the logs more specific - not related to the skipping of validation
@@ -1052,131 +1052,4 @@ describe('Email field validation V3', () => { | |||
new ValidateFieldError('Invalid answer submitted'), | |||
) | |||
}) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These TC are removed as they are migrated to the test for checkIsResponseChangedV3 instead, avoiding the need to spy and check if the spied function is invoked
: null | ||
return prevResponseValue !== responseValue | ||
case BasicField.Checkbox: | ||
if (prevResponse.fieldType !== response.fieldType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is required due to TS throwing an error as it fails to infer the type of prevResponse is same as response without it, despite being checked in L19 above.
6ef3ce7
to
7339522
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Problem
During MRF BE Validation, false positives occur for verifiable fields (due to signature being marked as invalid) and date fields with disallow past dates validation.
Details
1st jan 2024
, a respondent for step 1 can select the current date1st jan 2024
which is valid and passes the disallow past dates validation.3rd jan 2024
and the respondent leaves the date field value from step 1 unchanged. This fails the disallow past dates validation since the step 2 submission date of3rd jan 2024
is after1st jan 2024
.This edge case is considered acceptable and is similar to the current (as of this PR) frontend validation behavior. For example, if the admin tries to submit the form at step 2 where the date field with disallow past dates validation is editable, they would experience a frontend validation failure.
Closes FRM-1909
Solution
During field validation, there is a check if validation is required.
An additional check for if the field response is changed is added. In the event the field is unchanged, then the validation for the field is skipped. This is based on the idea where since a response has been validated in the previous step and is unchanged, it does not need to be re-validated in the subsequent step. This resolves the false positive issue and replicates the same frontend validation behavior described above.
Implementation
A new function
checkIsResponseChangedV3
is added to a filefield-validation.utils.ts
which allows for export without having to explicitly export acheckIsResponseChangedV3ForTest
if added to theindex.ts
file. This function is used to determine if validation should be skipped.This function is exported and unit tested to ensure it correctly checks for changes for the various field types.
Breaking Changes