Browse Source

Remove duplicate validations, add correct category (#2106)

pull/2109/head
kosiakkatrina 12 months ago committed by GitHub
parent
commit
fa3b5d16a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      app/services/bulk_upload/lettings/year2023/row_parser.rb
  2. 12
      spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb

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

@ -337,14 +337,6 @@ class BulkUpload::Lettings::Year2023::RowParser
},
on: :after_log
validates :field_15,
presence: {
if: proc { supported_housing? && log_uses_old_scheme_id? },
message: I18n.t("validations.not_answered", question: "management group code"),
category: :setup,
},
on: :after_log
validates :field_16,
presence: {
if: proc { supported_housing? },
@ -353,14 +345,6 @@ class BulkUpload::Lettings::Year2023::RowParser
},
on: :after_log
validates :field_17,
presence: {
if: proc { supported_housing? && log_uses_new_scheme_id? },
message: I18n.t("validations.not_answered", question: "location code"),
category: :setup,
},
on: :after_log
validates :field_46, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 1 must be a number or the letter R" }, on: :after_log
validates :field_52, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 2 must be a number or the letter R" }, on: :after_log, if: proc { details_known?(2).zero? }
validates :field_56, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 3 must be a number or the letter R" }, on: :after_log, if: proc { details_known?(3).zero? }
@ -775,7 +759,7 @@ private
def validate_location_data_given
if supported_housing? && location_id.blank? && location_field.present?
block_log_creation!
errors.add(location_field, I18n.t("validations.not_answered", question: "#{location_or_scheme} code"), category: "setup")
errors.add(location_field, I18n.t("validations.not_answered", question: "#{location_or_scheme} code"), category: :setup)
end
end
@ -789,7 +773,7 @@ private
def validate_scheme_data_given
if supported_housing? && scheme_field.present? && scheme_id.blank?
block_log_creation!
errors.add(scheme_field, I18n.t("validations.not_answered", question: "#{scheme_or_management_group} code"), category: "setup")
errors.add(scheme_field, I18n.t("validations.not_answered", question: "#{scheme_or_management_group} code"), category: :setup)
end
end

12
spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb

@ -900,6 +900,18 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
expect(parser.errors[:field_15]).to be_blank
expect(parser.errors[:field_16]).to be_blank
expect(parser.errors.where(:field_17, category: :setup).map(&:message)).to eq(["You must answer location code"])
expect(parser.errors[:field_17].count).to eq(1)
end
end
context "when missing management group code" do
let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_16: scheme.old_visible_id.to_s, field_15: nil, field_17: nil } }
it "returns a setup error" do
expect(parser.errors[:field_16]).to be_blank
expect(parser.errors[:field_17]).to be_blank
expect(parser.errors.where(:field_15, category: :setup).map(&:message)).to eq(["You must answer management group code"])
expect(parser.errors[:field_15].count).to eq(1)
end
end

Loading…
Cancel
Save