Skip to content

Commit

Permalink
Always send text messages for consent requests/reminders (#2824)
Browse files Browse the repository at this point in the history
This updates the `ConsentNotification` model to always send a text
message to a parent when sending consent requests and reminders, not
taking in to account whether the parent has opted-in to receive updates
on the vaccination.

Instead, opting-in relates to other updates like consent confirmation,
rejected, or vaccination given/not given updates.

To make this change I've had to update the `TextDeliveryJob` to not take
this value in to account and instead everywhere that the job is enqueued
considers whether to send the text or not based on the context and
whether the parent has opted-in.
  • Loading branch information
thomasleese authored Jan 8, 2025
2 parents bf319d2 + abaaba7 commit 99ce2d6
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 55 deletions.
19 changes: 14 additions & 5 deletions app/controllers/concerns/consent_form_mailer_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ def send_consent_form_confirmation(consent_form)
mailer.confirmation_injection.deliver_later
elsif consent_form.consent_refused?
mailer.confirmation_refused.deliver_later
TextDeliveryJob.perform_later(
:consent_confirmation_refused,
consent_form:
)

if consent_form.parent_phone_receive_updates
TextDeliveryJob.perform_later(
:consent_confirmation_refused,
consent_form:
)
end
elsif consent_form.needs_triage?
mailer.confirmation_triage.deliver_later
elsif consent_form.actual_upcoming_session ==
Expand All @@ -22,7 +25,13 @@ def send_consent_form_confirmation(consent_form)
mailer.confirmation_clinic.deliver_later
else
mailer.confirmation_given.deliver_later
TextDeliveryJob.perform_later(:consent_confirmation_given, consent_form:)

if consent_form.parent_phone_receive_updates
TextDeliveryJob.perform_later(
:consent_confirmation_given,
consent_form:
)
end
end
end
end
10 changes: 8 additions & 2 deletions app/controllers/concerns/triage_mailer_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ def send_triage_confirmation(patient_session, consent)
ConsentMailer.with(params).confirmation_triage.deliver_later
elsif consent.response_refused?
ConsentMailer.with(params).confirmation_refused.deliver_later
TextDeliveryJob.perform_later(:consent_confirmation_refused, **params)

if consent.parent.phone_receive_updates
TextDeliveryJob.perform_later(:consent_confirmation_refused, **params)
end
elsif consent.response_given?
ConsentMailer.with(params).confirmation_given.deliver_later
TextDeliveryJob.perform_later(:consent_confirmation_given, **params)

if consent.parent.phone_receive_updates
TextDeliveryJob.perform_later(:consent_confirmation_given, **params)
end
end
end

Expand Down
4 changes: 3 additions & 1 deletion app/controllers/concerns/vaccination_mailer_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def send_vaccination_confirmation(vaccination_record)
VaccinationMailer.with(params).public_send(mailer_action).deliver_later
end

TextDeliveryJob.perform_later(text_template_name, **params)
if parent.phone.present? && parent.phone_receive_updates
TextDeliveryJob.perform_later(text_template_name, **params)
end
end
end

Expand Down
6 changes: 0 additions & 6 deletions app/jobs/text_delivery_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ def perform(
consent_form&.parent_phone || consent&.parent&.phone || parent&.phone
return if phone_number.nil?

unless consent_form&.parent_phone_receive_updates ||
consent&.parent&.phone_receive_updates ||
parent&.phone_receive_updates
return
end

personalisation =
GovukNotifyPersonalisation.call(
session:,
Expand Down
2 changes: 2 additions & 0 deletions app/models/consent_notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def self.create_and_send!(
.deliver_later
end

next if parent.phone.nil?

TextDeliveryJob.perform_later(
text_template,
parent:,
Expand Down
7 changes: 7 additions & 0 deletions app/models/session_notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ def self.create_and_send!(
.deliver_later
end

unless consent.parent.phone.present? &&
consent.parent.phone_receive_updates
next
end

TextDeliveryJob.perform_later(
:session_school_reminder,
consent:,
Expand All @@ -102,6 +107,8 @@ def self.create_and_send!(
.deliver_later
end

next if parent.phone.blank?

TextDeliveryJob.perform_later(
:"session_#{type}",
parent:,
Expand Down
41 changes: 0 additions & 41 deletions spec/jobs/text_delivery_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,31 +82,6 @@
expect(notify_log_entry.sent_by).to eq(sent_by)
end

context "when the parent doesn't want to receive updates" do
let(:parent) { create(:parent, phone_receive_updates: false) }

it "doesn't send a text" do
expect(notifications_client).not_to receive(:send_sms)
perform_now
end
end

context "when the consent's parent doesn't want to receive updates" do
let(:parent) { nil }
let(:consent) do
create(
:consent,
parent: create(:parent, phone_receive_updates: false),
programme:
)
end

it "doesn't send a text" do
expect(notifications_client).not_to receive(:send_sms)
perform_now
end
end

context "when the parent doesn't have a phone number" do
let(:parent) { create(:parent, phone: nil) }

Expand Down Expand Up @@ -144,22 +119,6 @@
expect(notify_log_entry.consent_form).to eq(consent_form)
end

context "when the parent doesn't want to receive updates" do
let(:consent_form) do
create(
:consent_form,
programme:,
session:,
parent_phone_receive_updates: false
)
end

it "doesn't send a text" do
expect(notifications_client).not_to receive(:send_sms)
perform_now
end
end

context "when the parent doesn't have a phone number" do
let(:consent_form) do
create(:consent_form, programme:, session:, parent_phone: nil)
Expand Down
48 changes: 48 additions & 0 deletions spec/models/consent_notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@
sent_by: current_user
)
end

context "when parent doesn't want to receive updates by text" do
let(:parent) { parents.first }

before { parent.update!(phone_receive_updates: false) }

it "still enqueues a text" do
expect { create_and_send! }.to have_enqueued_text(
:consent_school_request
).with(parent:, patient:, programme:, session:, sent_by: current_user)
end
end
end

context "with a request and a clinic location" do
Expand Down Expand Up @@ -172,6 +184,18 @@
sent_by: current_user
)
end

context "when parent doesn't want to receive updates by text" do
let(:parent) { parents.first }

before { parent.update!(phone_receive_updates: false) }

it "still enqueues a text" do
expect { create_and_send! }.to have_enqueued_text(
:consent_clinic_request
).with(parent:, patient:, programme:, session:, sent_by: current_user)
end
end
end

context "with an initial reminder" do
Expand Down Expand Up @@ -229,6 +253,18 @@
sent_by: current_user
)
end

context "when parent doesn't want to receive updates by text" do
let(:parent) { parents.first }

before { parent.update!(phone_receive_updates: false) }

it "still enqueues a text" do
expect { create_and_send! }.to have_enqueued_text(
:consent_school_reminder
).with(parent:, patient:, programme:, session:, sent_by: current_user)
end
end
end

context "with a subsequent reminder" do
Expand Down Expand Up @@ -289,6 +325,18 @@
sent_by: current_user
)
end

context "when parent doesn't want to receive updates by text" do
let(:parent) { parents.first }

before { parent.update!(phone_receive_updates: false) }

it "still enqueues a text" do
expect { create_and_send! }.to have_enqueued_text(
:consent_school_reminder
).with(parent:, patient:, programme:, session:, sent_by: current_user)
end
end
end
end
end
32 changes: 32 additions & 0 deletions spec/models/session_notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@
:session_school_reminder
).with(consent:, patient_session:, sent_by: current_user)
end

context "when parent doesn't want to receive updates by text" do
before { parents.each { _1.update!(phone_receive_updates: false) } }

it "doesn't enqueues a text" do
expect { create_and_send! }.not_to have_enqueued_text
end
end
end

context "with an initial clinic invitation" do
Expand Down Expand Up @@ -137,6 +145,18 @@
sent_by: current_user
)
end

context "when parent doesn't want to receive updates by text" do
let(:parent) { parents.first }

before { parent.update!(phone_receive_updates: false) }

it "still enqueues a text" do
expect { create_and_send! }.to have_enqueued_text(
:session_clinic_initial_invitation
).with(parent:, patient_session:, sent_by: current_user)
end
end
end

context "with a subsequent clinic invitation" do
Expand Down Expand Up @@ -189,6 +209,18 @@
sent_by: current_user
)
end

context "when parent doesn't want to receive updates by text" do
let(:parent) { parents.first }

before { parent.update!(phone_receive_updates: false) }

it "still enqueues a text" do
expect { create_and_send! }.to have_enqueued_text(
:session_clinic_subsequent_invitation
).with(parent:, patient_session:, sent_by: current_user)
end
end
end
end
end

0 comments on commit 99ce2d6

Please sign in to comment.