Skip to content

Commit

Permalink
transform dependent's phone and email
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobkagon committed Aug 9, 2024
1 parent cabf5dd commit c800033
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 11 deletions.
19 changes: 10 additions & 9 deletions lib/aca_entities/crm/transformers/family_to/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def fetch_address(person, kind)
case kind
when 'billing_address_street'
address.try(:address_1)
when 'billing_address_street2'
when 'billing_address_street_2'
address.try(:address_2)
when 'billing_address_street3'
when 'billing_address_street_3'
address.try(:address_3)
when 'billing_address_city'
address.try(:city)
Expand Down Expand Up @@ -117,15 +117,16 @@ def fetch_relationship_to_primary(hbx_id, primary_person)

def transform_contacts(family_members, primary_person)
family_members.map do |family_member|
next unless family_member.person.present?
hbx_id = family_member.person.hbx_id
person = family_member.person
next unless person.present?
hbx_id = person.hbx_id
{
hbxid_c: hbx_id,
first_name: family_member.person.person_name.first_name,
last_name: family_member.person.person_name.last_name,
phone_mobile: fetch_and_format_phone(primary_person),
email1: primary_person.home_email || primary_person.work_email,
birthdate: family_member&.person&.person_demographics&.dob&.to_s,
first_name: person.person_name.first_name,
last_name: person.person_name.last_name,
phone_mobile: fetch_and_format_phone(person),
email1: person.home_email || person.work_email,
birthdate: person&.person_demographics&.dob&.to_s,
relationship_c: fetch_relationship_to_primary(hbx_id, primary_person)
}
end
Expand Down
14 changes: 14 additions & 0 deletions spec/aca_entities/crm/transformers/family_to/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,19 @@
expect(result.success[:contacts].last[:relationship_c]).to eql(relationship_mapper)
end
end

it 'returns the correctly formatted phone number for contact' do
phone = family_cv[:family_members].last[:person][:phones].first

phone_number = phone[:area_code] + phone[:number]

formatted_number = phone_number.gsub(/(\d{3})(\d{3})(\d{4})/, '(\1) \2-\3')
expect(@result.success[:contacts].last[:phone_mobile]).to eql(formatted_number)
end

it 'returns the correct email for contact' do
email = family_cv[:family_members].last[:person][:emails].first[:address]
expect(@result.success[:contacts].last[:email1]).to eql(formatted_number)
end
end
end
27 changes: 25 additions & 2 deletions spec/support/shared_content/families/sample_cv_family.rb
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,29 @@
]
end

let(:dependent_phones) do
[
{
kind: "home",
country_code: "",
area_code: "202",
number: "5555555",
extension: "",
primary: true,
full_phone_number: "2025555555"
}
]
end

let(:dependent_emails) do
[
{
kind: "home",
address: "[email protected]"
}
]
end

let(:emails) do
[
{
Expand Down Expand Up @@ -661,8 +684,8 @@
verification_types: verification_types,
broker_role: broker_role,
addresses: addresses,
phones: phones,
emails: emails,
phones: dependent_phones,
emails: dependent_emails,
documents: documents,
timestamp: timestamp
}
Expand Down

0 comments on commit c800033

Please sign in to comment.