Skip to content

Commit 2670caa

Browse files
committed
Fix: make export csv header more explicit in distribution and donation tests.
1 parent 6dae33a commit 2670caa

3 files changed

Lines changed: 19 additions & 80 deletions

File tree

spec/factories/donation_sites.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
FactoryBot.define do
1919
factory :donation_site do
2020
organization { Organization.try(:first) || create(:organization) }
21-
name { Faker::Company.name }
21+
name { Faker::Company.name.tr(",", ";") }
2222
address { "1500 Remount Road, Front Royal, VA 22630" }
2323
active { true }
2424
contact_name { Faker::Name.name }

spec/services/exports/export_distributions_csv_service_spec.rb

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,10 @@
4949
let(:item_name) { duplicate_item.name }
5050
let(:filters) { {by_item_id: item_id} }
5151

52-
let(:non_item_headers) do
53-
[
54-
"Partner",
55-
"Initial Allocation",
56-
"Scheduled for",
57-
"Source Inventory",
58-
"Total Number of #{item_name}",
59-
"Total Value of #{item_name}",
60-
"Delivery Method",
61-
"Shipping Cost",
62-
"Status",
63-
"Agency Representative",
64-
"Comments"
65-
]
66-
end
67-
6852
context 'while "Include in-kind value in donation and distribution exports?" is set to no' do
69-
let(:item_headers) { ["A Item", "B Item", "C Item", "Dupe Item", "E Item"] }
70-
let(:expected_headers) { non_item_headers + item_headers }
71-
7253
it 'should match the expected content without in-kind value of each item for the csv' do
7354
csv = <<~CSV
74-
#{expected_headers.join(",")}
55+
Partner,Initial Allocation,Scheduled for,Source Inventory,Total Number of #{item_name},Total Value of #{item_name},Delivery Method,Shipping Cost,Status,Agency Representative,Comments,A Item,B Item,C Item,Dupe Item,E Item
7556
#{partner.name},04/04/2025,04/04/2025,#{storage_location.name},8,24.0,shipped,$15.01,scheduled,"",comment 0,7,0,0,8,0
7657
#{partner.name},04/04/2025,04/04/2025,#{storage_location.name},0,0.0,shipped,$15.01,scheduled,"",comment 1,0,1,0,0,0
7758
#{partner.name},04/04/2025,04/04/2025,#{storage_location.name},0,0.0,shipped,$15.01,scheduled,"",comment 2,0,0,2,0,0
@@ -82,22 +63,11 @@
8263
end
8364

8465
context 'while "Include in-kind value in donation and distribution exports?" is set to yes' do
85-
let(:item_headers) {
86-
[
87-
"A Item", "A Item In-Kind Value",
88-
"B Item", "B Item In-Kind Value",
89-
"C Item", "C Item In-Kind Value",
90-
"Dupe Item", "Dupe Item In-Kind Value",
91-
"E Item", "E Item In-Kind Value"
92-
]
93-
}
94-
let(:expected_headers) { non_item_headers + item_headers }
95-
9666
it 'should match the expected content with in-kind value of each item for the csv' do
9767
allow(organization).to receive(:include_in_kind_values_in_exported_files).and_return(true)
9868

9969
csv = <<~CSV
100-
#{expected_headers.join(",")}
70+
Partner,Initial Allocation,Scheduled for,Source Inventory,Total Number of #{item_name},Total Value of #{item_name},Delivery Method,Shipping Cost,Status,Agency Representative,Comments,A Item,A Item In-Kind Value,B Item,B Item In-Kind Value,C Item,C Item In-Kind Value,Dupe Item,Dupe Item In-Kind Value,E Item,E Item In-Kind Value
10171
#{partner.name},04/04/2025,04/04/2025,#{storage_location.name},8,24.0,shipped,$15.01,scheduled,"",comment 0,7,70.00,0,0.00,0,0.00,8,24.00,0,0.00
10272
#{partner.name},04/04/2025,04/04/2025,#{storage_location.name},0,0.0,shipped,$15.01,scheduled,"",comment 1,0,0.00,1,20.00,0,0.00,0,0.00,0,0.00
10373
#{partner.name},04/04/2025,04/04/2025,#{storage_location.name},0,0.0,shipped,$15.01,scheduled,"",comment 2,0,0.00,0,0.00,2,60.00,0,0.00,0,0.00
@@ -108,8 +78,6 @@
10878
end
10979

