From 84db83859c07509f89a2a44d7299c3c94423a778 Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Fri, 6 Sep 2024 11:41:48 +0100 Subject: [PATCH] FE admin: conditionally show employment task --- app/models/claim_checking_tasks.rb | 48 +++++++++++-------- .../claim_checking_tasks.rb | 47 ++++++++++++++++++ spec/models/claim_checking_tasks_spec.rb | 26 ++++++++++ ...dmin_view_claim_feature_shared_examples.rb | 2 +- 4 files changed, 102 insertions(+), 21 deletions(-) create mode 100644 app/models/policies/further_education_payments/claim_checking_tasks.rb 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/claim_checking_tasks.rb b/app/models/policies/further_education_payments/claim_checking_tasks.rb new file mode 100644 index 0000000000..f349e9bea4 --- /dev/null +++ b/app/models/policies/further_education_payments/claim_checking_tasks.rb @@ -0,0 +1,47 @@ +# 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 + @applicable_task_names ||= Task::NAMES.dup.tap do |task_names| + task_names.delete("employment") if claim.eligibility.teacher_reference_number.blank? + + 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") + + 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 + end + end + + private + + def task_names_for_claim + claim.tasks.pluck(:name) + end + + def matching_claims + @matching_claims ||= Claim::MatchingAttributeFinder.new(claim).matching_claims + 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..d9ce17773c 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", "Qualifications", "Census subjects taught", "Matching details", "Decision"] else raise "Unimplemented policy: #{policy}" end