Skip to content

Commit

Permalink
Merge branch 'radavis/profile-contacts-error-conditions' into radavis…
Browse files Browse the repository at this point in the history
…/phcc-valid-contact-types
  • Loading branch information
radavis committed Mar 25, 2024
2 parents 3e9c6e1 + 151505e commit 62f649b
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 15 deletions.
6 changes: 4 additions & 2 deletions lib/va_profile/profile/v3/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -20,14 +20,16 @@ class Service < Common::Client::Base

def initialize(user)
@user = user
super()
super(user)
end

def get_health_benefit_bio
oid = MPI::Constants::VA_ROOT_OID
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
Expand Down
50 changes: 37 additions & 13 deletions spec/lib/va_profile/profile/v3/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 62f649b

Please sign in to comment.