11080
context 'when a new item is added' do
111-
let(:item_headers) { ["A Item", "B Item", "C Item", "Dupe Item", "E Item", "New Item"] }
112-
let(:expected_headers) { non_item_headers + item_headers }
11381
let(:new_item_name) { "New Item" }
11482
let(:original_columns_count) { 15 }
11583
before do
@@ -121,7 +89,7 @@
12189

12290
it 'should add it to the end of the row and show up with a 0 quantity if there are none of this item in any distribution' do
12391
csv = <<~CSV
124-
#{expected_headers.join(",")}
92+
Partner,Initial Allocation,Scheduled for,Source Inventory,Total Number of #{item_name},Total Value of #{item_name},Delivery Method,Shipping Cost,Status,Agency Representative,Comments,A Item,B Item,C Item,Dupe Item,E Item,New Item
12593
#{partner.name},04/04/2025,04/04/2025,#{storage_location.name},8,24.0,shipped,$15.01,scheduled,"",comment 0,7,0,0,8,0,0
12694
#{partner.name},04/04/2025,04/04/2025,#{storage_location.name},0,0.0,shipped,$15.01,scheduled,"",comment 1,0,1,0,0,0,0
12795
#{partner.name},04/04/2025,04/04/2025,#{storage_location.name},0,0.0,shipped,$15.01,scheduled,"",comment 2,0,0,2,0,0,0
@@ -132,12 +100,10 @@
132100
end
133101

134102
context 'when there are no distributions but the report is requested' do
135-
let(:item_headers) { ["Dupe Item"] }
136-
let(:expected_headers) { non_item_headers + item_headers }
137103
subject { described_class.new(distributions: [], organization: organization, filters: filters).generate_csv }
138104
it 'returns a csv with only headers and no rows' do
139105
csv = <<~CSV
140-
#{expected_headers.join(",")}
106+
Partner,Initial Allocation,Scheduled for,Source Inventory,Total Number of #{item_name},Total Value of #{item_name},Delivery Method,Shipping Cost,Status,Agency Representative,Comments,Dupe Item
141107
CSV
142108
expect(subject).to eq(csv)
143109
end

spec/services/exports/export_donations_csv_service_spec.rb

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require "csv"
2-
31
RSpec.describe Exports::ExportDonationsCSVService do
42
describe '#generate_csv' do
53
let(:organization) { create(:organization) }
@@ -51,21 +49,6 @@
5149
end
5250
end
5351

54-
let(:expected_headers) do
55-
[
56-
"Source",
57-
"Date",
58-
"Details",
59-
"Storage Location",
60-
"Quantity of Items",
61-
"Variety of Items",
62-
"In-Kind Total",
63-
"Comments"
64-
] + expected_item_headers
65-
end
66-
67-
let(:expected_item_headers) { ["A Item", "B Item", "C Item", "Dupe Item", "E Item"] }
68-
6952
def source_name(donation)
7053
if !donation.product_drive.nil?
7154
donation.product_drive.name
@@ -78,38 +61,28 @@ def source_name(donation)
7861

