From fa3b5d16a350f94e7122e3dc88968042955e74f0 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Tue, 2 Jan 2024 09:15:51 +0000 Subject: [PATCH] Remove duplicate validations, add correct category (#2106) --- .../lettings/year2023/row_parser.rb | 20 ++----------------- .../lettings/year2023/row_parser_spec.rb | 12 +++++++++++ 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/app/services/bulk_upload/lettings/year2023/row_parser.rb b/app/services/bulk_upload/lettings/year2023/row_parser.rb index 6d4b61f1b..468df787f 100644 --- a/app/services/bulk_upload/lettings/year2023/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2023/row_parser.rb @@ -337,14 +337,6 @@ class BulkUpload::Lettings::Year2023::RowParser }, on: :after_log - validates :field_15, - presence: { - if: proc { supported_housing? && log_uses_old_scheme_id? }, - message: I18n.t("validations.not_answered", question: "management group code"), - category: :setup, - }, - on: :after_log - validates :field_16, presence: { if: proc { supported_housing? }, @@ -353,14 +345,6 @@ class BulkUpload::Lettings::Year2023::RowParser }, on: :after_log - validates :field_17, - presence: { - if: proc { supported_housing? && log_uses_new_scheme_id? }, - message: I18n.t("validations.not_answered", question: "location code"), - category: :setup, - }, - on: :after_log - validates :field_46, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 1 must be a number or the letter R" }, on: :after_log validates :field_52, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 2 must be a number or the letter R" }, on: :after_log, if: proc { details_known?(2).zero? } validates :field_56, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 3 must be a number or the letter R" }, on: :after_log, if: proc { details_known?(3).zero? } @@ -775,7 +759,7 @@ private def validate_location_data_given if supported_housing? && location_id.blank? && location_field.present? block_log_creation! - errors.add(location_field, I18n.t("validations.not_answered", question: "#{location_or_scheme} code"), category: "setup") + errors.add(location_field, I18n.t("validations.not_answered", question: "#{location_or_scheme} code"), category: :setup) end end @@ -789,7 +773,7 @@ private def validate_scheme_data_given if supported_housing? && scheme_field.present? && scheme_id.blank? block_log_creation! - errors.add(scheme_field, I18n.t("validations.not_answered", question: "#{scheme_or_management_group} code"), category: "setup") + errors.add(scheme_field, I18n.t("validations.not_answered", question: "#{scheme_or_management_group} code"), category: :setup) end end diff --git a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb index 6c1c179d4..93059d4b7 100644 --- a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb @@ -900,6 +900,18 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do expect(parser.errors[:field_15]).to be_blank expect(parser.errors[:field_16]).to be_blank expect(parser.errors.where(:field_17, category: :setup).map(&:message)).to eq(["You must answer location code"]) + expect(parser.errors[:field_17].count).to eq(1) + end + end + + context "when missing management group code" do + let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_16: scheme.old_visible_id.to_s, field_15: nil, field_17: nil } } + + it "returns a setup error" do + expect(parser.errors[:field_16]).to be_blank + expect(parser.errors[:field_17]).to be_blank + expect(parser.errors.where(:field_15, category: :setup).map(&:message)).to eq(["You must answer management group code"]) + expect(parser.errors[:field_15].count).to eq(1) end end