Skip to content

Commit

Permalink
added specs
Browse files Browse the repository at this point in the history
  • Loading branch information
raghuramg committed Mar 26, 2024
1 parent 082bf73 commit e173a8d
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/aca_entities/atp/functions/relationship_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,14 @@ def call(cache)
private

def person_hash
dob_value = @memoized_data.find(Regexp.new("person.person_demographics.dob.#{@primary_applicant_id}"))&.first&.item
dob = dob_value ? Date.parse(dob_value) : nil

{ hbx_id: '1234', # default value
first_name: @memoized_data.find(Regexp.new("person_name.first_name.#{@primary_applicant_id}"))&.first&.item&.capitalize,
last_name: @memoized_data.find(Regexp.new("person_name.last_name.#{@primary_applicant_id}"))&.first&.item&.capitalize,
gender: @memoized_data.find(Regexp.new("person.person_demographics.gender.#{@primary_applicant_id}"))&.first&.item&.capitalize,
dob: @memoized_data.find(Regexp.new("person.person_demographics.dob.#{@primary_applicant_id}"))&.first&.item&.to_date,
dob: dob,
ssn: encrypt_ssn(@memoized_data.find(Regexp.new("person.person_demographics.ssn.#{@primary_applicant_id}"))&.first&.item) }
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ def to_hash(identifier: false) # rubocop:disable Metrics/CyclomaticComplexity, M
record: identifier ? { people: people.map(&:to_hash).group_by {|h| h[:id]}.transform_keys(&:to_s).transform_values(&:first) } : nil,
people: identifier ? nil : people.map(&:to_hash),
physical_households: physical_households&.map(&:to_hash),
assister: assister&.map(&:to_hash)
assister: assister&.to_hash
}
end
end
end
end
end
end
end
end
67 changes: 67 additions & 0 deletions spec/aca_entities/atp/transformers/cv/family_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# frozen_string_literal: true

require 'spec_helper'
require 'aca_entities/medicaid/atp'
require 'aca_entities/serializers/xml/medicaid/atp'
require 'aca_entities/atp/transformers/cv/family'

RSpec.describe AcaEntities::Atp::Transformers::Cv::Family do
let(:payload) { File.read(Pathname.pwd.join("spec/support/atp/sample_payloads/sample.xml")) }

let(:document) do
Nokogiri::XML(payload)
end

let(:account_transfer_request) do
::AcaEntities::Serializers::Xml::Medicaid::Atp::AccountTransferRequest.parse(document.root.canonicalize, :single => true)
end

describe 'When fixed address indicator passed as true' do

it 'should set homeless indicator false' do
transformed = ::AcaEntities::Atp::Transformers::Cv::Family.transform(account_transfer_request.to_hash(identifier: true))

transformed.dig(:family, :family_members).each do |family_member|
expect(family_member.dig(:person, :is_homeless)).to be_falsey
end
end
end

describe 'When fixed address indicator not passed in xml' do
let(:document) do
document = Nokogiri::XML(payload)
document.xpath('//ns5:InsuranceApplicantFixedAddressIndicator', 'ns5' => 'http://hix.cms.gov/0.1/hix-ee').each do |node|
node.remove
end
document
end

it 'should set homeless indicator based on addresses' do
transformed = ::AcaEntities::Atp::Transformers::Cv::Family.transform(account_transfer_request.to_hash(identifier: true))

transformed.dig(:family, :family_members).each do |family_member|
expect(family_member.dig(:person, :is_homeless)).to be_falsey
end
end
end

describe 'When fixed address indicator passed as false' do
let(:document) do
document = Nokogiri::XML(payload)
document.xpath('//ns5:InsuranceApplicantFixedAddressIndicator', 'ns5' => 'http://hix.cms.gov/0.1/hix-ee').each do |node|
node.content = 'false'
end
document
end

let(:expected_homeless_indicators) { [true, true, false] }

it 'should set homeless indicator true' do
transformed = ::AcaEntities::Atp::Transformers::Cv::Family.transform(account_transfer_request.to_hash(identifier: true))

transformed.dig(:family, :family_members).each_with_index do |family_member, index|
expect(family_member.dig(:person, :is_homeless)).to eq(expected_homeless_indicators[index])
end
end
end
end

0 comments on commit e173a8d

Please sign in to comment.