diff --git a/app/controllers/claims_form_callbacks.rb b/app/controllers/claims_form_callbacks.rb index 3634ba3c16..356a54218c 100644 --- a/app/controllers/claims_form_callbacks.rb +++ b/app/controllers/claims_form_callbacks.rb @@ -64,6 +64,11 @@ def check_your_answers_after_form_save_success create_and_save_claim_form end + def employee_email_after_form_save_failure + session[:slugs].delete("employee-email") + render_template_for_current_slug + end + private def set_backlink_override_to_current_slug diff --git a/app/models/concerns/eligibility_checkable.rb b/app/models/concerns/eligibility_checkable.rb index 77cd0f2dda..b5decfc117 100644 --- a/app/models/concerns/eligibility_checkable.rb +++ b/app/models/concerns/eligibility_checkable.rb @@ -3,6 +3,7 @@ module EligibilityCheckable FIRST_COMBINED_ECP_AND_LUP_POLICY_YEAR = AcademicYear.new(2022) FINAL_COMBINED_ECP_AND_LUP_POLICY_YEAR = AcademicYear.new(2024) + FINAL_LUP_POLICY_YEAR = AcademicYear.new(2025) COMBINED_ECP_AND_LUP_POLICY_YEARS = FIRST_COMBINED_ECP_AND_LUP_POLICY_YEAR..FINAL_COMBINED_ECP_AND_LUP_POLICY_YEAR COMBINED_ECP_AND_LUP_POLICY_YEARS_BEFORE_FINAL_YEAR = FIRST_COMBINED_ECP_AND_LUP_POLICY_YEAR...FINAL_COMBINED_ECP_AND_LUP_POLICY_YEAR diff --git a/app/models/journeys/additional_payments_for_teaching.rb b/app/models/journeys/additional_payments_for_teaching.rb index 046939829f..92fa5619b8 100644 --- a/app/models/journeys/additional_payments_for_teaching.rb +++ b/app/models/journeys/additional_payments_for_teaching.rb @@ -34,8 +34,16 @@ module AdditionalPaymentsForTeaching } }.freeze - def set_a_reminder?(itt_academic_year:, policy_year: configuration.current_academic_year) - return false if policy_year >= EligibilityCheckable::FINAL_COMBINED_ECP_AND_LUP_POLICY_YEAR + def final_policy_year(policy) + { + Policies::EarlyCareerPayments => EligibilityCheckable::FINAL_COMBINED_ECP_AND_LUP_POLICY_YEAR, + Policies::LevellingUpPremiumPayments => EligibilityCheckable::FINAL_LUP_POLICY_YEAR + }[policy] + end + + def set_a_reminder?(itt_academic_year:, policy:) + policy_year = configuration.current_academic_year + return false if policy_year >= final_policy_year(policy) next_year = policy_year + 1 eligible_itt_years = JourneySubjectEligibilityChecker.selectable_itt_years_for_claim_year(next_year) diff --git a/app/views/additional_payments/submissions/show.html.erb b/app/views/additional_payments/submissions/show.html.erb index 4ba72df2b7..e816ab749f 100644 --- a/app/views/additional_payments/submissions/show.html.erb +++ b/app/views/additional_payments/submissions/show.html.erb @@ -24,7 +24,7 @@ <%= render partial: "submissions/confirmation" %> - <% if journey.set_a_reminder?(itt_academic_year: submitted_claim.eligibility.itt_academic_year) %> + <% if journey.set_a_reminder?(itt_academic_year: submitted_claim.eligibility.itt_academic_year, policy: submitted_claim.policy) %> <%= render partial: "submissions/reminder" %> <% end %> diff --git a/spec/features/early_years_payment/provider/authenticated/employee_email_spec.rb b/spec/features/early_years_payment/provider/authenticated/employee_email_spec.rb new file mode 100644 index 0000000000..e03b088d19 --- /dev/null +++ b/spec/features/early_years_payment/provider/authenticated/employee_email_spec.rb @@ -0,0 +1,75 @@ +require "rails_helper" + +RSpec.feature "Early years payment provider" do + let(:email_address) { "johndoe@example.com" } + let(:journey_session) { Journeys::EarlyYearsPayment::Provider::Authenticated::Session.last } + let(:mail) { ActionMailer::Base.deliveries.last } + let(:magic_link) { mail[:personalisation].unparsed_value[:magic_link] } + let!(:nursery) { create(:eligible_ey_provider, primary_key_contact_email_address: email_address) } + + scenario "preventing the user from bypassing employee email" do + when_early_years_payment_provider_authenticated_journey_configuration_exists + when_early_years_payment_provider_start_journey_completed + + visit magic_link + expect(journey_session.reload.answers.email_address).to eq email_address + expect(journey_session.reload.answers.email_verified).to be true + expect(page).to have_content("Declaration of Employee Consent") + expect(page.current_path).to eq "/early-years-payment-provider/consent" + check "I confirm that I have obtained consent from my employee and have provided them with the relevant privacy notice." + click_button "Continue" + + expect(page.current_path).to eq "/early-years-payment-provider/current-nursery" + choose nursery.nursery_name + click_button "Continue" + + expect(page.current_path).to eq "/early-years-payment-provider/paye-reference" + expect(page).to have_content("What is #{nursery.nursery_name}’s employer PAYE reference?") + fill_in "claim-paye-reference-field", with: "123/123456SE90" + click_button "Continue" + + expect(page.current_path).to eq "/early-years-payment-provider/claimant-name" + fill_in "First name", with: "Bobby" + fill_in "Last name", with: "Bobberson" + click_button "Continue" + + expect(page.current_path).to eq "/early-years-payment-provider/start-date" + date = Date.yesterday + fill_in("Day", with: date.day) + fill_in("Month", with: date.month) + fill_in("Year", with: date.year) + click_button "Continue" + + expect(page.current_path).to eq "/early-years-payment-provider/child-facing" + choose "Yes" + click_button "Continue" + + expect(page.current_path).to eq "/early-years-payment-provider/returner" + choose "Yes" + click_button "Continue" + + expect(page.current_path).to eq "/early-years-payment-provider/returner-worked-with-children" + choose "Yes" + click_button "Continue" + + expect(page.current_path).to eq "/early-years-payment-provider/returner-contract-type" + choose "casual or temporary" + click_button "Continue" + + expect(page.current_path).to eq "/early-years-payment-provider/employee-email" + click_button "Continue" + expect(page).to have_content("Error: Enter a valid email address") + + click_link "Back" + expect(page.current_path).to eq "/early-years-payment-provider/returner-contract-type" + choose "voluntary or unpaid" + click_button "Continue" + + expect(page.current_path).to eq "/early-years-payment-provider/employee-email" + fill_in "claim-practitioner-email-address-field", with: "practitioner@example.com" + click_button "Continue" + + expect(page.current_path).to eq "/early-years-payment-provider/check-your-answers" + expect(page).to have_content("Check your answers before submitting this claim") + end +end diff --git a/spec/models/journeys/additional_payments_for_teaching_spec.rb b/spec/models/journeys/additional_payments_for_teaching_spec.rb index a2e8276cd1..f9be210508 100644 --- a/spec/models/journeys/additional_payments_for_teaching_spec.rb +++ b/spec/models/journeys/additional_payments_for_teaching_spec.rb @@ -67,112 +67,64 @@ it { is_expected.to eq(Journeys::AdditionalPaymentsForTeaching::AnswersPresenter) } end - describe ".set_a_reminder?" do - subject { described_class.set_a_reminder?(itt_academic_year: itt_academic_year, policy_year: policy_year) } - let(:itt_academic_year) { AcademicYear.new(year) } - - context "Claim year: 22/23" do - let(:policy_year) { AcademicYear.new(2022) } - - # Eligible now - but falls out of 5 year window next year so don't set a reminder - context "ITT year: 17/18" do - let(:year) { 2017 } + 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| + context "ITT year #{itt_academic_year}" do + let(:itt_academic_year) { itt_academic_year } - specify { expect(subject).to be false } - end - - context "ITT year: 18/19" do - let(:year) { 2018 } - - specify { expect(subject).to be true } + if start_years_range.include?(itt_academic_year.start_year) + it { is_expected.to be true } + else + it { is_expected.to be false } + end end + end + end - context "ITT year: 19/20" do - let(:year) { 2019 } + shared_examples "false for all years" do |policy_year| + JourneySubjectEligibilityChecker.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 } - specify { expect(subject).to be true } + it { is_expected.to be false } end + end + end - context "ITT year: 20/21" do - let(:year) { 2020 } - - specify { expect(subject).to be true } - end + describe ".set_a_reminder?" do + subject { described_class.set_a_reminder?(itt_academic_year: itt_academic_year, policy: policy) } + let(:policy) { Policies::EarlyCareerPayments } + let!(:configuration) { create(:journey_configuration, :additional_payments, current_academic_year: policy_year) } - context "ITT year: 21/22" do - let(:year) { 2021 } + context "Claim year: 22/23" do + let(:policy_year) { AcademicYear.new(2022) } - specify { expect(subject).to be true } - end + # 2017 is eligible now - but falls out of the 5 year window next year + it_behaves_like "true for years", 2018..2021, AcademicYear.new(2022) end context "Claim year: 23/24" do let(:policy_year) { AcademicYear.new(2023) } - # Eligible now - but falls out of 5 year window next year so don't set a reminder - context "ITT year: 18/19" do - let(:year) { 2018 } - - specify { expect(subject).to be false } - end - - context "ITT year: 19/20" do - let(:year) { 2019 } - - specify { expect(subject).to be true } - end - - context "ITT year: 20/21" do - let(:year) { 2020 } - - specify { expect(subject).to be true } - end - - context "ITT year: 21/22" do - let(:year) { 2021 } - - specify { expect(subject).to be true } - end - - context "ITT year: 22/23" do - let(:year) { 2022 } - - specify { expect(subject).to be true } - end + # 2018 is eligible now - but falls out of the 5 year window next year + it_behaves_like "true for years", 2019..2022, AcademicYear.new(2023) end - # Last policy year - no reminders to set context "Claim year: 24/25" do let(:policy_year) { AcademicYear.new(2024) } - context "ITT year: 19/20" do - let(:year) { 2019 } - - specify { expect(subject).to be false } - end - - context "ITT year: 20/21" do - let(:year) { 2020 } - - specify { expect(subject).to be false } - end - - context "ITT year: 21/22" do - let(:year) { 2021 } - - specify { expect(subject).to be false } - end - - context "ITT year: 22/23" do - let(:year) { 2022 } + context "Last year of the policy - ECP policy" do + let(:policy) { Policies::EarlyCareerPayments } - specify { expect(subject).to be false } + # ECP will be removed after 2024/2025 academic year + it_behaves_like "false for all years", AcademicYear.new(2024) end - context "ITT year: 23/24" do - let(:year) { 2023 } + context "LUP policy" do + let(:policy) { Policies::LevellingUpPremiumPayments } - specify { expect(subject).to be false } + # 2019 is eligible now - but falls out of the 5 year window next year + it_behaves_like "true for years", 2020..2023, AcademicYear.new(2024) end end end