From e447b7c9d9678de5b797cb26cef746e58c97e5eb Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Wed, 15 Mar 2023 11:21:12 +0000 Subject: [PATCH] add field_4 as 23/24 setup field --- .../bulk_upload/lettings/year2023/row_parser.rb | 8 +++++++- .../lettings/year2023/row_parser_spec.rb | 16 +++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/services/bulk_upload/lettings/year2023/row_parser.rb b/app/services/bulk_upload/lettings/year2023/row_parser.rb index 375e0ae2e..f1e4e1f82 100644 --- a/app/services/bulk_upload/lettings/year2023/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2023/row_parser.rb @@ -298,6 +298,7 @@ class BulkUpload::Lettings::Year2023::RowParser validates :field_9, format: { with: /\A\d{2}\z/, message: I18n.t("validations.setup.startdate.year_not_two_digits") } + validate :validate_needs_type_present validate :validate_data_types validate :validate_nulls validate :validate_relevant_collection_window @@ -376,6 +377,12 @@ class BulkUpload::Lettings::Year2023::RowParser private + def validate_needs_type_present + if field_4.blank? + errors.add(:field_4, I18n.t("validations.not_answered", question: "what is the needs type?"), category: :setup) + end + end + def start_date return if field_7.blank? || field_8.blank? || field_9.blank? @@ -752,7 +759,6 @@ private log.form.subsections.flat_map { |ss| ss.applicable_questions(log) } end - # TODO: whole method needs re-mapping def attributes_for_log attributes = {} 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 3a4e7f484..d88388839 100644 --- a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb @@ -223,7 +223,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do it "has errors on setup fields" do errors = parser.errors.select { |e| e.options[:category] == :setup }.map(&:attribute) - expect(errors).to eql(%i[field_5 field_7 field_8 field_9 field_1 field_2]) + expect(errors).to eql(%i[field_4 field_5 field_7 field_8 field_9 field_1 field_2]) end end @@ -641,6 +641,20 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do end end + describe "#field_4" do + context "when blank" do + let(:attributes) { { bulk_upload:, field_4: nil, field_13: "123" } } + + it "is reported as a setup error" do + errors = parser.errors.select { |e| e.options[:category] == :setup } + error = errors.find { |e| e.attribute == :field_4 } + + expect(error).to be_present + expect(error.type).to eql("You must answer what is the needs type?") + end + end + end + describe "#field_6" do context "when an unpermitted value" do let(:attributes) { { bulk_upload:, field_6: "3" } }