Skip to content

Commit

Permalink
Remove selectable_subject_symbols
Browse files Browse the repository at this point in the history
This method is only used in the eligible_itt_subject_form so we can just
inline it there and update the tests accordingly.
  • Loading branch information
rjlynch committed Dec 11, 2024
1 parent 7da4806 commit c63123d
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 223 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,23 @@ def chemistry_or_physics_available?
end

def subject_symbols
@subject_symbols ||=
AdditionalPaymentsForTeaching.selectable_subject_symbols(journey_session)
return [] if answers.itt_academic_year&.none?

if answers.nqt_in_academic_year_after_itt
EligibilityChecker.new(journey_session: journey_session)
.potentially_still_eligible.map do |policy|
policy.current_and_future_subject_symbols(
claim_year: answers.policy_year,
itt_year: answers.itt_academic_year
)
end.flatten.uniq
elsif answers.policy_year.in?(Policies::LevellingUpPremiumPayments::POLICY_RANGE)
# they get the standard, unchanging LUP subject set because they won't have qualified in time for ECP by 2022/2023
# and they won't have given an ITT year
Policies::LevellingUpPremiumPayments.fixed_subject_symbols
else
[]
end
end

def save
Expand Down
20 changes: 0 additions & 20 deletions app/models/journeys/additional_payments_for_teaching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,6 @@ def requires_student_loan_details?
true
end

def selectable_subject_symbols(journey_session)
return [] if journey_session.answers.itt_academic_year&.none?

if journey_session.answers.nqt_in_academic_year_after_itt
EligibilityChecker.new(journey_session: journey_session)
.potentially_still_eligible.map do |policy|
policy.current_and_future_subject_symbols(
claim_year: journey_session.answers.policy_year,
itt_year: journey_session.answers.itt_academic_year
)
end.flatten.uniq
elsif journey_session.answers.policy_year.in?(Policies::LevellingUpPremiumPayments::POLICY_RANGE)
# they get the standard, unchanging LUP subject set because they won't have qualified in time for ECP by 2022/2023
# and they won't have given an ITT year
Policies::LevellingUpPremiumPayments.fixed_subject_symbols
else
[]
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
create(
:journey_configuration,
:additional_payments,
current_academic_year: AcademicYear.new(2023)
current_academic_year: current_academic_year
)
end

let(:current_academic_year) { AcademicYear.new(2023) }

let(:journey) { Journeys::AdditionalPaymentsForTeaching }

let(:answers) do
Expand Down Expand Up @@ -53,7 +55,7 @@

context "when single subject available" do
before do
allow(Journeys::AdditionalPaymentsForTeaching).to receive(:selectable_subject_symbols).and_return([:mathematics])
allow(Policies::LevellingUpPremiumPayments).to receive(:fixed_subject_symbols).and_return([:mathematics])
end

let(:answers) do
Expand All @@ -76,6 +78,204 @@
end
end

describe ".subject_symbols" do
subject { form.subject_symbols }

let(:params) { ActionController::Parameters.new }

context "when academic year is 2022" do
context "2022 claim year" do
let(:current_academic_year) { AcademicYear.new(2022) }

context "None of the above ITT year" do
let(:itt_year) { AcademicYear.new }

let(:journey_session) do
create(
:additional_payments_session,
answers: attributes_for(
:additional_payments_answers,
itt_academic_year: itt_year
)
)
end

it { is_expected.to be_empty }
end

context "2017 ITT year" do
let(:itt_year) { AcademicYear.new(2017) }

context "ineligible LUP" do
let(:journey_session) do
create(
:additional_payments_session,
answers: attributes_for(
:additional_payments_answers,
:ecp_eligible,
itt_academic_year: itt_year
)
)
end

it { is_expected.to be_empty }
end

context "eligible LUP" do
let(:journey_session) do
create(
:additional_payments_session,
answers: attributes_for(
:additional_payments_answers,
:ecp_and_lup_eligible,
itt_academic_year: itt_year
)
)
end

it { is_expected.to contain_exactly(:chemistry, :computing, :mathematics, :physics) }
end
end

context "2018 ITT year" do
let(:itt_year) { AcademicYear.new(2018) }

context "ineligible LUP" do
let(:journey_session) do
create(
:additional_payments_session,
answers: attributes_for(
:additional_payments_answers,
:ecp_eligible,
itt_academic_year: itt_year
)
)
end

it { is_expected.to contain_exactly(:mathematics) }
end

context "eligible LUP" do
let(:journey_session) do
create(
:additional_payments_session,
answers: attributes_for(
:additional_payments_answers,
:ecp_and_lup_eligible,
itt_academic_year: itt_year
)
)
end

it { is_expected.to contain_exactly(:chemistry, :computing, :mathematics, :physics) }
end
end

context "2019 ITT year" do
let(:itt_year) { AcademicYear.new(2019) }

context "ineligible LUP" do
let(:journey_session) do
create(
:additional_payments_session,
answers: attributes_for(
:additional_payments_answers,
:ecp_eligible,
itt_academic_year: itt_year
)
)
end

it { is_expected.to contain_exactly(:mathematics) }
end

context "eligible LUP" do
let(:journey_session) do
create(
:additional_payments_session,
answers: attributes_for(
:additional_payments_answers,
:ecp_and_lup_eligible,
itt_academic_year: itt_year
)
)
end

it { is_expected.to contain_exactly(:chemistry, :computing, :mathematics, :physics) }
end
end

context "2020 ITT year" do
let(:itt_year) { AcademicYear.new(2020) }

context "ineligible LUP" do
let(:journey_session) do
create(
:additional_payments_session,
answers: attributes_for(
:additional_payments_answers,
:ecp_eligible,
itt_academic_year: itt_year
)
)
end

it { is_expected.to contain_exactly(:chemistry, :foreign_languages, :mathematics, :physics) }
end

context "eligible LUP" do
let(:journey_session) do
create(
:additional_payments_session,
answers: attributes_for(
:additional_payments_answers,
:ecp_and_lup_eligible,
itt_academic_year: itt_year
)
)
end

it { is_expected.to contain_exactly(:chemistry, :computing, :foreign_languages, :mathematics, :physics) }
end
end

context "2021 ITT year" do
let(:itt_year) { AcademicYear.new(2021) }

context "ineligible LUP" do
let(:journey_session) do
create(
:additional_payments_session,
answers: attributes_for(
:additional_payments_answers,
:ecp_eligible,
itt_academic_year: itt_year
)
)
end

it { is_expected.to be_empty }
end

context "eligible LUP" do
let(:journey_session) do
create(
:additional_payments_session,
answers: attributes_for(
:additional_payments_answers,
:ecp_and_lup_eligible,
itt_academic_year: itt_year
)
)
end

it { is_expected.to contain_exactly(:chemistry, :computing, :mathematics, :physics) }
end
end
end
end
end

describe "#available_subjects" do
subject(:available_subjects) { form.available_subjects }

Expand Down
6 changes: 5 additions & 1 deletion spec/helpers/early_career_payments_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@
subject do
helper.eligible_itt_subject_translation(
journey_session.answers,
Journeys::AdditionalPaymentsForTeaching.selectable_subject_symbols(journey_session)
Journeys::AdditionalPaymentsForTeaching::EligibleIttSubjectForm.new(
journey: Journeys::AdditionalPaymentsForTeaching,
journey_session: journey_session,
params: ActionController::Parameters.new
).subject_symbols
)
end

Expand Down
Loading

0 comments on commit c63123d

Please sign in to comment.