Browse Source

Add errors for optional soft validations

pull/1594/head
Kat 3 years ago
parent
commit
356f026eba
  1. 1
      app/services/bulk_upload/lettings/year2022/row_parser.rb
  2. 1
      app/services/bulk_upload/lettings/year2023/row_parser.rb
  3. 1
      app/services/bulk_upload/sales/year2022/row_parser.rb
  4. 28
      spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb

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

@ -721,7 +721,6 @@ private
routed_to_soft_validation_questions = log.form.questions.filter { |q| q.type == "interruption_screen" && q.page.routed_to?(log, nil) } routed_to_soft_validation_questions = log.form.questions.filter { |q| q.type == "interruption_screen" && q.page.routed_to?(log, nil) }
routed_to_soft_validation_questions.each do |question| routed_to_soft_validation_questions.each do |question|
next unless question next unless question
next if log.optional_fields.include?(question.id)
next if question.completed?(log) next if question.completed?(log)
question.page.interruption_screen_question_ids.each do |interruption_screen_question_id| question.page.interruption_screen_question_ids.each do |interruption_screen_question_id|

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

@ -463,7 +463,6 @@ private
routed_to_soft_validation_questions = log.form.questions.filter { |q| q.type == "interruption_screen" && q.page.routed_to?(log, nil) } routed_to_soft_validation_questions = log.form.questions.filter { |q| q.type == "interruption_screen" && q.page.routed_to?(log, nil) }
routed_to_soft_validation_questions.each do |question| routed_to_soft_validation_questions.each do |question|
next unless question next unless question
next if log.optional_fields.include?(question.id)
next if question.completed?(log) next if question.completed?(log)
question.page.interruption_screen_question_ids.each do |interruption_screen_question_id| question.page.interruption_screen_question_ids.each do |interruption_screen_question_id|

1
app/services/bulk_upload/sales/year2022/row_parser.rb

@ -950,7 +950,6 @@ private
routed_to_soft_validation_questions = log.form.questions.filter { |q| q.type == "interruption_screen" && q.page.routed_to?(log, nil) } routed_to_soft_validation_questions = log.form.questions.filter { |q| q.type == "interruption_screen" && q.page.routed_to?(log, nil) }
routed_to_soft_validation_questions.each do |question| routed_to_soft_validation_questions.each do |question|
next unless question next unless question
next if log.optional_fields.include?(question.id)
next if question.completed?(log) next if question.completed?(log)
question.page.interruption_screen_question_ids.each do |interruption_screen_question_id| question.page.interruption_screen_question_ids.each do |interruption_screen_question_id|

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

@ -31,6 +31,18 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
before do before do
create(:organisation_relationship, parent_organisation: owning_org, child_organisation: managing_org) create(:organisation_relationship, parent_organisation: owning_org, child_organisation: managing_org)
LaRentRange.create!(
ranges_rent_id: "1",
la: "E09000008",
beds: 1,
lettype: 3,
soft_min: 12.41,
soft_max: 118.85,
hard_min: 9.87,
hard_max: 200.99,
start_year: 2023,
)
end end
around do |example| around do |example|
@ -1005,6 +1017,22 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
expect(soft_validation_errors.find { |e| e.attribute == :field_50 }.message).to eql("You told us this person is under 60 and retired. The minimum expected retirement age for females in England is 60.") expect(soft_validation_errors.find { |e| e.attribute == :field_50 }.message).to eql("You told us this person is under 60 and retired. The minimum expected retirement age for females in England is 60.")
end end
end end
context "when soft validation is triggered and not required" do
let(:attributes) { setup_section_params.merge({ field_128: 120, field_126: 1, field_32: 1, field_4: 1, field_5: "3", field_25: "E09000008" }) }
it "adds an error to the relevant fields" do
soft_validation_errors = parser.errors.select { |e| e.options[:category] == :soft_validation }
expect(soft_validation_errors.find { |e| e.attribute == :field_128 }).to be_present
end
it "populates with correct error message" do
soft_validation_errors = parser.errors.select { |e| e.options[:category] == :soft_validation }
expect(soft_validation_errors.find { |e| e.attribute == :field_128 }.message).to eql("You told us the rent is £120.00 every week. The maximum rent expected for this type of property in this local authority is ££118.85 every week.")
end
end
end end
end end

Loading…
Cancel
Save