Skip to content

Commit

Permalink
API-24371-valid-ssn (#11899)
Browse files Browse the repository at this point in the history
* WIP

* Removes req to always have an ssn

* Fix exception message

* Incremental commit

* Finalize error return, update tests

* Remove unused code

---------

Co-authored-by: Matt Christianson <matthew.christianson1@va.gov>
  • Loading branch information
stiehlrod and mchristiansonVA authored Mar 6, 2023
1 parent 24d114c commit 6958800
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ def validate
}
end

def validate_ssn(ssn)
regex = /^(\d{9})$/
if !regex.match?(ssn) || ssn.size != 9
error_detail = 'Invalid claimantSsn parameter'
raise ::Common::Exceptions::UnprocessableEntity.new(detail: error_detail)
end
end

private

def intent_to_file_options(type)
Expand All @@ -76,7 +84,10 @@ def intent_to_file_options(type)
# BGS requires at least 1 of 'participant_claimant_id' or 'claimant_ssn'
def handle_claimant_fields(options:, params:, target_veteran:)
claimant_ssn = params[:claimantSsn]

if claimant_ssn.present?
claimant_ssn = claimant_ssn.gsub('-', '')
validate_ssn(claimant_ssn)
end
options[:claimant_ssn] = claimant_ssn if claimant_ssn

# if claimant_ssn field was not provided, then default to sending 'participant_claimant_id'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@
with_okta_user(scopes) do |auth_header|
survivor_data = data
survivor_data[:type] = 'survivor'
survivor_data[:claimantSsn] = '123456'
survivor_data[:claimantSsn] = '123456789'
post itf_submit_path, params: survivor_data, headers: auth_header
expect(response.status).to eq(200)
end
Expand All @@ -428,6 +428,18 @@
end
end
end

context 'when invalid parameter is provided' do
it 'returns a 422' do
with_okta_user(scopes) do |auth_header|
survivor_data = data
survivor_data[:type] = 'survivor'
survivor_data[:claimantSsn] = 'abcdefghi'
post itf_submit_path, params: survivor_data, headers: auth_header
expect(response.status).to eq(422)
end
end
end
end
end

Expand Down

0 comments on commit 6958800

Please sign in to comment.