Skip to content

Commit

Permalink
Merge pull request #3385 from DFE-Digital/ey-provider-submitted-mail
Browse files Browse the repository at this point in the history
[CAPT-1911][CAPT-1968] EY submission emails
  • Loading branch information
asmega authored Nov 11, 2024
2 parents 40c836b + 5c40bc4 commit f62de1f
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/forms/claim_submission_base_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def save
claim.save!
end

ClaimMailer.submitted(claim).deliver_later if claim.submitted_at
claim.policy.mailer.submitted(claim).deliver_later
ClaimVerifierJob.perform_later(claim)

true
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +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: "f97480c8-7869-4af6-b50c-413929b8cc88".freeze,
CLAIM_PRACTITIONER_NOTIFY_TEMPLATE_ID: "ef21f1d7-8a5c-4261-80b9-e1b78f844575".freeze,
CLAIM_REJECTED_NOTIFY_TEMPLATE_ID: "90e32881-1d11-4c6b-b33a-e7ae698de2f2".freeze
}
Expand Down
1 change: 1 addition & 0 deletions app/mailers/claim_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def early_years_payment_practitioner_email(claim)
template_mail(
template_id,
to: claim.practitioner_email_address,
reply_to_id: claim.policy.notify_reply_to_id,
personalisation: personalisation
)
end
Expand Down
44 changes: 44 additions & 0 deletions app/mailers/early_years_payments_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class EarlyYearsPaymentsMailer < ApplicationMailer
def submitted(claim)
if claim.submitted_at.present?
submitted_by_practitioner_and_send_to_practitioner(claim)
else
submitted_by_provider_and_send_to_provider(claim)
end
end

private

def submitted_by_provider_and_send_to_provider(claim)
personalisation = {
nursery_name: claim.eligibility.eligible_ey_provider.nursery_name,
practitioner_first_name: claim.eligibility.practitioner_first_name,
practitioner_last_name: claim.eligibility.practitioner_surname,
ref_number: claim.reference
}

template_mail(
"149c5999-12fb-4b99-aff5-23a7c3302783",
to: claim.eligibility.eligible_ey_provider.primary_key_contact_email_address,
subject: nil,
reply_to_id: claim.policy.notify_reply_to_id,
personalisation:
)
end

def submitted_by_practitioner_and_send_to_practitioner(claim)
personalisation = {
first_name: claim.first_name,
nursery_name: claim.eligibility.eligible_ey_provider.nursery_name,
ref_number: claim.reference
}

template_mail(
"f97480c8-7869-4af6-b50c-413929b8cc88",
to: claim.email_address,
subject: nil,
reply_to_id: claim.policy.notify_reply_to_id,
personalisation:
)
end
end
4 changes: 4 additions & 0 deletions app/models/base_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,8 @@ def decision_deadline_date(claim)
def award_amount_column
"award_amount"
end

def mailer
ClaimMailer
end
end
7 changes: 5 additions & 2 deletions app/models/policies/early_years_payments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ module EarlyYearsPayments
:other
]

# TODO: This is needed once the reply-to email address has been added to Gov Notify
def notify_reply_to_id
nil
"581f1cd6-3351-4fd6-b408-e53ce8d86a28"
end

def award_amount
Expand All @@ -82,5 +81,9 @@ def approvable?(claim)
def decision_deadline_date(claim)
claim.eligibility.start_date + RETENTION_PERIOD
end

def mailer
EarlyYearsPaymentsMailer
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@
expect(page.current_path).to eq "/early-years-payment-provider/check-your-answers"
expect(page).to have_content("Check your answers before submitting this claim")
fill_in "claim-provider-contact-name-field", with: "John Doe"
click_button "Accept and send"

expect do
perform_enqueued_jobs { click_on "Accept and send" }
end.to change { Claim.count }.by(1)
.and change { Policies::EarlyYearsPayments::Eligibility.count }.by(1)
.and change { ActionMailer::Base.deliveries.count }.by(2)

expect(page.current_path).to eq claim_confirmation_path(Journeys::EarlyYearsPayment::Provider::Authenticated::ROUTING_NAME)

Expand Down

0 comments on commit f62de1f

Please sign in to comment.