|
7 | 7 | end |
8 | 8 |
|
9 | 9 | describe "#report" do |
10 | | - it "should report zero values" do |
11 | | - expect(report.report[:entries]).to match(hash_including({ |
12 | | - "% period supplies bought" => "0%", |
13 | | - "% period supplies donated" => "0%", |
14 | | - "Period supplies distributed" => "0", |
15 | | - "Period supplies per adult per month" => 0, |
16 | | - "Money spent purchasing period supplies" => "$0.00" |
17 | | - })) |
18 | | - expect(report.report[:entries]["Period supplies"].split(", ")) |
19 | | - .to contain_exactly("Tampons", "Pads", "Liners (Menstrual)") |
| 10 | + context "with no values" do |
| 11 | + it "should report zero values" do |
| 12 | + expect(report.report[:entries]).to match(hash_including({ |
| 13 | + "% period supplies bought" => "0%", |
| 14 | + "% period supplies donated" => "0%", |
| 15 | + "Period supplies distributed" => "0", |
| 16 | + "Money spent purchasing period supplies" => "$0.00" |
| 17 | + })) |
| 18 | + expect(report.report[:entries]["Period supplies"].split(", ")) |
| 19 | + .to contain_exactly("Tampons", "Pads", "Liners (Menstrual)") |
| 20 | + end |
20 | 21 | end |
21 | 22 |
|
22 | | - describe "with values" do |
| 23 | + context "with values" do |
23 | 24 | before(:each) do |
24 | 25 | Organization.seed_items(organization) |
25 | 26 |
|
|
32 | 33 | # We will create data both within and outside our date range, and both period_supplies and non period_supplies. |
33 | 34 | # Spec will ensure that only the required data is included. |
34 | 35 |
|
| 36 | + # Kits |
| 37 | + period_supplies_kit = create(:kit, :with_item, organization: organization) |
| 38 | + another_period_supply_kit = create(:kit, :with_item, organization: organization) |
| 39 | + donated_period_supply_kit = create(:kit, :with_item, organization: organization) |
| 40 | + purchased_period_supply_kit = create(:kit, :with_item, organization: organization) |
| 41 | + pad_and_tampon_kit = create(:kit, :with_item, organization: organization) |
| 42 | + |
| 43 | + create(:base_item, name: "Adult Pads", partner_key: "adult pads", category: "Menstrual Supplies") |
| 44 | + create(:base_item, name: "Adult Tampons", partner_key: "adult tampons", category: "Menstrual Supplies") |
| 45 | + |
| 46 | + period_supplies_kit_item = create(:item, name: "Adult Pads", partner_key: "adult pads") |
| 47 | + another_period_supplies_kit_item = create(:item, name: "Adult Tampons", partner_key: "adult tampons") |
| 48 | + purchased_period_supplies_kit_item = create(:item, name: "Liners", partner_key: "adult tampons") |
| 49 | + |
| 50 | + period_supplies_kit.line_items.first.update!(item_id: period_supplies_kit_item.id, quantity: 5) |
| 51 | + another_period_supply_kit.line_items.first.update!(item_id: another_period_supplies_kit_item.id, quantity: 5) |
| 52 | + donated_period_supply_kit.line_items.first.update!(item_id: another_period_supplies_kit_item.id, quantity: 5) |
| 53 | + purchased_period_supply_kit.line_items.first.update!(item_id: purchased_period_supplies_kit_item.id, quantity: 5) |
| 54 | + |
| 55 | + pad_and_tampon_kit.line_items.first.update!(item_id: period_supplies_kit_item.id, quantity: 10) |
| 56 | + pad_and_tampon_kit.line_items.first.update!(item_id: another_period_supplies_kit_item.id, quantity: 10) |
| 57 | + |
| 58 | + period_supplies_kit_distribution = create(:distribution, organization: organization, issued_at: within_time) |
| 59 | + another_period_supplies_kit_distribution = create(:distribution, organization: organization, issued_at: within_time) |
| 60 | + pad_and_tampon_kit_distribution = create(:distribution, organization: organization, issued_at: within_time) |
| 61 | + |
| 62 | + kit_donation = create(:donation, product_drive: nil, issued_at: within_time, money_raised: 1000, organization: organization) |
| 63 | + |
| 64 | + kit_purchase = create(:purchase, issued_at: within_time, organization: organization, purchased_from: "TikTok Shop", amount_spent_in_cents: 1000, amount_spent_on_period_supplies_cents: 1000, line_items: [ |
| 65 | + create(:line_item, :purchase, item: period_supplies_kit_item, quantity: 5), |
| 66 | + create(:line_item, :purchase, item: purchased_period_supplies_kit_item, quantity: 5) |
| 67 | + ]) |
| 68 | + |
| 69 | + create(:line_item, :distribution, quantity: 10, item: period_supplies_kit.item, itemizable: period_supplies_kit_distribution) |
| 70 | + create(:line_item, :distribution, quantity: 10, item: another_period_supply_kit.item, itemizable: another_period_supplies_kit_distribution) |
| 71 | + |
| 72 | + create(:line_item, :distribution, quantity: 10, item: pad_and_tampon_kit.item, itemizable: pad_and_tampon_kit_distribution) |
| 73 | + create(:line_item, :distribution, quantity: 10, item: pad_and_tampon_kit.item, itemizable: pad_and_tampon_kit_distribution) |
| 74 | + |
| 75 | + create(:line_item, :donation, quantity: 10, item: donated_period_supply_kit.item, itemizable: kit_donation) |
| 76 | + |
| 77 | + create(:line_item, :purchase, quantity: 30, item: purchased_period_supply_kit.item, itemizable: kit_purchase) |
| 78 | + |
35 | 79 | # Distributions |
36 | 80 | distributions = create_list(:distribution, 2, issued_at: within_time, organization: organization) |
37 | 81 | outside_distributions = create_list(:distribution, 2, issued_at: outside_time, organization: organization) |
|
84 | 128 | end |
85 | 129 | end |
86 | 130 |
|
87 | | - it "should report normal values" do |
88 | | - organization.items.period_supplies.first.update!(distribution_quantity: 20) |
| 131 | + describe "with values" do |
| 132 | + it "should report normal values" do |
| 133 | + organization.items.period_supplies.first.update!(distribution_quantity: 20) |
89 | 134 |
|
90 | | - expect(report.report[:name]).to eq("Period Supplies") |
91 | | - expect(report.report[:entries]).to match(hash_including({ |
92 | | - "% period supplies bought" => "60%", |
93 | | - "% period supplies donated" => "40%", |
94 | | - "Period supplies distributed" => "2,000", |
95 | | - "Period supplies per adult per month" => 20, |
96 | | - "Money spent purchasing period supplies" => "$30.00" |
97 | | - })) |
98 | | - expect(report.report[:entries]["Period supplies"].split(", ")) |
99 | | - .to contain_exactly("Tampons", "Pads", "Liners (Menstrual)") |
| 135 | + expect(report.report[:name]).to eq("Period Supplies") |
| 136 | + expect(report.report[:entries]).to match(hash_including({ |
| 137 | + "% period supplies bought" => "67%", |
| 138 | + "% period supplies donated" => "33%", |
| 139 | + "Period supplies distributed" => "2,300", |
| 140 | + "Money spent purchasing period supplies" => "$40.00" |
| 141 | + })) |
| 142 | + expect(report.report[:entries]["Period supplies"].split(", ")) |
| 143 | + .to contain_exactly("Adult Pads", "Adult Tampons", "Liners", "Liners (Menstrual)", "Pads", "Tampons") |
| 144 | + end |
| 145 | + |
| 146 | + it "returns the correct quantity of period supplies from kits" do |
| 147 | + expect(report.distributed_period_supplies_from_kits).to eq(300) |
| 148 | + end |
| 149 | + |
| 150 | + it "returns the correct quantity of donated period supplies from kits" do |
| 151 | + expect(report.donated_supplies_from_kits).to eq(50) |
| 152 | + end |
| 153 | + |
| 154 | + it "returns the correct quantity of purchased items in kits" do |
| 155 | + expect(report.purchased_supplies_from_kits).to eq(150) |
| 156 | + end |
100 | 157 | end |
101 | 158 | end |
102 | 159 | end |
|
0 commit comments