Browse Source

Update test based on new validation messages

pull/1594/head
Kat 3 years ago
parent
commit
b75a551145
  1. 2
      app/services/bulk_upload/lettings/year2022/row_parser.rb
  2. 2
      app/services/bulk_upload/lettings/year2023/row_parser.rb
  3. 2
      app/services/bulk_upload/sales/year2022/row_parser.rb
  4. 8
      spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb
  5. 8
      spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb
  6. 8
      spec/services/bulk_upload/sales/year2022/row_parser_spec.rb

2
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

2
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

2
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

8
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

8
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

8
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

Loading…
Cancel
Save