|
40 | 40 |
|
41 | 41 | context "csv" do |
42 | 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') } |
| 43 | + let(:csv_body) { "Stubbed CSV" } |
66 | 44 |
|
67 | 45 | 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 | | - }) |
| 46 | + allow(Audit).to receive(:generate_csv).and_return(csv_body) |
76 | 47 | end |
77 | 48 |
|
78 | 49 | it "succeeds" do |
79 | 50 | get audits_path(format: response_format) |
| 51 | + expect(response.content_type).to eq("text/csv") |
80 | 52 | expect(response).to be_successful |
81 | 53 | end |
82 | 54 |
|
83 | | - it "includes headers followed by alphabetized item names" do |
| 55 | + it "returns a CSV" do |
84 | 56 | 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 | 57 |
|
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 | | - #{audits[0].updated_at.strftime("%B %d %Y")},in_progress,Storage Location with Duplicate Items,"1500 Remount Road, Front Royal, VA 22630",100,Residential space used,1,0,0,1 |
93 | | - #{audits[1].updated_at.strftime("%B %d %Y")},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) |
| 58 | + expect(Audit).to have_received(:generate_csv) |
| 59 | + expect(response.body).to eq(csv_body) |
96 | 60 | end |
97 | 61 | end |
98 | 62 | end |
|
0 commit comments