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 02d60c8c4e..9a3b67b035 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 @@ -18,7 +18,7 @@ def save reference_number:, start_email: email, reference_number_found: existing_claim.present?, - claim_already_submitted: existing_claim&.submitted?, + claim_already_submitted: existing_claim&.eligibility&.practitioner_claim_submitted?, nursery_name: existing_claim&.eligibility&.eligible_ey_provider&.nursery_name ) journey_session.save! diff --git a/app/models/policies/early_years_payments/eligibility.rb b/app/models/policies/early_years_payments/eligibility.rb index 4e576ba492..b8382d591c 100644 --- a/app/models/policies/early_years_payments/eligibility.rb +++ b/app/models/policies/early_years_payments/eligibility.rb @@ -16,6 +16,10 @@ def ineligible? def eligible_ey_provider EligibleEyProvider.find_by_urn(nursery_urn) end + + def practitioner_claim_submitted? + practitioner_claim_submitted_at.present? + end end end end diff --git a/config/analytics.yml b/config/analytics.yml index 6db12f45b8..0783c7d559 100644 --- a/config/analytics.yml +++ b/config/analytics.yml @@ -318,3 +318,4 @@ shared: - returning_within_6_months - created_at - updated_at + - practitioner_claim_submitted_at diff --git a/db/migrate/20241015093740_add_practitioner_claim_submitted_at_to_early_years_payment_eligibilities.rb b/db/migrate/20241015093740_add_practitioner_claim_submitted_at_to_early_years_payment_eligibilities.rb new file mode 100644 index 0000000000..9c1439b21d --- /dev/null +++ b/db/migrate/20241015093740_add_practitioner_claim_submitted_at_to_early_years_payment_eligibilities.rb @@ -0,0 +1,5 @@ +class AddPractitionerClaimSubmittedAtToEarlyYearsPaymentEligibilities < ActiveRecord::Migration[7.0] + def change + add_column :early_years_payment_eligibilities, :practitioner_claim_submitted_at, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 2aa35382cd..55d67f3a31 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_09_24_113642) do +ActiveRecord::Schema[7.0].define(version: 2024_10_15_093740) do # These are extensions that must be enabled in order to support this database enable_extension "citext" enable_extension "pg_trgm" @@ -197,6 +197,7 @@ t.date "start_date" t.boolean "child_facing_confirmation_given" t.boolean "returning_within_6_months" + t.datetime "practitioner_claim_submitted_at" end create_table "eligible_ey_providers", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| diff --git a/spec/factories/early_years_payments/eligibilities.rb b/spec/factories/early_years_payments/eligibilities.rb index d21ea169ff..f4ff4eed0a 100644 --- a/spec/factories/early_years_payments/eligibilities.rb +++ b/spec/factories/early_years_payments/eligibilities.rb @@ -1,4 +1,7 @@ FactoryBot.define do factory :early_years_payments_eligibility, class: "Policies::EarlyYearsPayments::Eligibility" do + trait :practitioner_claim_submitted do + practitioner_claim_submitted_at { Time.zone.now } + end 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 99af7c0ae9..06e6d8e277 100644 --- a/spec/features/early_years_payment/practitioner/find_reference_spec.rb +++ b/spec/features/early_years_payment/practitioner/find_reference_spec.rb @@ -6,7 +6,8 @@ :claim, policy: Policies::EarlyYearsPayments, reference: "foo", - practitioner_email_address: "user@example.com" + practitioner_email_address: "user@example.com", + submitted_at: Time.zone.now ) end @@ -67,7 +68,7 @@ :claim, :submitted, policy: Policies::EarlyYearsPayments, - eligibility: build(:early_years_payments_eligibility, nursery_urn: eligible_ey_provider.urn), + eligibility: build(:early_years_payments_eligibility, :practitioner_claim_submitted, nursery_urn: eligible_ey_provider.urn), reference: "foo", practitioner_email_address: "user@example.com" ) diff --git a/spec/features/early_years_payment/practitioner/happy_path_spec.rb b/spec/features/early_years_payment/practitioner/happy_path_spec.rb index c5bafbcc1c..1956c350fb 100644 --- a/spec/features/early_years_payment/practitioner/happy_path_spec.rb +++ b/spec/features/early_years_payment/practitioner/happy_path_spec.rb @@ -1,19 +1,18 @@ require "rails_helper" RSpec.feature "Early years payment practitioner" do - let(:claim) do - create( - :claim, - policy: Policies::EarlyYearsPayments, - reference: "foo", - practitioner_email_address: "user@example.com" - ) - end + 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) } + let(:claim) { Claim.last } scenario "Happy path" do + when_early_years_payment_provider_authenticated_journey_submitted when_early_years_payment_practitioner_journey_configuration_exists - visit "/early-years-payment-practitioner/find-reference?skip_landing_page=true&email=user@example.com" + visit "/early-years-payment-practitioner/find-reference?skip_landing_page=true&email=practitioner@example.com" expect(page).to have_content "Enter your claim reference" fill_in "Claim reference number", with: claim.reference click_button "Submit" 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 dbe109f70b..e8eab13f00 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 @@ -73,7 +73,7 @@ }.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 + context "when the claim has only been submitted by the provider, not the practitioner" do let(:claim) do create( :claim, @@ -84,7 +84,25 @@ ) end - it "updates claim_already_submitted in session" do + it "sets claim_already_submitted to false in session" do + expect { + subject.save + }.to change { journey_session.reload.answers.claim_already_submitted }.from(nil).to(false) + end + end + + context "when the claim has been submitted by the practitioner already" do + let(:claim) do + create( + :claim, + :submitted, + policy: Policies::EarlyYearsPayments, + eligibility: build(:early_years_payments_eligibility, :practitioner_claim_submitted, nursery_urn: eligible_ey_provider.urn), + reference: "foo" + ) + end + + it "sets claim_already_submitted in session" do expect { subject.save }.to change { journey_session.reload.answers.claim_already_submitted }.from(nil).to(true) diff --git a/spec/support/steps/eligible_ey_journey_authenticated.rb b/spec/support/steps/eligible_ey_journey_authenticated.rb index e0ff028afc..9a021d3785 100644 --- a/spec/support/steps/eligible_ey_journey_authenticated.rb +++ b/spec/support/steps/eligible_ey_journey_authenticated.rb @@ -28,3 +28,12 @@ def when_early_years_payment_provider_authenticated_journey_ready_to_submit fill_in "claim-practitioner-email-address-field", with: "practitioner@example.com" click_button "Continue" end + +def when_early_years_payment_provider_authenticated_journey_submitted + when_early_years_payment_provider_authenticated_journey_configuration_exists + when_early_years_payment_provider_start_journey_completed + when_early_years_payment_provider_authenticated_journey_ready_to_submit + + fill_in "claim-provider-contact-name-field", with: "John Doe" + click_button "Accept and send" +end