Skip to content

Commit 410a954

Browse files
authored
Merge pull request #3954 from nhsuk/ensure-consent-emails-send
Ensure consented_vaccine_methods_message is set for consents
2 parents 427aa7e + 0de7567 commit 410a954

2 files changed

Lines changed: 43 additions & 3 deletions

File tree

app/lib/govuk_notify_personalisation.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,15 @@ def consent_link
129129
end
130130

131131
def consented_vaccine_methods_message
132-
return nil if consent_form.nil?
133-
return "" if consent_form.programmes.none?(&:flu?)
132+
return nil if consent.nil? && consent_form.nil?
134133

135-
consent_form_programmes = consent_form.consent_form_programmes
134+
if (consent && !consent.programme.flu?) ||
135+
(consent_form && consent_form.programmes.none?(&:flu?))
136+
return ""
137+
end
138+
139+
consent_form_programmes =
140+
consent ? [consent] : consent_form.consent_form_programmes
136141

137142
consented_vaccine_methods =
138143
if consent_form_programmes.any?(&:vaccine_method_injection_and_nasal?)

spec/lib/govuk_notify_personalisation_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,46 @@
194194
it do
195195
expect(to_h).to match(
196196
hash_including(
197+
consented_vaccine_methods_message: "",
197198
reason_for_refusal: "of personal choice",
198199
survey_deadline_date: "8 January 2024"
199200
)
200201
)
201202
end
203+
204+
context "for the flu programme" do
205+
let(:programmes) { [create(:programme, :flu)] }
206+
207+
it do
208+
expect(to_h).to include(
209+
consented_vaccine_methods_message:
210+
"You’ve agreed that John can have the injected flu vaccine."
211+
)
212+
end
213+
214+
context "when consented to both nasal and injection" do
215+
before { consent.update!(vaccine_methods: %w[nasal injection]) }
216+
217+
it do
218+
expect(to_h).to include(
219+
consented_vaccine_methods_message:
220+
"You’ve agreed that John can have the nasal spray flu vaccine, " \
221+
"or the injected flu vaccine if the nasal spray is not suitable."
222+
)
223+
end
224+
end
225+
226+
context "when consented only to nasal" do
227+
before { consent.update!(vaccine_methods: %w[nasal]) }
228+
229+
it do
230+
expect(to_h).to include(
231+
consented_vaccine_methods_message:
232+
"You’ve agreed that John can have the nasal spray flu vaccine."
233+
)
234+
end
235+
end
236+
end
202237
end
203238

204239
context "with a consent form" do

0 commit comments

Comments
 (0)