Skip to content

Commit d223109

Browse files
Expanded partners request tests to account for new exported fields
1 parent 275e3d1 commit d223109

1 file changed

Lines changed: 197 additions & 83 deletions

File tree

spec/requests/partners_requests_spec.rb

Lines changed: 197 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
RSpec.describe "Partners", type: :request do
2-
let(:organization) { create(:organization) }
2+
let(:organization) { create(:organization, partner_form_fields: ["media_information"]) }
33
let(:user) { create(:user, organization: organization) }
44

55
before do
@@ -31,37 +31,64 @@
3131
let!(:profile) do
3232
create(:partner_profile,
3333
partner: partner,
34-
primary_contact_name: contact_name,
35-
primary_contact_email: contact_email,
36-
primary_contact_phone: contact_phone,
3734
address1: agency_address1,
3835
address2: agency_address2,
3936
city: agency_city,
4037
state: agency_state,
4138
zip_code: agency_zipcode,
4239
website: agency_website,
4340
agency_type: agency_type,
44-
other_agency_type: other_agency_type)
41+
other_agency_type: other_agency_type,
42+
primary_contact_name: contact_name,
43+
primary_contact_phone: contact_phone,
44+
primary_contact_mobile: contact_mobile,
45+
primary_contact_email: contact_email,
46+
agency_mission: agency_mission,
47+
enable_child_based_requests: enable_child_based_requests,
48+
enable_individual_requests: enable_individual_requests,
49+
enable_quantity_based_requests: enable_quantity_based_requests,
50+
program_address1: program_address1,
51+
program_address2: program_address2,
52+
program_city: program_city,
53+
program_state: program_state,
54+
program_zip_code: program_zip_code,
55+
facebook: facebook, # Columns from the media_information partial
56+
twitter: twitter,
57+
instagram: instagram,
58+
no_social_media_presence: no_social_media_presence)
4559
end
4660
let(:name) { "Leslie Sue" }
4761
let(:email) { "leslie@sue.com" }
48-
let(:contact_name) { "Jon Ralfeo" }
49-
let(:contact_email) { "jon@entertainment720.com" }
50-
let(:contact_phone) { "1231231234" }
5162
let(:agency_address1) { "4744 McDermott Mountain" }
5263
let(:agency_address2) { "333 Never land street" }
5364
let(:agency_city) { "Lake Shoshana" }
5465
let(:agency_state) { "ND" }
5566
let(:agency_zipcode) { "09980-7010" }
5667
let(:agency_website) { "bosco.example" }
5768
let(:agency_type) { :other }
58-
let(:notes) { "Some notes" }
5969
let(:other_agency_type) { "Another Agency Name" }
60-
let(:providing_diapers) { {value: "N", index: 13} }
61-
let(:providing_period_supplies) { {value: "N", index: 14} }
62-
63-
let(:response_format) { 'csv' }
64-
let(:expected_headers) do
70+
let(:contact_name) { "Jon Ralfeo" }
71+
let(:contact_phone) { "1231231234" }
72+
let(:contact_mobile) { "4564564567" }
73+
let(:contact_email) { "jon@entertainment720.com" }
74+
let(:notes) { "Some notes" }
75+
let(:providing_diapers) { {value: "N", index: 22} }
76+
let(:providing_period_supplies) { {value: "N", index: 23} }
77+
let(:agency_mission) { "agency_mission" }
78+
let(:enable_child_based_requests) { true }
79+
let(:enable_individual_requests) { true }
80+
let(:enable_quantity_based_requests) { true }
81+
let(:program_address1) { "program_address1" }
82+
let(:program_address2) { "program_address2" }
83+
let(:program_city) { "program_city" }
84+
let(:program_state) { "program_state" }
85+
let(:program_zip_code) { 12345 }
86+
let(:facebook) { "facebook" } # Columns from the media_information partial
87+
let(:twitter) { "twitter" }
88+
let(:instagram) { "instagram" }
89+
let(:no_social_media_presence) { false }
90+
91+
let(:expected_headers) {
6592
[
6693
"Agency Name",
6794
"Agency Email",
@@ -73,13 +100,59 @@
73100
"Agency Type",
74101
"Contact Name",
75102
"Contact Phone",
103+
"Contact Cell",
76104
"Contact Email",
105+
"Agency Mission",
106+
"Child-based Requests",
107+
"Individual Requests",
108+
"Quantity-based Requests",
109+
"Program/Delivery Address",
110+
"Program City",
111+
"Program State",
112+
"Program Zip Code",
77113
"Notes",
78114
"Counties Served",
79115
"Providing Diapers",
80-
"Providing Period Supplies"
81-
]
82-
end
116+
"Providing Period Supplies",
117+
"Facebook", # Columns from the media_information partial
118+
"Twitter",
119+
"Instagram",
120+
"No Social Media Presence"
121+
]
122+
}
123+
124+
let(:expected_values) {
125+
[
126+
partner.name,
127+
partner.email,
128+
"#{agency_address1}, #{agency_address2}",
129+
agency_city,
130+
agency_state,
131+
agency_zipcode,
132+
agency_website,
133+
"#{I18n.t "partners_profile.other"}: #{other_agency_type}",
134+
contact_name,
135+
contact_phone,
136+
contact_mobile,
137+
contact_email,
138+
agency_mission,
139+
enable_child_based_requests.to_s,
140+
enable_individual_requests.to_s,
141+
enable_quantity_based_requests.to_s,
142+
"#{program_address1}, #{program_address2}",
143+
program_city,
144+
program_state,
145+
program_zip_code.to_s,
146+
notes,
147+
"", # no counties
148+
providing_diapers[:value],
149+
providing_period_supplies[:value],
150+
facebook, # Columns from the media_information partial
151+
twitter,
152+
instagram,
153+
no_social_media_presence.to_s
154+
]
155+
}
83156

