diff --git a/app/services/bulk_upload/lettings/year2022/row_parser.rb b/app/services/bulk_upload/lettings/year2022/row_parser.rb index c6c92b58e..00bdb2d7e 100644 --- a/app/services/bulk_upload/lettings/year2022/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2022/row_parser.rb @@ -770,7 +770,7 @@ private next if question.completed?(log) question.page.interruption_screen_question_ids.each do |interruption_screen_question_id| - field_mapping_for_errors[interruption_screen_question_id.to_sym].each do |field| + field_mapping_for_errors[interruption_screen_question_id.to_sym]&.each do |field| unless errors.any? { |e| e.options[:category] == :soft_validation && field_mapping_for_errors[interruption_screen_question_id.to_sym].include?(e.attribute) } error_message = [display_title_text(question.page.title_text, log), display_informative_text(question.page.informative_text, log)].reject(&:empty?).join(". ") errors.add(field, message: error_message, category: :soft_validation) @@ -956,6 +956,7 @@ private mrcdate: %i[field_92 field_93 field_94], voiddate: %i[field_89 field_90 field_91], + is_carehome: %i[field_85], } end diff --git a/app/services/bulk_upload/lettings/year2023/row_parser.rb b/app/services/bulk_upload/lettings/year2023/row_parser.rb index 48eb02d60..8c9de5f62 100644 --- a/app/services/bulk_upload/lettings/year2023/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2023/row_parser.rb @@ -515,7 +515,7 @@ private next if question.completed?(log) question.page.interruption_screen_question_ids.each do |interruption_screen_question_id| - field_mapping_for_errors[interruption_screen_question_id.to_sym].each do |field| + field_mapping_for_errors[interruption_screen_question_id.to_sym]&.each do |field| unless errors.any? { |e| field_mapping_for_errors[interruption_screen_question_id.to_sym].include?(e.attribute) } error_message = [display_title_text(question.page.title_text, log), display_informative_text(question.page.informative_text, log)].reject(&:empty?).join(". ") errors.add(field, message: error_message, category: :soft_validation) diff --git a/app/services/bulk_upload/sales/year2022/row_parser.rb b/app/services/bulk_upload/sales/year2022/row_parser.rb index 6dfb6512d..405975974 100644 --- a/app/services/bulk_upload/sales/year2022/row_parser.rb +++ b/app/services/bulk_upload/sales/year2022/row_parser.rb @@ -996,7 +996,7 @@ private next if question.completed?(log) question.page.interruption_screen_question_ids.each do |interruption_screen_question_id| - field_mapping_for_errors[interruption_screen_question_id.to_sym].each do |field| + field_mapping_for_errors[interruption_screen_question_id.to_sym]&.each do |field| unless errors.any? { |e| e.options[:category] == :soft_validation && field_mapping_for_errors[interruption_screen_question_id.to_sym].include?(e.attribute) } error_message = [display_title_text(question.page.title_text, log), display_informative_text(question.page.informative_text, log)].reject(&:empty?).join(". ") errors.add(field, message: error_message, category: :soft_validation) diff --git a/app/services/bulk_upload/sales/year2023/row_parser.rb b/app/services/bulk_upload/sales/year2023/row_parser.rb index de23cb41e..1475269e0 100644 --- a/app/services/bulk_upload/sales/year2023/row_parser.rb +++ b/app/services/bulk_upload/sales/year2023/row_parser.rb @@ -1211,7 +1211,7 @@ private next if question.completed?(log) question.page.interruption_screen_question_ids.each do |interruption_screen_question_id| - field_mapping_for_errors[interruption_screen_question_id.to_sym].each do |field| + field_mapping_for_errors[interruption_screen_question_id.to_sym]&.each do |field| unless errors.any? { |e| e.options[:category] == :soft_validation && field_mapping_for_errors[interruption_screen_question_id.to_sym].include?(e.attribute) } error_message = [display_title_text(question.page.title_text, log), display_informative_text(question.page.informative_text, log)].reject(&:empty?).join(". ") errors.add(field, message: error_message, category: :soft_validation) diff --git a/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb index 0e0a3c961..e107d1662 100644 --- a/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb @@ -13,6 +13,7 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do let(:managing_org) { create(:organisation, :with_old_visible_id) } let(:scheme) { create(:scheme, :with_old_visible_id, owning_organisation: owning_org) } let(:location) { create(:location, :with_old_visible_id, scheme:) } + let(:mock_interrupion_ids) {} let(:setup_section_params) do { @@ -147,6 +148,7 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do end before do + mock_interrupion_ids create(:organisation_relationship, parent_organisation: owning_org, child_organisation: managing_org) end @@ -987,6 +989,17 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do expect(parser.errors.where(:field_35, category: :soft_validation).first.message).to eql("You told us this person is aged 22 years and retired.") end end + + context "when soft validation is triggered and the mappings for errors are not defined" do + let(:attributes) { setup_section_params.merge({ field_12: 22, field_35: 5 }) } + # rubocop:disable RSpec/AnyInstance + let(:mock_interrupion_ids) { allow_any_instance_of(Form::Page).to receive(:interruption_screen_question_ids).and_return(%w[fake_question_id]) } + # rubocop:enable RSpec/AnyInstance + + it "does not crash" do + expect(parser.errors).to be_present + end + end end end