Skip to content

Commit

Permalink
Merge pull request #4229 from callmarx/3067-add-fields-to-partner-age…
Browse files Browse the repository at this point in the history
…ncy-export

#3067: add required info on csv partner export (partial solution)
  • Loading branch information
cielf authored Jun 9, 2024
2 parents e391667 + cb16dde commit 9ec64db
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
27 changes: 27 additions & 0 deletions app/models/partner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ def self.csv_export_headers
[
"Agency Name",
"Agency Email",
"Agency Address",
"Agency City",
"Agency State",
"Agency Zip Code",
"Agency Website",
"Agency Type",
"Contact Name",
"Contact Phone",
"Contact Email",
Expand All @@ -183,6 +189,12 @@ def csv_export_attributes
[
name,
email,
agency_info[:address],
agency_info[:city],
agency_info[:state],
agency_info[:zip_code],
agency_info[:website],
agency_info[:agency_type],
contact_person[:name],
contact_person[:phone],
contact_person[:email],
Expand All @@ -203,6 +215,21 @@ def contact_person
}
end

def agency_info
return @agency_info if @agency_info

return {} if profile.blank?

@agency_info = {
address: [profile.address1, profile.address2].select(&:present?).join(', '),
city: profile.city,
state: profile.state,
zip_code: profile.zip_code,
website: profile.website,
agency_type: (profile.agency_type == AGENCY_TYPES["OTHER"]) ? "#{AGENCY_TYPES["OTHER"]}: #{profile.other_agency_type}" : profile.agency_type
}
end

def partials_to_show
organization.partner_form_fields.presence || ALL_PARTIALS
end
Expand Down
38 changes: 32 additions & 6 deletions spec/models/partner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,22 +284,48 @@
let(:contact_name) { "Jon Ralfeo" }
let(:contact_email) { "[email protected]" }
let(:contact_phone) { "1231231234" }
let(:agency_address1) { "4744 McDermott Mountain" }
let(:agency_address2) { "333 Never land street" }
let(:agency_city) { "Lake Shoshana" }
let(:agency_state) { "ND" }
let(:agency_zipcode) { "09980-7010" }
let(:agency_website) { "bosco.example" }
let(:agency_type) { Partner::AGENCY_TYPES["OTHER"] }
let(:other_agency_type) { "Another Agency Name" }
let(:notes) { "Some notes" }

before do
partner.profile.update({
primary_contact_name: contact_name,
primary_contact_email: contact_email,
primary_contact_phone: contact_phone
primary_contact_phone: contact_phone,
address1: agency_address1,
address2: agency_address2,
city: agency_city,
state: agency_state,
zip_code: agency_zipcode,
website: agency_website,
agency_type: agency_type,
other_agency_type: other_agency_type
})
partner.update(notes: notes)
end

it "includes contact person information from parnerbase" do
expect(partner.csv_export_attributes).to include(contact_name)
expect(partner.csv_export_attributes).to include(contact_phone)
expect(partner.csv_export_attributes).to include(contact_email)
expect(partner.csv_export_attributes).to include(notes)
it "should has the info in the columns order" do
expect(partner.csv_export_attributes).to eq([
partner.name,
partner.email,
"#{agency_address1}, #{agency_address2}",
agency_city,
agency_state,
agency_zipcode,
agency_website,
"#{Partner::AGENCY_TYPES["OTHER"]}: #{other_agency_type}",
contact_name,
contact_phone,
contact_email,
notes
])
end
end

Expand Down

0 comments on commit 9ec64db

Please sign in to comment.