|
127 | 127 | expect(Audit.finalized_since?(xfer3, storage_location4)).to be false # no audits at location |
128 | 128 | expect(Audit.finalized_since?(xfer3, storage_location5)).to be false # since status isn't finalized |
129 | 129 | end |
| 130 | + |
| 131 | + describe ".generate_csv" do |
| 132 | + let!(:item_1) { create(:item, name: "Baby Diapers") } |
| 133 | + let!(:item_2) { create(:item, name: "Adult Diapers") } |
| 134 | + let!(:sl_1) { create(:storage_location, organization: organization, name: "Diaperhaus") } |
| 135 | + let!(:sl_2) { create(:storage_location, organization: organization, name: "Pawnee Diaper Bank") } |
| 136 | + let!(:time_1) { Time.zone.parse("2025-10-02 01:00:00") } |
| 137 | + let!(:time_2) { Time.zone.parse("2025-10-03 01:00:00") } |
| 138 | + let!(:audit) { create(:audit, organization: organization, storage_location: sl_1, status: 1, updated_at: time_1) } |
| 139 | + let!(:audit_2) { create(:audit, organization: organization, storage_location: sl_2, status: 2, updated_at: time_2) } |
| 140 | + |
| 141 | + before do |
| 142 | + audit.line_items.create!(item: item_1, quantity: 150) |
| 143 | + audit_2.line_items.create!(item: item_2, quantity: 250) |
| 144 | + end |
| 145 | + |
| 146 | + it "generates a CSV" do |
| 147 | + csv_data = described_class.generate_csv([audit, audit_2]) |
| 148 | + |
| 149 | + expect(csv_data).to be_a(String) |
| 150 | + expect(csv_data).to eq( |
| 151 | + <<~CSV |
| 152 | + Audit Date,Audit Status,Storage Location Name,Baby Diapers,Adult Diapers |
| 153 | + October 02 2025,confirmed,Diaperhaus,150,0 |
| 154 | + October 03 2025,finalized,Pawnee Diaper Bank,0,250 |
| 155 | + CSV |
| 156 | + ) |
| 157 | + end |
| 158 | + end |
130 | 159 | end |
131 | 160 |
|
132 | 161 | describe "versioning" do |
|
0 commit comments