diff --git a/app/services/bulk_upload/sales/year2023/row_parser.rb b/app/services/bulk_upload/sales/year2023/row_parser.rb index 05ca8a383..bda3acb9d 100644 --- a/app/services/bulk_upload/sales/year2023/row_parser.rb +++ b/app/services/bulk_upload/sales/year2023/row_parser.rb @@ -310,21 +310,25 @@ class BulkUpload::Sales::Year2023::RowParser validates :field_3, presence: { message: I18n.t("validations.not_answered", question: "sale completion date (day)"), + category: :setup, }, on: :after_log validates :field_4, presence: { message: I18n.t("validations.not_answered", question: "sale completion date (month)"), + category: :setup, }, on: :after_log validates :field_5, presence: { message: I18n.t("validations.not_answered", question: "sale completion date (year)"), + category: :setup, }, format: { with: /\A\d{2}\z/, message: I18n.t("validations.setup.saledate.year_not_two_digits"), + category: :setup, }, on: :after_log validates :field_7, presence: { message: I18n.t("validations.not_answered", question: "ownership type") }, on: :after_log @@ -1102,9 +1106,9 @@ private return if saledate.blank? || bulk_upload.form.blank? unless bulk_upload.form.valid_start_date_for_form?(saledate) - errors.add(:field_3, I18n.t("validations.date.outside_collection_window", year_combo: bulk_upload.year_combo, start_year: bulk_upload.year, end_year: bulk_upload.end_year)) - errors.add(:field_4, I18n.t("validations.date.outside_collection_window", year_combo: bulk_upload.year_combo, start_year: bulk_upload.year, end_year: bulk_upload.end_year)) - errors.add(:field_5, I18n.t("validations.date.outside_collection_window", year_combo: bulk_upload.year_combo, start_year: bulk_upload.year, end_year: bulk_upload.end_year)) + errors.add(:field_3, I18n.t("validations.date.outside_collection_window", year_combo: bulk_upload.year_combo, start_year: bulk_upload.year, end_year: bulk_upload.end_year), category: :setup) + errors.add(:field_4, I18n.t("validations.date.outside_collection_window", year_combo: bulk_upload.year_combo, start_year: bulk_upload.year, end_year: bulk_upload.end_year), category: :setup) + errors.add(:field_5, I18n.t("validations.date.outside_collection_window", year_combo: bulk_upload.year_combo, start_year: bulk_upload.year, end_year: bulk_upload.end_year), category: :setup) end end end diff --git a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb index c6f1fabac..b39d14537 100644 --- a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb @@ -406,18 +406,18 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do context "when one of these fields is blank" do let(:attributes) { setup_section_params.merge({ field_3: "1", field_4: "1", field_5: nil }) } - it "returns an error only on blank field" do + it "returns an error only on blank field as setup error" do expect(parser.errors[:field_3]).to be_blank expect(parser.errors[:field_4]).to be_blank - expect(parser.errors[:field_5]).to be_present + expect(parser.errors.where(:field_5, category: :setup)).to be_present end end context "when field 5 is 4 digits instead of 2" do let(:attributes) { setup_section_params.merge({ bulk_upload:, field_5: "2022" }) } - it "returns an error" do - expect(parser.errors[:field_5]).to include("Sale completion year must be 2 digits") + it "returns a setup error" do + expect(parser.errors.where(:field_5, category: :setup).map(&:message)).to include("Sale completion year must be 2 digits") end end @@ -458,10 +458,10 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do let(:bulk_upload) { create(:bulk_upload, :sales, user:, year: 2022) } - it "returns errors" do - expect(parser.errors[:field_3]).to be_present - expect(parser.errors[:field_4]).to be_present - expect(parser.errors[:field_5]).to be_present + it "returns setup errors" do + expect(parser.errors.where(:field_3, category: :setup)).to be_present + expect(parser.errors.where(:field_4, category: :setup)).to be_present + expect(parser.errors.where(:field_5, category: :setup)).to be_present end end end