Skip to content

Commit

Permalink
Same work, different branch to get around ci/cd hang up. Adds a trans…
Browse files Browse the repository at this point in the history
…from method to add a space rather than submitting an empty string. Adds tests. (#19459)
  • Loading branch information
stiehlrod authored Nov 14, 2024
1 parent 7dc4da9 commit ab28b3e
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
10 changes: 10 additions & 0 deletions modules/claims_api/app/models/claims_api/auto_established_claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def to_internal # rubocop:disable Metrics/MethodLength
resolve_homelessness_risk_situation_type_mappings!
transform_homelessness_point_of_contact_primary_phone!
transform_address_lines_length!
transform_empty_unit_name!

{
form526: form_data
Expand Down Expand Up @@ -533,5 +534,14 @@ def transform_address_lines_length!

form_data['veteran']['currentMailingAddress'] = addr
end

def transform_empty_unit_name!
reserves = form_data&.dig('serviceInformation', 'reservesNationalGuardService')
return if reserves.nil?

unit_name = reserves['unitName']
unit_name = unit_name.presence || ' '
reserves['unitName'] = unit_name
end
end
end
15 changes: 15 additions & 0 deletions modules/claims_api/spec/models/auto_establish_claim_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,21 @@
end
end

describe '#transform_empty_unit_name!' do
let(:unit_name) { '' }

it 'trasforms an empty unit name to a space' do
temp_form_data = pending_record.form_data
temp_form_data['serviceInformation']['reservesNationalGuardService']['unitName'] = unit_name

pending_record.form_data = temp_form_data
payload = JSON.parse(pending_record.to_internal)
name = payload['form526']['serviceInformation']['reservesNationalGuardService']['unitName']

expect(name).to eq(' ')
end
end

describe 'evss_id_by_token' do
context 'with a record' do
let(:evss_record) { create(:auto_established_claim, evss_id: 123_456) }
Expand Down
59 changes: 59 additions & 0 deletions modules/claims_api/spec/requests/v1/forms/526_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,65 @@
end
end
end

context "when 'unitName' is empty" do
let(:unit_name) { '' }

it 'returns a successful response' do
mock_acg(scopes) do |auth_header|
VCR.use_cassette('claims_api/bgs/claims/claims') do
VCR.use_cassette('claims_api/brd/countries') do
par = json_data
par['data']['attributes']['serviceInformation']['reservesNationalGuardService']['unitName'] =
unit_name

post path, params: par.to_json, headers: headers.merge(auth_header)
expect(response).to have_http_status(:ok)
response_body = JSON.parse(response.body)
claim_id = response_body['data']['id']
claim = ClaimsApi::AutoEstablishedClaim.find(claim_id)
claim.to_internal
expect(claim.form_data['serviceInformation']['reservesNationalGuardService']['unitName']).to eq(' ')
end
end
end
end
end

context "when 'unitName' is nil" do
let(:unit_name) { nil }

it 'returns a unsuccessful response' do
mock_acg(scopes) do |auth_header|
VCR.use_cassette('claims_api/bgs/claims/claims') do
VCR.use_cassette('claims_api/brd/countries') do
par = json_data
par['data']['attributes']['serviceInformation']['reservesNationalGuardService']['unitName'] =
unit_name

post path, params: par.to_json, headers: headers.merge(auth_header)
expect(response).to have_http_status(:unprocessable_entity)
end
end
end
end
end

context "when 'unitName' is not present" do
it 'returns a unsuccessful response' do
mock_acg(scopes) do |auth_header|
VCR.use_cassette('claims_api/bgs/claims/claims') do
VCR.use_cassette('claims_api/brd/countries') do
par = json_data
par['data']['attributes']['serviceInformation']['reservesNationalGuardService'].delete('unitName')

post path, params: par.to_json, headers: headers.merge(auth_header)
expect(response).to have_http_status(:unprocessable_entity)
end
end
end
end
end
end

context '526 submission payload validations' do
Expand Down

0 comments on commit ab28b3e

Please sign in to comment.