diff --git a/app/services/bulk_upload/lettings/row_parser.rb b/app/services/bulk_upload/lettings/row_parser.rb index b772d0153..d21063a3a 100644 --- a/app/services/bulk_upload/lettings/row_parser.rb +++ b/app/services/bulk_upload/lettings/row_parser.rb @@ -174,9 +174,11 @@ class BulkUpload::Lettings::RowParser validate :validate_owning_org_permitted validate :validate_owning_org_owns_stock validate :validate_owning_org_exists + validate :validate_owning_org_data_given validate :validate_managing_org_related validate :validate_managing_org_exists + validate :validate_managing_org_data_given validate :validate_scheme_related validate :validate_scheme_exists @@ -222,10 +224,6 @@ class BulkUpload::Lettings::RowParser block_log_creation end - def setup_section_incomplete? - log.form.setup_sections[0].subsections[0].is_incomplete?(log) - end - private def validate_location_related @@ -277,6 +275,12 @@ private def validate_managing_org_exists if managing_organisation.nil? errors.delete(:field_113) + errors.add(:field_113, "The managing organisation code is incorrect") + end + end + + def validate_managing_org_data_given + if field_113.blank? errors.add(:field_113, "The managing organisation code is incorrect", category: :setup) end end @@ -292,6 +296,12 @@ private def validate_owning_org_exists if owning_organisation.nil? errors.delete(:field_111) + errors.add(:field_111, "The owning organisation code is incorrect") + end + end + + def validate_owning_org_data_given + if field_111.blank? errors.add(:field_111, "The owning organisation code is incorrect", category: :setup) end end diff --git a/app/services/bulk_upload/lettings/validator.rb b/app/services/bulk_upload/lettings/validator.rb index 779f0315b..f5450039f 100644 --- a/app/services/bulk_upload/lettings/validator.rb +++ b/app/services/bulk_upload/lettings/validator.rb @@ -175,7 +175,7 @@ class BulkUpload::Lettings::Validator end def create_logs? - return false if any_setup_sections_incomplete? + return false if any_setup_errors? return false if over_column_error_threshold? return false if row_parsers.any?(&:block_log_creation?) @@ -186,8 +186,12 @@ class BulkUpload::Lettings::Validator QUESTIONS[field] end - def any_setup_sections_incomplete? - row_parsers.any?(&:setup_section_incomplete?) + def any_setup_errors? + bulk_upload + .bulk_upload_errors + .where(category: "setup") + .count + .positive? end private diff --git a/app/services/bulk_upload/processor.rb b/app/services/bulk_upload/processor.rb index dcf68e594..ab4fe50a7 100644 --- a/app/services/bulk_upload/processor.rb +++ b/app/services/bulk_upload/processor.rb @@ -12,7 +12,7 @@ class BulkUpload::Processor validator.call - if validator.any_setup_sections_incomplete? + if validator.any_setup_errors? send_setup_errors_mail elsif validator.create_logs? create_logs diff --git a/spec/services/bulk_upload/lettings/row_parser_spec.rb b/spec/services/bulk_upload/lettings/row_parser_spec.rb index 73b35d70c..ca4afda4e 100644 --- a/spec/services/bulk_upload/lettings/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/row_parser_spec.rb @@ -619,6 +619,16 @@ RSpec.describe BulkUpload::Lettings::RowParser do end describe "#field_111" do # owning org + context "when no data given" do + let(:attributes) { { bulk_upload:, field_1: "1", field_111: "" } } + + it "is not permitted as setup error" do + setup_errors = parser.errors.select { |e| e.options[:category] == :setup } + + expect(setup_errors.find { |e| e.attribute == :field_111 }.message).to eql("The owning organisation code is incorrect") + end + end + context "when cannot find owning org" do let(:attributes) { { bulk_upload:, field_111: "donotexist" } } diff --git a/spec/services/bulk_upload/lettings/validator_spec.rb b/spec/services/bulk_upload/lettings/validator_spec.rb index b9d351281..ba48bd9e7 100644 --- a/spec/services/bulk_upload/lettings/validator_spec.rb +++ b/spec/services/bulk_upload/lettings/validator_spec.rb @@ -53,7 +53,7 @@ RSpec.describe BulkUpload::Lettings::Validator do expect(error.col).to eql("L") expect(error.category).to be_nil - error = BulkUploadError.order(:row, :field).find_by(field: "field_111") + error = BulkUploadError.find_by(row: "7", category: "setup", field: "field_111") expect(error.category).to eql("setup") end diff --git a/spec/services/bulk_upload/processor_spec.rb b/spec/services/bulk_upload/processor_spec.rb index 48b0c0258..8aaef8c36 100644 --- a/spec/services/bulk_upload/processor_spec.rb +++ b/spec/services/bulk_upload/processor_spec.rb @@ -106,7 +106,7 @@ RSpec.describe BulkUpload::Processor do BulkUpload::Lettings::Validator, invalid?: false, call: nil, - any_setup_sections_incomplete?: true, + any_setup_errors?: true, ) end @@ -142,7 +142,7 @@ RSpec.describe BulkUpload::Processor do BulkUpload::Lettings::Validator, invalid?: false, call: nil, - any_setup_sections_incomplete?: false, + any_setup_errors?: false, create_logs?: true, ) end @@ -193,7 +193,7 @@ RSpec.describe BulkUpload::Processor do BulkUpload::Lettings::Validator, invalid?: false, call: nil, - any_setup_sections_incomplete?: false, + any_setup_errors?: false, create_logs?: false, ) end @@ -254,7 +254,7 @@ RSpec.describe BulkUpload::Processor do BulkUpload::Lettings::Validator, call: nil, create_logs?: true, - any_setup_sections_incomplete?: false, + any_setup_errors?: false, invalid?: false, ) end