Browse Source

Validate that rent_type can be set (#1492)

pull/1504/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
311d83e62c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      app/services/bulk_upload/lettings/year2022/row_parser.rb
  2. 20
      spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb

11
app/services/bulk_upload/lettings/year2022/row_parser.rb

@ -129,7 +129,7 @@ class BulkUpload::Lettings::Year2022::RowParser
field_124: "Memory",
field_125: "Mental health",
field_126: "Stamina or breathing or fatigue",
field_127: "Socially or behaviourally, for example associated with autism spectral disorder (ASD) which includes Aspergers' or attention deficit hyperactivity disorder (ADHD)",
field_127: "Socially or behaviourally, for example associated with autism spectral disorder (ASD) which include Aspergers' or attention deficit hyperactivity disorder (ADHD)",
field_128: "Other",
field_129: "Is this letting a London Affordable Rent letting?",
field_130: "Which type of Intermediate Rent is this letting?",
@ -327,6 +327,7 @@ class BulkUpload::Lettings::Year2022::RowParser
validate :validate_created_by_exists
validate :validate_created_by_related
validate :validate_rent_type
def self.question_for_field(field)
QUESTIONS[field]
@ -611,6 +612,14 @@ private
end
end
def validate_rent_type
if [9, 10, 11, 12].include?(field_1) && field_130.blank?
errors.add(:field_130, I18n.t("validations.not_answered", question: "intermediate rent type"), category: :setup)
elsif [5, 6, 7, 8].include?(field_1) && field_129.blank?
errors.add(:field_129, I18n.t("validations.not_answered", question: "affordable rent type"), category: :setup)
end
end
def postcode_full
"#{field_108} #{field_109}" if field_108 && field_109
end

20
spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb

@ -228,6 +228,26 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do
end
end
context "when lettype is intermediate rent and intermediate rent type is not selected" do
let(:attributes) { valid_attributes.merge(field_1: "11", field_130: nil) }
it "has errors on setup field" do
errors = parser.errors.select { |e| e.options[:category] == :setup }.map(&:attribute)
expect(errors).to eql(%i[field_130])
end
end
context "when lettype is affordable rent and affordable rent type is not selected" do
let(:attributes) { valid_attributes.merge(field_1: "5", field_130: nil) }
it "has errors on setup field" do
errors = parser.errors.select { |e| e.options[:category] == :setup }.map(&:attribute)
expect(errors).to eql(%i[field_129])
end
end
describe "#field_1" do
context "when null" do
let(:attributes) { { bulk_upload:, field_1: nil, field_4: "1" } }

Loading…
Cancel
Save