7962
context 'while "Include in-kind value in donation and distribution exports?" is set to no' do
8063
it 'should match the expected content without in-kind value of each item for the csv' do
81-
csv = CSV.generate do |csv|
82-
csv << expected_headers
83-
csv << ["Product Drive", "2025-01-01", source_name(donations[0]), storage_location.name, 15, 2, 94.0, "It's a fine day for diapers.", 7, 0, 0, 8, 0]
84-
csv << ["Manufacturer", "2025-01-01", source_name(donations[1]), storage_location.name, 1, 1, 20.0, "It's a fine day for diapers.", 0, 1, 0, 0, 0]
85-
csv << ["Donation Site", "2025-01-01", source_name(donations[2]), storage_location.name, 2, 1, 60.0, "It's a fine day for diapers.", 0, 0, 2, 0, 0]
86-
csv << ["Misc. Donation", "2025-01-01", "It's a fine day for...", storage_location.name, 3, 1, 120.0, "It's a fine day for diapers.", 0, 0, 0, 0, 3]
87-
end
64+
csv = <<~CSV
65+
Source,Date,Details,Storage Location,Quantity of Items,Variety of Items,In-Kind Total,Comments,A Item,B Item,C Item,Dupe Item,E Item
66+
Product Drive,2025-01-01,#{source_name(donations[0])},#{storage_location.name},15,2,94.0,It's a fine day for diapers.,7,0,0,8,0
67+
Manufacturer,2025-01-01,#{source_name(donations[1])},#{storage_location.name},1,1,20.0,It's a fine day for diapers.,0,1,0,0,0
68+
Donation Site,2025-01-01,#{source_name(donations[2])},#{storage_location.name},2,1,60.0,It's a fine day for diapers.,0,0,2,0,0
69+
Misc. Donation,2025-01-01,It's a fine day for...,#{storage_location.name},3,1,120.0,It's a fine day for diapers.,0,0,0,0,3
70+
CSV
8871
expect(subject).to eq(csv)
8972
end
9073
end
9174

9275
context 'while "Include in-kind value in donation and distribution exports?" is set to yes' do
93-
let(:expected_item_headers) do
94-
[
95-
"A Item", "A Item In-Kind Value",
96-
"B Item", "B Item In-Kind Value",
97-
"C Item", "C Item In-Kind Value",
98-
"Dupe Item", "Dupe Item In-Kind Value",
99-
"E Item", "E Item In-Kind Value"
100-
]
101-
end
102-
10376
it 'should match the expected content with in-kind value of each item for the csv' do
10477
allow(organization).to receive(:include_in_kind_values_in_exported_files).and_return(true)
10578

106-
csv = CSV.generate do |csv|
107-
csv << expected_headers
108-
csv << ["Product Drive", "2025-01-01", source_name(donations[0]), storage_location.name, 15, 2, 94.0, "It's a fine day for diapers.", 7, "70.00", 0, "0.00", 0, "0.00", 8, "24.00", 0, "0.00"]
109-
csv << ["Manufacturer", "2025-01-01", source_name(donations[1]), storage_location.name, 1, 1, 20.0, "It's a fine day for diapers.", 0, "0.00", 1, "20.00", 0, "0.00", 0, "0.00", 0, "0.00"]
110-
csv << ["Donation Site", "2025-01-01", source_name(donations[2]), storage_location.name, 2, 1, 60.0, "It's a fine day for diapers.", 0, "0.00", 0, "0.00", 2, "60.00", 0, "0.00", 0, "0.00"]
111-
csv << ["Misc. Donation", "2025-01-01", "It's a fine day for...", storage_location.name, 3, 1, 120.0, "It's a fine day for diapers.", 0, "0.00", 0, "0.00", 0, "0.00", 0, "0.00", 3, "120.00"]
112-
end
79+
csv = <<~CSV
80+
Source,Date,Details,Storage Location,Quantity of Items,Variety of Items,In-Kind Total,Comments,A Item,A Item In-Kind Value,B Item,B Item In-Kind Value,C Item,C Item In-Kind Value,Dupe Item,Dupe Item In-Kind Value,E Item,E Item In-Kind Value
81+
Product Drive,2025-01-01,#{source_name(donations[0])},#{storage_location.name},15,2,94.0,It's a fine day for diapers.,7,70.00,0,0.00,0,0.00,8,24.00,0,0.00
82+
Manufacturer,2025-01-01,#{source_name(donations[1])},#{storage_location.name},1,1,20.0,It's a fine day for diapers.,0,0.00,1,20.00,0,0.00,0,0.00,0,0.00
83+
Donation Site,2025-01-01,#{source_name(donations[2])},#{storage_location.name},2,1,60.0,It's a fine day for diapers.,0,0.00,0,0.00,2,60.00,0,0.00,0,0.00
84+
Misc. Donation,2025-01-01,It's a fine day for...,#{storage_location.name},3,1,120.0,It's a fine day for diapers.,0,0.00,0,0.00,0,0.00,0,0.00,3,120.00
85+
CSV
11386
expect(subject).to eq(csv)
11487
end
11588
end

0 commit comments

Comments
 (0)