Browse Source

CLDC-1970: Use more relevant error message for shared ownership income below 0 (#2270)

pull/2279/head^2
Rachael Booth 10 months ago committed by GitHub
parent
commit
36553f4777
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 16
      app/models/validations/sales/financial_validations.rb
  2. 4
      config/locales/en.yml
  3. 76
      spec/models/validations/sales/financial_validations_spec.rb

16
app/models/validations/sales/financial_validations.rb

@ -6,10 +6,10 @@ module Validations::Sales::FinancialValidations
return unless record.income1 && record.la && record.shared_ownership_scheme?
relevant_fields = %i[income1 ownershipsch uprn la postcode_full]
if record.london_property? && record.income1 > 90_000
relevant_fields.each { |field| record.errors.add field, :over_hard_max_for_london, message: I18n.t("validations.financial.income.over_hard_max_for_london") }
elsif record.property_not_in_london? && record.income1 > 80_000
relevant_fields.each { |field| record.errors.add field, :over_hard_max_for_outside_london, message: I18n.t("validations.financial.income.over_hard_max_for_outside_london") }
if record.london_property? && !record.income1.between?(0, 90_000)
relevant_fields.each { |field| record.errors.add field, :outside_london_income_range, message: I18n.t("validations.financial.income.outside_london_income_range") }
elsif record.property_not_in_london? && !record.income1.between?(0, 80_000)
relevant_fields.each { |field| record.errors.add field, :outside_non_london_income_range, message: I18n.t("validations.financial.income.outside_non_london_income_range") }
end
end
@ -17,10 +17,10 @@ module Validations::Sales::FinancialValidations
return unless record.income2 && record.la && record.shared_ownership_scheme?
relevant_fields = %i[income2 ownershipsch uprn la postcode_full]
if record.london_property? && record.income2 > 90_000
relevant_fields.each { |field| record.errors.add field, :over_hard_max_for_london, message: I18n.t("validations.financial.income.over_hard_max_for_london") }
elsif record.property_not_in_london? && record.income2 > 80_000
relevant_fields.each { |field| record.errors.add field, :over_hard_max_for_outside_london, message: I18n.t("validations.financial.income.over_hard_max_for_outside_london") }
if record.london_property? && !record.income2.between?(0, 90_000)
relevant_fields.each { |field| record.errors.add field, :outside_london_income_range, message: I18n.t("validations.financial.income.outside_london_income_range") }
elsif record.property_not_in_london? && !record.income2.between?(0, 80_000)
relevant_fields.each { |field| record.errors.add field, :outside_non_london_income_range, message: I18n.t("validations.financial.income.outside_non_london_income_range") }
end
end

4
config/locales/en.yml

@ -368,8 +368,8 @@ en:
freq_missing: "Select how often the household receives income"
earnings_missing: "Enter how much income the household has in total"
income:
over_hard_max_for_london: "Income must be £90,000 or lower for properties within a London local authority"
over_hard_max_for_outside_london: "Income must be £80,000 or lower for properties outside London local authority"
outside_london_income_range: "Income must be between £0 and £90,000 for properties within a London local authority"
outside_non_london_income_range: "Income must be between £0 and £80,000 for properties in a non-London local authority"
combined_over_hard_max_for_london: "Combined income must be £90,000 or lower for properties within a London local authority"
combined_over_hard_max_for_outside_london: "Combined income must be £80,000 or lower for properties outside London local authorities"
child_has_income: "Child's income must be £0"

76
spec/models/validations/sales/financial_validations_spec.rb

@ -17,33 +17,51 @@ RSpec.describe Validations::Sales::FinancialValidations do
it "adds errors if buyer 1 has income over 80,000" do
record.income1 = 85_000
financial_validator.validate_income1(record)
expect(record.errors["income1"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_outside_london"))
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_outside_london"))
expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_outside_london"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_outside_london"))
expect(record.errors["income1"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
end
it "adds errors if buyer 2 has income over 80,000" do
record.income2 = 85_000
financial_validator.validate_income2(record)
expect(record.errors["income2"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_outside_london"))
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_outside_london"))
expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_outside_london"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_outside_london"))
expect(record.errors["income2"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
end
it "does not add errors if buyer 1 has income below 80_000" do
it "does not add errors if buyer 1 has income above 0 and below 80_000" do
record.income1 = 75_000
financial_validator.validate_income1(record)
expect(record.errors).to be_empty
end
it "does not add errors if buyer 2 has income below 80_000" do
it "does not add errors if buyer 2 has income above 0 and below 80_000" do
record.income2 = 75_000
financial_validator.validate_income2(record)
expect(record.errors).to be_empty
end
it "adds errors if buyer 1 has income below 0" do
record.income1 = -500
financial_validator.validate_income1(record)
expect(record.errors["income1"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
end
it "adds errors if buyer 2 has income below 0" do
record.income2 = -5
financial_validator.validate_income2(record)
expect(record.errors["income2"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
end
it "adds errors when combined income is over 80_000" do
record.income1 = 45_000
record.income2 = 40_000
@ -69,33 +87,51 @@ RSpec.describe Validations::Sales::FinancialValidations do
it "adds errors if buyer 1 has income over 90,000" do
record.income1 = 95_000
financial_validator.validate_income1(record)
expect(record.errors["income1"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_london"))
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_london"))
expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_london"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_london"))
expect(record.errors["income1"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
end
it "adds errors if buyer 2 has income over 90,000" do
record.income2 = 95_000
financial_validator.validate_income2(record)
expect(record.errors["income2"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_london"))
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_london"))
expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_london"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_london"))
expect(record.errors["income2"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
end
it "does not add errors if buyer 1 has income below 90_000" do
it "does not add errors if buyer 1 has income above 0 and below 90_000" do
record.income1 = 75_000
financial_validator.validate_income1(record)
expect(record.errors).to be_empty
end
it "does not add errors if buyer 2 has income below 90_000" do
it "does not add errors if buyer 2 has income above 0 and below 90_000" do
record.income2 = 75_000
financial_validator.validate_income2(record)
expect(record.errors).to be_empty
end
it "adds errors if buyer 1 has income below 0" do
record.income1 = -500
financial_validator.validate_income1(record)
expect(record.errors["income1"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
end
it "adds errors if buyer 2 has income below 0" do
record.income2 = -2
financial_validator.validate_income2(record)
expect(record.errors["income2"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
end
it "adds errors when combined income is over 90_000" do
record.income1 = 55_000
record.income2 = 40_000

Loading…
Cancel
Save