Skip to content

Commit

Permalink
Merge pull request #3199 from DFE-Digital/fe-provider-chaser-email
Browse files Browse the repository at this point in the history
FE provider chaser email
  • Loading branch information
kenfodder authored Sep 24, 2024
2 parents e28b295 + d7b01a0 commit 73e8a8a
Show file tree
Hide file tree
Showing 17 changed files with 409 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ def create
body: "Verification email sent to #{claim.school.name}"
)

ClaimMailer.further_education_payment_provider_verification_email(claim).deliver_later
Policies::FurtherEducationPayments::ProviderVerificationEmails.new(claim)
.send_further_education_payment_provider_verification_email

flash[:notice] = "Verification email sent to #{claim.school.name}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def save
# noop
# do not send provider verification email
else
ClaimMailer.further_education_payment_provider_verification_email(claim).deliver_later
Policies::FurtherEducationPayments::ProviderVerificationEmails.new(claim)
.send_further_education_payment_provider_verification_email
end

true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module FurtherEducationPayments
class ProviderVerificationChaseEmailJob < CronJob
# Daily 8am
self.cron_expression = "0 8 * * *"

queue_as :user_data

def perform
Rails.logger.info "ProviderVerificationChaseEmailJob sending chase emails..."

unverified_claims_with_provider_email_sent_over_3_weeks_ago.each do |claim|
claim.notes.create!(
label: "provider_verification",
body: "Verification chaser email sent to #{claim.school.name}"
)

Policies::FurtherEducationPayments::ProviderVerificationEmails.new(claim)
.send_further_education_payment_provider_verification_chase_email
end
end

private

def unverified_claims_with_provider_email_sent_over_3_weeks_ago
Policies::FurtherEducationPayments::Eligibility
.includes(:claim)
.unverified
.provider_verification_email_last_sent_over(3.weeks.ago)
.provider_verification_chase_email_not_sent
.map(&:claim)
.reject { |claim| claim.held? || claim.latest_decision&.rejected? }
end
end
end
1 change: 1 addition & 0 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ApplicationMailer < Mail::Notify::Mailer
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_CHASE_EMAIL_TEMPLATE_ID: "9c84a684-b751-449a-bce0-ebe4aa5b187a".freeze,
CLAIM_PROVIDER_VERIFICATION_CONFIRMATION_EMAIL_TEMPLATE_ID: "70942fe1-5838-4d37-904c-9d070f2582f0".freeze
}

Expand Down
21 changes: 21 additions & 0 deletions app/mailers/claim_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,27 @@ def further_education_payment_provider_verification_email(claim)
)
end

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

personalisation = {
recipient_name: claim.school.name,
claimant_name: claim.full_name,
claim_reference: claim.reference,
claim_submission_date: l(claim.created_at.to_date),
verification_due_date: l(Policies::FurtherEducationPayments.verification_chase_due_date_for_claim(claim)),
verification_url: Journeys::FurtherEducationPayments::Provider::SlugSequence.verify_claim_url(claim)
}

template_id = template_ids(claim)[:CLAIM_PROVIDER_VERIFICATION_CHASE_EMAIL_TEMPLATE_ID]

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

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

Expand Down
4 changes: 4 additions & 0 deletions app/models/policies/further_education_payments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ def verification_due_date_for_claim(claim)
(claim.created_at + 2.weeks).to_date
end

def verification_chase_due_date_for_claim(claim)
(claim.eligibility.provider_verification_chase_email_last_sent_at + 3.weeks).to_date
end

def duplicate_claim?(claim)
Claim::MatchingAttributeFinder.new(claim).matching_claims.exists?
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/policies/further_education_payments/eligibility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def description
belongs_to :possible_school, optional: true, class_name: "School"
belongs_to :school, optional: true

scope :unverified, -> { where(verification: {}) }
scope :provider_verification_email_last_sent_over, ->(older_than) { where("provider_verification_email_last_sent_at < ?", older_than) }
scope :provider_verification_chase_email_not_sent, -> { where(provider_verification_chase_email_last_sent_at: nil) }

# Claim#school expects this
alias_method :current_school, :school

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Policies
module FurtherEducationPayments
class ProviderVerificationEmails
def initialize(claim)
@claim = claim
end

# First provider email
def send_further_education_payment_provider_verification_email
@claim.eligibility.update!(provider_verification_email_last_sent_at: Time.now)
ClaimMailer.further_education_payment_provider_verification_email(@claim).deliver_later
end

