Browse Source

Only loop through existing field mappings for errors (#1648)

* Only loop through existing field mapings for errors

* Add a test
pull/1650/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
928af7b6d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      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. 2
      app/services/bulk_upload/sales/year2023/row_parser.rb
  5. 13
      spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb

3
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

2
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)

2
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)

2
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)

13
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

Loading…
Cancel
Save