From be781903fdb9de7584956e70553d4042448687ac Mon Sep 17 00:00:00 2001 From: Sam Seed Date: Mon, 3 Apr 2023 17:33:09 +0100 Subject: [PATCH] feat: add validation to check UPRN exists if address doesn't --- app/services/bulk_upload/lettings/year2023/row_parser.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/services/bulk_upload/lettings/year2023/row_parser.rb b/app/services/bulk_upload/lettings/year2023/row_parser.rb index 84f30cc7b..cf2bb9b59 100644 --- a/app/services/bulk_upload/lettings/year2023/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2023/row_parser.rb @@ -334,6 +334,8 @@ class BulkUpload::Lettings::Year2023::RowParser validate :validate_valid_radio_option, on: :before_log + validate :validate_uprn_exists_if_address_does_not + def self.question_for_field(field) QUESTIONS[field] end @@ -431,6 +433,12 @@ private @created_by ||= User.find_by(email: field_3) end + def validate_uprn_exists_if_address_does_not + if field_18.blank? && field_19.blank? && field_21.blank? + errors.add(:field_18, I18n.t("validations.not_answered", question: "UPRN known")) + end + end + def validate_needs_type_present if field_4.blank? errors.add(:field_4, I18n.t("validations.not_answered", question: "needs type"))