Browse Source

CLDC-3817 Only run net income validations when applicable_income_range exists (#2882)

* Only run net income validations when applicable_income_range exists

* Check that income ranges exist
pull/2887/head v0.4.93
kosiakkatrina 5 days ago committed by GitHub
parent
commit
19c5deb1d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      app/models/lettings_log.rb
  2. 4
      app/models/sales_log.rb
  3. 4
      app/models/validations/soft_validations.rb
  4. 9
      spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb

2
app/models/lettings_log.rb

@ -240,7 +240,7 @@ class LettingsLog < Log
end end
def applicable_income_range def applicable_income_range
return unless ecstat1 && hhmemb return unless ecstat1 && hhmemb && ALLOWED_INCOME_RANGES[ecstat1]
range = ALLOWED_INCOME_RANGES[ecstat1].clone range = ALLOWED_INCOME_RANGES[ecstat1].clone

4
app/models/sales_log.rb

@ -419,9 +419,9 @@ class SalesLog < Log
def income_soft_min_for_ecstat(ecstat_field) def income_soft_min_for_ecstat(ecstat_field)
economic_status_code = public_send(ecstat_field) economic_status_code = public_send(ecstat_field)
return unless ALLOWED_INCOME_RANGES_SALES return unless ALLOWED_INCOME_RANGES_SALES && ALLOWED_INCOME_RANGES_SALES[economic_status_code]
soft_min = ALLOWED_INCOME_RANGES_SALES[economic_status_code]&.soft_min soft_min = ALLOWED_INCOME_RANGES_SALES[economic_status_code].soft_min
format_as_currency(soft_min) format_as_currency(soft_min)
end end

4
app/models/validations/soft_validations.rb

@ -16,13 +16,13 @@ module Validations::SoftValidations
}.freeze }.freeze
def net_income_in_soft_max_range? def net_income_in_soft_max_range?
return unless weekly_net_income && ecstat1 && hhmemb return unless weekly_net_income && ecstat1 && hhmemb && applicable_income_range
weekly_net_income.between?(applicable_income_range.soft_max, applicable_income_range.hard_max) weekly_net_income.between?(applicable_income_range.soft_max, applicable_income_range.hard_max)
end end
def net_income_in_soft_min_range? def net_income_in_soft_min_range?
return unless weekly_net_income && ecstat1 && hhmemb return unless weekly_net_income && ecstat1 && hhmemb && applicable_income_range
weekly_net_income.between?(applicable_income_range.hard_min, applicable_income_range.soft_min) weekly_net_income.between?(applicable_income_range.hard_min, applicable_income_range.soft_min)
end end

9
spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb

@ -1915,6 +1915,15 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
expect(parser.errors.where(:field_125, category: :soft_validation).first.message).to eql("You told us the rent is £120.00 every week. This is higher than we would expect.") expect(parser.errors.where(:field_125, category: :soft_validation).first.message).to eql("You told us the rent is £120.00 every week. This is higher than we would expect.")
end end
end end
context "when an invalid ecstat1 is given" do
let(:attributes) { setup_section_params.merge({ field_46: 11, field_119: 123, field_118: 1 }) }
it "does not run net income soft validations validation" do
parser.valid?
expect(parser.errors.where(:field_46).count).to be(1)
end
end
end end
describe "log_already_exists?" do describe "log_already_exists?" do

Loading…
Cancel
Save