Skip to content

Commit

Permalink
Move selectable_itt_years_for_claim_year from lib
Browse files Browse the repository at this point in the history
As part of the refactor to remove ECP we want to move the policy
specific functionality into the respective polices. This commit moves
the `selectable_itt_years_for_claim_year` out of the lib class and into
each policy, with the journey delegating this method to any
potentially_still_eligible policies.
  • Loading branch information
rjlynch committed Dec 11, 2024
1 parent f94942a commit f46a866
Show file tree
Hide file tree
Showing 19 changed files with 74 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def qualification_is?(*symbols)
end

def selectable_itt_years_for_claim_year
JourneySubjectEligibilityChecker.selectable_itt_years_for_claim_year(
AdditionalPaymentsForTeaching.selectable_itt_years_for_claim_year(
journey.configuration.current_academic_year
)
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/concerns/eligibility_checkable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def no_selectable_subjects?
def ineligible_cohort?
return false if itt_academic_year.nil?

eligible_itt_years = JourneySubjectEligibilityChecker.selectable_itt_years_for_claim_year(claim_year)
eligible_itt_years = policy.selectable_itt_years_for_claim_year(claim_year)
!itt_academic_year.in? eligible_itt_years
end

Expand Down Expand Up @@ -121,7 +121,7 @@ def good_performance?
def eligible_cohort?
return false if itt_academic_year.nil?

eligible_itt_years = JourneySubjectEligibilityChecker.selectable_itt_years_for_claim_year(claim_year)
eligible_itt_years = policy.selectable_itt_years_for_claim_year(claim_year)
itt_academic_year.in? eligible_itt_years
end

Expand Down
8 changes: 7 additions & 1 deletion app/models/journeys/additional_payments_for_teaching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def set_a_reminder?(itt_academic_year:, policy:)
return false if policy_year >= policy::POLICY_END_YEAR

next_year = policy_year + 1
eligible_itt_years = JourneySubjectEligibilityChecker.selectable_itt_years_for_claim_year(next_year)
eligible_itt_years = selectable_itt_years_for_claim_year(next_year)
eligible_itt_years.include?(itt_academic_year)
end

Expand All @@ -62,5 +62,11 @@ def selectable_subject_symbols(journey_session)
[]
end
end

def selectable_itt_years_for_claim_year(claim_year)
POLICIES.flat_map do |policy|
policy.selectable_itt_years_for_claim_year(claim_year)
end.uniq
end
end
end
4 changes: 4 additions & 0 deletions app/models/policies/early_career_payments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,9 @@ def future_years(year)

year + 1..POLICY_END_YEAR
end

def selectable_itt_years_for_claim_year(claim_year)
(AcademicYear.new(claim_year - 5)...AcademicYear.new(claim_year)).to_a
end
end
end
2 changes: 1 addition & 1 deletion app/models/policies/early_career_payments/dqt_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def itt_academic_year_for_claim
return nil unless academic_date

year = AcademicYear.for(academic_date)
eligible_years = JourneySubjectEligibilityChecker.selectable_itt_years_for_claim_year(current_academic_year)
eligible_years = EarlyCareerPayments.selectable_itt_years_for_claim_year(current_academic_year)
eligible_years.include?(year) ? year : AcademicYear.new
end

Expand Down
4 changes: 4 additions & 0 deletions app/models/policies/levelling_up_premium_payments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,9 @@ def future_years(year)

year + 1..POLICY_END_YEAR
end

def selectable_itt_years_for_claim_year(claim_year)
(AcademicYear.new(claim_year - 5)...AcademicYear.new(claim_year)).to_a
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def no_invalid_subject_codes?
end

def itt_year_within_allowed_range?(year = itt_year)
eligible_itt_years = JourneySubjectEligibilityChecker.selectable_itt_years_for_claim_year(current_academic_year)
eligible_itt_years = LevellingUpPremiumPayments.selectable_itt_years_for_claim_year(current_academic_year)
eligible_itt_years.include?(year)
end
end
Expand Down
10 changes: 1 addition & 9 deletions lib/journey_subject_eligibility_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ def future_claim_years
end
end

def selectable_itt_years
JourneySubjectEligibilityChecker.selectable_itt_years_for_claim_year(@claim_year)
end

def self.selectable_subject_symbols(answers)
if answers.nqt_in_academic_year_after_itt
new(
Expand All @@ -37,10 +33,6 @@ def self.selectable_subject_symbols(answers)
end.sort
end

def self.selectable_itt_years_for_claim_year(claim_year)
(AcademicYear.new(claim_year - 5)...AcademicYear.new(claim_year)).to_a
end

# Ideally we wouldn't have this method at all. Unfortunately it was hardcoded like
# this before we realised trainee teachers weren't as special a case as we
# thought.
Expand Down Expand Up @@ -92,7 +84,7 @@ def potentially_still_eligible_policies(answers)

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?(selectable_itt_years)
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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def task_outcome

claim_year = Journeys.for_policy(policy).configuration.current_academic_year

itt_years = JourneySubjectEligibilityChecker.selectable_itt_years_for_claim_year(claim_year)
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

let!(:journey_configuration) { create(:journey_configuration, :additional_payments) }
let!(:school) { create(:school, :combined_journey_eligibile_for_all) }
let(:eligible_itt_years) { JourneySubjectEligibilityChecker.selectable_itt_years_for_claim_year(journey_configuration.current_academic_year) }
let(:eligible_itt_years) { Journeys::AdditionalPaymentsForTeaching.selectable_itt_years_for_claim_year(journey_configuration.current_academic_year) }
let(:academic_date) { Date.new(eligible_itt_years.first.start_year, 12, 1) }
let(:itt_year) { AcademicYear.for(academic_date) }
let(:trn) { 1234567 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

let!(:journey_configuration) { create(:journey_configuration, :additional_payments, current_academic_year: AcademicYear.new(2023)) }
let!(:school) { create(:school, :combined_journey_eligibile_for_all) }
let(:eligible_itt_years) { JourneySubjectEligibilityChecker.selectable_itt_years_for_claim_year(journey_configuration.current_academic_year) }
let(:eligible_itt_years) { Journeys::AdditionalPaymentsForTeaching.selectable_itt_years_for_claim_year(journey_configuration.current_academic_year) }
let(:academic_date) { Date.new(eligible_itt_years.first.start_year, 12, 1) }
let(:itt_year) { AcademicYear.for(academic_date) }
let(:trn) { 1234567 }
Expand Down
2 changes: 1 addition & 1 deletion spec/features/ineligible_student_loans_claims_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
let!(:ineligible_school) { create(:school, :student_loans_ineligible) }
let(:import_zero_amount_slc_data) { create(:student_loans_data, nino:, date_of_birth:, plan_type_of_deduction: 1, amount: 0) }
let(:import_no_data_slc_data) { create(:student_loans_data, nino:, date_of_birth:, plan_type_of_deduction: nil, amount: 0) }
let(:eligible_itt_years) { JourneySubjectEligibilityChecker.selectable_itt_years_for_claim_year(journey_configuration.current_academic_year) }
let(:eligible_itt_years) { Journeys::AdditionalPaymentsForTeaching.selectable_itt_years_for_claim_year(journey_configuration.current_academic_year) }
let(:academic_date) { Date.new(eligible_itt_years.first.start_year, 12, 1) }
let(:itt_year) { AcademicYear.for(academic_date) }
let(:trn) { 1234567 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

let!(:journey_configuration) { create(:journey_configuration, :student_loans) }
let!(:school) { create(:school, :student_loans_eligible) }
let(:eligible_itt_years) { JourneySubjectEligibilityChecker.selectable_itt_years_for_claim_year(journey_configuration.current_academic_year) }
let(:eligible_itt_years) { Journeys::AdditionalPaymentsForTeaching.selectable_itt_years_for_claim_year(journey_configuration.current_academic_year) }
let(:academic_date) { Date.new(eligible_itt_years.first.start_year, 12, 1) }
let(:itt_year) { AcademicYear.for(academic_date) }
let(:trn) { 1234567 }
Expand Down
40 changes: 0 additions & 40 deletions spec/lib/journey_subject_eligibility_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,46 +50,6 @@
end
end

describe "#selectable_itt_years" do
context "2022/2023 claim year" do
subject { described_class.new(claim_year: AcademicYear.new(2022), itt_year: AcademicYear.new(2021)).selectable_itt_years }

it { is_expected.to contain_exactly(AcademicYear.new(2017), AcademicYear.new(2018), AcademicYear.new(2019), AcademicYear.new(2020), AcademicYear.new(2021)) }
end

context "2023/2024 claim year" do
subject { described_class.new(claim_year: AcademicYear.new(2023), itt_year: AcademicYear.new(2022)).selectable_itt_years }

it { is_expected.to contain_exactly(AcademicYear.new(2018), AcademicYear.new(2019), AcademicYear.new(2020), AcademicYear.new(2021), AcademicYear.new(2022)) }
end

context "2024/2025 claim year" do
subject { described_class.new(claim_year: AcademicYear.new(2024), itt_year: AcademicYear.new(2023)).selectable_itt_years }

it { is_expected.to contain_exactly(AcademicYear.new(2019), AcademicYear.new(2020), AcademicYear.new(2021), AcademicYear.new(2022), AcademicYear.new(2023)) }
end
end

describe ".selectable_itt_years_for_view" do
context "2022/2023 claim year" do
subject { described_class.selectable_itt_years_for_claim_year(AcademicYear.new(2022)) }

it { is_expected.to eq([AcademicYear.new(2017), AcademicYear.new(2018), AcademicYear.new(2019), AcademicYear.new(2020), AcademicYear.new(2021)]) }
end

context "2023/2024 claim year" do
subject { described_class.selectable_itt_years_for_claim_year(AcademicYear.new(2023)) }

it { is_expected.to eq([AcademicYear.new(2018), AcademicYear.new(2019), AcademicYear.new(2020), AcademicYear.new(2021), AcademicYear.new(2022)]) }
end

context "2024/2025 claim year" do
subject { described_class.selectable_itt_years_for_claim_year(AcademicYear.new(2024)) }

it { is_expected.to eq([AcademicYear.new(2019), AcademicYear.new(2020), AcademicYear.new(2021), AcademicYear.new(2022), AcademicYear.new(2023)]) }
end
end

describe "#current_subject_symbols" do
subject { described_class.new(claim_year: claim_year, itt_year: itt_year).current_subject_symbols(policy) }

Expand Down
20 changes: 20 additions & 0 deletions spec/models/early_career_payments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,24 @@
end
end
end

describe ".selectable_itt_years_for_view" do
context "2022/2023 claim year" do
subject { described_class.selectable_itt_years_for_claim_year(AcademicYear.new(2022)) }

it { is_expected.to eq([AcademicYear.new(2017), AcademicYear.new(2018), AcademicYear.new(2019), AcademicYear.new(2020), AcademicYear.new(2021)]) }
end

context "2023/2024 claim year" do
subject { described_class.selectable_itt_years_for_claim_year(AcademicYear.new(2023)) }

it { is_expected.to eq([AcademicYear.new(2018), AcademicYear.new(2019), AcademicYear.new(2020), AcademicYear.new(2021), AcademicYear.new(2022)]) }
end

context "2024/2025 claim year" do
subject { described_class.selectable_itt_years_for_claim_year(AcademicYear.new(2024)) }

it { is_expected.to eq([AcademicYear.new(2019), AcademicYear.new(2020), AcademicYear.new(2021), AcademicYear.new(2022), AcademicYear.new(2023)]) }
end
end
end
4 changes: 2 additions & 2 deletions spec/models/journeys/additional_payments_for_teaching_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
end

shared_examples "true for years" do |start_years_range, policy_year|
JourneySubjectEligibilityChecker.selectable_itt_years_for_claim_year(policy_year).each do |itt_academic_year|
Journeys::AdditionalPaymentsForTeaching.selectable_itt_years_for_claim_year(policy_year).each do |itt_academic_year|
context "ITT year #{itt_academic_year}" do
let(:itt_academic_year) { itt_academic_year }

Expand All @@ -82,7 +82,7 @@
end

shared_examples "false for all years" do |policy_year|
JourneySubjectEligibilityChecker.selectable_itt_years_for_claim_year(policy_year).each do |itt_academic_year|
Journeys::AdditionalPaymentsForTeaching.selectable_itt_years_for_claim_year(policy_year).each do |itt_academic_year|
context "ITT year #{itt_academic_year}" do
let(:itt_academic_year) { itt_academic_year }

Expand Down
20 changes: 20 additions & 0 deletions spec/models/levelling_up_premium_payments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,24 @@
end
end
end

describe ".selectable_itt_years_for_view" do
context "2022/2023 claim year" do
subject { described_class.selectable_itt_years_for_claim_year(AcademicYear.new(2022)) }

it { is_expected.to eq([AcademicYear.new(2017), AcademicYear.new(2018), AcademicYear.new(2019), AcademicYear.new(2020), AcademicYear.new(2021)]) }
end

context "2023/2024 claim year" do
subject { described_class.selectable_itt_years_for_claim_year(AcademicYear.new(2023)) }

it { is_expected.to eq([AcademicYear.new(2018), AcademicYear.new(2019), AcademicYear.new(2020), AcademicYear.new(2021), AcademicYear.new(2022)]) }
end

context "2024/2025 claim year" do
subject { described_class.selectable_itt_years_for_claim_year(AcademicYear.new(2024)) }

it { is_expected.to eq([AcademicYear.new(2019), AcademicYear.new(2020), AcademicYear.new(2021), AcademicYear.new(2022), AcademicYear.new(2023)]) }
end
end
end
5 changes: 3 additions & 2 deletions spec/models/policies/early_career_payments/dqt_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2263,8 +2263,9 @@

describe "#itt_academic_year_for_claim" do
before do
allow(JourneySubjectEligibilityChecker).to receive(:new)
.and_return(double(selectable_itt_years_for_claim_year: eligible_years))
allow(Policies::EarlyCareerPayments).to(
receive(:selectable_itt_years_for_claim_year).and_return(eligible_years)
)
end

let(:record) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,9 @@

describe "#itt_academic_year_for_claim" do
before do
allow(JourneySubjectEligibilityChecker).to receive(:new)
.and_return(double(selectable_itt_years_for_claim_year: eligible_years))
allow(Policies::LevellingUpPremiumPayments).to(
receive(:selectable_itt_years_for_claim_year).and_return(eligible_years)
)
end

let(:record) do
Expand Down

0 comments on commit f46a866

Please sign in to comment.