# Second automated provider chase email
def send_further_education_payment_provider_verification_chase_email
@claim.eligibility.update!(provider_verification_chase_email_last_sent_at: Time.now)
ClaimMailer.further_education_payment_provider_verification_chase_email(@claim).deliver_later
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<% if @tasks_presenter.provider_verification.verification_email_sent? %>
<% if @tasks_presenter.provider_verification.verification_email_sent_by_admin_team? %>
<div class="govuk-inset-text">
<% @tasks_presenter.provider_verification.admin_sent_emails.each do |verification_email| %>
<% @tasks_presenter.provider_verification.admin_sent_emails.each do |verification_email|%>
<p>
The verification request was sent to the provider by
<%= user_details(verification_email.created_by) %> on <%= l(verification_email.created_at) %>
<% if verification_email.created_by %>
<%= user_details(verification_email.created_by) %>
<% else %>
an automated process
<% end %>
on <%= l(verification_email.created_at) %>
</p>
<% end %>
</div>
Expand Down
2 changes: 2 additions & 0 deletions config/analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ shared:
- subject_to_disciplinary_action
- half_teaching_hours
- flagged_as_duplicate
- provider_verification_email_last_sent_at
- provider_verification_chase_email_last_sent_at
:eligible_fe_providers:
- id
- ukprn
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddProviderVerificationEmailLastSentAtToFurtherEducationPaymentsEligibilities < ActiveRecord::Migration[7.0]
def change
add_column :further_education_payments_eligibilities, :provider_verification_email_last_sent_at, :datetime
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddProviderVerificationChaseEmailLastSentAtToFurtherEducationPaymentsEligibilities < ActiveRecord::Migration[7.0]
def change
add_column :further_education_payments_eligibilities, :provider_verification_chase_email_last_sent_at, :datetime
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2024_09_04_150711) do
ActiveRecord::Schema[7.0].define(version: 2024_09_23_130010) do
# These are extensions that must be enabled in order to support this database
enable_extension "citext"
enable_extension "pg_trgm"
Expand Down Expand Up @@ -261,6 +261,8 @@
t.boolean "half_teaching_hours"
t.jsonb "verification", default: {}
t.boolean "flagged_as_duplicate", default: false
t.datetime "provider_verification_email_last_sent_at"
t.datetime "provider_verification_chase_email_last_sent_at"
t.index ["possible_school_id"], name: "index_fe_payments_eligibilities_on_possible_school_id"
t.index ["school_id"], name: "index_fe_payments_eligibilities_on_school_id"
end
Expand Down
60 changes: 58 additions & 2 deletions spec/features/admin/admin_claim_further_education_payments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
"information"
)

expect(claim.eligibility.reload.provider_verification_email_last_sent_at).to be_nil

expect(page).to have_content(
"This task has not been sent to the provider yet."
)
Expand All @@ -78,6 +80,8 @@
verification_url: Journeys::FurtherEducationPayments::Provider::SlugSequence.verify_claim_url(claim)
)
)

expect(claim.eligibility.reload.provider_verification_email_last_sent_at).to eq Time.now
end
end

Expand Down Expand Up @@ -106,7 +110,8 @@
contract_type: "fixed_term",
claim: claim,
school: fe_provider,
award_amount: 1500
award_amount: 1500,
provider_verification_email_last_sent_at: DateTime.new(2024, 8, 1, 9, 0, 0)
)

create(
Expand Down Expand Up @@ -155,6 +160,8 @@
verification_url: Journeys::FurtherEducationPayments::Provider::SlugSequence.verify_claim_url(claim)
)
)

expect(claim.eligibility.reload.provider_verification_email_last_sent_at).to eq Time.now
end
end

Expand Down Expand Up @@ -182,7 +189,8 @@
contract_type: "fixed_term",
claim: claim,
school: fe_provider,
award_amount: 1500
award_amount: 1500,
provider_verification_email_last_sent_at: DateTime.new(2024, 8, 1, 9, 0, 0)
)

visit admin_claim_path(claim)
Expand Down Expand Up @@ -225,6 +233,54 @@
verification_url: Journeys::FurtherEducationPayments::Provider::SlugSequence.verify_claim_url(claim)
)
)

expect(claim.eligibility.reload.provider_verification_email_last_sent_at).to eq Time.now
end

it "shows the chaser verification email was sent if one was sent after 3 weeks" do
fe_provider = create(
:school,
:further_education,
:fe_eligible,
name: "Springfield A and M"
)

claim = create(
:claim,
first_name: "Edna",
surname: "Krabappel",
date_of_birth: Date.new(1945, 7, 3),
reference: "AB123456",
created_at: DateTime.new(2024, 8, 1, 9, 0, 0),
submitted_at: DateTime.new(2024, 8, 1, 9, 0, 0)
)

create(
:further_education_payments_eligibility,
contract_type: "fixed_term",
claim: claim,
school: fe_provider,
award_amount: 1500,
provider_verification_email_last_sent_at: DateTime.new(2024, 8, 1, 9, 0, 0)
)

perform_enqueued_jobs do
FurtherEducationPayments::ProviderVerificationChaseEmailJob.perform_now
end

visit admin_claim_path(claim)

click_on "View tasks"

click_on(
"Confirm the provider has responded and verified the claimant's " \
"information"
)

expect(page).to have_content(
"The verification request was sent to the provider by " \
"an automated process on 9 September 2024 11:00am"
)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
verification_url: Journeys::FurtherEducationPayments::Provider::SlugSequence.verify_claim_url(claim)
)
)

expect(claim.eligibility.reload.provider_verification_email_last_sent_at).to eq DateTime.new(2024, 10, 1, 0, 0, 0)
end

it "doesn't email the provider if the claim is a duplicate" do
Expand All @@ -119,7 +121,10 @@
duplicate_claim = second_claim_form.claim

expect(original_claim.eligibility.flagged_as_duplicate).to eq(false)
expect(original_claim.eligibility.provider_verification_email_last_sent_at).not_to be_nil

expect(duplicate_claim.eligibility.flagged_as_duplicate).to eq(true)
expect(duplicate_claim.eligibility.provider_verification_email_last_sent_at).to be_nil
end

context "when one login IDV mismatch" do
Expand Down
Loading

0 comments on commit 73e8a8a

Please sign in to comment.