From b57cc48621fe84e2165604a0661b618cf5f8a12a Mon Sep 17 00:00:00 2001 From: Aurora <19178435+aurora-a-k-a-lightning@users.noreply.github.com> Date: Tue, 26 Mar 2024 09:43:44 -0700 Subject: [PATCH 1/2] dbex/77177: EVSS Migration - /generatePDF migration: Abstract references to EVSS /getpdf (#16080) * dbex/77177: add GeneratePdfProvider - FEATURE TOGGLE: disability_compensation_lighthouse_generate_pdf - evss - lighthouse stub(s) - unit tests * dbex/77177: add GeneratePdfProvider - fix linting and unit test * dbex/77177: add GeneratePdfProvider - fix linting and unit test * dbex/77177: add GeneratePdfProvider - added a unit test for evss service class checking --- config/features.yml | 3 ++ .../factories/api_provider_factory.rb | 27 ++++++++++- .../evss_generate_pdf_provider.rb | 22 +++++++++ .../generate_pdf/generate_pdf_provider.rb | 7 +++ .../lighthouse_generate_pdf_provider.rb | 15 ++++++ .../processor.rb | 23 ++++++++- .../factories/api_provider_factory_spec.rb | 34 +++++++++++++ .../evss_generate_pdf_provider_spec.rb | 48 +++++++++++++++++++ .../generate_pdf_provider_spec.rb | 12 +++++ .../lighthouse_generate_pdf_provider_spec.rb | 31 ++++++++++++ .../submit_spec.rb | 2 + .../job_tracker_spec.rb | 4 ++ .../generate_pdf_service_provider.rb | 10 ++++ 13 files changed, 235 insertions(+), 3 deletions(-) create mode 100644 lib/disability_compensation/providers/generate_pdf/evss_generate_pdf_provider.rb create mode 100644 lib/disability_compensation/providers/generate_pdf/generate_pdf_provider.rb create mode 100644 lib/disability_compensation/providers/generate_pdf/lighthouse_generate_pdf_provider.rb create mode 100644 spec/lib/disability_compensation/providers/generate_pdf/evss_generate_pdf_provider_spec.rb create mode 100644 spec/lib/disability_compensation/providers/generate_pdf/generate_pdf_provider_spec.rb create mode 100644 spec/lib/disability_compensation/providers/generate_pdf/lighthouse_generate_pdf_provider_spec.rb create mode 100644 spec/support/disability_compensation_form/shared_examples/generate_pdf_service_provider.rb diff --git a/config/features.yml b/config/features.yml index 1d75967a58b..068190f7557 100644 --- a/config/features.yml +++ b/config/features.yml @@ -1257,6 +1257,9 @@ features: disability_compensation_lighthouse_brd: actor_type: user description: If enabled uses the lighthouse Benefits Reference Data service + disability_compensation_lighthouse_generate_pdf: + actor_type: user + description: If enabled uses the lighthouse Benefits Claims service to generate a 526 pdf virtual_agent_fetch_jwt_token: actor_type: user description: Enable the fetching of a JWT token to access MAP environment diff --git a/lib/disability_compensation/factories/api_provider_factory.rb b/lib/disability_compensation/factories/api_provider_factory.rb index e9d7b1913b7..a8b7185306e 100644 --- a/lib/disability_compensation/factories/api_provider_factory.rb +++ b/lib/disability_compensation/factories/api_provider_factory.rb @@ -15,6 +15,9 @@ require 'disability_compensation/providers/brd/brd_provider' require 'disability_compensation/providers/brd/evss_brd_provider' require 'disability_compensation/providers/brd/lighthouse_brd_provider' +require 'disability_compensation/providers/generate_pdf/generate_pdf_provider' +require 'disability_compensation/providers/generate_pdf/evss_generate_pdf_provider' +require 'disability_compensation/providers/generate_pdf/lighthouse_generate_pdf_provider' require 'logging/third_party_transaction' class ApiProviderFactory @@ -31,7 +34,8 @@ class UndefinedFactoryTypeError < StandardError; end intent_to_file: :intent_to_file, ppiu: :ppiu, claims: :claims, - brd: :brd + brd: :brd, + generate_pdf: :generate_pdf }.freeze # Splitting the rated disabilities functionality into two use cases: @@ -47,6 +51,7 @@ class UndefinedFactoryTypeError < StandardError; end # PPIU calls out to Direct Deposit APIs in Lighthouse FEATURE_TOGGLE_PPIU_DIRECT_DEPOSIT = 'disability_compensation_lighthouse_ppiu_direct_deposit_provider' FEATURE_TOGGLE_BRD = 'disability_compensation_lighthouse_brd' + FEATURE_TOGGLE_GENERATE_PDF = 'disability_compensation_lighthouse_generate_pdf' attr_reader :type @@ -56,6 +61,7 @@ class UndefinedFactoryTypeError < StandardError; end :ppiu_service_provider, :claims_service_provider, :brd_service_provider, + :generate_pdf_service_provider, additional_class_logs: { action: 'disability compensation factory choosing API Provider' }, @@ -91,6 +97,8 @@ def call claims_service_provider when FACTORIES[:brd] brd_service_provider + when FACTORIES[:generate_pdf] + generate_pdf_service_provider else raise UndefinedFactoryTypeError end @@ -153,6 +161,23 @@ def brd_service_provider end end + def generate_pdf_service_provider + case api_provider + when API_PROVIDER[:evss] + if @options[:auth_headers].nil? || @options[:auth_headers]&.empty? + raise StandardError, 'options[:auth_headers] is required to create a generate an EVSS pdf provider' + end + + # provide options[:breakered] = false if this needs to use the non-breakered configuration + # for instance, in the backup process + EvssGeneratePdfProvider.new(@options[:auth_headers], breakered: @options[:breakered]) + when API_PROVIDER[:lighthouse] + LighthouseGeneratePdfProvider.new({}) + else + raise NotImplementedError, 'No known Generate Pdf Api Provider type provided' + end + end + def api_provider @api_provider ||= if Flipper.enabled?(@feature_toggle, @current_user) API_PROVIDER[:lighthouse] diff --git a/lib/disability_compensation/providers/generate_pdf/evss_generate_pdf_provider.rb b/lib/disability_compensation/providers/generate_pdf/evss_generate_pdf_provider.rb new file mode 100644 index 00000000000..6cd03f26212 --- /dev/null +++ b/lib/disability_compensation/providers/generate_pdf/evss_generate_pdf_provider.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'disability_compensation/providers/generate_pdf/generate_pdf_provider' +require 'evss/disability_compensation_form/service' +require 'evss/disability_compensation_form/non_breakered_service' + +class EvssGeneratePdfProvider + include GeneratePdfProvider + + def initialize(auth_headers, breakered: true) + # both of these services implement `get_form526` + @service = if breakered + EVSS::DisabilityCompensationForm::Service.new(auth_headers) + else + EVSS::DisabilityCompensationForm::NonBreakeredService.new(auth_headers) + end + end + + def generate_526_pdf(form_content) + @service.get_form526(form_content) + end +end diff --git a/lib/disability_compensation/providers/generate_pdf/generate_pdf_provider.rb b/lib/disability_compensation/providers/generate_pdf/generate_pdf_provider.rb new file mode 100644 index 00000000000..f914f6c9772 --- /dev/null +++ b/lib/disability_compensation/providers/generate_pdf/generate_pdf_provider.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module GeneratePdfProvider + def self.generate_526_pdf(_form_content) + raise NotImplementedError, 'Do not use base module methods. Override this method in implementation class.' + end +end diff --git a/lib/disability_compensation/providers/generate_pdf/lighthouse_generate_pdf_provider.rb b/lib/disability_compensation/providers/generate_pdf/lighthouse_generate_pdf_provider.rb new file mode 100644 index 00000000000..0384339de2d --- /dev/null +++ b/lib/disability_compensation/providers/generate_pdf/lighthouse_generate_pdf_provider.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'disability_compensation/providers/generate_pdf/generate_pdf_provider' + +class LighthouseGeneratePdfProvider + include GeneratePdfProvider + + def initialize(_auth_headers) + # TODO: Implement in Ticket# + end + + def generate_526_pdf(_form_content) + # TODO: Implement in Ticket# + end +end diff --git a/lib/sidekiq/form526_backup_submission_process/processor.rb b/lib/sidekiq/form526_backup_submission_process/processor.rb index 0394818197d..1645719f412 100644 --- a/lib/sidekiq/form526_backup_submission_process/processor.rb +++ b/lib/sidekiq/form526_backup_submission_process/processor.rb @@ -13,6 +13,7 @@ require 'pdf_fill/filler' require 'logging/third_party_transaction' require 'simple_forms_api_submission/metadata_validator' +require 'disability_compensation/factories/api_provider_factory' module Sidekiq module Form526BackupSubmissionProcess @@ -341,7 +342,10 @@ def get_form526_pdf end def get_form_from_external_api(headers, form_json) - EVSS::DisabilityCompensationForm::Service.new(headers).get_form526(form_json) + # get the "breakered" version + service = choose_provider(headers, breakered: true) + + service.generate_526_pdf(form_json) end def get_uploads @@ -423,6 +427,18 @@ def convert_doc_to_pdf(doc, klass) Common::FileHelpers.delete_file_if_exists(actual_path_to_file) if ::Rails.env.production? end end + + def choose_provider(headers, breakered: true) + ApiProviderFactory.call( + type: ApiProviderFactory::FACTORIES[:generate_pdf], + # let Flipper - the feature toggle - choose which provider + provider: nil, + # this sends the auth headers and if we want the "breakered" or "non-breakered" version + options: { auth_headers: headers, breakered: }, + current_user: OpenStruct.new({ flipper_id: submission.user_uuid }), + feature_toggle: ApiProviderFactory::FEATURE_TOGGLE_GENERATE_PDF + ) + end end class NonBreakeredProcessor < Processor @@ -444,7 +460,10 @@ def get_form526_pdf end def get_from_non_breakered_service(headers, form_json) - EVSS::DisabilityCompensationForm::NonBreakeredService.new(headers).get_form526(form_json) + # get the "non-breakered" version + service = choose_provider(headers, breakered: false) + + service.get_form526(form_json) end class NonBreakeredForm526BackgroundLoader diff --git a/spec/lib/disability_compensation/factories/api_provider_factory_spec.rb b/spec/lib/disability_compensation/factories/api_provider_factory_spec.rb index b95ce03cd19..4f5202d5c3d 100644 --- a/spec/lib/disability_compensation/factories/api_provider_factory_spec.rb +++ b/spec/lib/disability_compensation/factories/api_provider_factory_spec.rb @@ -210,4 +210,38 @@ def provider(api_provider = nil) end.to raise_error NotImplementedError end end + + context 'generate_pdf' do + def provider(api_provider = nil) + ApiProviderFactory.call( + type: ApiProviderFactory::FACTORIES[:generate_pdf], + provider: api_provider, + options: { auth_headers: }, + current_user:, + feature_toggle: ApiProviderFactory::FEATURE_TOGGLE_GENERATE_PDF + ) + end + + it 'provides an EVSS generate_pdf provider' do + expect(provider(:evss).class).to equal(EvssGeneratePdfProvider) + end + + it 'provides a Lighthouse generate_pdf provider' do + expect(provider(:lighthouse).class).to equal(LighthouseGeneratePdfProvider) + end + + it 'provides generate_pdf provider based on Flipper' do + Flipper.enable(ApiProviderFactory::FEATURE_TOGGLE_GENERATE_PDF) + expect(provider.class).to equal(LighthouseGeneratePdfProvider) + + Flipper.disable(ApiProviderFactory::FEATURE_TOGGLE_GENERATE_PDF) + expect(provider.class).to equal(EvssGeneratePdfProvider) + end + + it 'throw error if provider unknown' do + expect do + provider(:random) + end.to raise_error NotImplementedError + end + end end diff --git a/spec/lib/disability_compensation/providers/generate_pdf/evss_generate_pdf_provider_spec.rb b/spec/lib/disability_compensation/providers/generate_pdf/evss_generate_pdf_provider_spec.rb new file mode 100644 index 00000000000..030d63de9d8 --- /dev/null +++ b/spec/lib/disability_compensation/providers/generate_pdf/evss_generate_pdf_provider_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'rails_helper' +require 'disability_compensation/factories/api_provider_factory' +require 'disability_compensation/providers/generate_pdf/evss_generate_pdf_provider' +require 'support/disability_compensation_form/shared_examples/generate_pdf_service_provider' + +RSpec.describe EvssGeneratePdfProvider do + let(:current_user) do + create(:user) + end + + let(:auth_headers) do + EVSS::AuthHeaders.new(current_user).to_h + end + + before do + Flipper.disable(ApiProviderFactory::FEATURE_TOGGLE_GENERATE_PDF) + end + + after do + Flipper.disable(ApiProviderFactory::FEATURE_TOGGLE_GENERATE_PDF) + end + + it_behaves_like 'generate pdf service provider' + + it 'creates a breakered evss service' do + provider = EvssGeneratePdfProvider.new(auth_headers) + expect(provider.instance_variable_get(:@service).class).to equal(EVSS::DisabilityCompensationForm::Service) + + provider = EvssGeneratePdfProvider.new(auth_headers, breakered: true) + expect(provider.instance_variable_get(:@service).class).to equal(EVSS::DisabilityCompensationForm::Service) + end + + it 'creates a non-breakered evss service' do + provider = EvssGeneratePdfProvider.new(auth_headers, breakered: false) + expect(provider.instance_variable_get(:@service).class) + .to equal(EVSS::DisabilityCompensationForm::NonBreakeredService) + end + + it 'retrieves a generated 526 pdf from the EVSS API' do + VCR.use_cassette('form526_backup/200_evss_get_pdf', match_requests_on: %i[uri method]) do + provider = EvssGeneratePdfProvider.new(auth_headers) + response = provider.generate_526_pdf({}.to_json) + expect(response.body['pdf']).to eq('') + end + end +end diff --git a/spec/lib/disability_compensation/providers/generate_pdf/generate_pdf_provider_spec.rb b/spec/lib/disability_compensation/providers/generate_pdf/generate_pdf_provider_spec.rb new file mode 100644 index 00000000000..943f88d3a65 --- /dev/null +++ b/spec/lib/disability_compensation/providers/generate_pdf/generate_pdf_provider_spec.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require 'rails_helper' +require 'disability_compensation/providers/generate_pdf/generate_pdf_provider' + +RSpec.describe GeneratePdfProvider do + it 'always raises an error on the BRDProvider base module' do + expect do + subject.generate_526_pdf({}) + end.to raise_error NotImplementedError + end +end diff --git a/spec/lib/disability_compensation/providers/generate_pdf/lighthouse_generate_pdf_provider_spec.rb b/spec/lib/disability_compensation/providers/generate_pdf/lighthouse_generate_pdf_provider_spec.rb new file mode 100644 index 00000000000..808fb69a552 --- /dev/null +++ b/spec/lib/disability_compensation/providers/generate_pdf/lighthouse_generate_pdf_provider_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'rails_helper' +require 'disability_compensation/factories/api_provider_factory' +require 'disability_compensation/providers/generate_pdf/lighthouse_generate_pdf_provider' +require 'support/disability_compensation_form/shared_examples/generate_pdf_service_provider' +require 'lighthouse/service_exception' + +RSpec.describe LighthouseGeneratePdfProvider do + let(:auth_headers) { {} } + + before do + @provider = LighthouseGeneratePdfProvider.new(auth_headers) + Flipper.enable(ApiProviderFactory::FEATURE_TOGGLE_GENERATE_PDF) + end + + after do + Flipper.disable(ApiProviderFactory::FEATURE_TOGGLE_GENERATE_PDF) + end + + it_behaves_like 'generate pdf service provider' + + # TODO: Implement in Ticket# + # it 'retrieves a generated 526 pdf from the Lighthouse API' do + # VCR.use_cassette('lighthouse/benefits_claims/generate_pdf/200_response') do + # + # response = @provider.generate_526_pdf + # expect(response).to eq(nil) + # end + # end +end diff --git a/spec/lib/sidekiq/form526_backup_submission_process/submit_spec.rb b/spec/lib/sidekiq/form526_backup_submission_process/submit_spec.rb index 69ff18ad1ff..0ec092ed2f5 100644 --- a/spec/lib/sidekiq/form526_backup_submission_process/submit_spec.rb +++ b/spec/lib/sidekiq/form526_backup_submission_process/submit_spec.rb @@ -4,12 +4,14 @@ require 'evss/disability_compensation_auth_headers' # required to build a Form526Submission require 'sidekiq/form526_backup_submission_process/submit' +require 'disability_compensation/factories/api_provider_factory' RSpec.describe Sidekiq::Form526BackupSubmissionProcess::Submit, type: :job do subject { described_class } before do Sidekiq::Job.clear_all + Flipper.disable(ApiProviderFactory::FEATURE_TOGGLE_GENERATE_PDF) end let(:user) { FactoryBot.create(:user, :loa3) } diff --git a/spec/lib/sidekiq/form526_job_status_tracker/job_tracker_spec.rb b/spec/lib/sidekiq/form526_job_status_tracker/job_tracker_spec.rb index a8c84527c9b..8ed993a919b 100644 --- a/spec/lib/sidekiq/form526_job_status_tracker/job_tracker_spec.rb +++ b/spec/lib/sidekiq/form526_job_status_tracker/job_tracker_spec.rb @@ -11,6 +11,10 @@ end end + before do + Flipper.disable(ApiProviderFactory::FEATURE_TOGGLE_GENERATE_PDF) + end + context 'with an exhausted callback message' do let!(:form526_submission) { create :form526_submission } let!(:form526_job_status) do diff --git a/spec/support/disability_compensation_form/shared_examples/generate_pdf_service_provider.rb b/spec/support/disability_compensation_form/shared_examples/generate_pdf_service_provider.rb new file mode 100644 index 00000000000..76fdc0fbf20 --- /dev/null +++ b/spec/support/disability_compensation_form/shared_examples/generate_pdf_service_provider.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +require 'rails_helper' + +shared_examples 'generate pdf service provider' do + # this is used to instantiate any Claim Service with a current_user + subject { described_class.new(auth_headers) } + + it { is_expected.to respond_to(:generate_526_pdf) } +end From 8253e76a36952dc9d656bcd52c49006147ddae7c Mon Sep 17 00:00:00 2001 From: Richard Davis Date: Tue, 26 Mar 2024 12:53:57 -0400 Subject: [PATCH 2/2] [Bugfix] Personal health care contacts: Selects only valid contact types (#16062) * Selects only valid contact types --- .../profile/v3/health_benefit_bio_response.rb | 44 ++++++++----- .../v3/health_benefit_bio_response_spec.rb | 62 +++++++++++++++++++ .../lib/va_profile/profile/v3/service_spec.rb | 56 +++++++++++++---- .../profile/v3/health_benefit_bio_500.yml | 61 ++++++++++++++++++ 4 files changed, 196 insertions(+), 27 deletions(-) create mode 100644 spec/lib/va_profile/profile/v3/health_benefit_bio_response_spec.rb create mode 100644 spec/support/vcr_cassettes/va_profile/profile/v3/health_benefit_bio_500.yml diff --git a/lib/va_profile/profile/v3/health_benefit_bio_response.rb b/lib/va_profile/profile/v3/health_benefit_bio_response.rb index ffea96f8731..1dde3fb9f89 100644 --- a/lib/va_profile/profile/v3/health_benefit_bio_response.rb +++ b/lib/va_profile/profile/v3/health_benefit_bio_response.rb @@ -4,23 +4,39 @@ require 'va_profile/models/associated_person' require 'va_profile/models/message' -module VAProfile::Profile::V3 - class HealthBenefitBioResponse < VAProfile::Response - attr_reader :body +module VAProfile + module Profile + module V3 + class HealthBenefitBioResponse < VAProfile::Response + attr_reader :body - attribute :contacts, Array[VAProfile::Models::AssociatedPerson] - attribute :messages, Array[VAProfile::Models::Message] + attribute :contacts, Array[VAProfile::Models::AssociatedPerson] + attribute :messages, Array[VAProfile::Models::Message] - def initialize(response) - @body = response.body - contacts = body.dig('profile', 'health_benefit', 'associated_persons') - &.sort_by { |p| VAProfile::Models::AssociatedPerson::CONTACT_TYPES.index(p['contact_type']) } - messages = body['messages'] - super(response.status, { contacts:, messages: }) - end + def initialize(response) + @body = response.body + contacts = body.dig('profile', 'health_benefit', 'associated_persons') + &.select { |p| valid_contact_types.include?(p['contact_type']) } + &.sort_by { |p| valid_contact_types.index(p['contact_type']) } + messages = body['messages'] + super(response.status, { contacts:, messages: }) + end + + def metadata + { status:, messages: } + end + + private - def metadata - { status:, messages: } + def valid_contact_types + [ + VAProfile::Models::AssociatedPerson::EMERGENCY_CONTACT, + VAProfile::Models::AssociatedPerson::OTHER_EMERGENCY_CONTACT, + VAProfile::Models::AssociatedPerson::PRIMARY_NEXT_OF_KIN, + VAProfile::Models::AssociatedPerson::OTHER_NEXT_OF_KIN + ] + end + end end end end diff --git a/spec/lib/va_profile/profile/v3/health_benefit_bio_response_spec.rb b/spec/lib/va_profile/profile/v3/health_benefit_bio_response_spec.rb new file mode 100644 index 00000000000..70f51f3ed61 --- /dev/null +++ b/spec/lib/va_profile/profile/v3/health_benefit_bio_response_spec.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +require 'rails_helper' +require 'va_profile/profile/v3/health_benefit_bio_response' + +describe VAProfile::Profile::V3::HealthBenefitBioResponse do + subject { described_class.new(response) } + + let(:response) do + double('Faraday::Response', + status: 200, + body: { + 'profile' => { + 'health_benefit' => { + 'associated_persons' => [{ + 'contact_type' => contact_type + }] + } + } + }) + end + + describe 'Emergency contact' do + let(:contact_type) { 'Emergency Contact' } + + it 'includes contact' do + expect(subject.contacts).not_to be_empty + end + end + + describe 'Other emergency contact' do + let(:contact_type) { 'Other emergency contact' } + + it 'includes contact' do + expect(subject.contacts).not_to be_empty + end + end + + describe 'Primary Next of Kin' do + let(:contact_type) { 'Primary Next of Kin' } + + it 'includes contact' do + expect(subject.contacts).not_to be_empty + end + end + + describe 'Other Next of Kin' do + let(:contact_type) { 'Other Next of Kin' } + + it 'includes contact' do + expect(subject.contacts).not_to be_empty + end + end + + describe 'Invalid contact type' do + let(:contact_type) { 'Invalid type' } + + it 'does not include contact' do + expect(subject.contacts).to be_empty + end + end +end diff --git a/spec/lib/va_profile/profile/v3/service_spec.rb b/spec/lib/va_profile/profile/v3/service_spec.rb index ddcae4f7b05..da5ec7b9b89 100644 --- a/spec/lib/va_profile/profile/v3/service_spec.rb +++ b/spec/lib/va_profile/profile/v3/service_spec.rb @@ -55,30 +55,60 @@ 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) + valid_contact_types = [ + VAProfile::Models::AssociatedPerson::EMERGENCY_CONTACT, + VAProfile::Models::AssociatedPerson::OTHER_EMERGENCY_CONTACT, + VAProfile::Models::AssociatedPerson::PRIMARY_NEXT_OF_KIN, + VAProfile::Models::AssociatedPerson::OTHER_NEXT_OF_KIN + ] + expect(types).to match_array(valid_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 received from the api' 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 + 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 - 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(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