Browse Source

Trigger income error on uprn_selection (#2771)

pull/2783/head
kosiakkatrina 1 month ago committed by GitHub
parent
commit
16393cf4ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      app/models/validations/sales/financial_validations.rb
  2. 4
      config/locales/validations/sales/financial.en.yml
  3. 8
      spec/models/validations/sales/financial_validations_spec.rb

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

@ -5,7 +5,7 @@ module Validations::Sales::FinancialValidations
def validate_income1(record)
return unless record.income1 && record.la && record.shared_ownership_scheme?
relevant_fields = %i[income1 ownershipsch uprn la postcode_full]
relevant_fields = %i[income1 ownershipsch uprn la postcode_full uprn_selection]
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.sales.financial.#{field}.outside_london_income_range") }
elsif record.property_not_in_london? && !record.income1.between?(0, 80_000)
@ -16,7 +16,7 @@ module Validations::Sales::FinancialValidations
def validate_income2(record)
return unless record.income2 && record.la && record.shared_ownership_scheme?
relevant_fields = %i[income2 ownershipsch uprn la postcode_full]
relevant_fields = %i[income2 ownershipsch uprn la postcode_full uprn_selection]
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.sales.financial.#{field}.outside_london_income_range") }
elsif record.property_not_in_london? && !record.income2.between?(0, 80_000)

4
config/locales/validations/sales/financial.en.yml

@ -79,3 +79,7 @@ en:
not_joint_purchase: "The initial equity stake is %{equity}% and the percentage owned in total minus the percentage bought is %{staircase_difference}%. In a staircasing transaction, the equity stake purchased cannot be larger than the percentage the buyer owns minus the percentage bought."
percentage_bought_must_be_at_least_threshold: "The minimum increase in equity while staircasing is %{threshold}%."
percentage_bought_equal_percentage_owned: "The percentage bought is %{stairbought}% and the percentage owned in total is %{stairowned}%. These figures cannot be the same."
uprn_selection:
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."

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

@ -20,6 +20,7 @@ RSpec.describe Validations::Sales::FinancialValidations do
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.sales.financial.ownershipsch.outside_non_london_income_range"))
expect(record.errors["la"]).to include(match I18n.t("validations.sales.financial.la.outside_non_london_income_range"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.sales.financial.postcode_full.outside_non_london_income_range"))
expect(record.errors["uprn_selection"]).to include(match I18n.t("validations.sales.financial.uprn_selection.outside_non_london_income_range"))
end
it "adds errors if buyer 2 has income over 80,000" do
@ -29,6 +30,7 @@ RSpec.describe Validations::Sales::FinancialValidations do
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.sales.financial.ownershipsch.outside_non_london_income_range"))
expect(record.errors["la"]).to include(match I18n.t("validations.sales.financial.la.outside_non_london_income_range"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.sales.financial.postcode_full.outside_non_london_income_range"))
expect(record.errors["uprn_selection"]).to include(match I18n.t("validations.sales.financial.uprn_selection.outside_non_london_income_range"))
end
it "does not add errors if buyer 1 has income above 0 and below 80_000" do
@ -50,6 +52,7 @@ RSpec.describe Validations::Sales::FinancialValidations do
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.sales.financial.ownershipsch.outside_non_london_income_range"))
expect(record.errors["la"]).to include(match I18n.t("validations.sales.financial.la.outside_non_london_income_range"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.sales.financial.postcode_full.outside_non_london_income_range"))
expect(record.errors["uprn_selection"]).to include(match I18n.t("validations.sales.financial.uprn_selection.outside_non_london_income_range"))
end
it "adds errors if buyer 2 has income below 0" do
@ -59,6 +62,7 @@ RSpec.describe Validations::Sales::FinancialValidations do
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.sales.financial.ownershipsch.outside_non_london_income_range"))
expect(record.errors["la"]).to include(match I18n.t("validations.sales.financial.la.outside_non_london_income_range"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.sales.financial.postcode_full.outside_non_london_income_range"))
expect(record.errors["uprn_selection"]).to include(match I18n.t("validations.sales.financial.uprn_selection.outside_non_london_income_range"))
end
it "adds errors when combined income is over 80_000" do
@ -89,6 +93,7 @@ RSpec.describe Validations::Sales::FinancialValidations do
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.sales.financial.ownershipsch.outside_london_income_range"))
expect(record.errors["la"]).to include(match I18n.t("validations.sales.financial.la.outside_london_income_range"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.sales.financial.postcode_full.outside_london_income_range"))
expect(record.errors["uprn_selection"]).to include(match I18n.t("validations.sales.financial.uprn_selection.outside_london_income_range"))
end
it "adds errors if buyer 2 has income over 90,000" do
@ -98,6 +103,7 @@ RSpec.describe Validations::Sales::FinancialValidations do
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.sales.financial.ownershipsch.outside_london_income_range"))
expect(record.errors["la"]).to include(match I18n.t("validations.sales.financial.la.outside_london_income_range"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.sales.financial.postcode_full.outside_london_income_range"))
expect(record.errors["uprn_selection"]).to include(match I18n.t("validations.sales.financial.uprn_selection.outside_london_income_range"))
end
it "does not add errors if buyer 1 has income above 0 and below 90_000" do
@ -119,6 +125,7 @@ RSpec.describe Validations::Sales::FinancialValidations do
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.sales.financial.ownershipsch.outside_london_income_range"))
expect(record.errors["la"]).to include(match I18n.t("validations.sales.financial.la.outside_london_income_range"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.sales.financial.postcode_full.outside_london_income_range"))
expect(record.errors["uprn_selection"]).to include(match I18n.t("validations.sales.financial.uprn_selection.outside_london_income_range"))
end
it "adds errors if buyer 2 has income below 0" do
@ -128,6 +135,7 @@ RSpec.describe Validations::Sales::FinancialValidations do
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.sales.financial.ownershipsch.outside_london_income_range"))
expect(record.errors["la"]).to include(match I18n.t("validations.sales.financial.la.outside_london_income_range"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.sales.financial.postcode_full.outside_london_income_range"))
expect(record.errors["uprn_selection"]).to include(match I18n.t("validations.sales.financial.uprn_selection.outside_london_income_range"))
end
it "adds errors when combined income is over 90_000" do

Loading…
Cancel
Save