diff --git a/app/controllers/v0/id_card_attributes_controller.rb b/app/controllers/v0/id_card_attributes_controller.rb index 232963018df..e46e6aaf4f2 100644 --- a/app/controllers/v0/id_card_attributes_controller.rb +++ b/app/controllers/v0/id_card_attributes_controller.rb @@ -28,7 +28,7 @@ def authorize raise VIC::IDCardAttributeError, status: 403, code: 'VIC002', detail: 'Unable to verify EDIPI' unless current_user.edipi.present? begin - unless current_user.veteran? + unless current_user.can_access_id_card? raise VIC::IDCardAttributeError, status: 403, code: 'VIC003', detail: 'Not eligible for a Veteran ID Card' end diff --git a/app/models/emis_redis/veteran_status.rb b/app/models/emis_redis/veteran_status.rb index 873d3ff11e5..a98e027950d 100644 --- a/app/models/emis_redis/veteran_status.rb +++ b/app/models/emis_redis/veteran_status.rb @@ -6,10 +6,14 @@ class VeteranStatus < Model CLASS_NAME = 'VeteranStatusService' def veteran? + title38_status == 'V1' + end + + def title38_status raise VeteranStatus::NotAuthorized unless @user.loa3? response = emis_response('get_veteran_status') raise VeteranStatus::RecordNotFound if response.empty? - any_veteran_indicator?(response.items.first) + response.items.first&.title38_status_code end class NotAuthorized < StandardError @@ -17,13 +21,5 @@ class NotAuthorized < StandardError class RecordNotFound < StandardError end - - private - - def any_veteran_indicator?(item) - item.post911_deployment_indicator == 'Y' || - item.post911_combat_indicator == 'Y' || - item.pre911_deployment_indicator == 'Y' - end end end diff --git a/app/models/id_card_attributes.rb b/app/models/id_card_attributes.rb index ddb4af7c375..d3bec91293e 100644 --- a/app/models/id_card_attributes.rb +++ b/app/models/id_card_attributes.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class IdCardAttributes attr_accessor :user @@ -20,6 +21,7 @@ def traits 'zip' => @user.va_profile&.address&.postal_code || '', 'email' => @user.email, 'phone' => @user.va_profile&.home_phone || '', + 'title38status' => title38_status_code, 'branchofservice' => branches_of_service, 'dischargetype' => discharge_types } @@ -38,6 +40,12 @@ def traits 'H' => 'PHS' # USPHS }.freeze + def title38_status_code + @user.veteran_status.title38_status || 'UNKNOWN' + rescue StandardError + 'UNKNOWN' + end + def branches_of_service branches = @user.military_information.service_episodes_by_date.map do |ep| SERVICE_KEYS[ep.branch_of_service_code] diff --git a/app/models/user.rb b/app/models/user.rb index 359b11b0284..4807139792d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'common/models/base' require 'common/models/redis_store' require 'mvi/messages/find_profile_message' @@ -12,6 +13,9 @@ class User < Common::RedisStore UNALLOCATED_SSN_PREFIX = '796' # most test accounts use this + # Defined per issue #6042 + ID_CARD_ALLOWED_STATUSES = %w(V1 V3 V6).freeze + redis_store REDIS_CONFIG['user_store']['namespace'] redis_ttl REDIS_CONFIG['user_store']['each_ttl'] redis_key :uuid @@ -111,8 +115,9 @@ def can_prefill_emis? end def can_access_id_card? - beta_enabled?(uuid, 'veteran_id_card') && loa3? && edipi.present? && veteran? - rescue # Default to false for any veteran_status error + loa3? && edipi.present? && beta_enabled?(uuid, 'veteran_id_card') && + ID_CARD_ALLOWED_STATUSES.include?(veteran_status.title38_status) + rescue StandardError # Default to false for any veteran_status error false end diff --git a/spec/lib/emis/veteran_status_service_spec.rb b/spec/lib/emis/veteran_status_service_spec.rb index fa60b425d47..aec71f59d48 100644 --- a/spec/lib/emis/veteran_status_service_spec.rb +++ b/spec/lib/emis/veteran_status_service_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' require 'emis/veteran_status_service' require 'emis/responses/get_veteran_status_response' @@ -8,26 +9,37 @@ require 'emis/veteran_status_configuration' describe EMIS::VeteranStatusService do - let(:edipi) { '1607472595' } + let(:edipi_veteran) { '1068619536' } + let(:edipi_non_veteran) { '1140840595' } let(:bad_edipi) { '595' } let(:missing_edipi) { '1111111111' } + let(:no_status) { '1005079361' } describe 'get_veteran_status' do context 'with a valid request' do it 'calls the get_veteran_status endpoint with a proper emis message' do VCR.use_cassette('emis/get_veteran_status/valid') do - response = subject.get_veteran_status(edipi: edipi) + response = subject.get_veteran_status(edipi: edipi_veteran) expect(response).to be_ok end end it 'gives me the right values back' do VCR.use_cassette('emis/get_veteran_status/valid') do - response = subject.get_veteran_status(edipi: edipi) - expect(response.items.first.title38_status_code).to eq('V4') + response = subject.get_veteran_status(edipi: edipi_veteran) + expect(response.items.first.title38_status_code).to eq('V1') expect(response.items.first.post911_deployment_indicator).to eq('Y') expect(response.items.first.post911_combat_indicator).to eq('N') - expect(response.items.first.pre911_deployment_indicator).to eq('Y') + expect(response.items.first.pre911_deployment_indicator).to eq('N') + end + end + end + + context 'with a valid request for a non-veteran' do + it 'gives me the right values back' do + VCR.use_cassette('emis/get_veteran_status/valid_non_veteran') do + response = subject.get_veteran_status(edipi: edipi_non_veteran) + expect(response.items.first.title38_status_code).to eq('V4') end end end @@ -50,6 +62,15 @@ end end end + + context 'with an empty response element' do + it 'returns nil' do + VCR.use_cassette('emis/get_veteran_status/empty_title38') do + response = subject.get_veteran_status(edipi: no_status) + expect(response.items.first).to be_nil + end + end + end end end diff --git a/spec/models/emis_redis/veteran_status_spec.rb b/spec/models/emis_redis/veteran_status_spec.rb index 3ebc62f54dc..dbbc40ab068 100644 --- a/spec/models/emis_redis/veteran_status_spec.rb +++ b/spec/models/emis_redis/veteran_status_spec.rb @@ -42,4 +42,22 @@ end end end + + describe 'title38_status' do + context 'with a valid response for a veteran' do + it 'returns true' do + VCR.use_cassette('emis/get_veteran_status/valid') do + expect(subject.title38_status).to eq('V1') + end + end + end + + context 'with a valid response for a non-veteran' do + it 'returns false' do + VCR.use_cassette('emis/get_veteran_status/valid_non_veteran') do + expect(subject.title38_status).to eq('V4') + end + end + end + end end diff --git a/spec/request/id_card_attributes_request_spec.rb b/spec/request/id_card_attributes_request_spec.rb index d57afab1f55..f21998b3bde 100644 --- a/spec/request/id_card_attributes_request_spec.rb +++ b/spec/request/id_card_attributes_request_spec.rb @@ -10,17 +10,15 @@ before do Settings.vic.signing_key_path = "#{::Rails.root}/spec/support/certificates/vic-signing-key.pem" use_authenticated_current_user(current_user: current_user) - end - - def url_param_map(url) - params = URI.decode_www_form(url.query) - params.each_with_object({}) { |a, h| h[a.first] = a.last } + expect(current_user).to receive('beta_enabled?').with(current_user.uuid, 'veteran_id_card').and_return(true) end describe '#show /v0/id_card/attributes' do it 'should return a signed redirect URL' do expect_any_instance_of(EMISRedis::MilitaryInformation) .to receive(:service_episodes_by_date).at_least(:once).and_return(service_episodes) + expect_any_instance_of(EMISRedis::VeteranStatus) + .to receive(:title38_status).at_least(:once).and_return('V1') get '/v0/id_card/attributes', headers: auth_header expect(response).to have_http_status(:ok) json = JSON.parse(response.body) @@ -30,6 +28,7 @@ def url_param_map(url) expect(traits.key?('edipi')).to be_truthy expect(traits.key?('firstname')).to be_truthy expect(traits.key?('lastname')).to be_truthy + expect(traits.key?('title38status')).to be_truthy expect(traits.key?('branchofservice')).to be_truthy expect(traits.key?('dischargetype')).to be_truthy expect(traits.key?('timestamp')).to be_truthy @@ -37,6 +36,8 @@ def url_param_map(url) end it 'should return Bad Gateway if military information not retrievable' do + expect_any_instance_of(EMISRedis::VeteranStatus) + .to receive(:title38_status).at_least(:once).and_return('V1') expect_any_instance_of(EMISRedis::MilitaryInformation) .to receive(:service_episodes_by_date).and_raise(StandardError) get '/v0/id_card/attributes', headers: auth_header @@ -45,14 +46,14 @@ def url_param_map(url) it 'should return Forbidden for non-veteran user' do expect_any_instance_of(EMISRedis::VeteranStatus) - .to receive(:veteran?).and_return(false) + .to receive(:title38_status).and_return('V2') get '/v0/id_card/attributes', headers: auth_header expect(response).to have_http_status(:forbidden) end it 'should return Forbidden when veteran status not retrievable' do expect_any_instance_of(EMISRedis::VeteranStatus) - .to receive(:veteran?).and_raise(StandardError) + .to receive(:title38_status).and_raise(StandardError) get '/v0/id_card/attributes', headers: auth_header expect(response).to have_http_status(:forbidden) end diff --git a/spec/support/vcr_cassettes/emis/get_veteran_status/empty_title38.yml b/spec/support/vcr_cassettes/emis/get_veteran_status/empty_title38.yml new file mode 100644 index 00000000000..48c3945763f --- /dev/null +++ b/spec/support/vcr_cassettes/emis/get_veteran_status/empty_title38.yml @@ -0,0 +1,68 @@ +--- +http_interactions: +- request: + method: post + uri: https://vaausvrsapp81.aac.va.gov/VIERSService/eMIS/v1/VeteranStatusService + body: + encoding: ASCII-8BIT + string: |2 + + + + + vets.gov + vets.gov + 43ca3df9-c348-466b-9a1c-7bc294ac0fde + + + + + + 1005079361 + EDIPI + + + + + headers: + Accept: + - text/xml;charset=UTF-8 + Content-Type: + - text/xml;charset=UTF-8 + User-Agent: + - Vets.gov Agent + Soapaction: + - http://viers.va.gov/cdi/eMIS/getVeteranStatus/v1 + Date: + - Thu, 16 Nov 2017 05:07:27 GMT + Content-Length: + - '944' + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 200 + message: OK + headers: + Date: + - Thu, 16 Nov 2017 05:07:27 GMT + Server: + - Apache/2.4.6 (Red Hat Enterprise Linux) + Set-Cookie: + - BlueStripe.PVN=a0c6b89f0000031e; path=/ + Content-Length: + - '559' + Cache-Control: + - max-age=0, no-store + Connection: + - close + Content-Type: + - application/soap+xml;charset=utf-8 + body: + encoding: UTF-8 + string: vets.govvets.gov43ca3df9-c348-466b-9a1c-7bc294ac0fde + http_version: + recorded_at: Thu, 16 Nov 2017 05:07:28 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/support/vcr_cassettes/emis/get_veteran_status/valid.yml b/spec/support/vcr_cassettes/emis/get_veteran_status/valid.yml index 74a16564027..be0ce97ce58 100644 --- a/spec/support/vcr_cassettes/emis/get_veteran_status/valid.yml +++ b/spec/support/vcr_cassettes/emis/get_veteran_status/valid.yml @@ -12,13 +12,13 @@ http_interactions: vets.gov vets.gov - 17f9cc3e-8004-439d-9b14-2f4482497b76 + 144135ae-d659-45f7-ae53-61952697f4f0 - 1607472595 + 1068619536 EDIPI @@ -34,7 +34,7 @@ http_interactions: Soapaction: - http://viers.va.gov/cdi/eMIS/getVeteranStatus/v1 Date: - - Wed, 19 Apr 2017 19:19:36 GMT + - Thu, 16 Nov 2017 00:22:07 GMT Content-Length: - '944' Accept-Encoding: @@ -45,11 +45,11 @@ http_interactions: message: OK headers: Date: - - Wed, 19 Apr 2017 19:19:32 GMT + - Thu, 16 Nov 2017 00:22:06 GMT Server: - Apache/2.4.6 (Red Hat Enterprise Linux) Set-Cookie: - - BlueStripe.PVN=8f791dcd0000002c; path=/ + - BlueStripe.PVN=a0c8dc6b000000ed; path=/ Content-Length: - '1312' Cache-Control: @@ -62,13 +62,13 @@ http_interactions: encoding: UTF-8 string: Successvets.govvets.gov17f9cc3e-8004-439d-9b14-2f4482497b76vets.govvets.gov144135ae-d659-45f7-ae53-61952697f4f01607472595V41068619536V1YNY + xmlns:NS10="http://viers.va.gov/cdi/eMIS/commonService/v1">N http_version: - recorded_at: Wed, 19 Apr 2017 19:19:37 GMT + recorded_at: Thu, 16 Nov 2017 00:22:07 GMT recorded_with: VCR 3.0.3 diff --git a/spec/support/vcr_cassettes/emis/get_veteran_status/valid_non_veteran.yml b/spec/support/vcr_cassettes/emis/get_veteran_status/valid_non_veteran.yml index 833af0626ed..58e7ea123d5 100644 --- a/spec/support/vcr_cassettes/emis/get_veteran_status/valid_non_veteran.yml +++ b/spec/support/vcr_cassettes/emis/get_veteran_status/valid_non_veteran.yml @@ -12,13 +12,13 @@ http_interactions: vets.gov vets.gov - 17f9cc3e-8004-439d-9b14-2f4482497b76 + a3cf46e0-5b2c-4bc8-9823-675bdfe0ded2 - 1607472595 + 1140840595 EDIPI @@ -34,7 +34,7 @@ http_interactions: Soapaction: - http://viers.va.gov/cdi/eMIS/getVeteranStatus/v1 Date: - - Wed, 19 Apr 2017 19:19:36 GMT + - Thu, 16 Nov 2017 00:22:06 GMT Content-Length: - '944' Accept-Encoding: @@ -45,11 +45,11 @@ http_interactions: message: OK headers: Date: - - Wed, 19 Apr 2017 19:19:32 GMT + - Thu, 16 Nov 2017 00:22:06 GMT Server: - Apache/2.4.6 (Red Hat Enterprise Linux) Set-Cookie: - - BlueStripe.PVN=8f791dcd0000002c; path=/ + - BlueStripe.PVN=a0b9910700000e32; path=/ Content-Length: - '1312' Cache-Control: @@ -62,14 +62,13 @@ http_interactions: encoding: UTF-8 string: Successvets.govvets.gov17f9cc3e-8004-439d-9b14-2f4482497b76vets.govvets.gova3cf46e0-5b2c-4bc8-9823-675bdfe0ded216074725951140840595V4NNN - http_version: - recorded_at: Wed, 19 Apr 2017 19:19:37 GMT + xmlns:NS10="http://viers.va.gov/cdi/eMIS/commonService/v1">N + http_version: + recorded_at: Thu, 16 Nov 2017 00:22:07 GMT recorded_with: VCR 3.0.3