From 16393cf4ab77f6ff88069c33afd5d3f72f1e82eb Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Thu, 14 Nov 2024 08:57:06 +0000 Subject: [PATCH] Trigger income error on uprn_selection (#2771) --- app/models/validations/sales/financial_validations.rb | 4 ++-- config/locales/validations/sales/financial.en.yml | 4 ++++ .../validations/sales/financial_validations_spec.rb | 8 ++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/models/validations/sales/financial_validations.rb b/app/models/validations/sales/financial_validations.rb index 1d2ef3d6f..a2cb2170f 100644 --- a/app/models/validations/sales/financial_validations.rb +++ b/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) diff --git a/config/locales/validations/sales/financial.en.yml b/config/locales/validations/sales/financial.en.yml index efd257ea5..55d563ee3 100644 --- a/config/locales/validations/sales/financial.en.yml +++ b/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." diff --git a/spec/models/validations/sales/financial_validations_spec.rb b/spec/models/validations/sales/financial_validations_spec.rb index cb55615c0..f579ae27e 100644 --- a/spec/models/validations/sales/financial_validations_spec.rb +++ b/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