Skip to content

Commit e5830a2

Browse files
committed
Validate vaccinator email address if provided
If a vaccinator email address has been provided, even if it's for historical records, we should validate that the email address exists otherwise we currently silently ignore these errors.
1 parent 7cd1f56 commit e5830a2

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

app/models/immunisation_import_row.rb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -421,23 +421,20 @@ def requires_care_setting?
421421
def performed_by_details_present_where_required
422422
if outcome_in_this_academic_year?
423423
errors.add(:performed_by_user, :blank) if performed_by_user.nil?
424-
elsif @programme.hpv? # previous academic years from here on
425-
nil
426-
# no validation required
427-
elsif @programme.flu?
424+
else # previous academic years from here on
428425
email_field_populated =
429426
@data["PERFORMING_PROFESSIONAL_EMAIL"]&.strip.present?
430-
if !email_field_populated &&
431-
(performed_by_given_name.blank? || performed_by_family_name.blank?)
427+
428+
if email_field_populated
429+
errors.add(:performed_by_user, :blank) if performed_by_user.nil?
430+
elsif @programme.flu? # no validation required for HPV
432431
if performed_by_given_name.blank?
433432
errors.add(:performed_by_given_name, :blank)
434433
end
435434
if performed_by_family_name.blank?
436435
errors.add(:performed_by_family_name, :blank)
437436
end
438437
end
439-
else
440-
raise "Unexpected programme"
441438
end
442439
end
443440

spec/models/immunisation_import_row_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,22 @@
343343
it { should be_valid }
344344
end
345345

346+
context "HPV vaccination in previous academic year, vaccinator email provided but doesn't exist" do
347+
let(:data) do
348+
valid_hpv_data.merge(
349+
"PERFORMING_PROFESSIONAL_EMAIL" => "non-existent@example.com",
350+
"DATE_OF_VACCINATION" => "20220101"
351+
)
352+
end
353+
354+
it "has errors" do
355+
expect(immunisation_import_row).to be_invalid
356+
expect(immunisation_import_row.errors[:performed_by_user]).to include(
357+
"Enter a valid email address"
358+
)
359+
end
360+
end
361+
346362
context "Flu vaccination in previous academic year, no vaccinator details provided" do
347363
let(:data) do
348364
valid_flu_data.except(

0 commit comments

Comments
 (0)