diff --git a/app/models/automated_checks/claim_verifiers/employment.rb b/app/models/automated_checks/claim_verifiers/employment.rb index d3186ef15c..eb689fb3eb 100644 --- a/app/models/automated_checks/claim_verifiers/employment.rb +++ b/app/models/automated_checks/claim_verifiers/employment.rb @@ -11,6 +11,7 @@ def initialize(claim:, admin_user: nil) end def perform + return unless required? return unless awaiting_task? no_data || no_match || matched @@ -18,6 +19,10 @@ def perform private + def required? + claim.eligibility.teacher_reference_number.present? + end + attr_accessor :admin_user, :claim, :teachers_pensions_service def awaiting_task? diff --git a/app/models/claim_checking_tasks.rb b/app/models/claim_checking_tasks.rb index 8a8e1f1261..48a7377686 100644 --- a/app/models/claim_checking_tasks.rb +++ b/app/models/claim_checking_tasks.rb @@ -12,26 +12,34 @@ def initialize(claim) delegate :policy, to: :claim def applicable_task_names - @applicable_task_names ||= Task::NAMES.dup.tap do |task_names| - task_names.delete("induction_confirmation") unless claim.policy == Policies::EarlyCareerPayments - task_names.delete("student_loan_amount") unless claim.policy == Policies::StudentLoans - task_names.delete("student_loan_plan") unless claim.has_ecp_or_lupp_policy? && claim.submitted_without_slc_data? - task_names.delete("payroll_details") unless claim.must_manually_validate_bank_details? - task_names.delete("matching_details") unless matching_claims.exists? - task_names.delete("payroll_gender") unless claim.payroll_gender_missing? || task_names_for_claim.include?("payroll_gender") - if claim.policy.international_relocation_payments? - task_names.delete("qualifications") - task_names.delete("census_subjects_taught") - end - unless claim.policy.international_relocation_payments? - task_names.delete("visa") - task_names.delete("arrival_date") - task_names.delete("employment_contract") - task_names.delete("employment_start") - task_names.delete("subject") - task_names.delete("teaching_hours") - end - unless claim.policy.further_education_payments? + case policy + when Policies::FurtherEducationPayments + Policies::FurtherEducationPayments::ClaimCheckingTasks + .new(claim) + .applicable_task_names + else + @applicable_task_names ||= Task::NAMES.dup.tap do |task_names| + task_names.delete("induction_confirmation") unless claim.policy == Policies::EarlyCareerPayments + task_names.delete("student_loan_amount") unless claim.policy == Policies::StudentLoans + task_names.delete("student_loan_plan") unless claim.has_ecp_or_lupp_policy? && claim.submitted_without_slc_data? + task_names.delete("payroll_details") unless claim.must_manually_validate_bank_details? + task_names.delete("matching_details") unless matching_claims.exists? + task_names.delete("payroll_gender") unless claim.payroll_gender_missing? || task_names_for_claim.include?("payroll_gender") + + if claim.policy.international_relocation_payments? + task_names.delete("qualifications") + task_names.delete("census_subjects_taught") + end + + unless claim.policy.international_relocation_payments? + task_names.delete("visa") + task_names.delete("arrival_date") + task_names.delete("employment_contract") + task_names.delete("employment_start") + task_names.delete("subject") + task_names.delete("teaching_hours") + end + task_names.delete("provider_verification") end end diff --git a/app/models/policies/further_education_payments.rb b/app/models/policies/further_education_payments.rb index 7d4e50f6e2..5877a93cd2 100644 --- a/app/models/policies/further_education_payments.rb +++ b/app/models/policies/further_education_payments.rb @@ -10,7 +10,8 @@ module FurtherEducationPayments MIN_QA_THRESHOLD = 10 VERIFIERS = [ - AutomatedChecks::ClaimVerifiers::ProviderVerification + AutomatedChecks::ClaimVerifiers::ProviderVerification, + AutomatedChecks::ClaimVerifiers::Employment ] # Options shown to admins when rejecting a claim diff --git a/app/models/policies/further_education_payments/admin_tasks_presenter.rb b/app/models/policies/further_education_payments/admin_tasks_presenter.rb index 37a3ec37a9..da9c1dfb17 100644 --- a/app/models/policies/further_education_payments/admin_tasks_presenter.rb +++ b/app/models/policies/further_education_payments/admin_tasks_presenter.rb @@ -26,6 +26,18 @@ def qualifications [] end + def employment + [] + end + + def identity_confirmation + [] + end + + def student_loan_plan + [] + end + private def verifier diff --git a/app/models/policies/further_education_payments/claim_checking_tasks.rb b/app/models/policies/further_education_payments/claim_checking_tasks.rb new file mode 100644 index 0000000000..b85c6adb51 --- /dev/null +++ b/app/models/policies/further_education_payments/claim_checking_tasks.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +module Policies + module FurtherEducationPayments + class ClaimCheckingTasks + attr_reader :claim + + def initialize(claim) + @claim = claim + end + + delegate :policy, to: :claim + + def applicable_task_names + tasks = [] + + tasks << "identity_confirmation" + tasks << "provider_verification" + tasks << "employment" if claim.eligibility.teacher_reference_number.present? + tasks << "student_loan_plan" + tasks << "payroll_details" + tasks << "matching_details" if matching_claims.exists? + tasks << "payroll_gender" if claim.payroll_gender_missing? + + tasks + end + + private + + def matching_claims + @matching_claims ||= Claim::MatchingAttributeFinder.new(claim).matching_claims + end + end + end +end diff --git a/spec/models/automated_checks/claim_verifier_spec.rb b/spec/models/automated_checks/claim_verifier_spec.rb index a36cdc91c4..65fcde043d 100644 --- a/spec/models/automated_checks/claim_verifier_spec.rb +++ b/spec/models/automated_checks/claim_verifier_spec.rb @@ -111,5 +111,42 @@ it { is_expected.to eq(0) } end end + + context "when verifier is conditional" do + subject(:perform) { claim_verifier } + + let(:claim) { create(:claim, policy: Policies::FurtherEducationPayments) } + + let(:claim_verifier_args) do + { + claim:, + dqt_teacher_status: nil + } + end + + context "and is needed" do + before do + claim.eligibility.update teacher_reference_number: "1234567" + end + + it "creates relevant task" do + expect { + subject.perform + }.to change { Task.where(name: "employment").count }.by(1) + end + end + + context "and is not needed" do + before do + claim.eligibility.update teacher_reference_number: nil + end + + it "does not create relevant task" do + expect { + subject.perform + }.to change { Task.where(name: "employment").count }.by(0) + end + end + end end end diff --git a/spec/models/claim_checking_tasks_spec.rb b/spec/models/claim_checking_tasks_spec.rb index cdd181bded..63a05a1eb2 100644 --- a/spec/models/claim_checking_tasks_spec.rb +++ b/spec/models/claim_checking_tasks_spec.rb @@ -88,6 +88,32 @@ include_examples :payroll_details_task include_examples :student_loan_plan_task end + + context "FurtherEducationPayments claim" do + subject { described_class.new(claim) } + + let(:policy) { Policies::FurtherEducationPayments } + + context "when TRN is provided" do + before do + claim.eligibility.update!(teacher_reference_number: "1234567") + end + + it "includes employment task" do + expect(subject.applicable_task_names).to include("employment") + end + end + + context "when TRN is not included" do + before do + claim.eligibility.update!(teacher_reference_number: nil) + end + + it "excludes employment task" do + expect(subject.applicable_task_names).not_to include("employment") + end + end + end end describe "#incomplete_task_names" do diff --git a/spec/support/admin_view_claim_feature_shared_examples.rb b/spec/support/admin_view_claim_feature_shared_examples.rb index 56d2218154..f9bb1f79bf 100644 --- a/spec/support/admin_view_claim_feature_shared_examples.rb +++ b/spec/support/admin_view_claim_feature_shared_examples.rb @@ -181,7 +181,7 @@ def expect_page_to_have_policy_sections(policy) when Policies::InternationalRelocationPayments ["Identity confirmation", "Visa", "Arrival date", "Employment", "Employment contract", "Employment start", "Subject", "Teaching hours", "Decision"] when Policies::FurtherEducationPayments - ["Identity confirmation", "Provider verification", "Qualifications", "Census subjects taught", "Employment", "Matching details", "Decision"] + ["Identity confirmation", "Provider verification", "Student loan plan", "Payroll details", "Matching details", "Decision"] else raise "Unimplemented policy: #{policy}" end