From 1e5859e49634b69342a3063837a81e597060354d Mon Sep 17 00:00:00 2001 From: Kat Date: Fri, 6 Jan 2023 16:18:27 +0000 Subject: [PATCH] Fix null error setting and add builtype --- .../bulk_upload/lettings/row_parser.rb | 7 +++-- .../bulk_upload/lettings/row_parser_spec.rb | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/app/services/bulk_upload/lettings/row_parser.rb b/app/services/bulk_upload/lettings/row_parser.rb index dd40362e9..1b69e7275 100644 --- a/app/services/bulk_upload/lettings/row_parser.rb +++ b/app/services/bulk_upload/lettings/row_parser.rb @@ -196,8 +196,9 @@ private end def validate_nulls - field_mapping_for_errors.each do |question, fields| - question = questions.find { |q| q.id == question } + field_mapping_for_errors.each do |error_key, fields| + question_id = error_key.to_s + question = questions.find { |q| q.id == question_id } next unless question next if log.optional_fields.include?(question.id) @@ -222,6 +223,7 @@ private rent_type: %i[field_1 field_129 field_130], startdate: %i[field_98 field_97 field_96], unittype_gn: %i[field_102], + builtype: %i[field_103], } end @@ -286,6 +288,7 @@ private attributes["rent_type"] = rent_type attributes["startdate"] = startdate attributes["unittype_gn"] = field_102 + attributes["builtype"] = field_103 attributes end diff --git a/spec/services/bulk_upload/lettings/row_parser_spec.rb b/spec/services/bulk_upload/lettings/row_parser_spec.rb index 300c83c8e..e75087369 100644 --- a/spec/services/bulk_upload/lettings/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/row_parser_spec.rb @@ -7,6 +7,18 @@ RSpec.describe BulkUpload::Lettings::RowParser do let(:bulk_upload) { create(:bulk_upload, :lettings) } let(:owning_org) { create(:organisation) } let(:managing_org) { create(:organisation) } + let(:setup_section_params) do + { + field_1: "1", + field_111: owning_org.old_visible_id, + field_113: managing_org.old_visible_id, + bulk_upload:, + field_96: "1", + field_97: "1", + field_98: "2023", + field_134: "0", + } + end around do |example| FormHandler.instance.use_real_forms! @@ -50,6 +62,7 @@ RSpec.describe BulkUpload::Lettings::RowParser do field_130: "1", field_134: "0", field_102: "2", + field_103: "1", } end @@ -158,5 +171,23 @@ RSpec.describe BulkUpload::Lettings::RowParser do end end end + + describe "#field_103" do + context "when null" do + let(:attributes) { setup_section_params.merge({ field_103: nil }) } + + it "returns an error" do + expect(parser.errors[:field_103]).to be_present + end + end + + context "when unpermitted values" do + let(:attributes) { setup_section_params.merge({ field_103: "4" }) } + + it "returns an error" do + expect(parser.errors[:field_103]).to be_present + end + end + end end end