Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/models/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ class Site < VitaPartner
where(parent_organization_id: Organization.with_capacity.pluck(:id))
}

scope :with_language_capability, -> (language) do
org_ids = Organization.with_language_capability(language).pluck(:id)

# Sites under those Orgs
where(type: Site::TYPE, parent_organization_id: org_ids)
end

def coalition
parent_organization.coalition
end
Expand Down
18 changes: 18 additions & 0 deletions app/services/partner_routing_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ def determine_partner
private

def set_base_vita_partners(language_routing:)
@base_sites = if language_routing
Site.with_language_capability(@intake&.preferred_interview_language)
else
Site
end

@base_orgs = if language_routing
Organization.with_language_capability(@intake&.preferred_interview_language)
else
Expand Down Expand Up @@ -129,6 +135,18 @@ def vita_partner_from_itin_enabled
def vita_partner_from_zip_code
return unless @zip_code.present?

# Step 1/2: Check sites.
eligible_with_capacity = @base_sites.joins(:serviced_zip_codes)
.where(vita_partner_zip_codes: { zip_code: @zip_code })

vita_partner = eligible_with_capacity.sample

if vita_partner.present?
@routing_method = :zip_code
return vita_partner
end

# Step 2/2: Check orgs.
eligible_with_capacity = @base_orgs.with_capacity.joins(:serviced_zip_codes)
.where(vita_partner_zip_codes: { zip_code: @zip_code })

Expand Down
13 changes: 13 additions & 0 deletions spec/services/partner_routing_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,19 @@
end
end

context "when client zip corresponds to a Site but not the Site's parent Org" do
# That is, the Site and its parent Org have no zips in common (GYR1-925).
let!(:org) { create :organization }
let!(:zip) { create :vita_partner_zip_code, zip_code: "78729", vita_partner: org }
let!(:site) { create :site, parent_organization: org }
let!(:zip) { create :vita_partner_zip_code, zip_code: "12345", vita_partner: site }
subject { PartnerRoutingService.new(zip_code: "12345") }
it "routes to the Site" do
expect(subject.determine_partner).to eq site
expect(subject.routing_method).to eq :zip_code
end
end

context "when clients zip code doesn't correspond to a Vita Partner" do
context "when state for that zip code has associated Vita Partners" do
subject { PartnerRoutingService.new(zip_code: "28806") } #NC
Expand Down
Loading