Skip to content

Commit 245a805

Browse files
committed
Fix query spec
1 parent f99e5d1 commit 245a805

File tree

3 files changed

+33
-21
lines changed

3 files changed

+33
-21
lines changed

app/queries/distribution_summary_by_county_query.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class DistributionSummaryByCountyQuery
2626
COALESCE(c.name, 'Unspecified') county_name,
2727
COALESCE(c.region, 'ZZZ') county_region
2828
FROM distribution_totals dt
29-
JOIN partner_profiles pp ON pp.id = dt.partner_id
29+
LEFT JOIN partner_profiles pp ON pp.id = dt.partner_id
3030
LEFT JOIN partner_served_areas psa ON psa.partner_profile_id = pp.partner_id
3131
LEFT JOIN counties c ON c.id = psa.county_id
3232
UNION

spec/factories/partners.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@
2424
send_reminders { true }
2525
organization_id { Organization.try(:first).try(:id) || create(:organization).id }
2626

27+
transient do
28+
without_profile { false }
29+
end
30+
2731
trait :approved do
2832
status { :approved }
2933
end
3034

3135
trait :uninvited do
3236
status { :uninvited }
33-
34-
transient do
35-
without_profile { false }
36-
end
3737
end
3838

3939
trait :awaiting_review do

spec/queries/distribution_summary_by_county_query_spec.rb

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,41 @@
11
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
923

10-
include_examples "distribution_by_county"
24+
let(:now) { Time.current.to_datetime }
1125

12-
before do
13-
create(:storage_location, organization: organization)
14-
end
26+
let(:params) { {organization_id: organization.id, start_date: nil, end_date: nil} }
1527

16-
describe "get_breakdown" do
28+
describe "call" do
1729
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)
1931
breakdown = DistributionSummaryByCountyQuery.new(**params).call
2032
expect(breakdown.size).to eq(1)
2133
expect(breakdown[0]["quantity"]).to eq(100)
2234
expect(breakdown[0]["amount"]).to be_within(0.01).of(105000.0)
2335
end
2436

2537
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)
2739
breakdown = DistributionSummaryByCountyQuery.new(**params).call
2840
expect(breakdown.size).to eq(5)
2941
expect(breakdown[4]["quantity"]).to eq(0)
@@ -35,8 +47,8 @@
3547
end
3648

3749
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)
4052
breakdown = DistributionSummaryByCountyQuery.new(**params).call
4153
num_with_45 = 0
4254
num_with_20 = 0

0 commit comments

Comments
 (0)