Skip to content

Commit

Permalink
Selects only valid contact types
Browse files Browse the repository at this point in the history
  • Loading branch information
radavis committed Mar 25, 2024
1 parent 83d2875 commit 3e9c6e1
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 14 deletions.
44 changes: 30 additions & 14 deletions lib/va_profile/profile/v3/health_benefit_bio_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
62 changes: 62 additions & 0 deletions spec/lib/va_profile/profile/v3/health_benefit_bio_response_spec.rb
Original file line number Diff line number Diff line change
@@ -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 'includes contact' do
expect(subject.contacts).to be_empty
end
end
end

0 comments on commit 3e9c6e1

Please sign in to comment.