diff --git a/app/forms/journeys/early_years_payment/provider/authenticated/claim_submission_form.rb b/app/forms/journeys/early_years_payment/provider/authenticated/claim_submission_form.rb index 07ea12ec2a..e75cad2649 100644 --- a/app/forms/journeys/early_years_payment/provider/authenticated/claim_submission_form.rb +++ b/app/forms/journeys/early_years_payment/provider/authenticated/claim_submission_form.rb @@ -3,6 +3,14 @@ module EarlyYearsPayment module Provider module Authenticated class ClaimSubmissionForm < ::ClaimSubmissionBaseForm + def save + super + + ClaimMailer.early_years_payment_practitioner_email(claim).deliver_later + + true + end + private def main_eligibility diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index a4cfa32cce..9b67e58402 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -48,6 +48,7 @@ class ApplicationMailer < Mail::Notify::Mailer EARLY_YEARS_PAYMENTS = { CLAIM_PROVIDER_EMAIL_TEMPLATE_ID: "e0b78a08-601b-40ba-a97f-61fb00a7c951".freeze, - CLAIM_RECEIVED_NOTIFY_TEMPLATE_ID: "149c5999-12fb-4b99-aff5-23a7c3302783".freeze + CLAIM_RECEIVED_NOTIFY_TEMPLATE_ID: "149c5999-12fb-4b99-aff5-23a7c3302783".freeze, + CLAIM_PRACTITIONER_NOTIFY_TEMPLATE_ID: "ef21f1d7-8a5c-4261-80b9-e1b78f844575".freeze } end diff --git a/app/mailers/claim_mailer.rb b/app/mailers/claim_mailer.rb index dc234f8e1c..0be387b0a0 100644 --- a/app/mailers/claim_mailer.rb +++ b/app/mailers/claim_mailer.rb @@ -83,6 +83,26 @@ def early_years_payment_provider_email(claim, one_time_password, email) send_mail(template_ids(claim)[:CLAIM_PROVIDER_EMAIL_TEMPLATE_ID], personalisation) end + def early_years_payment_practitioner_email(claim) + policy_check!(claim, Policies::EarlyYearsPayments) + + personalisation = { + full_name: claim.full_name, + setting_name: claim.eligibility.eligible_ey_provider.nursery_name, + ref_number: claim.reference, + # TODO: Reference new route for practitioner journey + complete_claim_url: "https://gov.uk/claim-an-early-years-financial-incentive-payment?claim=#{claim.reference}&email=#{CGI.escape claim.practitioner_email_address}" + } + + template_id = template_ids(claim)[:CLAIM_PRACTITIONER_NOTIFY_TEMPLATE_ID] + + template_mail( + template_id, + to: claim.practitioner_email_address, + personalisation: personalisation + ) + end + def further_education_payment_provider_verification_email(claim) policy_check!(claim, Policies::FurtherEducationPayments) diff --git a/app/models/policies/early_years_payments/eligibility.rb b/app/models/policies/early_years_payments/eligibility.rb index 349fda1682..4e576ba492 100644 --- a/app/models/policies/early_years_payments/eligibility.rb +++ b/app/models/policies/early_years_payments/eligibility.rb @@ -12,6 +12,10 @@ def policy def ineligible? false end + + def eligible_ey_provider + EligibleEyProvider.find_by_urn(nursery_urn) + end end end end diff --git a/spec/forms/journeys/early_years_payment/provider/authenticated/claim_submission_form_spec.rb b/spec/forms/journeys/early_years_payment/provider/authenticated/claim_submission_form_spec.rb index 22426cd311..3be4d88636 100644 --- a/spec/forms/journeys/early_years_payment/provider/authenticated/claim_submission_form_spec.rb +++ b/spec/forms/journeys/early_years_payment/provider/authenticated/claim_submission_form_spec.rb @@ -38,5 +38,21 @@ expect(eligibility.returning_within_6_months).to eq answers.returning_within_6_months expect(eligibility.start_date).to eq answers.start_date end + + it "sends a notify email to the practitioner" do + allow(ClaimVerifierJob).to receive(:perform_later) + + perform_enqueued_jobs { subject } + + expect(claim.practitioner_email_address).to( + have_received_email( + "ef21f1d7-8a5c-4261-80b9-e1b78f844575", + full_name: claim.full_name, + setting_name: claim.eligibility.eligible_ey_provider.nursery_name, + ref_number: claim.reference, + complete_claim_url: "https://gov.uk/claim-an-early-years-financial-incentive-payment?claim=#{claim.reference}&email=#{CGI.escape claim.practitioner_email_address}" + ) + ) + end end end diff --git a/spec/mailers/claim_mailer_spec.rb b/spec/mailers/claim_mailer_spec.rb index 56f577f893..29ace77d76 100644 --- a/spec/mailers/claim_mailer_spec.rb +++ b/spec/mailers/claim_mailer_spec.rb @@ -387,4 +387,22 @@ class SomePolicy; end expect(mail.body).to be_empty end end + + describe "#early_years_payment_practitioner_email" do + let(:mail) { ClaimMailer.early_years_payment_practitioner_email(claim) } + let(:email_address) { "test@example.com" } + let(:practitioner_email_address) { "practitioner@example.com" } + let(:claim) { build(:claim, reference: "TEST123", first_name: "Test", surname: "Practitioner", policy:, email_address:, practitioner_email_address:) } + let(:policy) { Policies::EarlyYearsPayments } + let(:nursery_name) { "Test Nursery" } + let(:eligible_ey_provider) { create(:eligible_ey_provider, nursery_name:) } + + before { create(:journey_configuration, :early_years_payment_provider_start) } + before { claim.eligibility.update!(nursery_urn: eligible_ey_provider.urn) } + + it "has personalisation keys for: full_name, setting_name, ref_number, complete_claim_url" do + expect(mail[:personalisation].decoded).to eq("{:full_name=>\"Test Practitioner\", :setting_name=>\"Test Nursery\", :ref_number=>\"TEST123\", :complete_claim_url=>\"https://gov.uk/claim-an-early-years-financial-incentive-payment?claim=TEST123&email=practitioner%40example.com\"}") + expect(mail.body).to be_empty + end + end end