From 013ca263eed2456e2c7f4ef32d28eeef90de3006 Mon Sep 17 00:00:00 2001 From: Richard Lynch Date: Fri, 30 Aug 2024 11:47:14 +0100 Subject: [PATCH] Provider confirmation email 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. --- .../provider/verify_claim_form.rb | 4 ++ app/mailers/application_mailer.rb | 3 +- app/mailers/claim_mailer.rb | 37 ++++++++++++++++++- .../provider/verify_claim_form_spec.rb | 37 +++++++++++++++---- spec/support/have_received_email_matcher.rb | 2 +- 5 files changed, 73 insertions(+), 10 deletions(-) diff --git a/app/forms/journeys/further_education_payments/provider/verify_claim_form.rb b/app/forms/journeys/further_education_payments/provider/verify_claim_form.rb index 7f6f0ae6aa..749eec2770 100644 --- a/app/forms/journeys/further_education_payments/provider/verify_claim_form.rb +++ b/app/forms/journeys/further_education_payments/provider/verify_claim_form.rb @@ -109,6 +109,10 @@ def save claim.save! + ClaimMailer + .further_education_payment_provider_confirmation_email(claim) + .deliver_later + ClaimVerifierJob.perform_later(claim) true diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 255911f399..7d432cc3f9 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -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 = { diff --git a/app/mailers/claim_mailer.rb b/app/mailers/claim_mailer.rb index 5c6cef5cba..7f87ff04e1 100644 --- a/app/mailers/claim_mailer.rb +++ b/app/mailers/claim_mailer.rb @@ -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, @@ -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) @@ -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 diff --git a/spec/forms/journeys/further_education_payments/provider/verify_claim_form_spec.rb b/spec/forms/journeys/further_education_payments/provider/verify_claim_form_spec.rb index 578560998c..e1036f6d1f 100644 --- a/spec/forms/journeys/further_education_payments/provider/verify_claim_form_spec.rb +++ b/spec/forms/journeys/further_education_payments/provider/verify_claim_form_spec.rb @@ -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" } @@ -26,7 +31,8 @@ eligibility: eligibility, policy: Policies::FurtherEducationPayments, first_name: "Edna", - surname: "Krabappel" + surname: "Krabappel", + reference: "ABC123" ) end @@ -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 @@ -330,5 +340,18 @@ "seymour.skinner@springfield-elementary.edu" ) 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 diff --git a/spec/support/have_received_email_matcher.rb b/spec/support/have_received_email_matcher.rb index d3967c3b6b..0b6c53985e 100644 --- a/spec/support/have_received_email_matcher.rb +++ b/spec/support/have_received_email_matcher.rb @@ -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