Skip to content

Commit

Permalink
API 24828 v2 526 address validation (#12795)
Browse files Browse the repository at this point in the history
* Validate Change Of Address

* Fix typo

* Fix tests

---------

Co-authored-by: Austin Covrig <austin.covrig@oddball.io>
  • Loading branch information
acovrig and acovrig authored Jun 1, 2023
1 parent 589af8f commit 2dd990e
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def validate_form_526_submission_values!
validate_form_526_disabilities!
# ensure homeless information is valid
validate_form_526_veteran_homelessness!
# ensure new address is valid
validate_form_526_change_of_address!
# ensure military service pay information is valid
validate_form_526_service_pay!
# ensure treament centers information is valid
Expand All @@ -24,6 +26,45 @@ def validate_form_526_submission_values!
validate_form_526_service_information!
end

def validate_form_526_change_of_address!
return if form_attributes['changeOfAddress'].blank?

validate_form_526_change_of_address_beginning_date!
validate_form_526_change_of_address_ending_date!
validate_form_526_change_of_address_country!
end

def validate_form_526_change_of_address_beginning_date!
change_of_address = form_attributes['changeOfAddress']
date = change_of_address.dig('dates', 'beginningDate')
return unless 'TEMPORARY'.casecmp?(change_of_address['typeOfAddressChange'])

# If the date parse fails, then fall back to the InvalidFieldValue
begin
return if Date.parse(date) < Time.zone.now
rescue
raise ::Common::Exceptions::InvalidFieldValue.new('changeOfAddress.dates.beginningDate', date)
end

raise ::Common::Exceptions::InvalidFieldValue.new('changeOfAddress.dates.beginningDate', date)
end

def validate_form_526_change_of_address_ending_date!
change_of_address = form_attributes['changeOfAddress']
date = change_of_address.dig('dates', 'endingDate')
return unless 'TEMPORARY'.casecmp?(change_of_address['typeOfAddressChange'])
return if Date.parse(date) > Date.parse(change_of_address.dig('dates', 'beginningDate'))

raise ::Common::Exceptions::InvalidFieldValue.new('changeOfAddress.dates.endingDate', date)
end

def validate_form_526_change_of_address_country!
change_of_address = form_attributes['changeOfAddress']
return if valid_countries.include?(change_of_address['country'])

raise ::Common::Exceptions::InvalidFieldValue.new('changeOfAddress.country', change_of_address['country'])
end

def validate_form_526_submission_claim_date!
return if form_attributes['claimDate'].blank?
# EVSS runs in the Central US Time Zone.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"claimDate": "2023-02-18",
"changeOfAddress": {
"dates": {
"beginningDate": "2012-11-31",
"beginningDate": "2012-11-30",
"endingDate": "2013-10-11"
},
"typeOfAddressChange": "TEMPORARY",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
zip = pdf_data[:data][:attributes][:changeOfAddress][:zip]
state = pdf_data[:data][:attributes][:changeOfAddress][:state]

expect(beginning_date).to eq('2012-11-31')
expect(beginning_date).to eq('2012-11-30')
expect(ending_date).to eq('2013-10-11')
expect(type_of_addr_change).to eq('TEMPORARY')
expect(number_and_street).to eq('10 Peach St')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,90 @@
end
end

describe 'validation of claimant change of address elements' do
context 'when the country is valid' do
let(:country) { 'USA' }

it 'responds with a 200' do
with_okta_user(scopes) do |auth_header|
VCR.use_cassette('evss/claims/claims') do
VCR.use_cassette('brd/countries') do
VCR.use_cassette('brd/disabilities') do
json = JSON.parse(data)
json['data']['attributes']['changeOfAddress']['country'] = country
data = json.to_json
post path, params: data, headers: headers.merge(auth_header)
expect(response).to have_http_status(:ok)
end
end
end
end
end
end

context 'when the country is invalid' do
let(:country) { 'United States of Nada' }

it 'responds with bad request' do
with_okta_user(scopes) do |auth_header|
VCR.use_cassette('evss/claims/claims') do
VCR.use_cassette('brd/countries') do
VCR.use_cassette('brd/disabilities') do
json = JSON.parse(data)
json['data']['attributes']['changeOfAddress']['country'] = country
data = json.to_json
post path, params: data, headers: headers.merge(auth_header)
expect(response).to have_http_status(:bad_request)
end
end
end
end
end
end

context 'when no mailing address data is found' do
it 'responds with bad request' do
with_okta_user(scopes) do |auth_header|
VCR.use_cassette('evss/claims/claims') do
VCR.use_cassette('brd/countries') do
json = JSON.parse(data)
json['data']['attributes']['changeOfAddress'] = {}
data = json.to_json
post path, params: data, headers: headers.merge(auth_header)
expect(response).to have_http_status(:unprocessable_entity)
end
end
end
end
end

context 'when the begin date is after the end date' do
let(:begin_date) { '2023-01-01' }
let(:end_date) { '2022-01-01' }

it 'responds with bad request' do
with_okta_user(scopes) do |auth_header|
VCR.use_cassette('evss/claims/claims') do
VCR.use_cassette('brd/countries') do
VCR.use_cassette('brd/disabilities') do
json = JSON.parse(data)
json['data']['attributes']['changeOfAddress']['dates']['beginningDate'] = begin_date
json['data']['attributes']['changeOfAddress']['dates']['endingDate'] = end_date
data = json.to_json
post path, params: data, headers: headers.merge(auth_header)
expect(response).to have_http_status(:bad_request)
end
end
end
end
end
end
end

context 'when the phone has non-digits included' do
let(:telephone) { '123456789X' }

it 'responds with bad request' do
it 'responds with unprocessable request' do
with_okta_user(scopes) do |auth_header|
VCR.use_cassette('evss/claims/claims') do
VCR.use_cassette('brd/countries') do
Expand Down

0 comments on commit 2dd990e

Please sign in to comment.