From 429884b1038b80ac99f64fa5b1f173ea247b4d8a Mon Sep 17 00:00:00 2001 From: Richard Lynch Date: Tue, 19 Nov 2024 16:47:30 +0000 Subject: [PATCH] Remove JourneySubjectEligibilityChecker This class is no longer needed --- app/helpers/claims/itt_subject_helper.rb | 2 - .../dqt_record.rb | 2 - .../policy_eligibility_checker.rb | 22 +- lib/journey_subject_eligibility_checker.rb | 74 --- ...in_claim_tasks_update_with_dqt_api_spec.rb | 8 +- ...ourney_subject_eligibility_checker_spec.rb | 521 ------------------ .../early_career_payments/dqt_record_spec.rb | 2 +- 7 files changed, 18 insertions(+), 613 deletions(-) delete mode 100644 lib/journey_subject_eligibility_checker.rb delete mode 100644 spec/lib/journey_subject_eligibility_checker_spec.rb diff --git a/app/helpers/claims/itt_subject_helper.rb b/app/helpers/claims/itt_subject_helper.rb index 79e057a780..2a6a4253e7 100644 --- a/app/helpers/claims/itt_subject_helper.rb +++ b/app/helpers/claims/itt_subject_helper.rb @@ -1,5 +1,3 @@ -require "journey_subject_eligibility_checker" - module Claims module IttSubjectHelper def subjects_to_sentence_for_hint_text(answers) diff --git a/app/models/policies/levelling_up_premium_payments/dqt_record.rb b/app/models/policies/levelling_up_premium_payments/dqt_record.rb index 69ec93512e..235f2e85f9 100644 --- a/app/models/policies/levelling_up_premium_payments/dqt_record.rb +++ b/app/models/policies/levelling_up_premium_payments/dqt_record.rb @@ -1,5 +1,3 @@ -require "journey_subject_eligibility_checker" - module Policies module LevellingUpPremiumPayments class DqtRecord diff --git a/app/models/policies/levelling_up_premium_payments/policy_eligibility_checker.rb b/app/models/policies/levelling_up_premium_payments/policy_eligibility_checker.rb index c3d86f1c6d..4361b67e76 100644 --- a/app/models/policies/levelling_up_premium_payments/policy_eligibility_checker.rb +++ b/app/models/policies/levelling_up_premium_payments/policy_eligibility_checker.rb @@ -18,14 +18,14 @@ def policy def indicated_ineligible_itt_subject? return false if eligible_itt_subject.blank? - args = {claim_year: claim_year, itt_year: itt_academic_year} - - if args.values.any?(&:blank?) + if claim_year.blank? || itt_academic_year.blank? # trainee teacher who won't have given their ITT year - eligible_itt_subject.present? && !eligible_itt_subject.to_sym.in?(policy.fixed_subject_symbols) + eligible_itt_subject.present? && LevellingUpPremiumPayments.fixed_subject_symbols.exclude?(eligible_itt_subject.to_sym) else - itt_subject_checker = JourneySubjectEligibilityChecker.new(**args) - eligible_itt_subject.present? && !eligible_itt_subject.to_sym.in?(itt_subject_checker.current_subject_symbols(policy)) + LevellingUpPremiumPayments.subject_symbols( + claim_year: claim_year, + itt_year: itt_academic_year + ).exclude?(eligible_itt_subject.to_sym) end end @@ -58,14 +58,14 @@ def eligible_itt_subject_or_relevant_degree? def good_itt_subject? return false if eligible_itt_subject.blank? - args = {claim_year: claim_year, itt_year: itt_academic_year} - - if args.values.any?(&:blank?) + if claim_year.blank? || itt_academic_year.blank? # trainee teacher who won't have given their ITT year eligible_itt_subject.present? && eligible_itt_subject.to_sym.in?(Policies::LevellingUpPremiumPayments.fixed_subject_symbols) else - itt_subject_checker = JourneySubjectEligibilityChecker.new(**args) - eligible_itt_subject.to_sym.in?(itt_subject_checker.current_subject_symbols(policy)) + LevellingUpPremiumPayments.current_subject_symbols( + claim_year: claim_year, + itt_year: itt_academic_year + ).include?(eligible_itt_subject.to_sym) end end diff --git a/lib/journey_subject_eligibility_checker.rb b/lib/journey_subject_eligibility_checker.rb deleted file mode 100644 index a1048c9c87..0000000000 --- a/lib/journey_subject_eligibility_checker.rb +++ /dev/null @@ -1,74 +0,0 @@ -# TODO: Move this into an additional-payments journey specific namespace -# -class JourneySubjectEligibilityChecker - def initialize(claim_year:, itt_year:) - raise "Claim year #{claim_year} is after ECP and LUP both ended" if claim_year > EligibilityCheckable::FINAL_COMBINED_ECP_AND_LUP_POLICY_YEAR - - @claim_year = claim_year - - validate_itt_year(itt_year) - @itt_year = itt_year - end - - def future_claim_years - if none_of_the_above_or_blank?(@itt_year) - [] - else - ((@claim_year + 1)..EligibilityCheckable::FINAL_COMBINED_ECP_AND_LUP_POLICY_YEAR).to_a - end - end - - # FIXME RL - should be able to delete all the methods using this - def current_and_future_subject_symbols(policy) - (current_subject_symbols(policy) + future_subject_symbols(policy)).uniq - end - - def current_subject_symbols(policy) - if none_of_the_above_or_blank?(@itt_year) - [] - else - subject_symbols( - policy: policy, - claim_year: @claim_year, - itt_year: @itt_year - ) - end - end - - def future_subject_symbols(policy) - if none_of_the_above_or_blank?(@itt_year) - [] - else - future_claim_years.collect { |future_year| subject_symbols(policy: policy, claim_year: future_year, itt_year: @itt_year) }.flatten.uniq - end - end - - private - - # Move this - def potentially_still_eligible_policies(answers) - Journeys::AdditionalPaymentsForTeaching::POLICIES.select do |policy| - policy::PolicyEligibilityChecker.new(answers: answers).status != :ineligible - end - end - - def validate_itt_year(itt_year) - unless none_of_the_above_or_blank?(itt_year) - raise "ITT year #{itt_year} is outside the window for claim year #{@claim_year}" unless itt_year.in?(Journeys::AdditionalPaymentsForTeaching.selectable_itt_years_for_claim_year(@claim_year)) - end - end - - def none_of_the_above_or_blank?(itt_year) - itt_year.blank? || none_of_the_above?(itt_year) - end - - def none_of_the_above?(itt_year) - itt_year.in? [AcademicYear.new, "None"] - end - - def subject_symbols(policy:, claim_year:, itt_year:) - raise "Unsupported policy: #{policy}" unless policy.in?(Journeys::AdditionalPaymentsForTeaching::POLICIES) - - policy.subject_symbols(claim_year: claim_year, itt_year: itt_year) - end -end diff --git a/spec/features/admin/admin_claim_tasks_update_with_dqt_api_spec.rb b/spec/features/admin/admin_claim_tasks_update_with_dqt_api_spec.rb index 5bf497afa5..8b1c18edc9 100644 --- a/spec/features/admin/admin_claim_tasks_update_with_dqt_api_spec.rb +++ b/spec/features/admin/admin_claim_tasks_update_with_dqt_api_spec.rb @@ -148,8 +148,12 @@ def task_outcome itt_years = policy.selectable_itt_years_for_claim_year(claim_year) itt_years.detect do |itt_year| - checker = JourneySubjectEligibilityChecker.new(claim_year: claim_year, itt_year: itt_year) - subject_symbol.in?(checker.current_subject_symbols(policy)) + subject_symbol.in?( + policy.current_subject_symbols( + claim_year: claim_year, + itt_year: itt_year + ) + ) end } diff --git a/spec/lib/journey_subject_eligibility_checker_spec.rb b/spec/lib/journey_subject_eligibility_checker_spec.rb deleted file mode 100644 index c4daf1fb00..0000000000 --- a/spec/lib/journey_subject_eligibility_checker_spec.rb +++ /dev/null @@ -1,521 +0,0 @@ -require "rails_helper" -require "journey_subject_eligibility_checker" - -RSpec.describe JourneySubjectEligibilityChecker do - describe ".new" do - context "claim year validation" do - context "after LUP and ECP" do - specify { expect { described_class.new(claim_year: AcademicYear.new(2025), itt_year: AcademicYear.new(2024)) }.to raise_error("Claim year 2025/2026 is after ECP and LUP both ended") } - end - end - - context "ITT year validation" do - context "inside window" do - specify { expect { described_class.new(claim_year: AcademicYear.new(2022), itt_year: AcademicYear.new(2017)) }.not_to raise_error } - end - - context "outside window" do - specify { expect { described_class.new(claim_year: AcademicYear.new(2022), itt_year: AcademicYear.new(2016)) }.to raise_error("ITT year 2016/2017 is outside the window for claim year 2022/2023") } - end - - context "None of the above" do - specify { expect { described_class.new(claim_year: AcademicYear.new(2022), itt_year: AcademicYear.new) }.not_to raise_error } - end - end - end - - describe "#future_claim_years" do - context "2022/2023 claim year" do - subject { described_class.new(claim_year: AcademicYear.new(2022), itt_year: AcademicYear.new(2021)) } - - specify { expect(subject.future_claim_years).to contain_exactly(AcademicYear.new(2023), AcademicYear.new(2024)) } - end - - context "2023/2024 claim year" do - subject { described_class.new(claim_year: AcademicYear.new(2023), itt_year: AcademicYear.new(2022)) } - - specify { expect(subject.future_claim_years).to contain_exactly(AcademicYear.new(2024)) } - end - - context "2024/2025 claim year" do - subject { described_class.new(claim_year: AcademicYear.new(2024), itt_year: AcademicYear.new(2023)) } - - specify { expect(subject.future_claim_years).to be_empty } - end - - context "None of the above ITT year" do - subject { described_class.new(claim_year: AcademicYear.new(2022), itt_year: AcademicYear.new) } - - specify { expect(subject.future_claim_years).to be_empty } - end - end - - describe "#current_subject_symbols" do - subject { described_class.new(claim_year: claim_year, itt_year: itt_year).current_subject_symbols(policy) } - - context "ECP" do - let(:policy) { Policies::EarlyCareerPayments } - - context "2022 claim year" do - let(:claim_year) { AcademicYear.new(2022) } - - context "None of the above ITT year" do - let(:itt_year) { AcademicYear.new } - - it { is_expected.to be_empty } - end - - context "2017 ITT year" do - let(:itt_year) { AcademicYear.new(2017) } - - it { is_expected.to be_empty } - end - - context "2018 ITT year" do - let(:itt_year) { AcademicYear.new(2018) } - - it { is_expected.to be_empty } - end - - context "2019 ITT year" do - let(:itt_year) { AcademicYear.new(2019) } - - it { is_expected.to contain_exactly(:mathematics) } - end - - context "2020 ITT year" do - let(:itt_year) { AcademicYear.new(2020) } - - it { is_expected.to contain_exactly(:chemistry, :foreign_languages, :mathematics, :physics) } - end - - context "2021 ITT year" do - let(:itt_year) { AcademicYear.new(2021) } - - it { is_expected.to be_empty } - end - end - - context "2023 claim year" do - let(:claim_year) { AcademicYear.new(2023) } - - context "2018 ITT year" do - let(:itt_year) { AcademicYear.new(2018) } - - it { is_expected.to contain_exactly(:mathematics) } - end - - context "2019 ITT year" do - let(:itt_year) { AcademicYear.new(2019) } - - it { is_expected.to be_empty } - end - - context "2020 ITT year" do - let(:itt_year) { AcademicYear.new(2020) } - - it { is_expected.to contain_exactly(:chemistry, :foreign_languages, :mathematics, :physics) } - end - - context "2021 ITT year" do - let(:itt_year) { AcademicYear.new(2021) } - - it { is_expected.to be_empty } - end - - context "2022 ITT year" do - let(:itt_year) { AcademicYear.new(2022) } - - it { is_expected.to be_empty } - end - end - - context "2024 claim year" do - let(:claim_year) { AcademicYear.new(2024) } - - context "2019 ITT year" do - let(:itt_year) { AcademicYear.new(2019) } - - it { is_expected.to contain_exactly(:mathematics) } - end - - context "2020 ITT year" do - let(:itt_year) { AcademicYear.new(2020) } - - it { is_expected.to contain_exactly(:chemistry, :foreign_languages, :mathematics, :physics) } - end - - context "2021 ITT year" do - let(:itt_year) { AcademicYear.new(2021) } - - it { is_expected.to be_empty } - end - - context "2022 ITT year" do - let(:itt_year) { AcademicYear.new(2022) } - - it { is_expected.to be_empty } - end - - context "2023 ITT year" do - let(:itt_year) { AcademicYear.new(2023) } - - it { is_expected.to be_empty } - end - end - end - - context "LUP" do - let(:policy) { Policies::LevellingUpPremiumPayments } - let(:the_constant_lup_subjects) { [:chemistry, :computing, :mathematics, :physics] } - - context "claim year before 2022" do - let(:claim_year) { AcademicYear.new(2021) } - let(:itt_year) { AcademicYear.new(2017) } - - it { is_expected.to be_empty } - end - - context "2022 claim year" do - let(:claim_year) { AcademicYear.new(2022) } - - context "2017 itt year" do - let(:itt_year) { AcademicYear.new(2017) } - - it { is_expected.to contain_exactly(*the_constant_lup_subjects) } - end - - context "2018 itt year" do - let(:itt_year) { AcademicYear.new(2018) } - - it { is_expected.to contain_exactly(*the_constant_lup_subjects) } - end - - context "2019 itt year" do - let(:itt_year) { AcademicYear.new(2019) } - - it { is_expected.to contain_exactly(*the_constant_lup_subjects) } - end - - context "2020 itt year" do - let(:itt_year) { AcademicYear.new(2020) } - - it { is_expected.to contain_exactly(*the_constant_lup_subjects) } - end - - context "2021 itt year" do - let(:itt_year) { AcademicYear.new(2021) } - - it { is_expected.to contain_exactly(*the_constant_lup_subjects) } - end - end - - context "2023 claim year" do - let(:claim_year) { AcademicYear.new(2023) } - - context "2018 itt year" do - let(:itt_year) { AcademicYear.new(2018) } - - it { is_expected.to contain_exactly(*the_constant_lup_subjects) } - end - - context "2019 itt year" do - let(:itt_year) { AcademicYear.new(2019) } - - it { is_expected.to contain_exactly(*the_constant_lup_subjects) } - end - - context "2020 itt year" do - let(:itt_year) { AcademicYear.new(2020) } - - it { is_expected.to contain_exactly(*the_constant_lup_subjects) } - end - - context "2021 itt year" do - let(:itt_year) { AcademicYear.new(2021) } - - it { is_expected.to contain_exactly(*the_constant_lup_subjects) } - end - - context "2022 itt year" do - let(:itt_year) { AcademicYear.new(2022) } - - it { is_expected.to contain_exactly(*the_constant_lup_subjects) } - end - end - - context "2024 claim year" do - let(:claim_year) { AcademicYear.new(2024) } - - context "2019 itt year" do - let(:itt_year) { AcademicYear.new(2019) } - - it { is_expected.to contain_exactly(*the_constant_lup_subjects) } - end - - context "2020 itt year" do - let(:itt_year) { AcademicYear.new(2020) } - - it { is_expected.to contain_exactly(*the_constant_lup_subjects) } - end - - context "2021 itt year" do - let(:itt_year) { AcademicYear.new(2021) } - - it { is_expected.to contain_exactly(*the_constant_lup_subjects) } - end - - context "2022 itt year" do - let(:itt_year) { AcademicYear.new(2022) } - - it { is_expected.to contain_exactly(*the_constant_lup_subjects) } - end - - context "2023 itt year" do - let(:itt_year) { AcademicYear.new(2023) } - - it { is_expected.to contain_exactly(*the_constant_lup_subjects) } - end - end - end - - context "unsupported policy" do - let(:policy) { Policies::StudentLoans } - - context "2022 claim year" do - let(:claim_year) { AcademicYear.new(2022) } - - context "2017 ITT year" do - let(:itt_year) { AcademicYear.new(2017) } - - specify { expect { described_class.new(claim_year: claim_year, itt_year: itt_year).current_subject_symbols(policy) }.to raise_error("Unsupported policy: StudentLoans") } - end - end - end - end - - describe "#future_subject_symbols" do - subject { described_class.new(claim_year: claim_year, itt_year: itt_year).future_subject_symbols(policy) } - - context "ECP" do - let(:policy) { Policies::EarlyCareerPayments } - - context "2022 claim year" do - let(:claim_year) { AcademicYear.new(2022) } - - context "None of the above ITT year" do - let(:itt_year) { AcademicYear.new } - - it { is_expected.to be_empty } - end - - context "2017 ITT year" do - let(:itt_year) { AcademicYear.new(2017) } - - it { is_expected.to be_empty } - end - - context "2018 ITT year" do - let(:itt_year) { AcademicYear.new(2018) } - - it { is_expected.to contain_exactly(:mathematics) } - end - - context "2019 ITT year" do - let(:itt_year) { AcademicYear.new(2019) } - - it { is_expected.to contain_exactly(:mathematics) } - end - - context "2020 ITT year" do - let(:itt_year) { AcademicYear.new(2020) } - - it { is_expected.to contain_exactly(:chemistry, :foreign_languages, :mathematics, :physics) } - end - end - - context "2023 claim year" do - let(:claim_year) { AcademicYear.new(2023) } - - context "2018 ITT year" do - let(:itt_year) { AcademicYear.new(2018) } - - it { is_expected.to be_empty } - end - - context "2019 ITT year" do - let(:itt_year) { AcademicYear.new(2019) } - - it { is_expected.to contain_exactly(:mathematics) } - end - - context "2020 ITT year" do - let(:itt_year) { AcademicYear.new(2020) } - - it { is_expected.to contain_exactly(:chemistry, :foreign_languages, :mathematics, :physics) } - end - - context "2021 ITT year" do - let(:itt_year) { AcademicYear.new(2021) } - - it { is_expected.to be_empty } - end - - context "2022 ITT year" do - let(:itt_year) { AcademicYear.new(2022) } - - it { is_expected.to be_empty } - end - end - - context "2024 claim year" do - let(:claim_year) { AcademicYear.new(2024) } - - context "2019 ITT year" do - let(:itt_year) { AcademicYear.new(2019) } - - it { is_expected.to be_empty } - end - - context "2020 ITT year" do - let(:itt_year) { AcademicYear.new(2020) } - - it { is_expected.to be_empty } - end - - context "2021 ITT year" do - let(:itt_year) { AcademicYear.new(2021) } - - it { is_expected.to be_empty } - end - - context "2022 ITT year" do - let(:itt_year) { AcademicYear.new(2022) } - - it { is_expected.to be_empty } - end - - context "2023 ITT year" do - let(:itt_year) { AcademicYear.new(2023) } - - it { is_expected.to be_empty } - end - end - end - - context "LUP" do - let(:policy) { Policies::LevellingUpPremiumPayments } - let(:the_constant_lup_subjects) { [:chemistry, :computing, :mathematics, :physics] } - - context "2022 claim year" do - let(:claim_year) { AcademicYear.new(2022) } - - context "2017 ITT year" do - let(:itt_year) { AcademicYear.new(2017) } - - it { is_expected.to be_empty } - end - - context "2018 ITT year" do - let(:itt_year) { AcademicYear.new(2018) } - - it { is_expected.to contain_exactly(*the_constant_lup_subjects) } - end - - context "2019 ITT year" do - let(:itt_year) { AcademicYear.new(2019) } - - it { is_expected.to contain_exactly(*the_constant_lup_subjects) } - end - - context "2020 ITT year" do - let(:itt_year) { AcademicYear.new(2020) } - - it { is_expected.to contain_exactly(*the_constant_lup_subjects) } - end - - context "2021 ITT year" do - let(:itt_year) { AcademicYear.new(2021) } - - it { is_expected.to contain_exactly(*the_constant_lup_subjects) } - end - end - - context "2023 claim year" do - let(:claim_year) { AcademicYear.new(2023) } - - context "2018 ITT year" do - let(:itt_year) { AcademicYear.new(2018) } - - it { is_expected.to be_empty } - end - - context "2019 ITT year" do - let(:itt_year) { AcademicYear.new(2019) } - - it { is_expected.to contain_exactly(*the_constant_lup_subjects) } - end - - context "2020 ITT year" do - let(:itt_year) { AcademicYear.new(2020) } - - it { is_expected.to contain_exactly(*the_constant_lup_subjects) } - end - - context "2021 ITT year" do - let(:itt_year) { AcademicYear.new(2021) } - - it { is_expected.to contain_exactly(*the_constant_lup_subjects) } - end - - context "2022 ITT year" do - let(:itt_year) { AcademicYear.new(2022) } - - it { is_expected.to contain_exactly(*the_constant_lup_subjects) } - end - end - - context "2024 claim year" do - let(:claim_year) { AcademicYear.new(2024) } - - context "2019 ITT year" do - let(:itt_year) { AcademicYear.new(2019) } - - it { is_expected.to be_empty } - end - - context "2020 ITT year" do - let(:itt_year) { AcademicYear.new(2020) } - - it { is_expected.to be_empty } - end - - context "2021 ITT year" do - let(:itt_year) { AcademicYear.new(2021) } - - it { is_expected.to be_empty } - end - - context "2022 ITT year" do - let(:itt_year) { AcademicYear.new(2022) } - - it { is_expected.to be_empty } - end - end - end - - context "unsupported policy" do - let(:policy) { Policies::StudentLoans } - - context "2022 claim year" do - let(:claim_year) { AcademicYear.new(2022) } - - context "2017 ITT year" do - let(:itt_year) { AcademicYear.new(2017) } - - specify { expect { described_class.new(claim_year: claim_year, itt_year: itt_year).future_subject_symbols(policy) }.to raise_error("Unsupported policy: StudentLoans") } - end - end - end - end -end diff --git a/spec/models/policies/early_career_payments/dqt_record_spec.rb b/spec/models/policies/early_career_payments/dqt_record_spec.rb index 641eca89ed..c30fb04b2f 100644 --- a/spec/models/policies/early_career_payments/dqt_record_spec.rb +++ b/spec/models/policies/early_career_payments/dqt_record_spec.rb @@ -2251,7 +2251,7 @@ let(:itt_subjects) { ["mathematics"] } before do - allow(JourneySubjectEligibilityChecker).to receive(:new) + allow(Policies::EarlyCareerPayments).to receive(:current_and_future_subject_symbols) .and_raise(StandardError.new("ITT year")) end