diff --git a/app/forms/journeys/early_years_payment/practitioner/find_reference_form.rb b/app/forms/journeys/early_years_payment/practitioner/find_reference_form.rb index 89f7055c1f..02d60c8c4e 100644 --- a/app/forms/journeys/early_years_payment/practitioner/find_reference_form.rb +++ b/app/forms/journeys/early_years_payment/practitioner/find_reference_form.rb @@ -10,23 +10,19 @@ class FindReferenceForm < Form def save return false if invalid? + existing_claim = Claim + .by_policy(Policies::EarlyYearsPayments) + .find_by(reference: reference_number, practitioner_email_address: email) + journey_session.answers.assign_attributes( reference_number:, start_email: email, - reference_number_found: claim_exists? + reference_number_found: existing_claim.present?, + claim_already_submitted: existing_claim&.submitted?, + nursery_name: existing_claim&.eligibility&.eligible_ey_provider&.nursery_name ) journey_session.save! end - - private - - def claim_exists? - Claim - .by_policy(Policies::EarlyYearsPayments) - .where(reference: reference_number) - .where(practitioner_email_address: email) - .exists? - end end end end diff --git a/app/models/journeys/early_years_payment/practitioner/session_answers.rb b/app/models/journeys/early_years_payment/practitioner/session_answers.rb index 2415e58378..45963da9de 100644 --- a/app/models/journeys/early_years_payment/practitioner/session_answers.rb +++ b/app/models/journeys/early_years_payment/practitioner/session_answers.rb @@ -4,6 +4,8 @@ module Practitioner class SessionAnswers < Journeys::SessionAnswers attribute :reference_number, :string attribute :reference_number_found, :boolean, default: nil + attribute :claim_already_submitted, :boolean, default: nil + attribute :nursery_name attribute :start_email, :string def policy diff --git a/app/models/policies/early_years_payments/policy_eligibility_checker.rb b/app/models/policies/early_years_payments/policy_eligibility_checker.rb index 67f5908415..859a932a8f 100644 --- a/app/models/policies/early_years_payments/policy_eligibility_checker.rb +++ b/app/models/policies/early_years_payments/policy_eligibility_checker.rb @@ -48,6 +48,8 @@ def practitioner_ineligibility_reason if answers.reference_number_found == false :reference_number_not_found + elsif answers.claim_already_submitted == true + :claim_already_submitted end end diff --git a/app/views/early_years_payment/practitioner/claims/_ineligibility_claim_already_submitted.html.erb b/app/views/early_years_payment/practitioner/claims/_ineligibility_claim_already_submitted.html.erb new file mode 100644 index 0000000000..65096ee4ad --- /dev/null +++ b/app/views/early_years_payment/practitioner/claims/_ineligibility_claim_already_submitted.html.erb @@ -0,0 +1,28 @@ +<% content_for(:page_title, page_title("You've already submitted your claim", journey: current_journey_routing_name)) %> +<% @backlink_path = claim_path(current_journey_routing_name, "find-reference", request.query_parameters) %> + +
+
+

+ You've already submitted your claim +

+ +

+ We're reviewing your application and we'll let you know by email if it's accepted or rejected. +

+ +

+ After 6 months in your role, we'll check that you’re still working at <%= answers.nursery_name %>. If you are: +

+ + + +

+ If you have questions or need support with this claim, email + <%= govuk_link_to t("early_years_payment_practitioner.feedback_email"), "mailto:#{t("early_years_payment_practitioner.feedback_email")}", no_visited_state: true %> +

