Skip to content

Commit

Permalink
API-27078-526-v2-allow-yyyy-mm-date-format-2 (#12927)
Browse files Browse the repository at this point in the history
* Updates 526.json and related json fles to be inline with new date formats
* Updates valdations file to handle new date formats
* Updates validation specs t handle tests with new date formats
	* Also adds some new tests for handling new scenarios
* Updates swagger docs
Changes to be committed:
	modified:   modules/claims_api/app/controllers/concerns/claims_api/v2/disability_compensation_validation.rb
	modified:   modules/claims_api/app/swagger/claims_api/v2/dev/swagger.json
	modified:   modules/claims_api/config/schemas/v2/526.json
	modified:   modules/claims_api/config/schemas/v2/request_bodies/disability_compensation/example.json
	modified:   modules/claims_api/config/schemas/v2/request_bodies/disability_compensation/request.json
	modified:   modules/claims_api/spec/fixtures/v2/veterans/disability_compensation/form_526_json_api.json
	modified:   modules/claims_api/spec/lib/claims_api/v2/disability_compensation_pdf_mapper_spec.rb
	modified:   modules/claims_api/spec/requests/v2/veterans/disability_compensation_request_spec.rb
	modified:   spec/support/schemas/claims_api/v2/forms/disability/submission.json
  • Loading branch information
rockwellwindsor-va authored Jun 7, 2023
1 parent 7aba5ed commit ae4f586
Show file tree
Hide file tree
Showing 9 changed files with 1,550 additions and 1,290 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def validate_form_526_disability_approximate_begin_date!
approx_begin_date = disability['approximateDate']
next if approx_begin_date.blank?

next if Date.parse(approx_begin_date) < Time.zone.today
next if date_is_valid_against_current_time_after_check_on_format?(approx_begin_date)

raise ::Common::Exceptions::InvalidFieldValue.new('disability.approximateDate', approx_begin_date)
end
Expand Down Expand Up @@ -245,7 +245,7 @@ def validate_form_526_disability_secondary_disability_classification_code_matche
end

def validate_form_526_disability_secondary_disability_approximate_begin_date!(secondary_disability)
return if Date.parse(secondary_disability['approximateDate']) < Time.zone.today
return if date_is_valid_against_current_time_after_check_on_format?(secondary_disability['approximateDate'])

raise ::Common::Exceptions::InvalidFieldValue.new(
'disabilities.secondaryDisabilities.approximateDate',
Expand Down Expand Up @@ -368,7 +368,7 @@ def validate_form_526_separation_pay_received_date!
'datePaymentReceived')
return if separation_pay_received_date.blank?

return if Date.parse(separation_pay_received_date) < Time.zone.today
return if date_is_valid_against_current_time_after_check_on_format?(separation_pay_received_date)

raise ::Common::Exceptions::InvalidFieldValue.new('separationSeverancePay.datePaymentReceived',
separation_pay_received_date)
Expand Down Expand Up @@ -468,7 +468,8 @@ def validate_confinements!
service_information['confinements'].each do |confinement|
approximate_begin_date = confinement['approximateBeginDate']
approximate_end_date = confinement['approximateEndDate']
if Date.parse(approximate_begin_date) > Date.parse(approximate_end_date)

if begin_date_is_not_after_end_date?(approximate_begin_date, approximate_end_date)
raise ::Common::Exceptions::UnprocessableEntity.new(
detail: 'Approximate end date must be after approximate begin date.'
)
Expand Down Expand Up @@ -576,6 +577,55 @@ def raise_exception_if_value_present(val)
detail: "The #{val} is required for direct deposit."
)
end

private

def begin_date_is_not_after_end_date?(begin_date, end_date)
# see what format each date is in
begin_date_has_day = date_has_day?(begin_date)
end_date_has_day = date_has_day?(end_date)
# determine how to compare, being = is ok
if (begin_date_has_day && end_date_has_day) || (!begin_date_has_day && !end_date_has_day) # same format
begin_date > end_date
else # mixed formats on dates
begin_date_not_after_end_date_with_mixed_format_dates?(begin_date, end_date)
end
end

# Either date could be in MM-YYYY or MM-DD-YYYY format
def begin_date_not_after_end_date_with_mixed_format_dates?(begin_date, end_date)
# figure out which one has the day and remove it
if date_has_day?(begin_date)
begin_date = remove_chars(begin_date.dup)
elsif date_has_day?(end_date)
end_date = remove_chars(end_date.dup)
end
Date.strptime(begin_date, '%m-%Y') > Date.strptime(end_date, '%m-%Y') # = is ok
end

def date_is_valid_against_current_time_after_check_on_format?(date)
if date_has_day?(date)
param_date = Date.strptime(date, '%m-%d-%Y')
now_date = Date.strptime(Time.zone.today.strftime('%m-%d-%Y'), '%m-%d-%Y')
else
param_date = Date.strptime(date, '%m-%Y')
now_date = Date.strptime(Time.zone.today.strftime('%m-%Y'), '%m-%Y')
end
param_date <= now_date # Since it is approximate we go with <=
end

# just need to know if day is present or not
def date_has_day?(date)
date.length == 10
end

# making date approximate to compare
def remove_chars(str)
indices = [2, 3, 4] # MM| -DD |-YYYY
sz = str.size
indices.map { |i| i >= 0 ? i : sz + i }.sort.reverse_each { |i| str[i] = '' }
str
end
end
end
end
257 changes: 118 additions & 139 deletions modules/claims_api/app/swagger/claims_api/v2/dev/swagger.json

Large diffs are not rendered by default.

Loading

0 comments on commit ae4f586

Please sign in to comment.