Skip to content

Commit

Permalink
Add error messaging to Veteran Verification /status endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
khenson-oddball committed Nov 14, 2024
1 parent 367d277 commit 6fc4210
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
16 changes: 16 additions & 0 deletions lib/lighthouse/veteran_verification/constants.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module VeteranVerification

Check failure on line 1 in lib/lighthouse/veteran_verification/constants.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Style/FrozenStringLiteralComment: Missing frozen string literal comment.
module Constants
NOT_FOUND_MESSAGE = [

Check failure on line 3 in lib/lighthouse/veteran_verification/constants.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Style/MutableConstant: Freeze mutable objects assigned to constants.
'We’re sorry. There’s a problem with your discharge status records. We can’t provide a Veteran status ' \
'card for you right now.',

Check failure on line 5 in lib/lighthouse/veteran_verification/constants.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/LineEndStringConcatenationIndentation: Align parts of a string concatenated with backslash.
'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.'

Check failure on line 7 in lib/lighthouse/veteran_verification/constants.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/LineEndStringConcatenationIndentation: Align parts of a string concatenated with backslash.
]
NOT_ELIGIBLE_MESSAGE = [

Check failure on line 9 in lib/lighthouse/veteran_verification/constants.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Style/MutableConstant: Freeze mutable objects assigned to constants.
'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.',

Check failure on line 11 in lib/lighthouse/veteran_verification/constants.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/LineEndStringConcatenationIndentation: Align parts of a string concatenated with backslash.
'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.'

Check failure on line 13 in lib/lighthouse/veteran_verification/constants.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/LineEndStringConcatenationIndentation: Align parts of a string concatenated with backslash.
]
end
end

Check failure on line 16 in lib/lighthouse/veteran_verification/constants.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/TrailingEmptyLines: Final newline missing.
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.include?('not_confirmed_reason')

Check failure on line 63 in lib/lighthouse/veteran_verification/service.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Rails/NegateInclude: Use `.exclude?` and remove the negation part.

if attributes['not_confirmed_reason'] == 'NOT_TITLE_38'

Check failure on line 65 in lib/lighthouse/veteran_verification/service.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Style/ConditionalAssignment: Use the return of the conditional for variable assignment and comparison.
response['data']['message'] = VeteranVerification::Constants::NOT_ELIGIBLE_MESSAGE
else
response['data']['message'] = 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

0 comments on commit 6fc4210

Please sign in to comment.