Skip to content

Commit

Permalink
Api 24364 improve validation for survivor (#11898)
Browse files Browse the repository at this point in the history
* Fix logic to check claimant vs vet ssn

* Update test to correct HTTP code returned

* Fix Rubocop line length, add rswag entry for 422

* Remove byebug

* Changes to 422 test for v2

* Going with Rubocop correction

* Remove optional participant_claimant_id param

* Update docs for param removal

* Generated swagger reflecting param removal

* Commit tested version of validator

* Fix test per new validation

* Add test for updated survivor validation

* Update test user and setup to return 422 with uddated logic

* Update validate to return 422 if no claimantSsn provided for survivor type
  • Loading branch information
mchristiansonVA authored Mar 2, 2023
1 parent 868a634 commit 994cd9f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module IntentToFile
class IntentToFileValidator < ActiveModel::Validator
def validate(record)
validate_type(record)
validate_ssn_for_survivor(record)
end

private
Expand All @@ -19,6 +20,17 @@ def validate_type(record)
record.errors.add :type, value
end
end

def validate_ssn_for_survivor(record)
type = record.data[:type]
if type == 'survivor' && record.data[:action] != 'type'
value = record.data[:claimantSsn]
if value.blank?
error_detail = "claimantSsn parameter cannot be blank for type 'survivor'"
raise ::Common::Exceptions::UnprocessableEntity.new(detail: error_detail)
end
end
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,20 @@
end

context 'when payload is invalid' do
context "when 'type' is survivor" do
context "when 'claimantSsn' is blank" do
it 'returns a 422' do
with_okta_user(scopes) do |auth_header|
invalid_data = data
invalid_data[:type] = 'survivor'
invalid_data[:claimantSsn] = ''
post itf_validate_path, params: invalid_data, headers: auth_header
expect(response.status).to eq(422)
end
end
end
end

context "when 'type' is invalid" do
context "when 'type' is blank" do
it 'returns a 400' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,17 @@
'default.json')))

let(:scopes) { %w[claim.write] }
let(:data) { { type: 'survivor' } }
let(:data) { { type: 'survivor', claimantSsn: '796111863' } }
let(:veteranId) { '1013062086V794840' } # rubocop:disable RSpec/VariableName

before do |example|
stub_poa_verification
stub_mpi

with_okta_user(scopes) do
submit_request(example.metadata)
VCR.use_cassette('bgs/intent_to_file_web_service/insert_intent_to_file') do
submit_request(example.metadata)
end
end
end

Expand Down

0 comments on commit 994cd9f

Please sign in to comment.