Browse Source

Fix tests and add missing validation messages

pull/388/head
Kat 3 years ago
parent
commit
e43d84d37e
  1. 8
      app/models/validations/financial_validations.rb
  2. 26
      config/locales/en.yml
  3. 2
      spec/factories/case_log.rb
  4. 1
      spec/fixtures/complete_case_log.json
  5. 4
      spec/fixtures/exports/case_logs.xml
  6. 18
      spec/models/validations/financial_validations_spec.rb

8
app/models/validations/financial_validations.rb

@ -69,11 +69,11 @@ module Validations::FinancialValidations
record.errors.add :tcharge, I18n.t("validations.financial.tcharge.under_10")
end
answered_questions = [record.tcharge, record.chcharge].concat(!(record.household_charge && record.household_charge.zero?).nil? ? [record.household_charge] : [])
answered_questions = [record.tcharge, record.chcharge].concat(record.household_charge && record.household_charge.zero? ? [record.household_charge] : [])
if answered_questions.count(&:present?) > 1
record.errors.add :tcharge, I18n.t("validations.financial.tcharge.complete_1_of_3") if record.tcharge.present?
record.errors.add :chcharge, I18n.t("validations.financial.chcharge.complete_1_of_3") if record.chcharge.present?
record.errors.add :household_charge, I18n.t("validations.financial.household_charge.complete_1_of_3") if record.household_charge.present?
record.errors.add :tcharge, I18n.t("validations.financial.charges.complete_1_of_3") if record.tcharge.present?
record.errors.add :chcharge, I18n.t("validations.financial.charges.complete_1_of_3") if record.chcharge.present?
record.errors.add :household_charge, I18n.t("validations.financial.charges.complete_1_of_3") if record.household_charge.present?
end
validate_charges(record)

26
config/locales/en.yml

@ -94,11 +94,29 @@ en:
less_than_double_shortfall: "Answer must be more than double the shortfall in basic rent"
scharge:
this_landlord:
general_needs: "Service charge must be between 0 and 55 per week if the landlord is this landlord and it is a general needs letting"
supported_housing: "Service charge must be between 0 and 280 per week if the landlord is this landlord and it is a suported housing letting"
general_needs: "Service charge must be between £0 and £55 per week if the landlord is this landlord and it is a general needs letting"
supported_housing: "Service charge must be between £0 and £280 per week if the landlord is this landlord and it is a suported housing letting"
other_landlord:
general_needs: "Service charge must be between 0 and 45 per week if the landlord is another RP and it is a general needs letting"
supported_housing: "Service charge must be between 0 and 165 per week if the landlord is another RP and it is a suported housing letting"
general_needs: "Service charge must be between £0 and £45 per week if the landlord is another RP and it is a general needs letting"
supported_housing: "Service charge must be between £0 and £165 per week if the landlord is another RP and it is a suported housing letting"
pscharge:
this_landlord:
general_needs: "Personal service charge must be between £0 and £30 per week if the landlord is this landlord and it is a general needs letting"
supported_housing: "Personal service charge must be between £0 and £200 per week if the landlord is this landlord and it is a suported housing letting"
other_landlord:
general_needs: "Personal service charge must be between £0 and £35 per week if the landlord is another RP and it is a general needs letting"
supported_housing: "Personal service charge must be between £0 and £75 per week if the landlord is another RP and it is a suported housing letting"
supcharg:
this_landlord:
general_needs: "Support charge must be between £0 and £40 per week if the landlord is this landlord and it is a general needs letting"
supported_housing: "Support charge must be between £0 and £465 per week if the landlord is this landlord and it is a suported housing letting"
other_landlord:
general_needs: "Support charge must be between £0 and £60 per week if the landlord is another RP and it is a general needs letting"
supported_housing: "Support charge must be between £0 and £120 per week if the landlord is another RP and it is a suported housing letting"
charges:
complete_1_of_3: 'Only one question out of "Total charge", "Charges for carehomes" and "Does the household pay rent or charges?" needs to be selected and completed'
tcharge:
under_10: "Total charge must be at least £10 per week"
household:
reasonpref:

2
spec/factories/case_log.rb

@ -139,10 +139,8 @@ FactoryBot.define do
armedforces { 0 }
builtype { 1 }
unitletas { 2 }
household_charge { 1 }
has_benefits { 1 }
is_carehome { 0 }
chcharge { 7 }
letting_in_sheltered_accommodation { 0 }
la_known { 1 }
declaration { 1 }

1
spec/fixtures/complete_case_log.json vendored

@ -141,7 +141,6 @@
"has_benefits": 1,
"household_charge": 1,
"is_carehome": 1,
"chcharge": 6,
"letting_in_sheltered_accommodation": 0,
"declaration": 1,
"referral": 1

4
spec/fixtures/exports/case_logs.xml vendored

@ -135,7 +135,7 @@
<nocharge>0</nocharge>
<is_carehome>0</is_carehome>
<letting_in_sheltered_accommodation>0</letting_in_sheltered_accommodation>
<household_charge>1</household_charge>
<household_charge/>
<referral/>
<brent>200.0</brent>
<scharge>50.0</scharge>
@ -143,7 +143,7 @@
<supcharg>35.0</supcharg>
<tcharge>325.0</tcharge>
<tshortfall>12.0</tshortfall>
<chcharge>7.0</chcharge>
<chcharge/>
<declaration>1</declaration>
<previous_postcode_known>1</previous_postcode_known>
<previous_la_known/>

18
spec/models/validations/financial_validations_spec.rb

@ -635,11 +635,11 @@ RSpec.describe Validations::FinancialValidations do
record.household_charge = 0
financial_validator.validate_rent_amount(record)
expect(record.errors["tcharge"])
.to include(match I18n.t("validations.financial.tcharge.complete_1_of_3"))
.to include(match I18n.t("validations.financial.charges.complete_1_of_3"))
expect(record.errors["chcharge"])
.to include(match I18n.t("validations.financial.chcharge.complete_1_of_3"))
.to include(match I18n.t("validations.financial.charges.complete_1_of_3"))
expect(record.errors["household_charge"])
.to include(match I18n.t("validations.financial.household_charge.complete_1_of_3"))
.to include(match I18n.t("validations.financial.charges.complete_1_of_3"))
end
it "returns an error for tcharge and chcharge types selected" do
@ -649,9 +649,9 @@ RSpec.describe Validations::FinancialValidations do
expect(record.errors["household_charge"])
.to be_empty
expect(record.errors["tcharge"])
.to include(match I18n.t("validations.financial.tcharge.complete_1_of_3"))
.to include(match I18n.t("validations.financial.charges.complete_1_of_3"))
expect(record.errors["chcharge"])
.to include(match I18n.t("validations.financial.chcharge.complete_1_of_3"))
.to include(match I18n.t("validations.financial.charges.complete_1_of_3"))
end
it "returns an error for tcharge and household_charge types selected" do
@ -661,9 +661,9 @@ RSpec.describe Validations::FinancialValidations do
expect(record.errors["chcharge"])
.to be_empty
expect(record.errors["tcharge"])
.to include(match I18n.t("validations.financial.tcharge.complete_1_of_3"))
.to include(match I18n.t("validations.financial.charges.complete_1_of_3"))
expect(record.errors["household_charge"])
.to include(match I18n.t("validations.financial.household_charge.complete_1_of_3"))
.to include(match I18n.t("validations.financial.charges.complete_1_of_3"))
end
it "returns an error for chcharge and household_charge types selected" do
@ -673,9 +673,9 @@ RSpec.describe Validations::FinancialValidations do
expect(record.errors["tcharge"])
.to be_empty
expect(record.errors["chcharge"])
.to include(match I18n.t("validations.financial.chcharge.complete_1_of_3"))
.to include(match I18n.t("validations.financial.charges.complete_1_of_3"))
expect(record.errors["household_charge"])
.to include(match I18n.t("validations.financial.household_charge.complete_1_of_3"))
.to include(match I18n.t("validations.financial.charges.complete_1_of_3"))
end
end

Loading…
Cancel
Save