84157
it { is_expected.to be_successful }
85158
it "returns the expected headers" do
@@ -91,29 +164,48 @@
91164
end
92165

93166
context "with missing partner info" do
94-
let(:name) { "Leslie" }
95-
let(:email) { "leslie@humanessentials.com" }
96-
let(:contact_name) { nil }
97-
let(:contact_email) { nil }
98-
let(:contact_phone) { nil }
99-
let(:agency_address1) { nil }
100-
let(:agency_address2) { nil }
101-
let(:agency_city) { nil }
102-
let(:agency_state) { nil }
103-
let(:agency_zipcode) { nil }
104-
let(:agency_website) { nil }
105-
let(:agency_type) { nil }
106-
let(:notes) { nil }
107-
let(:other_agency_type) { nil }
108-
109167
it "returns a CSV with correct data" do
110-
get partners_path(partner, format: response_format)
168+
partner.update(profile: create(
169+
:partner_profile,
170+
website: nil,
171+
primary_contact_name: nil,
172+
primary_contact_email: nil
173+
))
174+
175+
expected_values = [
176+
partner.name,
177+
partner.email,
178+
", ",
179+
"",
180+
"",
181+
"",
182+
"",
183+
"",
184+
"",
185+
"",
186+
"",
187+
"",
188+
"",
189+
enable_child_based_requests.to_s,
190+
enable_individual_requests.to_s,
191+
enable_quantity_based_requests.to_s,
192+
", ",
193+
"",
194+
"",
195+
"",
196+
notes,
197+
"",
198+
providing_diapers[:value],
199+
providing_period_supplies[:value],
200+
"", # Columns from the media_information partial
201+
"",
202+
"",
203+
""
204+
]
111205

206+
get partners_path(partner, format: response_format)
112207
csv = CSV.parse(response.body)
113-
114-
expect(csv[1]).to eq(
115-
["Leslie", "leslie@humanessentials.com", "", "", "", "", "", "", "", "", "", "", "", "N", "N"]
116-
)
208+
expect(csv[1]).to eq(expected_values)
117209
end
118210
end
119211

@@ -122,35 +214,16 @@
122214

123215
csv = CSV.parse(response.body)
124216

125-
expect(csv[1]).to eq(
126-
[
127-
"Leslie Sue",
128-
"leslie@sue.com",
129-
"4744 McDermott Mountain, 333 Never land street",
130-
"Lake Shoshana",
131-
"ND",
132-
"09980-7010",
133-
"bosco.example",
134-
"Other: Another Agency Name",
135-
"Jon Ralfeo",
136-
"1231231234",
137-
"jon@entertainment720.com",
138-
"Some notes",
139-
"",
140-
"N",
141-
"N"
142-
]
143-
)
217+
expect(csv[1]).to eq(expected_values)
144218
end
145219

146220
it "returns only active partners by default" do
147221
partner.update(status: :deactivated)
148222

149223
get partners_path(partner, format: response_format)
150-
151224
csv = CSV.parse(response.body)
152-
153225
# Expect no parner rows in csv
226+
expect(csv[0]).to eq(expected_headers)
154227
expect(csv[1]).to eq(nil)
155228
end
156229

