Skip to content

Commit 4aa4dc8

Browse files
Add UUID + SESSION_ID validation check
This is a nonsensical case which causes an error. As such it should be validated out.
1 parent 96f4d90 commit 4aa4dc8

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

app/models/immunisation_import_row.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,15 @@ def validate_school_urn
939939

940940
def validate_session_id
941941
if session_id.present?
942-
if session_id.to_i.nil?
942+
if uuid.present? &&
943+
VaccinationRecord.find_by(
944+
uuid: uuid.to_s
945+
)&.sourced_from_nhs_immunisations_api?
946+
errors.add(
947+
session_id.header,
948+
"A session ID cannot be provided for this record; this record was sourced from an external source."
949+
)
950+
elsif session_id.to_i.nil?
943951
errors.add(
944952
session_id.header,
945953
"The session ID is not recognised. Download the offline spreadsheet " \

spec/models/immunisation_import_row_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,37 @@
794794
end
795795
end
796796

797+
context "vaccination in a session, but UUID matches a record sourced from NHS immunisations API" do
798+
let(:data) do
799+
{
800+
"VACCINATED" => "Y",
801+
"PROGRAMME" => "Flu",
802+
"SESSION_ID" => 1,
803+
"DATE_OF_VACCINATION" => "#{AcademicYear.current}0901",
804+
"UUID" => "12345678-1234-1234-1234-123456789abc"
805+
}
806+
end
807+
808+
before do
809+
create(
810+
:vaccination_record,
811+
programme: create(:programme, :flu),
812+
uuid: "12345678-1234-1234-1234-123456789abc",
813+
source: :nhs_immunisations_api
814+
)
815+
end
816+
817+
it "has errors" do
818+
expect(immunisation_import_row).to be_invalid
819+
expect(immunisation_import_row.errors["SESSION_ID"]).to eq(
820+
[
821+
"A session ID cannot be provided for this record; " \
822+
"this record was sourced from an external source."
823+
]
824+
)
825+
end
826+
end
827+
797828
context "with valid fields for Flu" do
798829
let(:programmes) { [create(:programme, :flu)] }
799830

0 commit comments

Comments
 (0)