Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API-41802-empty-unit-test #19305

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
stiehlrod marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,65 @@
end
end
end

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

it 'returns a successful response' do
stiehlrod marked this conversation as resolved.
Show resolved Hide resolved
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
end

Expand Down
Loading