+
+
diff --git a/spec/factories/journeys/early_years_payment/provider/authenticated/early_years_practitioner_answers.rb b/spec/factories/journeys/early_years_payment/provider/authenticated/early_years_practitioner_answers.rb new file mode 100644 index 0000000000..8bdf78a187 --- /dev/null +++ b/spec/factories/journeys/early_years_payment/provider/authenticated/early_years_practitioner_answers.rb @@ -0,0 +1,4 @@ +FactoryBot.define do + factory :early_years_practitioner_answers, class: "Journeys::EarlyYearsPayment::Practitioner::SessionAnswers" do + end +end diff --git a/spec/features/early_years_payment/practitioner/find_reference_spec.rb b/spec/features/early_years_payment/practitioner/find_reference_spec.rb index fd3c9be9dd..99af7c0ae9 100644 --- a/spec/features/early_years_payment/practitioner/find_reference_spec.rb +++ b/spec/features/early_years_payment/practitioner/find_reference_spec.rb @@ -58,4 +58,34 @@ expect(page).to have_content "Enter your claim reference" end + + context "when the claim is already submitted" do + let(:eligible_ey_provider) { create(:eligible_ey_provider, nursery_name: "Test Nursery") } + + let(:claim) do + create( + :claim, + :submitted, + policy: Policies::EarlyYearsPayments, + eligibility: build(:early_years_payments_eligibility, nursery_urn: eligible_ey_provider.urn), + reference: "foo", + practitioner_email_address: "user@example.com" + ) + end + + scenario "should show ineligibility page when a submitted claim reference is given" do + when_early_years_payment_practitioner_journey_configuration_exists + + visit "/early-years-payment-practitioner/find-reference?skip_landing_page=true&email=user@example.com" + expect(page).to have_content "Enter your claim reference" + fill_in "Claim reference number", with: claim.reference + click_button "Submit" + + expect(page).to have_content "You've already submitted your claim" + expect(page).to have_content "After 6 months in your role, we'll check that you’re still working at Test Nursery." + + click_link "Back" + expect(page).to have_content "Enter your claim reference" + end + end end diff --git a/spec/forms/journeys/early_years_payment/practitioner/find_reference_form_spec.rb b/spec/forms/journeys/early_years_payment/practitioner/find_reference_form_spec.rb index b78fc4e50c..dbe109f70b 100644 --- a/spec/forms/journeys/early_years_payment/practitioner/find_reference_form_spec.rb +++ b/spec/forms/journeys/early_years_payment/practitioner/find_reference_form_spec.rb @@ -9,6 +9,8 @@ let(:reference_number) { nil } let(:email) { nil } + let(:eligible_ey_provider) { create(:eligible_ey_provider) } + let(:params) do ActionController::Parameters.new(claim: {reference_number:, email:}) end @@ -48,6 +50,7 @@ create( :claim, policy: Policies::EarlyYearsPayments, + eligibility: build(:early_years_payments_eligibility, nursery_urn: eligible_ey_provider.urn), reference: "foo" ) end @@ -64,6 +67,30 @@ }.to change { journey_session.reload.answers.reference_number_found }.from(nil).to(true) end + it "updates nursery_name in session" do + expect { + subject.save + }.to change { journey_session.reload.answers.nursery_name }.from(nil).to(eligible_ey_provider.nursery_name) + end + + context "when the claim is already submitted" do + let(:claim) do + create( + :claim, + :submitted, + policy: Policies::EarlyYearsPayments, + eligibility: build(:early_years_payments_eligibility, nursery_urn: eligible_ey_provider.urn), + reference: "foo" + ) + end + + it "updates claim_already_submitted in session" do + expect { + subject.save + }.to change { journey_session.reload.answers.claim_already_submitted }.from(nil).to(true) + end + end + context "when reference is a random string" do let(:reference_number) { "foo" } diff --git a/spec/models/policies/early_years_payments/policy_eligibility_checker_spec.rb b/spec/models/policies/early_years_payments/policy_eligibility_checker_spec.rb index 23fe365f52..1c8d494816 100644 --- a/spec/models/policies/early_years_payments/policy_eligibility_checker_spec.rb +++ b/spec/models/policies/early_years_payments/policy_eligibility_checker_spec.rb @@ -84,5 +84,35 @@ expect(subject.ineligibility_reason).to eql(:nursery_is_not_listed) end end + + context "when ineligible as :reference_number_not_found" do + let(:answers) do + build( + :early_years_practitioner_answers, + reference_number_found: false + ) + end + + it "is ineligble as :reference_number_not_found" do + expect(subject).to be_ineligible + expect(subject.status).to eql(:ineligible) + expect(subject.ineligibility_reason).to eql(:reference_number_not_found) + end + end + + context "when ineligible as :claim_already_submitted" do + let(:answers) do + build( + :early_years_practitioner_answers, + claim_already_submitted: true + ) + end + + it "is ineligble as :claim_already_submitted" do + expect(subject).to be_ineligible + expect(subject.status).to eql(:ineligible) + expect(subject.ineligibility_reason).to eql(:claim_already_submitted) + end + end end end