Skip to content

LG-9825: Add back-end validation for the DOB on the state id form#8501

Merged
dawei-nava merged 25 commits intomainfrom
dwang/LG-9825-dob-validation
Jun 1, 2023
Merged

LG-9825: Add back-end validation for the DOB on the state id form#8501
dawei-nava merged 25 commits intomainfrom
dwang/LG-9825-dob-validation

Conversation

@dawei-nava
Copy link
Contributor

@dawei-nava dawei-nava commented May 27, 2023

🎫 Ticket LG9825 Backend validation of DOB.

🛠 Summary of changes

Validate the DOB for minimum age requirement on the state id form.

📜 Testing Plan

Provide a checklist of steps to confirm the changes.

  • Modify form_state_id_validator.rb and change age to Time.zone.today - 200.years
  • Navigate through ipp flow and to the state_id step. Use an invalid first name like First5, an invalid DOB like 12-2-2022
  • Submit it will flag the first name as invalid, but DOB as valid
  • Modify the age to be greater than 13 but less than 200
  • Submit the form again, it will flag the DOB as invalid(validation by backend)
  • Remove change form_state_id_validator.rb to restore the original validate function.
  • Submit the form, the DOB field validated as normal

👀 Screenshots

Disable both frontend and backend validation:

Screenshot 2023-05-30 at 9 25 23 AM

After restore backend validation

Screenshot 2023-05-30 at 9 28 57 AM

and test cases.

changelog: Internal, In-Person Proofing, Add DOB validation for minimal age.
@dawei-nava dawei-nava force-pushed the dwang/LG-9825-dob-validation branch from 8f3e122 to 60faf4d Compare May 27, 2023 13:04
@dawei-nava dawei-nava marked this pull request as ready for review May 30, 2023 14:19
@dawei-nava dawei-nava requested review from a team and eileen-nava May 30, 2023 14:38
@tomas-nava tomas-nava changed the title Dwang/lg 9825 dob validation LG-9825: Add back-end validation for the DOB on the state id form May 31, 2023
@@ -0,0 +1,37 @@
module UspsInPersonProofing
# Validator that can be attached to a form or other model
# to verify that specific supported fields are comparable to other dates.
Copy link
Contributor

Choose a reason for hiding this comment

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

This validator is to make sure a user's age is within an accepted range right? Would it be more accurate/clear to say "...to verify that user input in supported date fields fall within an accepted range".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@svalexander, it not necessarily a single range, can be combinations of following:
greater_than, greater_than_or_equal_to, equal_to, less_than, less_than_or_equal_to and other_than.


# @param [String,Date,#to_hash] param
# @return [Date]
# It's caller's responsibility to ensure the param contains required entries
Copy link
Contributor

@svalexander svalexander Jun 1, 2023

Choose a reason for hiding this comment

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

i'm not quite sure I understand this comment. what are required entries?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@svalexander, the param can be a type of ActionController::Parameters from state id form submission, where it contains 3 keys, year, month, day. Here we treat it as a hash, so if you pass in anything can be treated as a hash(.to_hash method), it assumes that these three entries exists, it's caller's responsibility to make sure they exists to avoid error.

Copy link
Contributor

Choose a reason for hiding this comment

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

ahh ok thank you for clarifying

Copy link
Contributor

@NavaTim NavaTim left a comment

Choose a reason for hiding this comment

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

Main issues are to correct the test file naming and ensure that the tests are using the values that they're setting. Other changes are recommended, but I'd be willing to approve without them.

Copy link
Contributor

Choose a reason for hiding this comment

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

Typo in file name - should be address_form_spec.rb.

Comment on lines 46 to 47
good_params[:same_address_as_id] = false
result = subject.submit(bad_params)
Copy link
Contributor

Choose a reason for hiding this comment

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

You're setting a value on good_params here but instead using bad_params.

Comment on lines 66 to 67
good_params[:same_address_as_id] = false
result = subject.submit(bad_params)
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to the above:

You're setting a value on good_params here but instead using bad_params.

Comment on lines 5 to 23
let(:good_params) do
{
address1: Faker::Address.street_address,
address2: Faker::Address.secondary_address,
zipcode: Faker::Address.zip_code,
state: Faker::Address.state_abbr,
city: Faker::Address.city,
}
end
let(:invalid_char) { '$' }
let(:bad_params) do
{
address1: invalid_char + Faker::Address.street_address,
address2: invalid_char + Faker::Address.secondary_address + invalid_char,
zipcode: Faker::Address.zip_code,
state: Faker::Address.state_abbr,
city: invalid_char + Faker::Address.city,
}
end
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to wrap these in an additional context indicating that these values and the following tests pertain specifically to transliteration. i.e. especially since the usage of good/bad here could otherwise seem ambiguous.

expect(subject.errors.to_hash).to include(:address1, :address2, :city)
expect(result).to be_kind_of(FormResponse)
expect(result.success?).to be(false)
expect(result.errors.empty?).to be(true)
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be best to intentionally include at least one error unrelated to transliteration in this test in order to ensure that the combined behavior is correct.

Comment on lines +79 to +84
expect(subject.errors[:first_name]).to eq [
I18n.t(
'in_person_proofing.form.state_id.errors.unsupported_chars',
char_list: [invalid_char].join(', '),
),
]
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good here to add an additional line or test confirming that the result errors don't include the transliteration error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@NavaTim addressed all comments on tests.

Copy link
Contributor

@NavaTim NavaTim left a comment

Choose a reason for hiding this comment

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

The PR works, but I recommend restricting the usage of the # prefix to usages like:

context '#submit' do

i.e. only in a context/describe block (not it/test), and only when the string name passed exactly matches the name of the method being tested.

before(:each) do
allow(IdentityConfig.store).to receive(:usps_ipp_transliteration_enabled).and_return(false)
end
it '#submit success with good params' do
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
it '#submit success with good params' do
it 'submit success with good params' do

expect(result.success?).to be(true)
end

it '#submit success with good params' do
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
it '#submit success with good params' do
it 'submit success with good params' do

expect(result.success?).to be(true)
end

it '#submit success with bad params' do
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
it '#submit success with bad params' do
it 'submit success with bad params' do

before(:each) do
allow(IdentityConfig.store).to receive(:usps_ipp_transliteration_enabled).and_return(true)
end
it '#submit success with good params' do
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
it '#submit success with good params' do
it 'submit success with good params' do

expect(result).to be_kind_of(FormResponse)
expect(result.success?).to be(true)
end
it '#submit failure with bad params' do
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
it '#submit failure with bad params' do
it 'submit failure with bad params' do

end
context 'when capture_secondary_id_enabled is true' do
let(:subject) { described_class.new(capture_secondary_id_enabled: true) }
it '#submit with missing same_address_as_id should be successful' do
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
it '#submit with missing same_address_as_id should be successful' do
it 'submit with missing same_address_as_id should be successful' do

end
context 'when capture_secondary_id_enabled is false' do
let(:subject) { described_class.new(capture_secondary_id_enabled: false) }
it '#submit with missing same_address_as_id will fail' do
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
it '#submit with missing same_address_as_id will fail' do
it 'submit with missing same_address_as_id will fail' do

@dawei-nava dawei-nava merged commit 1e7362d into main Jun 1, 2023
@dawei-nava dawei-nava deleted the dwang/LG-9825-dob-validation branch June 1, 2023 17:52
This was referenced Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants