Skip to content

Commit

Permalink
Provider confirmation email
Browse files Browse the repository at this point in the history
When the provider has verified the claim we want to email their
organisation with a confirmation email, letting them know a claim has
been verified and who did it.

Also fixes the `have_received_email_matcher` to show the template id if
a match cant be found.
  • Loading branch information
rjlynch committed Sep 5, 2024
1 parent f692d0c commit ddcb85a
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ def save

claim.save!

ClaimMailer
.further_education_payment_provider_confirmation_email(claim)
.deliver_later

ClaimVerifierJob.perform_later(claim)

true
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 @@ -41,7 +41,8 @@ class ApplicationMailer < Mail::Notify::Mailer
CLAIM_UPDATE_AFTER_THREE_WEEKS_NOTIFY_TEMPLATE_ID: "95c11ee0-c9a9-4c6e-a040-54b1e1907b2c".freeze,
CLAIM_REJECTED_NOTIFY_TEMPLATE_ID: "a1bb5f64-585f-4b03-b9db-0b20ad801b34".freeze,

CLAIM_PROVIDER_VERIFICATION_EMAIL_TEMPLATE_ID: "9a25fe46-2ee4-4a5c-8d47-0f04f058a87d".freeze
CLAIM_PROVIDER_VERIFICATION_EMAIL_TEMPLATE_ID: "9a25fe46-2ee4-4a5c-8d47-0f04f058a87d".freeze,
CLAIM_PROVIDER_VERIFICATION_CONFIRMATION_EMAIL_TEMPLATE_ID: "70942fe1-5838-4d37-904c-9d070f2582f0".freeze
}

EARLY_YEARS_PAYMENTS = {
Expand Down
37 changes: 36 additions & 1 deletion app/mailers/claim_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def early_years_payment_provider_email(claim, one_time_password, email)
end

def further_education_payment_provider_verification_email(claim)
unknown_policy_check(claim)
policy_check!(claim, Policies::FurtherEducationPayments)

personalisation = {
recipient_name: claim.school.name,
Expand All @@ -103,6 +103,32 @@ def further_education_payment_provider_verification_email(claim)
)
end

def further_education_payment_provider_confirmation_email(claim)
policy_check!(claim, Policies::FurtherEducationPayments)

verification = claim.eligibility.verification

verifier = verification.fetch("verifier")
verifier_name = "#{verifier.fetch("first_name")} #{verifier.fetch("last_name")}"
verification_date = verification.fetch("created_at").to_date

personalisation = {
recipient_name: claim.school.name,
claim_reference: claim.reference,
claimant_name: claim.full_name,
verifier_name: verifier_name,
verification_date: l(verification_date)
}

template_id = template_ids(claim)[:CLAIM_PROVIDER_VERIFICATION_CONFIRMATION_EMAIL_TEMPLATE_ID]

template_mail(
template_id,
to: claim.school.eligible_fe_provider.primary_key_contact_email_address,
personalisation: personalisation
)
end

private

def set_common_instance_variables(claim)
Expand Down Expand Up @@ -143,4 +169,13 @@ def unknown_policy_check(claim)
def early_years_payment_provider_magic_link(one_time_password, email)
"https://#{ENV["CANONICAL_HOSTNAME"]}/#{Journeys::EarlyYearsPayment::Provider::Authenticated::ROUTING_NAME}/claim?code=#{one_time_password}&email=#{email}"
end

def policy_check!(claim, policy)
return if claim.policy == policy

raise(
ArgumentError,
"Claim policy does not match the expected policy `#{policy}`"
)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
let(:journey) { Journeys::FurtherEducationPayments::Provider }

let(:school) do
create(:school, :further_education, name: "Springfield Elementary")
create(
:school,
:further_education,
:fe_eligible,
name: "Springfield Elementary"
)
end

let(:teaching_hours_per_week) { "more_than_12" }
Expand All @@ -26,7 +31,8 @@
eligibility: eligibility,
policy: Policies::FurtherEducationPayments,
first_name: "Edna",
surname: "Krabappel"
surname: "Krabappel",
reference: "ABC123"
)
end

Expand Down Expand Up @@ -267,16 +273,20 @@
)
end

around do |example|
travel_to DateTime.new(2024, 1, 1, 12, 0, 0) do
perform_enqueued_jobs do
example.run
end
end
end

before do
dqt_teacher_resource = instance_double(Dqt::TeacherResource, find: nil)
dqt_client = instance_double(Dqt::Client, teacher: dqt_teacher_resource)
allow(Dqt::Client).to receive(:new).and_return(dqt_client)

travel_to DateTime.new(2024, 1, 1, 12, 0, 0) do
perform_enqueued_jobs do
form.save
end
end
form.save
end

it "verifies the claim" do
Expand Down Expand Up @@ -330,5 +340,18 @@
"[email protected]"
)
end

it "sends the provider a confirmation email" do
expect(
claim.school.eligible_fe_provider.primary_key_contact_email_address
).to have_received_email(
"70942fe1-5838-4d37-904c-9d070f2582f0",
recipient_name: "Springfield Elementary",
claim_reference: "ABC123",
claimant_name: "Edna Krabappel",
verifier_name: "Seymour Skinner",
verification_date: "1 January 2024"
)
end
end
end
2 changes: 1 addition & 1 deletion spec/support/have_received_email_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
found = ActionMailer::Base.deliveries.map do |mail|
<<-TEXT.squish
To: #{mail.to} -
template id: #{mail["template_id"]} -
template id: #{mail.try(:template_id)} -
personalisation: #{mail["personalisation"]}"
TEXT
end
Expand Down

0 comments on commit ddcb85a

Please sign in to comment.