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

Add error messaging to Veteran Verification /status endpoint #19467

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 18 additions & 0 deletions lib/lighthouse/veteran_verification/constants.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module VeteranVerification
module Constants
NOT_FOUND_MESSAGE = [
'We’re sorry. There’s a problem with your discharge status records. We can’t provide a Veteran status ' \
'card for you right now.',
'To fix the problem with your records, call the Defense Manpower Data Center at 800-538-9552 (TTY: 711).' \
' They’re open Monday through Friday, 8:00 a.m. to 8:00 p.m. ET.'
].freeze
NOT_ELIGIBLE_MESSAGE = [
'Our records show that you’re not eligible for a Veteran status card. To get a Veteran status card, you ' \
'must have received an honorable discharge for at least one period of service.',
'If you think your discharge status is incorrect, call the Defense Manpower Data Center at 800-538-9552 ' \
'(TTY: 711). They’re open Monday through Friday, 8:00 a.m. to 8:00 p.m. ET.'
].freeze
end
end
18 changes: 17 additions & 1 deletion lib/lighthouse/veteran_verification/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'common/client/base'
require 'lighthouse/veteran_verification/configuration'
require 'lighthouse/veteran_verification/constants'
require 'lighthouse/service_exception'

module VeteranVerification
Expand Down Expand Up @@ -36,12 +37,14 @@ def get_rated_disabilities(icn, lighthouse_client_id = nil, lighthouse_rsa_key_p
# see https://developer.va.gov/explore/api/veteran-service-history-and-eligibility/docs
def get_vet_verification_status(icn, lighthouse_client_id = nil, lighthouse_rsa_key_path = nil, options = {})
endpoint = 'status'
config.get(
response = config.get(
"#{endpoint}/#{icn}",
lighthouse_client_id,
lighthouse_rsa_key_path,
options
).body

transform_response(response)
rescue => e
handle_error(e, lighthouse_client_id, endpoint)
end
Expand All @@ -54,5 +57,18 @@ def handle_error(error, lighthouse_client_id, endpoint)
"#{config.base_api_path}/#{endpoint}"
)
end

def transform_response(response)
attributes = response['data']['attributes']
return response if attributes['veteran_status'] != 'not confirmed' || attributes.exclude?('not_confirmed_reason')

response['data']['message'] =
if attributes['not_confirmed_reason'] == 'NOT_TITLE_38'
VeteranVerification::Constants::NOT_ELIGIBLE_MESSAGE
else
VeteranVerification::Constants::NOT_FOUND_MESSAGE
end
response
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
parsed_body = JSON.parse(response.body)
expect(parsed_body['data']['attributes']['veteran_status']).to eq('not confirmed')
expect(parsed_body['data']['attributes']['not_confirmed_reason']).to eq('PERSON_NOT_FOUND')
expect(parsed_body['data']['message']).to eq(VeteranVerification::Constants::NOT_FOUND_MESSAGE)
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions spec/lib/lighthouse/veteran_verification/service_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'rails_helper'
require 'lighthouse/veteran_verification/constants'
require 'lighthouse/veteran_verification/service'
require 'lighthouse/service_exception'

Expand Down Expand Up @@ -65,9 +66,22 @@ def test_error(cassette_path)
it 'retrieves veteran not confirmed status from the Lighthouse API' do
VCR.use_cassette('lighthouse/veteran_verification/status/200_not_confirmed_response') do
response = @service.get_vet_verification_status('1012666182V203559', '', '')

expect(response['data']['id']).to eq('1012666182V203559')
expect(response['data']['attributes']['veteran_status']).to eq('not confirmed')
expect(response['data']['attributes']).to have_key('not_confirmed_reason')
expect(response['data']['message']).to eq(VeteranVerification::Constants::NOT_ELIGIBLE_MESSAGE)
end
end

it 'retrieves veteran not found status from the Lighthouse API' do
VCR.use_cassette('lighthouse/veteran_verification/status/200_person_not_found_response') do
response = @service.get_vet_verification_status('1012667145V762141', '', '')

expect(response['data']['id']).to eq(nil)
expect(response['data']['attributes']['veteran_status']).to eq('not confirmed')
expect(response['data']['attributes']).to have_key('not_confirmed_reason')
expect(response['data']['message']).to eq(VeteranVerification::Constants::NOT_FOUND_MESSAGE)
end
end

Expand Down
Loading