Skip to content

Commit ab131fb

Browse files
authored
Merge pull request #6275 from NHSDigital/improved-spec-coverage-for-comms-scenarios
Improved spec coverage for comms scenarios
2 parents 2904451 + 15a92ce commit ab131fb

7 files changed

Lines changed: 440 additions & 11 deletions

spec/features/mmr_already_had_spec.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@
9191
then_i_see_the_mmr_date_instead_of_the_mmr_or_mmrv_page
9292
end
9393

94+
scenario "parents are notified when their child's prior vaccination is added to the record" do
95+
given_an_mmr_programme_with_a_session
96+
and_a_patient_with_a_consenting_parent_is_in_the_session
97+
and_the_patients_prior_vaccination_is_recorded
98+
99+
when_the_status_updater_runs
100+
101+
when_the_prior_vaccination_notification_is_sent
102+
then_the_parent_receives_a_vaccination_already_had_email
103+
and_the_parent_receives_a_vaccination_already_had_sms
104+
end
105+
94106
scenario "record a patient born after January 2020 as already had their 2nd MMRV dose outside the school session" do
95107
given_an_mmr_programme_with_a_session
96108
and_a_patient_is_in_the_session_born_after_january_2020
@@ -431,4 +443,48 @@ def and_it_includes_the_mmrv_programme_and_both_reported_and_performed_at_dates
431443
"Vaccination given #{@vaccination_date.strftime("%-d %B %Y")}"
432444
)
433445
end
446+
447+
def and_a_patient_with_a_consenting_parent_is_in_the_session
448+
@parent = create(:parent, phone_receive_updates: true)
449+
@patient =
450+
create(
451+
:patient,
452+
session: @session,
453+
date_of_birth: Date.new(2020, 1, 1),
454+
parents: [@parent]
455+
)
456+
create(
457+
:consent,
458+
:given,
459+
patient: @patient,
460+
programme: @programme,
461+
parent: @parent,
462+
team: @session.team
463+
)
464+
end
465+
466+
def and_the_patients_prior_vaccination_is_recorded
467+
@vaccination_record =
468+
create(
469+
:vaccination_record,
470+
:already_had,
471+
:sourced_from_manual_report,
472+
patient: @patient,
473+
programme: @programme,
474+
session: @session,
475+
performed_at: 6.months.ago
476+
)
477+
end
478+
479+
def when_the_prior_vaccination_notification_is_sent
480+
AlreadyHadNotificationSender.call(vaccination_record: @vaccination_record)
481+
end
482+
483+
def then_the_parent_receives_a_vaccination_already_had_email
484+
expect_email_to @parent.email, :vaccination_already_had
485+
end
486+
487+
def and_the_parent_receives_a_vaccination_already_had_sms
488+
expect_sms_to @parent.phone, :vaccination_already_had, :any
489+
end
434490
end

spec/features/parental_consent_clinic_spec.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,28 @@
6969
then_the_nurse_should_see_home_schooled
7070
end
7171

72+
scenario "submitting a consent form with mismatched contact details warns existing parent" do
73+
stub_pds_search_to_return_no_patients
74+
75+
given_an_hpv_programme_is_underway
76+
and_the_patient_has_a_parent_with_known_contact_details
77+
78+
when_i_go_to_the_consent_form
79+
and_i_fill_in_my_childs_name_and_birthday
80+
when_i_choose_yes # home educated
81+
then_i_see_the_parent_step
82+
83+
when_i_give_consent
84+
and_i_answer_no_to_all_the_medical_questions
85+
then_i_can_check_my_answers
86+
87+
when_i_submit_the_consent_form
88+
and_i_refuse_to_answer_questions_on_ethnicity
89+
then_i_see_a_confirmation_page_in_clinic
90+
91+
then_the_existing_parent_receives_a_contact_details_mismatch_warning
92+
end
93+
7294
scenario "Child attending a clinic is not in education" do
7395
stub_pds_search_to_return_no_patients
7496

@@ -243,6 +265,7 @@ def then_i_see_a_confirmation_page_in_clinic
243265
expect(page).not_to have_content("at school")
244266

245267
perform_enqueued_jobs # match consent form with patient
268+
expect_email_to "jane@example.com", :consent_confirmation_clinic, :any
246269
end
247270

248271
def when_the_nurse_checks_the_school_moves
@@ -306,4 +329,28 @@ def and_i_refuse_to_answer_questions_on_ethnicity
306329
choose "No, skip the ethnicity questions"
307330
click_on "Continue"
308331
end
332+
333+
def and_the_patient_has_a_parent_with_known_contact_details
334+
@existing_parent =
335+
create(
336+
:parent,
337+
email: "original@example.com",
338+
phone: "07700 900100",
339+
phone_receive_updates: true
340+
)
341+
create(
342+
:parent_relationship,
343+
:mother,
344+
patient: @child,
345+
parent: @existing_parent
346+
)
347+
end
348+
349+
def then_the_existing_parent_receives_a_contact_details_mismatch_warning
350+
perform_enqueued_jobs
351+
expect_email_to "original@example.com",
352+
:consent_unknown_contact_details_warning,
353+
:any
354+
expect_sms_to "07700 900100", :consent_unknown_contact_details_warning, :any
355+
end
309356
end

spec/features/scheduled_consent_requests_and_reminders_spec.rb

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,16 @@
4343
["07700 900000", "07700 900001", "07700 900002", "07700 900003"]
4444
end
4545

