Skip to content

Commit

Permalink
Merge pull request #1984 from DFE-Digital/consent-reminders
Browse files Browse the repository at this point in the history
Allow sending reminders for consent requests
  • Loading branch information
thomasleese authored Feb 14, 2024
2 parents 2d7a605 + a659f6a commit bd0e35a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
16 changes: 15 additions & 1 deletion app/models/application_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,18 @@ def created_under_new_regulations?
end

def reminder_email_names
%w[expiration references]
%w[consent expiration references]
end

def should_send_reminder_email?(name, number_of_reminders_sent)
return false if teacher.application_form != self

case name
when "consent"
number_of_reminders_sent.zero? &&
consent_requests_not_yet_received.any? do |qualification_request|
qualification_request.days_until_expired <= 21
end
when "expiration"
return false if days_until_expired.nil?

Expand All @@ -271,6 +276,8 @@ def should_send_reminder_email?(name, number_of_reminders_sent)

def send_reminder_email(name, number_of_reminders_sent)
case name
when "consent"
TeacherMailer.with(application_form: self).consent_reminder.deliver_later
when "expiration"
TeacherMailer
.with(application_form: self, number_of_reminders_sent:)
Expand Down Expand Up @@ -306,4 +313,11 @@ def reference_requests_not_yet_received_or_rejected
.where.not(requested_at: nil)
.where(received_at: nil, verify_passed: nil, review_passed: nil)
end

def consent_requests_not_yet_received
QualificationRequest
.joins(:qualification)
.where(qualifications: { application_form_id: id })
.consent_respondable
end
end
4 changes: 2 additions & 2 deletions app/models/qualification_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class QualificationRequest < ApplicationRecord
scope :consent_received, -> { where.not(consent_received_at: nil) }
scope :consent_respondable,
-> do
consent_required
.consent_requested
consent_requested
.where(consent_received_at: nil)
.joins(assessment: :application_form)
.merge(ApplicationForm.assessable)
end

Expand Down
53 changes: 53 additions & 0 deletions spec/models/application_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,59 @@
end
end

describe "#should_send_reminder_email?" do
subject(:should_send_reminder_email?) do
application_form.should_send_reminder_email?(
name,
number_of_reminders_sent,
)
end

let(:application_form) { create(:application_form, :verification_stage) }
let(:assessment) { create(:assessment, application_form:) }
let(:qualification) { create(:qualification, application_form:) }

context "with consent reminders" do
let(:name) { "consent" }

context "with no reminders sent" do
let(:number_of_reminders_sent) { 0 }
it { is_expected.to be false }

context "with a qualification request" do
before do
create(
:qualification_request,
assessment:,
qualification:,
consent_requested_at: 1.week.ago,
)
end

it { is_expected.to be false }
end

context "with a qualification request older than 3 weeks ago" do
before do
create(
:qualification_request,
assessment:,
qualification:,
consent_requested_at: 4.weeks.ago,
)
end

it { is_expected.to be true }
end
end

context "with no reminders sent" do
let(:number_of_reminders_sent) { 1 }
it { is_expected.to be false }
end
end
end

describe "#from_ineligible_country" do
subject(:from_ineligible_country) do
described_class.from_ineligible_country
Expand Down

0 comments on commit bd0e35a

Please sign in to comment.