diff --git a/lib/va_profile/profile/v3/service.rb b/lib/va_profile/profile/v3/service.rb index 8c26e61e49f..2eee7fbd6de 100644 --- a/lib/va_profile/profile/v3/service.rb +++ b/lib/va_profile/profile/v3/service.rb @@ -10,7 +10,7 @@ module Profile module V3 # NOTE: This controller is used for discovery purposes. # Please contact the Authenticated Experience Profile team before using. - class Service < Common::Client::Base + class Service < VAProfile::Service configuration VAProfile::Profile::V3::Configuration OID = '2.16.840.1.113883.3.42.10001.100001.12' @@ -20,7 +20,7 @@ class Service < Common::Client::Base def initialize(user) @user = user - super() + super(user) end def get_health_benefit_bio @@ -28,6 +28,8 @@ def get_health_benefit_bio path = "#{oid}/#{ERB::Util.url_encode(icn_with_aaid)}" response = perform(:post, path, { bios: [{ bioPath: 'healthBenefit' }] }) VAProfile::Profile::V3::HealthBenefitBioResponse.new(response) + rescue => e + handle_error(e) end def get_military_info diff --git a/spec/lib/va_profile/profile/v3/service_spec.rb b/spec/lib/va_profile/profile/v3/service_spec.rb index ddcae4f7b05..cc7f96f57b2 100644 --- a/spec/lib/va_profile/profile/v3/service_spec.rb +++ b/spec/lib/va_profile/profile/v3/service_spec.rb @@ -55,30 +55,54 @@ describe '#get_health_benefit_bio' do let(:user) { build(:user, :loa3, idme_uuid:) } + around do |ex| + VCR.use_cassette(cassette) { ex.run } + end + context '200 response' do let(:idme_uuid) { 'dd681e7d6dea41ad8b80f8d39284ef29' } + let(:cassette) { 'va_profile/profile/v3/health_benefit_bio_200' } it 'returns the contacts (aka associated_persons) for a user, sorted' do - VCR.use_cassette('va_profile/profile/v3/health_benefit_bio_200') do - response = subject.get_health_benefit_bio - expect(response.status).to eq(200) - expect(response.contacts.size).to eq(4) - types = response.contacts.map(&:contact_type) - expect(types).to match_array(VAProfile::Models::AssociatedPerson::CONTACT_TYPES) - end + response = subject.get_health_benefit_bio + expect(response.status).to eq(200) + expect(response.contacts.size).to eq(4) + types = response.contacts.map(&:contact_type) + expect(types).to match_array(VAProfile::Models::AssociatedPerson::CONTACT_TYPES) end end context '404 response' do let(:idme_uuid) { '88f572d4-91af-46ef-a393-cba6c351e252' } + let(:cassette) { 'va_profile/profile/v3/health_benefit_bio_404' } it 'includes messages recieved from the api' do - VCR.use_cassette('va_profile/profile/v3/health_benefit_bio_404') do - response = subject.get_health_benefit_bio - expect(response.status).to eq(404) - expect(response.contacts.size).to eq(0) - expect(response.messages.size).to eq(1) - end + response = subject.get_health_benefit_bio + expect(response.status).to eq(404) + expect(response.contacts.size).to eq(0) + expect(response.messages.size).to eq(1) + end + end + + context '500 response' do + let(:idme_uuid) { '88f572d4-91af-46ef-a393-cba6c351e252' } + let(:cassette) { 'va_profile/profile/v3/health_benefit_bio_500' } + + it 'includes messages recieved from the api' do + response = subject.get_health_benefit_bio + expect(response.status).to eq(500) + expect(response.contacts.size).to eq(0) + expect(response.messages.size).to eq(1) + end + end + + context 'api timeout' do + let(:idme_uuid) { '88f572d4-91af-46ef-a393-cba6c351e252' } + let(:cassette) { 'va_profile/profile/v3/health_benefit_bio_500' } + + it 'raises an error' do + allow_any_instance_of(Faraday::Connection).to receive(:post).and_raise(Faraday::TimeoutError) + expect { subject.get_health_benefit_bio }.to raise_error(Common::Exceptions::GatewayTimeout) end end end diff --git a/spec/support/vcr_cassettes/va_profile/profile/v3/health_benefit_bio_500.yml b/spec/support/vcr_cassettes/va_profile/profile/v3/health_benefit_bio_500.yml new file mode 100644 index 00000000000..66944f355f2 --- /dev/null +++ b/spec/support/vcr_cassettes/va_profile/profile/v3/health_benefit_bio_500.yml @@ -0,0 +1,61 @@ +--- +http_interactions: +- request: + method: post + uri: https://int.vet360.va.gov/profile-service/profile/v3/2.16.840.1.113883.4.349/88f572d4-91af-46ef-a393-cba6c351e252%5EPN%5E200VIDM%5EUSDVA + body: + encoding: UTF-8 + string: '{"bios":[{"bioPath":"healthBenefit"}]}' + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - Vets.gov Agent + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 500 + message: Internal Server Error + headers: + X-Oneagent-Js-Injection: + - 'true' + Server-Timing: + - dtRpid;desc="-552585048", dtSInfo;desc="0" + - dtRpid;desc="667499283", dtSInfo;desc="0" + Vaprofiletxauditid: + - ab45e9d3-6491-4062-8384-40d23135d252 + X-Content-Type-Options: + - nosniff + X-Xss-Protection: + - '0' + Cache-Control: + - no-cache, no-store, max-age=0, must-revalidate + Pragma: + - no-cache + Expires: + - '0' + X-Frame-Options: + - DENY + Content-Security-Policy: + - 'default-src ''self'' ''unsafe-eval'' ''unsafe-inline'' data: filesystem: + about: blob: ws: wss:' + Date: + - Mon, 05 Feb 2024 22:13:44 GMT + Referrer-Policy: + - no-referrer + Content-Type: + - application/json + Content-Length: + - '184' + Strict-Transport-Security: + - max-age=16000000; includeSubDomains; preload; + body: + encoding: UTF-8 + string: '{"messages":[{"code":"MVI203","key":"MviResponseError","text":"MVI returned + acknowledgement error code AE with error detail: More Than One Active Correlation + Exists","severity":"FATAL"}]}' + recorded_at: Mon, 05 Feb 2024 22:13:44 GMT +recorded_with: VCR 6.2.0