Skip to content

Commit

Permalink
[LUPEYALPHA-877] Send an email to the practitioner when the provider …
Browse files Browse the repository at this point in the history
…submits a claim (#3219)
  • Loading branch information
vacabor authored Sep 26, 2024
1 parent 44169b1 commit 3894160
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions app/mailers/claim_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions app/models/policies/early_years_payments/eligibility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def policy
def ineligible?
false
end

def eligible_ey_provider
EligibleEyProvider.find_by_urn(nursery_urn)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 18 additions & 0 deletions spec/mailers/claim_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) { "[email protected]" }
let(:practitioner_email_address) { "[email protected]" }
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

0 comments on commit 3894160

Please sign in to comment.