-
Notifications
You must be signed in to change notification settings - Fork 94
Api 55108 v2 val use claim date #27550
Changes from 7 commits
03ec21b
a3dea9c
9c4fd6a
4554b02
5cb1a6e
2b96d22
715c5c0
2a47ffc
cd0c8e3
e947997
f1ec987
851b7d7
d632710
b054557
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,11 +2,13 @@ | |
|
|
||
| require 'claims_api/v2/disability_compensation_shared_service_module' | ||
| require 'claims_api/lighthouse_military_address_validator' | ||
| require 'claims_api/disability_compensation_validations_helper' | ||
|
|
||
| module ClaimsApi | ||
| module V2 | ||
| module DisabilityCompensationValidation # rubocop:disable Metrics/ModuleLength | ||
| include DisabilityCompensationSharedServiceModule | ||
| include ClaimsApi::DisabilityCompensationValidationsHelper | ||
|
jeremyhunton-va marked this conversation as resolved.
|
||
| include LighthouseMilitaryAddressValidator | ||
|
|
||
| DATE_FORMATS = { | ||
|
|
@@ -25,6 +27,8 @@ def validate_form_526_submission_values(target_veteran) | |
| return if form_attributes.empty? | ||
|
|
||
| validate_claim_process_type_bdd if bdd_claim? | ||
| # ensure 'claimDate', if provided, is not in the future | ||
| validate_form_526_claim_date | ||
| # ensure 'claimantCertification' is true | ||
| validate_form_526_claimant_certification | ||
| # ensure mailing address country is valid | ||
|
|
@@ -51,12 +55,13 @@ def validate_form_526_submission_values(target_veteran) | |
|
|
||
| private | ||
|
|
||
| def claim_date | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a repeat of the helper file |
||
| @claim_date = if date_is_valid?(form_attributes['claimDate'], 'claimDate', true) | ||
| Date.parse(form_attributes['claimDate']) | ||
| else | ||
| Time.zone.today | ||
| end | ||
| def validate_form_526_claim_date | ||
| return if claim_date <= Date.current | ||
|
|
||
| collect_error_messages( | ||
| source: '/claimDate', | ||
| detail: 'claimDate must not be in the future.' | ||
| ) | ||
| end | ||
|
|
||
| def validate_form_526_change_of_address | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1487,5 +1487,20 @@ def validate_field(field_path, expected_detail, expected_source) | |
| expect(errors).to be_empty | ||
| end | ||
| end | ||
|
|
||
| context 'when claimDate is in the future' do | ||
| it 'collects an error with the correct message' do | ||
| future_date = (Date.current + 1.day).iso8601 | ||
| test_526_validation_instance.form_attributes['claimDate'] = future_date | ||
| test_526_validation_instance.instance_variable_set(:@claim_date, nil) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test manually resets @claim_date with instance_variable_set(:@claim_date, nil). This is fine for testing, but note that claim_date in the shared helper uses memoization (@claim_date = ...). If claim_date was previously called in the test setup with a non-future date, and @claim_date isn't reset, the validation would pass incorrectly. The test does reset it, so it works — but this is worth noting as a pattern that couples tests to internal implementation details. |
||
|
|
||
| test_526_validation_instance.send(:alt_rev_validate_form_526_claim_date) | ||
| errors = current_error_array | ||
|
|
||
| expect(errors).not_to be_empty | ||
| expect(errors[0][:detail]).to eq('claimDate must not be in the future.') | ||
| expect(errors[0][:source]).to eq('/claimDate') | ||
| end | ||
| end | ||
| end | ||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
noticed claimDate business logic was not being checked before we used it for validations. This probably could have waited until the claimDate was actually added to the schema, so open to revert but I don't think it hurts anything.