Browse Source

Validate rent_type subquestions (#2109)

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

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

@ -329,14 +329,6 @@ class BulkUpload::Lettings::Year2023::RowParser
},
on: :after_log
validates :field_11,
presence: {
if: proc { renttype == :intermediate },
message: I18n.t("validations.not_answered", question: "intermediate rent type"),
category: :setup,
},
on: :after_log
validates :field_16,
presence: {
if: proc { supported_housing? },
@ -397,6 +389,9 @@ class BulkUpload::Lettings::Year2023::RowParser
validate :validate_incomplete_soft_validations, on: :after_log
validate :validate_correct_intermediate_rent_type, on: :after_log, if: proc { renttype == :intermediate }
validate :validate_correct_affordable_rent_type, on: :after_log, if: proc { renttype == :affordable }
def self.question_for_field(field)
QUESTIONS[field]
end
@ -841,6 +836,18 @@ private
end
end
def validate_correct_intermediate_rent_type
if field_11.blank? || ![1, 2, 3].include?(field_11.to_i)
errors.add(:field_11, I18n.t("validations.not_answered", question: "intermediate rent type"), category: :setup)
end
end
def validate_correct_affordable_rent_type
if field_10.blank? || ![1, 2, 3].include?(field_10.to_i)
errors.add(:field_10, I18n.t("validations.not_answered", question: "is this a London Affordable Rent letting"), category: :setup)
end
end
def setup_question?(question)
log.form.setup_sections[0].subsections[0].questions.include?(question)
end
@ -1327,9 +1334,10 @@ private
when :social
LettingsLog::RENT_TYPE[:social_rent]
when :affordable
if field_10 == 1
case field_10
when 1
LettingsLog::RENT_TYPE[:london_affordable_rent]
else
when 2, 3
LettingsLog::RENT_TYPE[:affordable_rent]
end
when :intermediate

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

@ -803,6 +803,33 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
end
end
context "when intermediate rent and field_11 (Which type of Intermediate Rent) is invalid/gets cleared" do
let(:attributes) { { bulk_upload:, field_5: "9", field_11: "Intermediate rent" } }
it "adds error on field_11" do
expect(parser.errors[:field_5]).to be_present
expect(parser.errors[:field_11]).to eq(["You must answer intermediate rent type"])
end
end
context "when affordable rent and field_10 (Is this a London Affordable Rent letting?) is not given" do
let(:attributes) { { bulk_upload:, field_5: "5", field_10: nil } }
it "adds error on field_10" do
expect(parser.errors[:field_5]).to be_present
expect(parser.errors[:field_10]).to eq(["You must answer is this a London Affordable Rent letting"])
end
end
context "when affordable rent and field_10 (Is this a London Affordable Rent letting?) is invalid/gets cleared" do
let(:attributes) { { bulk_upload:, field_5: "5", field_10: "Intermediate rent" } }
it "adds error on field_10" do
expect(parser.errors[:field_5]).to be_present
expect(parser.errors[:field_10]).to eq(["You must answer is this a London Affordable Rent letting"])
end
end
context "when intermediate rent other and field_12 is not given" do
let(:attributes) { { bulk_upload:, field_5: "9", field_11: "3", field_12: nil } }

Loading…
Cancel
Save