Browse Source

tag bulk upload setup errors for downsteam use

pull/1358/head
Phil Lee 3 years ago
parent
commit
9d1b472093
  1. 20
      app/services/bulk_upload/lettings/row_parser.rb
  2. 10
      spec/services/bulk_upload/lettings/row_parser_spec.rb

20
app/services/bulk_upload/lettings/row_parser.rb

@ -226,7 +226,7 @@ private
def validate_location_exists
if scheme && field_5.present? && location.nil?
errors.add(:field_5, "Location could be found with provided scheme code")
errors.add(:field_5, "Location could be found with provided scheme code", category: :setup)
end
end
@ -244,7 +244,7 @@ private
def validate_scheme_exists
if field_4.present? && scheme.nil?
errors.add(:field_4, "The management group code is not correct")
errors.add(:field_4, "The management group code is not correct", category: :setup)
end
end
@ -258,7 +258,7 @@ private
def validate_managing_org_exists
if managing_organisation.nil?
errors.delete(:field_113)
errors.add(:field_113, "The managing organisation code is incorrect")
errors.add(:field_113, "The managing organisation code is incorrect", category: :setup)
end
end
@ -273,7 +273,7 @@ private
def validate_owning_org_exists
if owning_organisation.nil?
errors.delete(:field_111)
errors.add(:field_111, "The owning organisation code is incorrect")
errors.add(:field_111, "The owning organisation code is incorrect", category: :setup)
end
end
@ -391,10 +391,18 @@ private
next if log.optional_fields.include?(question.id)
next if question.completed?(log)
fields.each { |field| errors.add(field, I18n.t("validations.not_answered", question: question.check_answer_label&.downcase)) }
if setup_question?(question)
fields.each { |field| errors.add(field, I18n.t("validations.not_answered", question: question.check_answer_label&.downcase), category: :setup) }
else
fields.each { |field| errors.add(field, I18n.t("validations.not_answered", question: question.check_answer_label&.downcase)) }
end
end
end
def setup_question?(question)
log.form.setup_sections[0].subsections[0].questions.include?(question)
end
def field_mapping_for_errors
{
lettype: [:field_1],
@ -402,6 +410,8 @@ private
postcode_known: %i[field_107 field_108 field_109],
postcode_full: %i[field_107 field_108 field_109],
la: %i[field_107],
owning_organisation: [:field_111],
managing_organisation: [:field_113],
owning_organisation_id: [:field_111],
managing_organisation_id: [:field_113],
renewal: [:field_134],

10
spec/services/bulk_upload/lettings/row_parser_spec.rb

@ -210,6 +210,16 @@ RSpec.describe BulkUpload::Lettings::RowParser do
end
end
context "when setup section not complete" do
let(:attributes) { { bulk_upload:, field_7: "123" } }
it "has errors on setup fields" do
errors = parser.errors.select { |e| e.options[:category] == :setup }.map(&:attribute)
expect(errors).to eql(%i[field_1 field_129 field_130 field_98 field_97 field_96 field_111 field_113])
end
end
describe "#field_1" do
context "when null" do
let(:attributes) { { bulk_upload:, field_1: nil, field_4: "1" } }

Loading…
Cancel
Save