diff --git a/Gemfile.lock b/Gemfile.lock index 3b8cd2768b..54039a468f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/app/controllers/partners/base_controller.rb b/app/controllers/partners/base_controller.rb index 0b217375d1..37435df4a6 100644 --- a/app/controllers/partners/base_controller.rb +++ b/app/controllers/partners/base_controller.rb @@ -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' diff --git a/app/services/reports/partner_info_report_service.rb b/app/services/reports/partner_info_report_service.rb index 9db4d27199..b27f583115 100644 --- a/app/services/reports/partner_info_report_service.rb +++ b/app/services/reports/partner_info_report_service.rb @@ -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 diff --git a/spec/requests/partners/dashboard_requests_spec.rb b/spec/requests/partners/dashboard_requests_spec.rb index 761f379abb..b800f4f776 100644 --- a/spec/requests/partners/dashboard_requests_spec.rb +++ b/spec/requests/partners/dashboard_requests_spec.rb @@ -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) diff --git a/spec/services/reports/partner_info_report_service_spec.rb b/spec/services/reports/partner_info_report_service_spec.rb index c858307768..a8f26e8ae5 100644 --- a/spec/services/reports/partner_info_report_service_spec.rb +++ b/spec/services/reports/partner_info_report_service_spec.rb @@ -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