Browse Source

Merge branch 'main' into BuErrors

pull/2686/head
Rachael Booth 2 years ago committed by GitHub
parent
commit
5554766d9f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      app/controllers/form_controller.rb
  2. 5
      app/models/validations/financial_validations.rb
  3. 2
      config/locales/en.yml
  4. 16
      spec/models/validations/financial_validations_spec.rb
  5. 27
      spec/requests/check_errors_controller_spec.rb
  6. 2
      spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb
  7. 2
      spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb

1
app/controllers/form_controller.rb

@ -409,6 +409,7 @@ private
next if question.subsection.id == "setup" next if question.subsection.id == "setup"
question.page.questions.map(&:id).each { |id| @log[id] = nil } question.page.questions.map(&:id).each { |id| @log[id] = nil }
@log.previous_la_known = nil if question.id == "ppostcode_full"
end end
@log.save! @log.save!
@questions = params[@log.model_name.param_key].keys.reject { |id| %w[clear_question_ids page].include?(id) }.map { |id| @log.form.get_question(id, @log) } @questions = params[@log.model_name.param_key].keys.reject { |id| %w[clear_question_ids page].include?(id) }.map { |id| @log.form.get_question(id, @log) }

5
app/models/validations/financial_validations.rb

@ -121,6 +121,11 @@ module Validations::FinancialValidations
def validate_rent_amount(record) def validate_rent_amount(record)
if record.wtshortfall if record.wtshortfall
if record.is_supported_housing? && record.wchchrg && (record.wtshortfall > record.wchchrg)
record.errors.add :tshortfall, message: I18n.t("validations.financial.tshortfall.more_than_carehome_charge")
record.errors.add :chcharge, I18n.t("validations.financial.carehome.less_than_shortfall")
end
if record.wtcharge && (record.wtshortfall > record.wtcharge) if record.wtcharge && (record.wtshortfall > record.wtcharge)
record.errors.add :tshortfall, :more_than_rent, message: I18n.t("validations.financial.tshortfall.more_than_total_charge") record.errors.add :tshortfall, :more_than_rent, message: I18n.t("validations.financial.tshortfall.more_than_total_charge")
record.errors.add :tcharge, I18n.t("validations.financial.tcharge.less_than_shortfall") record.errors.add :tcharge, I18n.t("validations.financial.tcharge.less_than_shortfall")

2
config/locales/en.yml

@ -384,6 +384,7 @@ en:
tshortfall: tshortfall:
outstanding_amount_not_expected: "You cannot answer the outstanding amount question if you don’t have outstanding rent or charges." outstanding_amount_not_expected: "You cannot answer the outstanding amount question if you don’t have outstanding rent or charges."
more_than_total_charge: "Enter a value less than the total charge." more_than_total_charge: "Enter a value less than the total charge."
more_than_carehome_charge: "Enter a value less than the care home charge."
must_be_positive: "Enter a value over £0.01 as you told us there is an outstanding amount." must_be_positive: "Enter a value over £0.01 as you told us there is an outstanding amount."
hbrentshortfall: hbrentshortfall:
outstanding_amount_not_expected: "Answer must be ‘yes’ as you have answered the outstanding amount question." outstanding_amount_not_expected: "Answer must be ‘yes’ as you have answered the outstanding amount question."
@ -456,6 +457,7 @@ en:
carehome: carehome:
out_of_range: "Household rent and other charges must be between %{min_chcharge} and %{max_chcharge} if paying %{period}." out_of_range: "Household rent and other charges must be between %{min_chcharge} and %{max_chcharge} if paying %{period}."
not_provided: "Enter how much rent and other charges the household pays %{period}." not_provided: "Enter how much rent and other charges the household pays %{period}."
less_than_shortfall: "The care home charge must be more than the outstanding amount."
cash_discount_invalid: "Cash discount must be £0 - £999,999." cash_discount_invalid: "Cash discount must be £0 - £999,999."
staircasing: staircasing:
percentage_bought_must_be_greater_than_percentage_owned: "Total percentage %{buyer_now_owns} must be more than percentage bought in this transaction." percentage_bought_must_be_greater_than_percentage_owned: "Total percentage %{buyer_now_owns} must be more than percentage bought in this transaction."

16
spec/models/validations/financial_validations_spec.rb

@ -123,6 +123,22 @@ RSpec.describe Validations::FinancialValidations do
.to include(match I18n.t("validations.financial.tshortfall.more_than_total_charge")) .to include(match I18n.t("validations.financial.tshortfall.more_than_total_charge"))
end end
it "validates that carehome charge is no less than the shortfall" do
record.hb = 6
record.hbrentshortfall = 1
record.tshortfall_known = 0
record.tshortfall = 299.50
record.chcharge = 198
record.needstype = 2
record.period = 2
record.set_derived_fields!
financial_validator.validate_rent_amount(record)
expect(record.errors["chcharge"])
.to include(match I18n.t("validations.financial.carehome.less_than_shortfall"))
expect(record.errors["tshortfall"])
.to include(match I18n.t("validations.financial.tshortfall.more_than_carehome_charge"))
end
it "expects that rent can be less than the shortfall if total charge is higher" do it "expects that rent can be less than the shortfall if total charge is higher" do
record.hb = 6 record.hb = 6
record.hbrentshortfall = 1 record.hbrentshortfall = 1

27
spec/requests/check_errors_controller_spec.rb

@ -300,6 +300,33 @@ RSpec.describe CheckErrorsController, type: :request do
end end
end end
context "and clearing ppostcode_full when previous_la_known is yes" do
let(:params) do
{
id: lettings_log.id,
lettings_log: {
layear: "1",
clear_question_ids: "ppostcode_full",
page: "time_lived_in_local_authority",
},
check_errors: "",
}
end
before do
lettings_log.update!(previous_la_known: 1, ppcodenk: 0, ppostcode_full: "AA11AA")
sign_in user
post "/lettings-logs/#{lettings_log.id}/time-lived-in-local-authority", params:
end
it "clears related previous location fields" do
expect(lettings_log.reload.prevloc).to eq(nil)
expect(lettings_log.reload.previous_la_known).to eq(nil)
expect(lettings_log.reload.ppostcode_full).to eq(nil)
expect(lettings_log.reload.ppcodenk).to eq(nil)
end
end
context "and clearing specific sales question" do context "and clearing specific sales question" do
let(:params) do let(:params) do
{ {

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

@ -215,7 +215,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
field_131: "101.11", field_131: "101.11",
field_132: "1500.19", field_132: "1500.19",
field_133: "1", field_133: "1",
field_134: "234.56", field_134: "34.56",
field_27: "15", field_27: "15",
field_28: "0", field_28: "0",

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

@ -235,7 +235,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
field_127: "13.14", field_127: "13.14",
field_128: "101.11", field_128: "101.11",
field_129: "1", field_129: "1",
field_130: "234.56", field_130: "34.56",
field_24: "15", field_24: "15",
field_30: now.day.to_s, field_30: now.day.to_s,

Loading…
Cancel
Save