|
1 | 1 | RSpec.describe Exports::ExportPurchasesCSVService do |
2 | 2 | describe "#generate_csv_data" do |
3 | | - subject { described_class.new(purchase_ids: purchase_ids).generate_csv_data } |
| 3 | + let(:organization) { create(:organization) } |
4 | 4 | let(:purchase_ids) { purchases.map(&:id) } |
| 5 | + let(:storage_location) { create(:storage_location, organization: organization) } |
| 6 | + subject { described_class.new(purchase_ids: purchase_ids, organization: organization).generate_csv_data } |
| 7 | + |
5 | 8 | let(:duplicate_item) do |
6 | | - FactoryBot.create( |
7 | | - :item, name: Faker::Appliance.unique.equipment |
8 | | - ) |
| 9 | + create(:item, name: Faker::Appliance.unique.equipment, organization: organization) |
9 | 10 | end |
| 11 | + |
10 | 12 | let(:items_lists) do |
11 | 13 | [ |
12 | 14 | [ |
13 | 15 | [duplicate_item, 5], |
14 | 16 | [ |
15 | | - FactoryBot.create( |
16 | | - :item, name: Faker::Appliance.unique.equipment |
17 | | - ), |
| 17 | + FactoryBot.create(:item, name: Faker::Appliance.unique.equipment, |
| 18 | + organization: organization), |
18 | 19 | 7 |
19 | 20 | ], |
20 | 21 | [duplicate_item, 3] |
|
35 | 36 | items_lists.each_with_index.map do |items, i| |
36 | 37 | purchase = create( |
37 | 38 | :purchase, |
38 | | - vendor: create( |
39 | | - :vendor, business_name: "Vendor Name #{i}" |
40 | | - ), |
| 39 | + organization: organization, |
| 40 | + storage_location: storage_location, |
| 41 | + vendor: create(:vendor, business_name: "Vendor Name #{i}", organization: organization), |
41 | 42 | issued_at: start_time + i.days, |
42 | 43 | comment: "This is the #{i}-th purchase in the test.", |
43 | 44 | amount_spent_in_cents: i * 4 + 555, |
|
114 | 115 | expect(subject[idx + 1]).to eq(row) |
115 | 116 | end |
116 | 117 | end |
| 118 | + # new purchase export regression test |
| 119 | + it "includes all organization item headers even when exported purchases only use a subset of items" do |
| 120 | + unused_item = create(:item, name: "Z Unused Item", organization: organization) |
| 121 | + |
| 122 | + headers = subject[0] |
| 123 | + |
| 124 | + expect(headers).to include("Z Unused Item") |
| 125 | + end |
117 | 126 | end |
118 | 127 | end |
0 commit comments