From 1c56c6517f9bee8f2e17e827a315c0a1c23d2017 Mon Sep 17 00:00:00 2001 From: vacabor <166112501+vacabor@users.noreply.github.com> Date: Mon, 23 Sep 2024 19:38:50 +0100 Subject: [PATCH] Send an email to the practitioner when the provider submits a claim for them --- .../authenticated/claim_submission_form.rb | 8 ++++++++ app/mailers/application_mailer.rb | 3 ++- app/mailers/claim_mailer.rb | 20 +++++++++++++++++++ .../early_years_payments/eligibility.rb | 4 ++++ spec/mailers/claim_mailer_spec.rb | 18 +++++++++++++++++ 5 files changed, 52 insertions(+), 1 deletion(-) 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 7d432cc3f9..868d902cda 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -47,6 +47,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 7f87ff04e1..edc0f8c402 100644 --- a/app/mailers/claim_mailer.rb +++ b/app/mailers/claim_mailer.rb @@ -82,6 +82,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/mailers/claim_mailer_spec.rb b/spec/mailers/claim_mailer_spec.rb index e5a7064d3e..989b857505 100644 --- a/spec/mailers/claim_mailer_spec.rb +++ b/spec/mailers/claim_mailer_spec.rb @@ -359,4 +359,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