diff --git a/app/forms/journeys/additional_payments_for_teaching/eligible_itt_subject_form.rb b/app/forms/journeys/additional_payments_for_teaching/eligible_itt_subject_form.rb index 199a069f0a..e18f388ae4 100644 --- a/app/forms/journeys/additional_payments_for_teaching/eligible_itt_subject_form.rb +++ b/app/forms/journeys/additional_payments_for_teaching/eligible_itt_subject_form.rb @@ -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 diff --git a/app/models/journeys/additional_payments_for_teaching.rb b/app/models/journeys/additional_payments_for_teaching.rb index 3b5ad6b6a3..9fb5fc4b2f 100644 --- a/app/models/journeys/additional_payments_for_teaching.rb +++ b/app/models/journeys/additional_payments_for_teaching.rb @@ -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) diff --git a/spec/forms/journeys/additional_payments_for_teaching/eligible_itt_subject_form_spec.rb b/spec/forms/journeys/additional_payments_for_teaching/eligible_itt_subject_form_spec.rb index b6792241c6..9c9d74aa2c 100644 --- a/spec/forms/journeys/additional_payments_for_teaching/eligible_itt_subject_form_spec.rb +++ b/spec/forms/journeys/additional_payments_for_teaching/eligible_itt_subject_form_spec.rb @@ -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 @@ -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 @@ -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 } diff --git a/spec/helpers/early_career_payments_helper_spec.rb b/spec/helpers/early_career_payments_helper_spec.rb index 7a02816854..9d468ee527 100644 --- a/spec/helpers/early_career_payments_helper_spec.rb +++ b/spec/helpers/early_career_payments_helper_spec.rb @@ -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 diff --git a/spec/models/journeys/additional_payments_for_teaching_spec.rb b/spec/models/journeys/additional_payments_for_teaching_spec.rb index 3d111ccb4b..8a46dd3538 100644 --- a/spec/models/journeys/additional_payments_for_teaching_spec.rb +++ b/spec/models/journeys/additional_payments_for_teaching_spec.rb @@ -128,202 +128,4 @@ end end end - - describe ".selectable_subject_symbols" do - subject { described_class.selectable_subject_symbols(journey_session) } - - context "when academic year is 2022" do - before { create(:journey_configuration, :additional_payments, current_academic_year: claim_year) } - - context "2022 claim year" do - let(:claim_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 end