diff --git a/app/models/partner.rb b/app/models/partner.rb index 455428869c..be47fe962a 100644 --- a/app/models/partner.rb +++ b/app/models/partner.rb @@ -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", @@ -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], @@ -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 diff --git a/spec/models/partner_spec.rb b/spec/models/partner_spec.rb index ab3e5bfc93..c9ffc2b1fe 100644 --- a/spec/models/partner_spec.rb +++ b/spec/models/partner_spec.rb @@ -291,22 +291,48 @@ let(:contact_name) { "Jon Ralfeo" } let(:contact_email) { "jon@entertainment720.com" } 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