Skip to content

Commit

Permalink
Merge branch 'main' into 4596-restore_reset_password_capability
Browse files Browse the repository at this point in the history
  • Loading branch information
cielf authored Aug 23, 2024
2 parents 44a816b + 1813bf3 commit beab008
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ GEM
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
standard (1.39.1)
standard (1.39.2)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.64.0)
Expand Down
11 changes: 11 additions & 0 deletions app/controllers/partners/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@ module Partners
class BaseController < ApplicationController
layout 'partners/application'

before_action :require_partner

private

def redirect_to_root
redirect_to root_path
end

def require_partner
unless current_partner
respond_to do |format|
format.html { redirect_to dashboard_path, flash: {error: "Logged in user is not set up as a 'partner'."} }
format.json { render body: nil, status: :forbidden }
end
end
end

def verify_partner_is_active
if current_partner.deactivated?
flash[:alert] = 'Your account has been disabled, contact the organization via their email to reactivate'
Expand Down
2 changes: 1 addition & 1 deletion app/services/reports/partner_info_report_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def partner_agency_counts
end

def partner_zipcodes_serviced
partner_agency_profiles.map(&:zips_served).uniq.sort.join(', ')
partner_agency_profiles.map(&:zips_served).uniq.compact.sort.join(', ')
end
end
end
10 changes: 10 additions & 0 deletions spec/requests/partners/dashboard_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@
end
end

context "without a partner role" do
it "should redirect to the organization dashboard" do
partner_user.add_role(Role::ORG_USER, @organization)
partner_user.remove_role(Role::PARTNER, partner)
allow(UsersRole).to receive(:current_role_for).and_return(partner_user.roles.find_by(name: "partner"))
get partners_dashboard_path
expect(response).to redirect_to(dashboard_path)
end
end

context "BroadcastAnnouncement card" do
it "displays announcements if there are valid ones" do
BroadcastAnnouncement.create(message: "test announcement", user_id: user.id, organization_id: organization.id)
Expand Down
69 changes: 49 additions & 20 deletions spec/services/reports/partner_info_report_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,58 @@
end

describe '#report' do
it 'should report zero values' do
expect(report.report).to eq({
entries: { "Number of Partner Agencies" => 0,
"Zip Codes Served" => "" },
name: "Partner Agencies and Service Area"
})
context "with no partners available" do
it 'should report zero values' do
expect(report.report).to eq({
entries: { "Number of Partner Agencies" => 0,
"Zip Codes Served" => "" },
name: "Partner Agencies and Service Area"
})
end
end

it 'should report normal values' do
p1 = create(:partner, :uninvited, organization: organization, name: 'Partner 1')
p1.profile.update!(zips_served: '90210-1234', agency_type: Partner::AGENCY_TYPES['CAREER'])
p2 = create(:partner, :uninvited, organization: organization, name: 'Partner 2')
p2.profile.update!(zips_served: '12345', agency_type: Partner::AGENCY_TYPES['CAREER'])
p3 = create(:partner, :uninvited, organization: organization, name: 'Partner 3')
p3.profile.update!(zips_served: '09876-3564', agency_type: Partner::AGENCY_TYPES['EDU'])
context "with partners available" do
let!(:p1) do
create(:partner, :uninvited, organization: organization, name: 'Partner 1') do |p|
p.profile.update!(zips_served: '90210-1234', agency_type: Partner::AGENCY_TYPES['CAREER'])
end
end
let!(:p2) do
create(:partner, :uninvited, organization: organization, name: 'Partner 2') do |p|
p.profile.update!(zips_served: '12345', agency_type: Partner::AGENCY_TYPES['CAREER'])
end
end
let!(:p3) do
create(:partner, :uninvited, organization: organization, name: 'Partner 3') do |p|
p.profile.update!(zips_served: '09876-3564', agency_type: Partner::AGENCY_TYPES['EDU'])
end
end

expect(report.report).to eq({
entries: { "Agency Type: Career technical training" => 2,
"Agency Type: Education program" => 1,
"Number of Partner Agencies" => 3,
"Zip Codes Served" => "09876-3564, 12345, 90210-1234" },
name: "Partner Agencies and Service Area"
})
context "with all profiles have zips_served" do
it 'should report normal values' do
expect(report.report).to eq({
entries: { "Agency Type: Career technical training" => 2,
"Agency Type: Education program" => 1,
"Number of Partner Agencies" => 3,
"Zip Codes Served" => "09876-3564, 12345, 90210-1234" },
name: "Partner Agencies and Service Area"
})
end
end

context "with some profiles missing zip_served" do
before { p2.profile.update!(zips_served: nil) }

it 'should report normal values' do
expect(report.report).to eq({
entries: { "Agency Type: Career technical training" => 2,
"Agency Type: Education program" => 1,
"Number of Partner Agencies" => 3,
"Zip Codes Served" => "09876-3564, 90210-1234" },
name: "Partner Agencies and Service Area"
})
end
end
end
end
end

0 comments on commit beab008

Please sign in to comment.