Browse Source

CLDC-4432: Skip invalid field errors if the question is not routed to (#3322)

* CLDC-4432: Skip invalid field errors if the question is not routed to

* CLDC-4432: Add tests

* CLDC-4432: Lint

* fixup! CLDC-4432: Add tests

comment test dependencies
main
Samuel Young 4 days ago committed by GitHub
parent
commit
1dbcd70bb8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 8
      app/services/bulk_upload/lettings/year2025/row_parser.rb
  2. 8
      app/services/bulk_upload/lettings/year2026/row_parser.rb
  3. 8
      app/services/bulk_upload/sales/year2025/row_parser.rb
  4. 8
      app/services/bulk_upload/sales/year2026/row_parser.rb
  5. 15
      spec/services/bulk_upload/lettings/year2025/row_parser_spec.rb
  6. 15
      spec/services/bulk_upload/lettings/year2026/row_parser_spec.rb
  7. 18
      spec/services/bulk_upload/sales/year2025/row_parser_spec.rb
  8. 18
      spec/services/bulk_upload/sales/year2026/row_parser_spec.rb

8
app/services/bulk_upload/lettings/year2025/row_parser.rb

@ -1035,6 +1035,14 @@ private
def add_errors_for_invalid_fields def add_errors_for_invalid_fields
invalid_fields.each do |field| invalid_fields.each do |field|
# ensure questions not routed to are not included in error report
error_questions_ids = field_mapping_for_errors
.select { |_k, fields| fields.map(&:to_s).include?(field.to_s) }
.keys
.map(&:to_s)
error_questions = questions.select { |question| error_questions_ids.include?(question.id) }
next if error_questions.none? { |question| question.page.routed_to?(log, nil) }
errors.delete(field) # take precedence over any other errors as this is a BU format issue errors.delete(field) # take precedence over any other errors as this is a BU format issue
errors.add(field, I18n.t("#{ERROR_BASE_KEY}.invalid_option", question: QUESTIONS[field.to_sym])) errors.add(field, I18n.t("#{ERROR_BASE_KEY}.invalid_option", question: QUESTIONS[field.to_sym]))
end end

8
app/services/bulk_upload/lettings/year2026/row_parser.rb

@ -1113,6 +1113,14 @@ private
def add_errors_for_invalid_fields def add_errors_for_invalid_fields
invalid_fields.each do |field| invalid_fields.each do |field|
# ensure questions not routed to are not included in error report
error_questions_ids = field_mapping_for_errors
.select { |_k, fields| fields.map(&:to_s).include?(field.to_s) }
.keys
.map(&:to_s)
error_questions = questions.select { |question| error_questions_ids.include?(question.id) }
next if error_questions.none? { |question| question.page.routed_to?(log, nil) }
errors.delete(field) # take precedence over any other errors as this is a BU format issue errors.delete(field) # take precedence over any other errors as this is a BU format issue
errors.add(field, I18n.t("#{ERROR_BASE_KEY}.invalid_option", question: QUESTIONS[field.to_sym])) errors.add(field, I18n.t("#{ERROR_BASE_KEY}.invalid_option", question: QUESTIONS[field.to_sym]))
end end

8
app/services/bulk_upload/sales/year2025/row_parser.rb

@ -689,6 +689,14 @@ private
def add_errors_for_invalid_fields def add_errors_for_invalid_fields
invalid_fields.each do |field| invalid_fields.each do |field|
# ensure questions not routed to are not included in error report
error_questions_ids = field_mapping_for_errors
.select { |_k, fields| fields.map(&:to_s).include?(field.to_s) }
.keys
.map(&:to_s)
error_questions = questions.select { |question| error_questions_ids.include?(question.id) }
next if error_questions.none? { |question| question.page.routed_to?(log, nil) }
errors.delete(field) # take precedence over any other errors as this is a BU format issue errors.delete(field) # take precedence over any other errors as this is a BU format issue
errors.add(field, I18n.t("#{ERROR_BASE_KEY}.invalid_option", question: QUESTIONS[field.to_sym])) errors.add(field, I18n.t("#{ERROR_BASE_KEY}.invalid_option", question: QUESTIONS[field.to_sym]))
end end

8
app/services/bulk_upload/sales/year2026/row_parser.rb

@ -750,6 +750,14 @@ private
def add_errors_for_invalid_fields def add_errors_for_invalid_fields
invalid_fields.each do |field| invalid_fields.each do |field|
# ensure questions not routed to are not included in error report
error_questions_ids = field_mapping_for_errors
.select { |_k, fields| fields.map(&:to_s).include?(field.to_s) }
.keys
.map(&:to_s)
error_questions = questions.select { |question| error_questions_ids.include?(question.id) }
next if error_questions.none? { |question| question.page.routed_to?(log, nil) }
errors.delete(field) # take precedence over any other errors as this is a BU format issue errors.delete(field) # take precedence over any other errors as this is a BU format issue
errors.add(field, I18n.t("#{ERROR_BASE_KEY}.invalid_option", question: QUESTIONS[field.to_sym])) errors.add(field, I18n.t("#{ERROR_BASE_KEY}.invalid_option", question: QUESTIONS[field.to_sym]))
end end

15
spec/services/bulk_upload/lettings/year2025/row_parser_spec.rb

@ -646,9 +646,9 @@ RSpec.describe BulkUpload::Lettings::Year2025::RowParser do
end end
describe "invalid fields" do describe "invalid fields" do
context "when a field has been marked as invalid" do
let(:attributes) { setup_section_params.merge({ field_45: 0 }) } let(:attributes) { setup_section_params.merge({ field_45: 0 }) }
context "when a field has been marked as invalid" do
before do before do
parser.add_invalid_field("field_45") parser.add_invalid_field("field_45")
end end
@ -659,6 +659,19 @@ RSpec.describe BulkUpload::Lettings::Year2025::RowParser do
expect(parser.errors[:field_45]).to include(I18n.t("validations.lettings.2025.bulk_upload.invalid_option", question: "What is the lead tenant’s nationality?")) expect(parser.errors[:field_45]).to include(I18n.t("validations.lettings.2025.bulk_upload.invalid_option", question: "What is the lead tenant’s nationality?"))
end end
end end
context "when a field has been marked as invalid but it is not routed to" do
let(:attributes) { setup_section_params.merge({ field_117: 2 }) }
before do
parser.add_invalid_field("field_118")
end
it "does not set an error on that field" do
parser.valid?
expect(parser.errors[:field_118].size).to eq(0)
end
end
end end
end end
end end

15
spec/services/bulk_upload/lettings/year2026/row_parser_spec.rb

@ -538,9 +538,9 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
end end
describe "invalid fields" do describe "invalid fields" do
context "when a field has been marked as invalid" do
let(:attributes) { setup_section_params.merge({ field_46: 0 }) } let(:attributes) { setup_section_params.merge({ field_46: 0 }) }
context "when a field has been marked as invalid" do
before do before do
parser.add_invalid_field("field_46") parser.add_invalid_field("field_46")
end end
@ -551,6 +551,19 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
expect(parser.errors[:field_46]).to include(match(I18n.t("validations.lettings.2026.bulk_upload.invalid_option", question: "What is the lead tenant’s nationality?"))) expect(parser.errors[:field_46]).to include(match(I18n.t("validations.lettings.2026.bulk_upload.invalid_option", question: "What is the lead tenant’s nationality?")))
end end
end end
context "when a field has been marked as invalid but it is not routed to" do
let(:attributes) { setup_section_params.merge({ field_135: 2 }) }
before do
parser.add_invalid_field("field_136")
end
it "does not set an error on that field" do
parser.valid?
expect(parser.errors[:field_136].size).to eq(0)
end
end
end end
end end

18
spec/services/bulk_upload/sales/year2025/row_parser_spec.rb

@ -338,9 +338,10 @@ RSpec.describe BulkUpload::Sales::Year2025::RowParser do
end end
describe "invalid fields" do describe "invalid fields" do
let(:attributes) { setup_section_params.merge({ field_31: 0 }) }
context "when a field has been marked as invalid" do context "when a field has been marked as invalid" do
# field_34 nationality is only shown if field_10 staircasing is no
let(:attributes) { setup_section_params.merge({ field_10: 2, field_31: 0 }) }
before do before do
parser.add_invalid_field("field_31") parser.add_invalid_field("field_31")
end end
@ -351,6 +352,19 @@ RSpec.describe BulkUpload::Sales::Year2025::RowParser do
expect(parser.errors[:field_31]).to include(match(I18n.t("validations.sales.2025.bulk_upload.invalid_option", question: "What is buyer 1’s nationality?"))) expect(parser.errors[:field_31]).to include(match(I18n.t("validations.sales.2025.bulk_upload.invalid_option", question: "What is buyer 1’s nationality?")))
end end
end end
context "when a field has been marked as invalid but it is not routed to" do
let(:attributes) { setup_section_params.merge({ field_10: 1, field_31: 0 }) }
before do
parser.add_invalid_field("field_31")
end
it "does not set an error on that field" do
parser.valid?
expect(parser.errors[:field_31].size).to eq(0)
end
end
end end
end end
end end

18
spec/services/bulk_upload/sales/year2026/row_parser_spec.rb

@ -344,9 +344,10 @@ RSpec.describe BulkUpload::Sales::Year2026::RowParser do
end end
describe "invalid fields" do describe "invalid fields" do
let(:attributes) { setup_section_params.merge({ field_34: 0 }) }
context "when a field has been marked as invalid" do context "when a field has been marked as invalid" do
# field_34 nationality is only shown if field_10 staircasing is no
let(:attributes) { setup_section_params.merge({ field_10: 2, field_34: 0 }) }
before do before do
parser.add_invalid_field("field_34") parser.add_invalid_field("field_34")
end end
@ -357,6 +358,19 @@ RSpec.describe BulkUpload::Sales::Year2026::RowParser do
expect(parser.errors[:field_34]).to include(match(I18n.t("validations.sales.2026.bulk_upload.invalid_option", question: "What is buyer 1's nationality?"))) expect(parser.errors[:field_34]).to include(match(I18n.t("validations.sales.2026.bulk_upload.invalid_option", question: "What is buyer 1's nationality?")))
end end
end end
context "when a field has been marked as invalid but it is not routed to" do
let(:attributes) { setup_section_params.merge({ field_10: 1, field_34: 0 }) }
before do
parser.add_invalid_field("field_34")
end
it "does not set an error on that field" do
parser.valid?
expect(parser.errors[:field_34].size).to eq(0)
end
end
end end
end end
end end

Loading…
Cancel
Save