diff --git a/app/forms/admin/claims_filter_form.rb b/app/forms/admin/claims_filter_form.rb index 1bc54e89d5..524874e267 100644 --- a/app/forms/admin/claims_filter_form.rb +++ b/app/forms/admin/claims_filter_form.rb @@ -28,7 +28,7 @@ def claims when "awaiting_provider_verification" Claim.by_policy(Policies::FurtherEducationPayments).awaiting_further_education_provider_verification else - Claim.includes(:decisions).not_held.awaiting_decision + Claim.includes(:decisions).not_held.awaiting_decision.not_awaiting_further_education_provider_verification end @claims = @claims.by_policy(selected_policy) if selected_policy diff --git a/app/helpers/admin/claims_helper.rb b/app/helpers/admin/claims_helper.rb index 733fe25124..37c76943d7 100644 --- a/app/helpers/admin/claims_helper.rb +++ b/app/helpers/admin/claims_helper.rb @@ -172,7 +172,9 @@ def claim_summary_heading(claim) end def status(claim) - if claim.all_payrolled? + if claim.awaiting_provider_verification? + "Awaiting provider verification" + elsif claim.all_payrolled? "Payrolled" elsif claim.latest_decision&.approved? && claim.awaiting_qa? && !claim.held? "Approved awaiting QA" diff --git a/app/models/claim.rb b/app/models/claim.rb index 10e38dd469..ba0c5d1e9d 100644 --- a/app/models/claim.rb +++ b/app/models/claim.rb @@ -211,7 +211,15 @@ class Claim < ApplicationRecord scope :qa_required, -> { where(qa_required: true) } scope :awaiting_further_education_provider_verification, -> do joins("INNER JOIN further_education_payments_eligibilities ON further_education_payments_eligibilities.id = claims.eligibility_id") + .left_outer_joins(:notes) .where("further_education_payments_eligibilities.verification = '{}'") + .and( + Claim.where("further_education_payments_eligibilities.flagged_as_duplicate = FALSE") + .or(Claim.where("further_education_payments_eligibilities.flagged_as_duplicate = TRUE").and(Claim.where(notes: {label: "provider_verification"}))) + ) + end + scope :not_awaiting_further_education_provider_verification, -> do + where.not(id: Claim.awaiting_further_education_provider_verification) end def onelogin_idv_full_name @@ -439,6 +447,12 @@ def one_login_idv_mismatch? !one_login_idv_name_match? || !one_login_idv_dob_match? end + def awaiting_provider_verification? + return false unless has_further_education_policy? + + eligibility.awaiting_provider_verification? + end + private def one_login_idv_name_match? @@ -449,6 +463,10 @@ def one_login_idv_dob_match? onelogin_idv_date_of_birth == date_of_birth end + def has_further_education_policy? + policy == Policies::FurtherEducationPayments + end + def normalise_ni_number self.national_insurance_number = normalised_ni_number end diff --git a/app/models/policies/further_education_payments/admin_provider_verification_task_presenter.rb b/app/models/policies/further_education_payments/admin_provider_verification_task_presenter.rb index 890ca01694..a8ac063ad6 100644 --- a/app/models/policies/further_education_payments/admin_provider_verification_task_presenter.rb +++ b/app/models/policies/further_education_payments/admin_provider_verification_task_presenter.rb @@ -30,7 +30,7 @@ def admin_sent_emails end def verification_email_sent? - !claim.eligibility.flagged_as_duplicate? || verification_email_sent_by_admin_team? + claim.eligibility.awaiting_provider_verification? end def verification_email_sent_by_admin_team? diff --git a/app/models/policies/further_education_payments/eligibility.rb b/app/models/policies/further_education_payments/eligibility.rb index 90be4cc547..01ace6850c 100644 --- a/app/models/policies/further_education_payments/eligibility.rb +++ b/app/models/policies/further_education_payments/eligibility.rb @@ -70,6 +70,13 @@ def permanent_contract? def verified? verification.present? end + + def awaiting_provider_verification? + return false if verified? + + # when a provider verification email is sent by the admin team, a note is created + !flagged_as_duplicate? || claim.notes.where(label: "provider_verification").any? + end end end end diff --git a/spec/factories/policies/further_education_payments/eligibilities.rb b/spec/factories/policies/further_education_payments/eligibilities.rb index 868766b622..8ccd7c472b 100644 --- a/spec/factories/policies/further_education_payments/eligibilities.rb +++ b/spec/factories/policies/further_education_payments/eligibilities.rb @@ -18,6 +18,10 @@ association :school, factory: :fe_eligible_school end + trait :duplicate do + flagged_as_duplicate { true } + end + trait :verified do contract_type { "permanent" } teaching_responsibilities { true } diff --git a/spec/features/admin/admin_claim_further_education_payments_spec.rb b/spec/features/admin/admin_claim_further_education_payments_spec.rb index 8c1220a5ec..2a2c69383e 100644 --- a/spec/features/admin/admin_claim_further_education_payments_spec.rb +++ b/spec/features/admin/admin_claim_further_education_payments_spec.rb @@ -16,7 +16,7 @@ describe "provider verification task" do context "when the provider is yet to verify the claim" do context "when a verification email has not been sent" do - it "allows the admins to sent the email" do + it "allows the admins to send the email" do fe_provider = create( :school, :further_education, diff --git a/spec/features/admin/admin_claims_filtering_spec.rb b/spec/features/admin/admin_claims_filtering_spec.rb index d6018c972d..926d988014 100644 --- a/spec/features/admin/admin_claims_filtering_spec.rb +++ b/spec/features/admin/admin_claims_filtering_spec.rb @@ -23,6 +23,7 @@ let(:auto_approved_awaiting_payroll_claims) { create_list(:claim, 2, :auto_approved, policy: Policies::LevellingUpPremiumPayments) } let(:approved_claim) { create(:claim, :approved, policy: Policies::LevellingUpPremiumPayments, assigned_to: mette, decision_creator: mary) } let(:further_education_claims_awaiting_provider_verification) { create_list(:claim, 2, :submitted, policy: Policies::FurtherEducationPayments, eligibility_trait: :not_verified, assigned_to: valentino) } + let(:further_education_claims_provider_verification_email_not_sent) { create_list(:claim, 2, :submitted, policy: Policies::FurtherEducationPayments, eligibility_trait: :duplicate, assigned_to: valentino) } let(:rejected_claim) { create(:claim, :rejected, policy: Policies::LevellingUpPremiumPayments, assigned_to: valentino) } let!(:claims) do @@ -38,6 +39,7 @@ auto_approved_awaiting_payroll_claims, approved_claim, further_education_claims_awaiting_provider_verification, + further_education_claims_provider_verification_email_not_sent, rejected_claim ] end @@ -124,7 +126,7 @@ early_career_payments_claims_for_mette, early_career_payments_claims_failed_bank_validation, lup_claims_unassigned, - further_education_claims_awaiting_provider_verification + further_education_claims_provider_verification_email_not_sent ) select "Awaiting provider verification", from: "Status:" diff --git a/spec/features/admin/admin_view_claim_further_education_payments_spec.rb b/spec/features/admin/admin_view_claim_further_education_payments_spec.rb index 7b148db727..469615e50f 100644 --- a/spec/features/admin/admin_view_claim_further_education_payments_spec.rb +++ b/spec/features/admin/admin_view_claim_further_education_payments_spec.rb @@ -2,14 +2,13 @@ RSpec.feature "Admin view claim for FurtherEducationPayments" do let!(:journey_configuration) { create(:journey_configuration, "further_education_payments") } - let(:eligibility) { create(:further_education_payments_eligibility, :eligible) } let(:eligibility_with_trn) { create(:further_education_payments_eligibility, :eligible, :with_trn) } let!(:claim) { create( :claim, :submitted, policy: Policies::FurtherEducationPayments, - eligibility: eligibility + eligibility_trait: :duplicate ) } let!(:claim_with_trn) { @@ -20,9 +19,45 @@ eligibility: eligibility_with_trn ) } + let!(:claim_not_verified) { + create( + :claim, + :submitted, + policy: Policies::FurtherEducationPayments, + eligibility_trait: :not_verified + ) + } + let!(:claim_with_duplicates_no_provider_email_sent) { + create( + :claim, + :submitted, + policy: Policies::FurtherEducationPayments, + eligibility_trait: :duplicate + ) + } + let!(:claim_with_duplicates_provider_email_sent) { + create( + :claim, + :submitted, + policy: Policies::FurtherEducationPayments, + eligibility_trait: :duplicate + ) + } + let!(:verified_claim) { + create( + :claim, + :submitted, + policy: Policies::FurtherEducationPayments, + eligibility_trait: :verified + ) + } - scenario "view claim summary for claim with no TRN" do + before do sign_in_as_service_operator + create(:note, claim: claim_with_duplicates_provider_email_sent, label: "provider_verification") + end + + scenario "view claim summary for claim with no TRN" do visit admin_claims_path find("a[href='#{admin_claim_tasks_path(claim)}']").click expect(page).not_to have_content("Claim route") @@ -33,7 +68,6 @@ end scenario "view claim summary for claim with TRN" do - sign_in_as_service_operator visit admin_claims_path find("a[href='#{admin_claim_tasks_path(claim_with_trn)}']").click expect(page).not_to have_content("Not provided") @@ -41,4 +75,22 @@ expect(page).to have_content("UK Provider Reference Number (UKPRN)") expect(page).to have_content(claim_with_trn.school.ukprn) end + + scenario "Awaiting provider verification claim status" do + visit admin_claims_path(status: "awaiting_provider_verification") + find("a[href='#{admin_claim_tasks_path(claim_not_verified)}']").click + expect(page).to have_content("Awaiting provider verification") + + visit admin_claims_path + find("a[href='#{admin_claim_tasks_path(claim_with_duplicates_no_provider_email_sent)}']").click + expect(page).to have_content("Awaiting decision - not on hold") + + visit admin_claims_path(status: "awaiting_provider_verification") + find("a[href='#{admin_claim_tasks_path(claim_with_duplicates_provider_email_sent)}']").click + expect(page).to have_content("Awaiting provider verification") + + visit admin_claims_path + find("a[href='#{admin_claim_tasks_path(verified_claim)}']").click + expect(page).to have_content("Awaiting decision - not on hold") + end end diff --git a/spec/jobs/further_education_payments/provider_verification_chase_email_spec.rb b/spec/jobs/further_education_payments/provider_verification_chase_email_spec.rb index d0726c1fc2..6dd8d09d65 100644 --- a/spec/jobs/further_education_payments/provider_verification_chase_email_spec.rb +++ b/spec/jobs/further_education_payments/provider_verification_chase_email_spec.rb @@ -47,7 +47,6 @@ eligibility: build( :further_education_payments_eligibility, :eligible, - :verified, provider_verification_email_last_sent_at: DateTime.new(2024, 10, 1, 7, 0, 0) )) } @@ -59,7 +58,6 @@ eligibility: build( :further_education_payments_eligibility, :eligible, - :verified, provider_verification_email_last_sent_at: DateTime.new(2024, 9, 1, 8, 0, 0), provider_verification_chase_email_last_sent_at: DateTime.new(2024, 9, 22, 8, 0, 0) )) @@ -83,7 +81,7 @@ policy: Policies::FurtherEducationPayments, eligibility: build( :further_education_payments_eligibility, - :eligible, + :not_verified, provider_verification_email_last_sent_at: DateTime.new(2024, 10, 1, 7, 0, 0) )) } diff --git a/spec/models/claim_spec.rb b/spec/models/claim_spec.rb index b028feb62c..a6962a42ff 100644 --- a/spec/models/claim_spec.rb +++ b/spec/models/claim_spec.rb @@ -906,15 +906,45 @@ end end - describe ".awaiting_further_education_provider_verification" do - subject { described_class.awaiting_further_education_provider_verification } - + describe "awaiting further education provider verification scopes" do + let!(:claim_not_verified_provider_email_automatically_sent) { create(:claim, :submitted, policy: Policies::FurtherEducationPayments, eligibility_trait: :not_verified) } + let!(:claim_not_verified_has_duplicates_provider_email_not_sent_has_other_note) { create(:claim, :submitted, policy: Policies::FurtherEducationPayments, eligibility_trait: :duplicate) } + let!(:claim_not_verified_has_duplicates_provider_email_not_sent) { create(:claim, :submitted, policy: Policies::FurtherEducationPayments, eligibility_trait: :duplicate) } + let!(:claim_not_verified_has_duplicates_provider_email_manually_sent) { create(:claim, :submitted, policy: Policies::FurtherEducationPayments, eligibility_trait: :duplicate) } let!(:claim_with_fe_provider_verification) { create(:claim, policy: Policies::FurtherEducationPayments, eligibility_trait: :verified) } - let!(:claim_awaiting_fe_provider_verification) { create(:claim, policy: Policies::FurtherEducationPayments, eligibility_trait: :not_verified) } let!(:non_fe_claim) { create(:claim, policy: Policies::StudentLoans) } - it "returns claims that are awaiting FE provider verification" do - is_expected.to match_array([claim_awaiting_fe_provider_verification]) + before do + create(:note, claim: claim_not_verified_has_duplicates_provider_email_manually_sent, label: "provider_verification") + create(:note, claim: claim_not_verified_has_duplicates_provider_email_not_sent_has_other_note, label: "student_loan_plan") + end + + describe ".awaiting_further_education_provider_verification" do + subject { described_class.awaiting_further_education_provider_verification } + + it "returns claims that have not been verified by the provider, and have had a provider email sent" do + is_expected.to match_array( + [ + claim_not_verified_provider_email_automatically_sent, + claim_not_verified_has_duplicates_provider_email_manually_sent + ] + ) + end + end + + describe ".not_awaiting_further_education_provider_verification" do + subject { described_class.not_awaiting_further_education_provider_verification } + + it "returns claims that have no FE eligiblity, or FE claims that have been verified by the provider, or non-verified claims where a provider email has not been sent" do + is_expected.to match_array( + [ + claim_not_verified_has_duplicates_provider_email_not_sent_has_other_note, + claim_not_verified_has_duplicates_provider_email_not_sent, + claim_with_fe_provider_verification, + non_fe_claim + ] + ) + end end end @@ -1330,4 +1360,42 @@ it { is_expected.to be false } end end + + describe "#awaiting_provider_verification?" do + subject { claim.awaiting_provider_verification? } + + context "when the eligiblity is not verified" do + context "when there are no duplicates" do + let(:claim) { create(:claim, :submitted, policy: Policies::FurtherEducationPayments, eligibility_trait: :not_verified) } + + it { is_expected.to be true } + end + + context "when there are duplicates" do + let(:claim) { create(:claim, :submitted, policy: Policies::FurtherEducationPayments, eligibility_trait: :duplicate) } + + context "the provider email has not been sent" do + it { is_expected.to be false } + end + + context "when the provider email has been sent" do + before { create(:note, claim: claim, label: "provider_verification") } + + it { is_expected.to be true } + end + end + end + + context "when the eligiblity is verified" do + let(:claim) { build(:claim, policy: Policies::FurtherEducationPayments, eligibility_trait: :verified) } + + it { is_expected.to be false } + end + + context "when the eligiblity is not further education payments" do + let(:claim) { build(:claim, policy: Policies::StudentLoans) } + + it { is_expected.to be false } + end + end end