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 Aug 30, 2024
1 parent d5bb7a9 commit cafa127
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ def save

claim.save!

ClaimMailer
.further_education_payment_provider_confirmation_email(claim)
.deliver_later

true
end

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 @@ -3,17 +3,40 @@
RSpec.describe Journeys::FurtherEducationPayments::Provider::VerifyClaimForm, type: :model do
let(:journey) { Journeys::FurtherEducationPayments::Provider }

let(:eligibility) { create(:further_education_payments_eligibility) }
let(:school) do
create(
:school,
:further_education,
:fe_eligible,
name: "Springfield A and M"
)
end

let(:eligibility) do
create(
:further_education_payments_eligibility,
school: school
)
end

let(:claim) { eligibility.claim }
let(:claim) do
create(
:claim,
first_name: "Edna",
surname: "Krabappel",
reference: "ABC123",
policy: Policies::FurtherEducationPayments,
eligibility: eligibility
)
end

let(:journey_session) do
create(
:further_education_payments_provider_session,
answers: {
claim_id: claim.id,
dfe_sign_in_uid: "123",
dfe_sign_in_first_name: "Seymoure",
dfe_sign_in_first_name: "Seymour",
dfe_sign_in_last_name: "Skinner",
dfe_sign_in_email: "[email protected]"
}
Expand Down Expand Up @@ -129,11 +152,15 @@
)
end

it "verifies the claim" do
before do
travel_to DateTime.new(2024, 1, 1, 12, 0, 0) do
form.save
perform_enqueued_jobs do
form.save
end
end
end

it "verifies the claim" do
expect(claim.reload.eligibility.verification).to match(
{
"assertions" => [
Expand Down Expand Up @@ -164,13 +191,26 @@
],
"verifier" => {
"dfe_sign_in_uid" => "123",
"first_name" => "Seymoure",
"first_name" => "Seymour",
"last_name" => "Skinner",
"email" => "[email protected]"
},
"created_at" => "2024-01-01T12:00:00.000+00:00"
}
)
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 A and M",
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 cafa127

Please sign in to comment.