From 34912ed64c700888967a5f96b85512e71fef4e31 Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Thu, 31 Oct 2024 14:01:29 +0000 Subject: [PATCH 1/2] rejecting EY claim also emails provider --- app/controllers/admin/decisions_controller.rb | 4 +++ app/mailers/claim_mailer.rb | 20 +++++++++++ app/models/claim.rb | 4 +++ app/models/policies/early_years_payments.rb | 2 -- .../early_years_payments/eligibility.rb | 4 +++ .../features/admin/admin_reject_claim_spec.rb | 23 +++++++++++++ spec/mailers/claim_mailer_spec.rb | 33 +++++++++++++++++++ 7 files changed, 88 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/decisions_controller.rb b/app/controllers/admin/decisions_controller.rb index 18a7f236b5..3c464af0af 100644 --- a/app/controllers/admin/decisions_controller.rb +++ b/app/controllers/admin/decisions_controller.rb @@ -86,6 +86,10 @@ def send_claim_result_email ClaimMailer.approved(@claim).deliver_later if @claim.latest_decision.result == "approved" ClaimMailer.rejected(@claim).deliver_later if @claim.latest_decision.result == "rejected" + + if @claim.latest_decision.result == "rejected" && @claim.has_early_years_policy? + ClaimMailer.rejected_provider_notification(@claim).deliver_later + end end def decision_params diff --git a/app/mailers/claim_mailer.rb b/app/mailers/claim_mailer.rb index 7a07b4e888..777ab1f385 100644 --- a/app/mailers/claim_mailer.rb +++ b/app/mailers/claim_mailer.rb @@ -42,6 +42,26 @@ def rejected(claim) send_mail(template_ids(claim)[:CLAIM_REJECTED_NOTIFY_TEMPLATE_ID], personalisation) end + def rejected_provider_notification(claim) + unknown_policy_check(claim) + set_common_instance_variables(claim) + + personalisation = { + nursery_name: claim.eligibility.eligible_ey_provider.nursery_name, + ref_number: claim.reference, + practitioner_name: claim.eligibility.practitioner_name, + support_email_address: @support_email_address, + **rejected_reasons_personalisation(@claim.latest_decision&.rejected_reasons_hash) + } + + template_mail( + "0c345721-c8d6-493a-95b7-006e84ba9c4e", + to: @claim.eligibility.eligible_ey_provider.primary_key_contact_email_address, + reply_to_id: @policy.notify_reply_to_id, + personalisation: + ) + end + def update_after_three_weeks(claim) unknown_policy_check(claim) set_common_instance_variables(claim) diff --git a/app/models/claim.rb b/app/models/claim.rb index c598aa3aef..d579a4612e 100644 --- a/app/models/claim.rb +++ b/app/models/claim.rb @@ -453,6 +453,10 @@ def awaiting_provider_verification? eligibility.awaiting_provider_verification? end + def has_early_years_policy? + policy == Policies::EarlyYearsPayments + end + private def one_login_idv_name_match? diff --git a/app/models/policies/early_years_payments.rb b/app/models/policies/early_years_payments.rb index 13624c2577..c9113c5f9b 100644 --- a/app/models/policies/early_years_payments.rb +++ b/app/models/policies/early_years_payments.rb @@ -56,8 +56,6 @@ module EarlyYearsPayments LevellingUpPremiumPayments ] - VERIFIERS = [] - # TODO: This is needed once the reply-to email address has been added to Gov Notify def notify_reply_to_id nil diff --git a/app/models/policies/early_years_payments/eligibility.rb b/app/models/policies/early_years_payments/eligibility.rb index ba3aa44f5a..f006ab9e0d 100644 --- a/app/models/policies/early_years_payments/eligibility.rb +++ b/app/models/policies/early_years_payments/eligibility.rb @@ -33,6 +33,10 @@ def employment_task_available_at def employment_task_available? Date.today >= employment_task_available_at end + + def practitioner_name + [practitioner_first_name, practitioner_surname].join(" ") + end end end end diff --git a/spec/features/admin/admin_reject_claim_spec.rb b/spec/features/admin/admin_reject_claim_spec.rb index 9c169ca490..885e11409c 100644 --- a/spec/features/admin/admin_reject_claim_spec.rb +++ b/spec/features/admin/admin_reject_claim_spec.rb @@ -108,4 +108,27 @@ expect(page).not_to have_content("Reasons") end + + context "early years claim" do + let!(:claim) do + create( + :claim, + :submitted, + policy: Policies::EarlyYearsPayments + ) + end + + scenario "rejecting sends email to claimant + provider" do + visit admin_claim_tasks_path(claim) + click_on "Approve or reject this claim" + choose "Reject" + check "Claim cancelled by employer" + + expect { + click_button "Confirm decision" + }.to change { enqueued_jobs.count { |job| job[:job] == ActionMailer::MailDeliveryJob } }.by(2) + + expect(page).to have_content("Claim has been rejected successfully") + end + end end diff --git a/spec/mailers/claim_mailer_spec.rb b/spec/mailers/claim_mailer_spec.rb index 2da6e40bba..106217ec23 100644 --- a/spec/mailers/claim_mailer_spec.rb +++ b/spec/mailers/claim_mailer_spec.rb @@ -413,4 +413,37 @@ class SomePolicy; end expect(mail.body).to be_empty end end + + describe "#rejected_provider_notification" do + let(:claim) do + create( + :claim, + :rejected, + policy: Policies::EarlyYearsPayments + ) + end + + before do + claim.eligibility.update!( + practitioner_first_name: "John", + practitioner_surname: "Doe" + ) + end + + it "sends correct email to provider" do + mail = described_class.rejected_provider_notification(claim) + + expect(mail.to).to eql([claim.eligibility.eligible_ey_provider.primary_key_contact_email_address]) + expect(mail.personalisation[:nursery_name]).to eql(claim.eligibility.eligible_ey_provider.nursery_name) + expect(mail.personalisation[:ref_number]).to eql(claim.reference) + expect(mail.personalisation[:practitioner_name]).to eql("John Doe") + expect(mail.personalisation[:support_email_address]).to eql("earlycareerteacherpayments@digital.education.gov.uk") + + expect(mail.personalisation[:reason_claim_cancelled_by_employer]).to eql("yes") + expect(mail.personalisation[:reason_six_month_retention_check_failed]).to eql("no") + expect(mail.personalisation[:reason_duplicate]).to eql("no") + expect(mail.personalisation[:reason_no_response]).to eql("no") + expect(mail.personalisation[:reason_other]).to eql("no") + end + end end From dcdd63379578145c1d69e9b5ca176aedf802f284 Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Fri, 1 Nov 2024 11:11:30 +0000 Subject: [PATCH 2/2] claimant does not receive rejection if no email --- app/controllers/admin/decisions_controller.rb | 5 +- .../features/admin/admin_reject_claim_spec.rb | 60 +++++++++++++------ 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/app/controllers/admin/decisions_controller.rb b/app/controllers/admin/decisions_controller.rb index 3c464af0af..f44181fd75 100644 --- a/app/controllers/admin/decisions_controller.rb +++ b/app/controllers/admin/decisions_controller.rb @@ -85,7 +85,10 @@ def send_claim_result_email return if @claim.awaiting_qa? ClaimMailer.approved(@claim).deliver_later if @claim.latest_decision.result == "approved" - ClaimMailer.rejected(@claim).deliver_later if @claim.latest_decision.result == "rejected" + + if @claim.latest_decision.result == "rejected" && @claim.email_address.present? + ClaimMailer.rejected(@claim).deliver_later + end if @claim.latest_decision.result == "rejected" && @claim.has_early_years_policy? ClaimMailer.rejected_provider_notification(@claim).deliver_later diff --git a/spec/features/admin/admin_reject_claim_spec.rb b/spec/features/admin/admin_reject_claim_spec.rb index 885e11409c..8ed33b5077 100644 --- a/spec/features/admin/admin_reject_claim_spec.rb +++ b/spec/features/admin/admin_reject_claim_spec.rb @@ -110,25 +110,51 @@ end context "early years claim" do - let!(:claim) do - create( - :claim, - :submitted, - policy: Policies::EarlyYearsPayments - ) + context "claimant has not completed their half" do + let!(:claim) do + create( + :claim, + :submitted, + policy: Policies::EarlyYearsPayments, + email_address: nil + ) + end + + scenario "rejecting sends email to provider only when claimant yet to complete" do + visit admin_claim_tasks_path(claim) + click_on "Approve or reject this claim" + choose "Reject" + check "Claim cancelled by employer" + + expect { + click_button "Confirm decision" + }.to change { enqueued_jobs.count { |job| job[:job] == ActionMailer::MailDeliveryJob } }.by(1) + + expect(page).to have_content("Claim has been rejected successfully") + end end - scenario "rejecting sends email to claimant + provider" do - visit admin_claim_tasks_path(claim) - click_on "Approve or reject this claim" - choose "Reject" - check "Claim cancelled by employer" - - expect { - click_button "Confirm decision" - }.to change { enqueued_jobs.count { |job| job[:job] == ActionMailer::MailDeliveryJob } }.by(2) - - expect(page).to have_content("Claim has been rejected successfully") + context "claimant has completed their half" do + let!(:claim) do + create( + :claim, + :submitted, + policy: Policies::EarlyYearsPayments + ) + end + + scenario "rejecting sends email to claimant + provider" do + visit admin_claim_tasks_path(claim) + click_on "Approve or reject this claim" + choose "Reject" + check "Claim cancelled by employer" + + expect { + click_button "Confirm decision" + }.to change { enqueued_jobs.count { |job| job[:job] == ActionMailer::MailDeliveryJob } }.by(2) + + expect(page).to have_content("Claim has been rejected successfully") + end end end end