@@ -178,35 +251,63 @@
178251
let!(:profile_2) do
179252
create(:partner_profile,
180253
partner: partner_2,
181-
primary_contact_name: contact_name_2,
182-
primary_contact_email: contact_email_2,
183-
primary_contact_phone: contact_phone_2,
184254
address1: agency_address1_2,
185255
address2: agency_address2_2,
186256
city: agency_city_2,
187257
state: agency_state_2,
188258
zip_code: agency_zipcode_2,
189259
website: agency_website_2,
190260
agency_type: agency_type_2,
191-
other_agency_type: other_agency_type_2)
261+
other_agency_type: other_agency_type_2,
262+
primary_contact_name: contact_name_2,
263+
primary_contact_phone: contact_phone_2,
264+
primary_contact_mobile: contact_mobile_2,
265+
primary_contact_email: contact_email_2,
266+
agency_mission: agency_mission_2,
267+
enable_child_based_requests: enable_child_based_requests_2,
268+
enable_individual_requests: enable_individual_requests_2,
269+
enable_quantity_based_requests: enable_quantity_based_requests_2,
270+
program_address1: program_address1_2,
271+
program_address2: program_address2_2,
272+
program_city: program_city_2,
273+
program_state: program_state_2,
274+
program_zip_code: program_zip_code_2,
275+
facebook: facebook_2, # Columns from the media_information partial
276+
twitter: twitter_2,
277+
instagram: instagram_2,
278+
no_social_media_presence: no_social_media_presence_2)
192279
end
193280

194281
let(:name_2) { "Jane Doe" }
195282
let(:email_2) { "jane@doe.com" }
196-
let(:contact_name_2) { "Fakey McFakePerson" }
197-
let(:contact_email_2) { "fakey@gmail.com" }
198-
let(:contact_phone_2) { "1234567890" }
199283
let(:agency_address1_2) { "123 Main St" }
200284
let(:agency_address2_2) { "C.O. box 678" }
201285
let(:agency_city_2) { "Paris" }
202286
let(:agency_state_2) { "TX" }
203287
let(:agency_zipcode_2) { "30234-0000" }
204288
let(:agency_website_2) { "human.example" }
205289
let(:agency_type_2) { :other }
290+
let(:other_agency_type_2) { "Another Agency Name" }
291+
let(:contact_name_2) { "Fakey McFakePerson" }
292+
let(:contact_phone_2) { "1234567890" }
293+
let(:contact_mobile_2) { "1234567890" }
294+
let(:contact_email_2) { "fakey@gmail.com" }
206295
let(:notes_2) { "Some notes 2" }
207-
let(:other_agency_type_2) { "Fake Agency Name" }
208-
let(:providing_diapers_2) { {value: "N", index: 13} }
209-
let(:providing_period_supplies_2) { {value: "N", index: 14} }
296+
let(:providing_diapers_2) { {value: "N", index: 22} }
297+
let(:providing_period_supplies_2) { {value: "N", index: 23} }
298+
let(:agency_mission_2) { "agency_mission" }
299+
let(:enable_child_based_requests_2) { true }
300+
let(:enable_individual_requests_2) { true }
301+
let(:enable_quantity_based_requests_2) { true }
302+
let(:program_address1_2) { "program_address1" }
303+
let(:program_address2_2) { "program_address2" }
304+
let(:program_city_2) { "program_city" }
305+
let(:program_state_2) { "program_state" }
306+
let(:program_zip_code_2) { 12345 }
307+
let(:facebook_2) { "facebook" } # Columns from the media_information partial
308+
let(:twitter_2) { "twitter" }
309+
let(:instagram_2) { "instagram" }
310+
let(:no_social_media_presence_2) { false }
210311

211312
it "orders partners alphaetically" do
212313
get partners_path(partner, format: response_format)
@@ -215,21 +316,34 @@
215316

216317
expect(csv[1]).to eq(
217318
[
218-
"Jane Doe",
219-
"jane@doe.com",
220-
"123 Main St, C.O. box 678",
221-
"Paris",
222-
"TX",
223-
"30234-0000",
224-
"human.example",
225-
"Other: Fake Agency Name",
226-
"Fakey McFakePerson",
227-
"1234567890",
228-
"fakey@gmail.com",
229-
"Some notes 2",
230-
"",
231-
"N",
232-
"N"
319+
partner_2.name,
320+
partner_2.email,
321+
"#{agency_address1_2}, #{agency_address2_2}",
322+
agency_city_2,
323+
agency_state_2,
324+
agency_zipcode_2,
325+
agency_website_2,
326+
"#{I18n.t "partners_profile.other"}: #{other_agency_type_2}",
327+
contact_name_2,
328+
contact_phone_2,
329+
contact_mobile_2,
330+
contact_email_2,
331+
agency_mission_2,
332+
enable_child_based_requests_2.to_s,
333+
enable_individual_requests_2.to_s,
334+
enable_quantity_based_requests_2.to_s,
335+
"#{program_address1_2}, #{program_address2_2}",
336+
program_city_2,
337+
program_state_2,
338+
program_zip_code_2.to_s,
339+
notes_2,
340+
"", # no counties
341+
providing_diapers_2[:value],
342+
providing_period_supplies_2[:value],
343+
facebook_2, # Columns from the media_information partial
344+
twitter_2,
345+
instagram_2,
346+
no_social_media_presence_2.to_s
233347
]
234348
)
235349
end

0 commit comments

Comments
 (0)