|
1 | 1 | RSpec.describe "Audits", type: :request do |
2 | 2 | let(:organization) { create(:organization) } |
3 | 3 | let(:organization_admin) { create(:organization_admin, organization: organization) } |
4 | | - |
| 4 | + let(:storage_location) { create(:storage_location, organization: organization) } |
5 | 5 | let(:valid_attributes) do |
6 | 6 | { |
7 | 7 | organization_id: organization.id, |
8 | | - storage_location_id: create(:storage_location, organization: organization).id, |
| 8 | + storage_location_id: storage_location.id, |
9 | 9 | user_id: create(:organization_admin, organization: organization).id |
10 | 10 | } |
11 | 11 | end |
|
30 | 30 | end |
31 | 31 |
|
32 | 32 | describe "GET #index" do |
33 | | - it "is successful" do |
34 | | - Audit.create! valid_attributes |
35 | | - get audits_path |
36 | | - expect(response).to be_successful |
| 33 | + context "html" do |
| 34 | + it "is successful" do |
| 35 | + Audit.create! valid_attributes |
| 36 | + get audits_path |
| 37 | + expect(response).to be_successful |
| 38 | + end |
| 39 | + end |
| 40 | + |
| 41 | + context "csv" do |
| 42 | + let(:response_format) { 'csv' } |
| 43 | + let!(:audits) do |
| 44 | + [ |
| 45 | + create(:audit, organization: organization, storage_location: storage_location_with_duplicate_item), |
| 46 | + create(:audit, organization: organization, storage_location: storage_location_with_items) |
| 47 | + ] |
| 48 | + end |
| 49 | + let(:storage_location_with_duplicate_item) { |
| 50 | + create(:storage_location, |
| 51 | + name: "Storage Location with Duplicate Items", |
| 52 | + address: "1500 Remount Road, Front Royal, VA 22630", |
| 53 | + warehouse_type: StorageLocation::WAREHOUSE_TYPES.first, |
| 54 | + square_footage: 100) |
| 55 | + } |
| 56 | + let(:storage_location_with_items) { |
| 57 | + create(:storage_location, |
| 58 | + name: "Storage Location with Items", |
| 59 | + address: "123 Donation Site Way", |
| 60 | + warehouse_type: StorageLocation::WAREHOUSE_TYPES.first, |
| 61 | + square_footage: 100) |
| 62 | + } |
| 63 | + let(:item1) { create(:item, name: 'A') } |
| 64 | + let(:item2) { create(:item, name: 'B') } |
| 65 | + let(:item3) { create(:item, name: 'C') } |
| 66 | + |
| 67 | + before do |
| 68 | + TestInventory.create_inventory(storage_location_with_items.organization, { |
| 69 | + storage_location_with_items.id => { |
| 70 | + item1.id => 1, |
| 71 | + item2.id => 1, |
| 72 | + item3.id => 1 |
| 73 | + }, |
| 74 | + storage_location_with_duplicate_item.id => { item3.id => 1 } |
| 75 | + }) |
| 76 | + end |
| 77 | + |
| 78 | + it "succeeds" do |
| 79 | + get audits_path(format: response_format) |
| 80 | + expect(response).to be_successful |
| 81 | + end |
| 82 | + |
| 83 | + it "includes headers followed by alphabetized item names" do |
| 84 | + get audits_path(format: response_format) |
| 85 | + expect(response.body.split("\n")[0]).to eq([Audit.csv_export_headers, item1.name, item2.name, item3.name].join(',')) |
| 86 | + end |
| 87 | + |
| 88 | + it "Generates csv with Storage Location fields, alphabetized item names, item quantities lined up in their columns, and zeroes for no inventory" do |
| 89 | + get audits_path(format: response_format) |
| 90 | + csv = <<~CSV |
| 91 | + Audit Date,Audit Status,Name,Address,Square Footage,Warehouse Type,Total Inventory,A,B,C |
| 92 | + August 21 2025,in_progress,Storage Location with Duplicate Items,"1500 Remount Road, Front Royal, VA 22630",100,Residential space used,1,0,0,1 |
| 93 | + August 21 2025,in_progress,Storage Location with Items,123 Donation Site Way,100,Residential space used,3,1,1,1 |
| 94 | + CSV |
| 95 | + expect(response.body).to eq(csv) |
| 96 | + end |
37 | 97 | end |
38 | 98 | end |
39 | 99 |
|
|
0 commit comments