|
1 | 1 | RSpec.describe DistributionSummaryByCountyQuery do |
2 | | - let(:year) { Time.current.year } |
3 | | - let(:issued_at_last_year) { Time.current.change(year: year - 1).to_datetime } |
4 | | - let(:distributions) { [] } |
5 | | - let(:organization_id) { organization.id } |
6 | | - let(:start_date) { nil } |
7 | | - let(:end_date) { nil } |
8 | | - let(:params) { {organization_id:, start_date:, end_date:} } |
| 2 | + let(:organization) { create(:organization, name: "Some Unique Name") } |
| 3 | + let(:item_1) { create(:item, value_in_cents: 1050, organization: organization) } |
| 4 | + let(:partner_1) do |
| 5 | + create(:partner, organization:, without_profile: true) do |p| |
| 6 | + p.profile = create(:partner_profile, partner: p, organization:) do |pp| |
| 7 | + pp.served_areas = create_list(:partners_served_area, 4, partner_profile: pp, client_share: 25) do |sa| |
| 8 | + sa.county = create(:county) |
| 9 | + end |
| 10 | + end |
| 11 | + end |
| 12 | + end |
| 13 | + let(:partner_2) do |
| 14 | + create(:partner, organization:, without_profile: true) do |p| |
| 15 | + p.profile = create(:partner_profile, partner: p, organization:) do |pp| |
| 16 | + pp.served_areas = create_list(:partners_served_area, 5, partner_profile: pp, client_share: 20) do |sa, i| |
| 17 | + # create one overlapping service area |
| 18 | + sa.county = i.zero? ? partner_1.profile.served_areas[0].county : create(:county) |
| 19 | + end |
| 20 | + end |
| 21 | + end |
| 22 | + end |
9 | 23 |
|
10 | | - include_examples "distribution_by_county" |
| 24 | + let(:now) { Time.current.to_datetime } |
11 | 25 |
|
12 | | - before do |
13 | | - create(:storage_location, organization: organization) |
14 | | - end |
| 26 | + let(:params) { {organization_id: organization.id, start_date: nil, end_date: nil} } |
15 | 27 |
|
16 | | - describe "get_breakdown" do |
| 28 | + describe "call" do |
17 | 29 | it "will have 100% unspecified shows if no served_areas" do |
18 | | - create(:distribution, :with_items, item: item_1, organization: user.organization) |
| 30 | + create(:distribution, :with_items, item: item_1, organization: organization) |
19 | 31 | breakdown = DistributionSummaryByCountyQuery.new(**params).call |
20 | 32 | expect(breakdown.size).to eq(1) |
21 | 33 | expect(breakdown[0]["quantity"]).to eq(100) |
22 | 34 | expect(breakdown[0]["amount"]).to be_within(0.01).of(105000.0) |
23 | 35 | end |
24 | 36 |
|
25 | 37 | it "divides the item numbers and values according to the partner profile" do |
26 | | - create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_1) |
| 38 | + create(:distribution, :with_items, item: item_1, organization: organization, partner: partner_1) |
27 | 39 | breakdown = DistributionSummaryByCountyQuery.new(**params).call |
28 | 40 | expect(breakdown.size).to eq(5) |
29 | 41 | expect(breakdown[4]["quantity"]).to eq(0) |
|
35 | 47 | end |
36 | 48 |
|
37 | 49 | it "handles multiple partners with overlapping service areas properly" do |
38 | | - create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_1, issued_at: issued_at_present) |
39 | | - create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_2, issued_at: issued_at_present) |
| 50 | + create(:distribution, :with_items, item: item_1, organization: organization, partner: partner_1, issued_at: now) |
| 51 | + create(:distribution, :with_items, item: item_1, organization: organization, partner: partner_2, issued_at: now) |
40 | 52 | breakdown = DistributionSummaryByCountyQuery.new(**params).call |
41 | 53 | num_with_45 = 0 |
42 | 54 | num_with_20 = 0 |
|
0 commit comments