From b75a551145c08dcdcf6d9c1d7bd5993f43af1874 Mon Sep 17 00:00:00 2001 From: Kat Date: Tue, 2 May 2023 17:22:05 +0100 Subject: [PATCH] Update test based on new validation messages --- app/services/bulk_upload/lettings/year2022/row_parser.rb | 2 +- app/services/bulk_upload/lettings/year2023/row_parser.rb | 2 +- app/services/bulk_upload/sales/year2022/row_parser.rb | 2 +- .../bulk_upload/lettings/year2022/row_parser_spec.rb | 8 +++----- .../bulk_upload/lettings/year2023/row_parser_spec.rb | 8 +++----- .../bulk_upload/sales/year2022/row_parser_spec.rb | 8 +++----- 6 files changed, 12 insertions(+), 18 deletions(-) diff --git a/app/services/bulk_upload/lettings/year2022/row_parser.rb b/app/services/bulk_upload/lettings/year2022/row_parser.rb index c15033265..80b65c133 100644 --- a/app/services/bulk_upload/lettings/year2022/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2022/row_parser.rb @@ -727,7 +727,7 @@ private 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| 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)].join(". ") + 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) end end diff --git a/app/services/bulk_upload/lettings/year2023/row_parser.rb b/app/services/bulk_upload/lettings/year2023/row_parser.rb index abd35c5c8..46ff0ff12 100644 --- a/app/services/bulk_upload/lettings/year2023/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2023/row_parser.rb @@ -469,7 +469,7 @@ private 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| 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)].join(". ") + 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) end end diff --git a/app/services/bulk_upload/sales/year2022/row_parser.rb b/app/services/bulk_upload/sales/year2022/row_parser.rb index 6bdf1f1b5..e53b42ecb 100644 --- a/app/services/bulk_upload/sales/year2022/row_parser.rb +++ b/app/services/bulk_upload/sales/year2022/row_parser.rb @@ -956,7 +956,7 @@ private 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| 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)].join(". ") + 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) end end 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 1d539c13d..25fc64cf9 100644 --- a/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb @@ -957,22 +957,20 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do describe "soft validations" do context "when soft validation is triggered" do - let(:attributes) { setup_section_params.merge({ field_12: 22, field_35: 5, field_20: "F" }) } + let(:attributes) { setup_section_params.merge({ field_12: 22, field_35: 5 }) } it "adds an error to the relevant fields" do soft_validation_errors = parser.errors.select { |e| e.options[:category] == :soft_validation } expect(soft_validation_errors.find { |e| e.attribute == :field_12 }).to be_present - expect(soft_validation_errors.find { |e| e.attribute == :field_20 }).to be_present expect(soft_validation_errors.find { |e| e.attribute == :field_35 }).to be_present end it "populates with correct error message" do soft_validation_errors = parser.errors.select { |e| e.options[:category] == :soft_validation } - expect(soft_validation_errors.find { |e| e.attribute == :field_12 }.message).to eql("You told us this person is under 60 and retired. The minimum expected retirement age for females in England is 60.") - expect(soft_validation_errors.find { |e| e.attribute == :field_20 }.message).to eql("You told us this person is under 60 and retired. The minimum expected retirement age for females in England is 60.") - expect(soft_validation_errors.find { |e| e.attribute == :field_35 }.message).to eql("You told us this person is under 60 and retired. The minimum expected retirement age for females in England is 60.") + expect(soft_validation_errors.find { |e| e.attribute == :field_12 }.message).to eql("You told us this person is aged 22 years and retired.") + expect(soft_validation_errors.find { |e| e.attribute == :field_35 }.message).to eql("You told us this person is aged 22 years and retired.") end 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 ffa4bba32..f98eed6d0 100644 --- a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb @@ -999,22 +999,20 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do describe "soft validations" do context "when soft validation is triggered" do - let(:attributes) { setup_section_params.merge({ field_46: 22, field_50: 5, field_47: "F" }) } + let(:attributes) { setup_section_params.merge({ field_46: 22, field_50: 5 }) } it "adds an error to the relevant fields" do soft_validation_errors = parser.errors.select { |e| e.options[:category] == :soft_validation } expect(soft_validation_errors.find { |e| e.attribute == :field_46 }).to be_present - expect(soft_validation_errors.find { |e| e.attribute == :field_47 }).to be_present expect(soft_validation_errors.find { |e| e.attribute == :field_50 }).to be_present end it "populates with correct error message" do soft_validation_errors = parser.errors.select { |e| e.options[:category] == :soft_validation } - expect(soft_validation_errors.find { |e| e.attribute == :field_46 }.message).to eql("You told us this person is under 60 and retired. The minimum expected retirement age for females in England is 60.") - expect(soft_validation_errors.find { |e| e.attribute == :field_47 }.message).to eql("You told us this person is under 60 and retired. The minimum expected retirement age for females in England is 60.") - expect(soft_validation_errors.find { |e| e.attribute == :field_50 }.message).to eql("You told us this person is under 60 and retired. The minimum expected retirement age for females in England is 60.") + expect(soft_validation_errors.find { |e| e.attribute == :field_46 }.message).to eql("You told us this person is aged 22 years and retired.") + expect(soft_validation_errors.find { |e| e.attribute == :field_50 }.message).to eql("You told us this person is aged 22 years and retired.") end end diff --git a/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb index 70bed8aa6..8c0a4cd45 100644 --- a/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb @@ -523,22 +523,20 @@ RSpec.describe BulkUpload::Sales::Year2022::RowParser do describe "soft validations" do context "when soft validation is triggered" do - let(:attributes) { valid_attributes.merge({ field_7: 22, field_24: 5, field_13: "F" }) } + let(:attributes) { valid_attributes.merge({ field_7: 22, field_24: 5 }) } it "adds an error to the relevant fields" do soft_validation_errors = parser.errors.select { |e| e.options[:category] == :soft_validation } expect(soft_validation_errors.find { |e| e.attribute == :field_7 }).to be_present expect(soft_validation_errors.find { |e| e.attribute == :field_24 }).to be_present - expect(soft_validation_errors.find { |e| e.attribute == :field_13 }).to be_present end it "populates with correct error message" do soft_validation_errors = parser.errors.select { |e| e.options[:category] == :soft_validation } - expect(soft_validation_errors.find { |e| e.attribute == :field_7 }.message).to eql("You told us this person is under 60 and retired. The minimum expected retirement age for females in England is 60.") - expect(soft_validation_errors.find { |e| e.attribute == :field_24 }.message).to eql("You told us this person is under 60 and retired. The minimum expected retirement age for females in England is 60.") - expect(soft_validation_errors.find { |e| e.attribute == :field_13 }.message).to eql("You told us this person is under 60 and retired. The minimum expected retirement age for females in England is 60.") + expect(soft_validation_errors.find { |e| e.attribute == :field_7 }.message).to eql("You told us this person is aged 22 years and retired.") + expect(soft_validation_errors.find { |e| e.attribute == :field_24 }.message).to eql("You told us this person is aged 22 years and retired.") end end end