46+
let(:mmrv_parent_emails) do
47+
%w[parent1.child3@example.com parent2.child3@example.com]
48+
end
49+
50+
let(:mmrv_parent_phones) { ["07700 900004", "07700 900005"] }
51+
4652
scenario "Consent requests and reminders are sent automatically" do
4753
given_my_team_is_running_all_vaccination_programmes
4854
and_one_unscheduled_session_exists_with_two_children_and_two_parents_each
55+
and_an_mmrv_eligible_child_with_two_parents_exists
4956
and_i_am_signed_in
5057

5158
when_i_go_to_my_team_page
@@ -75,7 +82,7 @@ def given_my_team_is_running_all_vaccination_programmes
7582
Programme.td_ipv
7683
]
7784
@team = create(:team, :with_one_nurse, :with_generic_clinic, programmes:)
78-
@location = create(:school, :secondary, team: @team)
85+
@location = create(:school, team: @team)
7986
@session =
8087
create(
8188
:session,
@@ -116,6 +123,33 @@ def and_one_unscheduled_session_exists_with_two_children_and_two_parents_each
116123
end
117124
end
118125

126+
def and_an_mmrv_eligible_child_with_two_parents_exists
127+
parents = [
128+
create(
129+
:parent,
130+
email: "parent1.child3@example.com",
131+
phone: "07700900004",
132+
phone_receive_updates: true
133+
),
134+
create(
135+
:parent,
136+
email: "parent2.child3@example.com",
137+
phone: "07700900005",
138+
phone_receive_updates: true
139+
)
140+
]
141+
# Child3 is born after the MMRV eligibility cutoff (2020-01-01) so they
142+
# receive MMRV consent request and reminder emails.
143+
create(
144+
:patient,
145+
date_of_birth: Date.new(2020, 6, 1),
146+
session: @session,
147+
given_name: "Child3",
148+
family_name: "Test",
149+
parents:
150+
)
151+
end
152+
119153
def and_i_am_signed_in
120154
sign_in @user
121155
end
@@ -205,6 +239,16 @@ def then_all_four_parents_received_all_programme_consent_requests
205239
parent_phones.each do |phone|
206240
expect_sms_to(phone, :consent_school_request, :any)
207241
end
242+
243+
mmrv_parent_emails.each do |email|
244+
expect(email_deliveries).to include(
245+
matching_notify_email(to: email, template: :consent_school_request_mmrv)
246+
)
247+
end
248+
249+
mmrv_parent_phones.each do |phone|
250+
expect_sms_to(phone, :consent_school_request, :any)
251+
end
208252
end
209253

210254
def then_all_four_parents_received_all_programme_initial_reminders
@@ -223,6 +267,19 @@ def then_all_four_parents_received_all_programme_initial_reminders
223267
parent_phones.each do |phone|
224268
expect_sms_to(phone, :consent_school_reminder, :any)
225269
end
270+
271+
mmrv_parent_emails.each do |email|
272+
expect(email_deliveries).to include(
273+
matching_notify_email(
274+
to: email,
275+
template: :consent_school_initial_reminder_mmrv
276+
)
277+
)
278+
end
279+
280+
mmrv_parent_phones.each do |phone|
281+
expect_sms_to(phone, :consent_school_reminder, :any)
282+
end
226283
end
227284

228285
def then_all_four_parents_received_all_programme_subsequent_reminders
@@ -241,5 +298,18 @@ def then_all_four_parents_received_all_programme_subsequent_reminders
241298
parent_phones.each do |phone|
242299
expect_sms_to(phone, :consent_school_reminder, :any)
243300
end
301+
302+
mmrv_parent_emails.each do |email|
303+
expect(email_deliveries).to include(
304+
matching_notify_email(
305+
to: email,
306+
template: :consent_school_subsequent_reminder_mmrv
307+
)
308+
)
309+
end
310+
311+
mmrv_parent_phones.each do |phone|
312+
expect_sms_to(phone, :consent_school_reminder, :any)
313+
end
244314
end
245315
end
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# frozen_string_literal: true
2+
3+
describe "Session school reminders" do
4+
scenario "parents with consent given receive a reminder the day before a session" do
5+
given_a_school_session_is_scheduled_for_tomorrow
6+
and_a_patient_has_given_consent
7+
8+
when_school_session_reminders_are_sent
9+
10+
then_the_consenting_parent_receives_an_email_reminder
11+
and_the_consenting_parent_receives_an_sms_reminder
12+
end
13+
14+
def given_a_school_session_is_scheduled_for_tomorrow
15+
programme = Programme.hpv
16+
@team = create(:team, programmes: [programme])
17+
school = create(:school, team: @team)
18+
@session =
19+
create(
20+
:session,
21+
date: Date.tomorrow,
22+
team: @team,
23+
programmes: [programme],
24+
location: school
25+
)
26+
end
27+
28+
def and_a_patient_has_given_consent
29+
@patient =
30+
create(
31+
:patient,
32+
:consent_given_triage_not_needed,
33+
session: @session,
34+
team: @team,
35+
programmes: @session.programmes
36+
)
37+
@parent = @patient.consents.first.parent
38+
end
39+
40+
def when_school_session_reminders_are_sent
41+
EnqueueSchoolSessionRemindersJob.perform_now
42+
perform_enqueued_jobs
43+
Sidekiq::Job.drain_all
44+
end
45+
46+
def then_the_consenting_parent_receives_an_email_reminder
47+
expect_email_to @parent.email, :session_school_reminder
48+
end
49+
50+
def and_the_consenting_parent_receives_an_sms_reminder
51+
expect_sms_to @parent.phone, :session_school_reminder, :any
52+
end
53+
end

0 commit comments

Comments
 (0)