From 97893d20adc9bee4d4334840bef89069ace8de8c Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Wed, 5 Apr 2023 12:55:06 +0100 Subject: [PATCH] feat: add buyer 2 value check --- .../pages/buyer2_income_max_value_check.rb | 27 +++++++++++++++++++ ...ck.rb => buyer2_income_min_value_check.rb} | 2 +- .../subsections/household_characteristics.rb | 2 +- .../income_benefits_and_savings.rb | 3 ++- .../sales/subsections/property_information.rb | 2 ++ .../validations/sales/soft_validations.rb | 18 ++++++++++++- config/locales/en.yml | 3 ++- .../household_characteristics_spec.rb | 4 +-- .../income_benefits_and_savings_spec.rb | 6 +++-- .../subsections/property_information_spec.rb | 2 ++ 10 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 app/models/form/sales/pages/buyer2_income_max_value_check.rb rename app/models/form/sales/pages/{buyer2_income_value_check.rb => buyer2_income_min_value_check.rb} (92%) diff --git a/app/models/form/sales/pages/buyer2_income_max_value_check.rb b/app/models/form/sales/pages/buyer2_income_max_value_check.rb new file mode 100644 index 000000000..444f78559 --- /dev/null +++ b/app/models/form/sales/pages/buyer2_income_max_value_check.rb @@ -0,0 +1,27 @@ +class Form::Sales::Pages::Buyer2IncomeMaxValueCheck < ::Form::Page + def initialize(id, hsh, subsection) + super + @depends_on = [ + { + "income2_over_soft_max?" => true, + }, + ] + @title_text = { + "translation" => "soft_validations.income.over_soft_max_for_la", + "arguments" => [ + { + "key" => "field_formatted_as_currency", + "arguments_for_key" => "income2", + "i18n_template" => "income", + }, + ], + } + @informative_text = {} + end + + def questions + @questions ||= [ + Form::Sales::Questions::Buyer2IncomeValueCheck.new(nil, nil, self), + ] + end +end diff --git a/app/models/form/sales/pages/buyer2_income_value_check.rb b/app/models/form/sales/pages/buyer2_income_min_value_check.rb similarity index 92% rename from app/models/form/sales/pages/buyer2_income_value_check.rb rename to app/models/form/sales/pages/buyer2_income_min_value_check.rb index 598c4c7a6..d4f5847bd 100644 --- a/app/models/form/sales/pages/buyer2_income_value_check.rb +++ b/app/models/form/sales/pages/buyer2_income_min_value_check.rb @@ -1,4 +1,4 @@ -class Form::Sales::Pages::Buyer2IncomeValueCheck < ::Form::Page +class Form::Sales::Pages::Buyer2IncomeMinValueCheck < ::Form::Page def initialize(id, hsh, subsection) super @header = "" diff --git a/app/models/form/sales/subsections/household_characteristics.rb b/app/models/form/sales/subsections/household_characteristics.rb index af85130b4..1fef204d1 100644 --- a/app/models/form/sales/subsections/household_characteristics.rb +++ b/app/models/form/sales/subsections/household_characteristics.rb @@ -37,7 +37,7 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection buyer_2_ethnicity_nationality_pages, Form::Sales::Pages::Buyer2WorkingSituation.new(nil, nil, self), Form::Sales::Pages::RetirementValueCheck.new("working_situation_2_retirement_value_check_joint_purchase", nil, self, person_index: 2), - Form::Sales::Pages::Buyer2IncomeValueCheck.new("working_situation_buyer_2_income_value_check", nil, self), + Form::Sales::Pages::Buyer2IncomeMinValueCheck.new("working_situation_buyer_2_income_min_value_check", nil, self), Form::Sales::Pages::PersonStudentNotChildValueCheck.new("buyer_2_working_situation_student_not_child_value_check", nil, self, person_index: 2), Form::Sales::Pages::Buyer2LiveInProperty.new(nil, nil, self), Form::Sales::Pages::NumberOfOthersInProperty.new("number_of_others_in_property", nil, self, joint_purchase: false), diff --git a/app/models/form/sales/subsections/income_benefits_and_savings.rb b/app/models/form/sales/subsections/income_benefits_and_savings.rb index 293c11657..e2728b6e2 100644 --- a/app/models/form/sales/subsections/income_benefits_and_savings.rb +++ b/app/models/form/sales/subsections/income_benefits_and_savings.rb @@ -16,7 +16,8 @@ class Form::Sales::Subsections::IncomeBenefitsAndSavings < ::Form::Subsection Form::Sales::Pages::MortgageValueCheck.new("buyer_1_mortgage_value_check", nil, self, 1), Form::Sales::Pages::Buyer2Income.new(nil, nil, self), Form::Sales::Pages::MortgageValueCheck.new("buyer_2_income_mortgage_value_check", nil, self, 2), - Form::Sales::Pages::Buyer2IncomeValueCheck.new("buyer_2_income_value_check", nil, self), + Form::Sales::Pages::Buyer2IncomeMinValueCheck.new("buyer_2_income_min_value_check", nil, self), + Form::Sales::Pages::Buyer2IncomeMaxValueCheck.new("buyer_2_income_max_value_check", nil, self), Form::Sales::Pages::Buyer2Mortgage.new(nil, nil, self), Form::Sales::Pages::MortgageValueCheck.new("buyer_2_mortgage_value_check", nil, self, 2), Form::Sales::Pages::HousingBenefits.new("housing_benefits_joint_purchase", nil, self, joint_purchase: true), diff --git a/app/models/form/sales/subsections/property_information.rb b/app/models/form/sales/subsections/property_information.rb index ea4b51deb..5a1545da2 100644 --- a/app/models/form/sales/subsections/property_information.rb +++ b/app/models/form/sales/subsections/property_information.rb @@ -29,6 +29,7 @@ class Form::Sales::Subsections::PropertyInformation < ::Form::Subsection Form::Sales::Pages::Address.new(nil, nil, self), Form::Sales::Pages::PropertyLocalAuthority.new(nil, nil, self), Form::Sales::Pages::Buyer1IncomeMaxValueCheck.new("local_authority_buyer_1_income_max_value_check", nil, self), + Form::Sales::Pages::Buyer2IncomeMaxValueCheck.new("local_authority_buyer_2_income_max_value_check", nil, self), ] end end @@ -39,6 +40,7 @@ class Form::Sales::Subsections::PropertyInformation < ::Form::Subsection Form::Sales::Pages::Postcode.new(nil, nil, self), Form::Sales::Pages::PropertyLocalAuthority.new(nil, nil, self), Form::Sales::Pages::Buyer1IncomeMaxValueCheck.new("local_authority_buyer_1_income_max_value_check", nil, self), + Form::Sales::Pages::Buyer2IncomeMaxValueCheck.new("local_authority_buyer_2_income_max_value_check", nil, self), ] end end diff --git a/app/models/validations/sales/soft_validations.rb b/app/models/validations/sales/soft_validations.rb index e439c7369..d95a1d723 100644 --- a/app/models/validations/sales/soft_validations.rb +++ b/app/models/validations/sales/soft_validations.rb @@ -22,7 +22,19 @@ module Validations::Sales::SoftValidations def income1_over_soft_max? return unless income1 && la && discounted_ownership_sale? - (london_property? && income1 > 90_000) || (property_not_in_london? && income1 > 80_000) + income_over_soft_max?(income1) + end + + def income2_over_soft_max? + return unless income2 && la && discounted_ownership_sale? + + income_over_soft_max?(income2) + end + + def combined_income_over_soft_max? + return unless income1 && income2 && la && discounted_ownership_sale? + + income_over_soft_max?(income1 + income2) end def staircase_bought_above_fifty? @@ -138,4 +150,8 @@ private bedrooms: beds_for_la_sale_range, ) end + + def income_over_soft_max?(income) + (london_property? && income > 90_000) || (property_not_in_london? && income > 80_000) + end end diff --git a/config/locales/en.yml b/config/locales/en.yml index a25b2d1dd..d2941e9eb 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -510,7 +510,8 @@ en: message: "Net income is higher than expected based on the lead tenant’s working situation. Are you sure this is correct?" income: under_soft_min_for_economic_status: "You said income was %{income}, which is below this working situation's minimum (%{minimum})" - over_soft_max_for_la: "You told us the income of this household is %{income}, which seems high." + over_soft_max_for_la: "You told us the income of this buyer is %{income}, which seems high." + over_soft_max_for_la_combined: "You told us the income of this household is %{income}, which seems high." rent: outside_range_title: "You told us the rent is %{brent}" min_hint_text: "The minimum rent expected for this type of property in this local authority is £%{soft_min_for_period}." diff --git a/spec/models/form/sales/subsections/household_characteristics_spec.rb b/spec/models/form/sales/subsections/household_characteristics_spec.rb index 1277749ef..faf7d28b4 100644 --- a/spec/models/form/sales/subsections/household_characteristics_spec.rb +++ b/spec/models/form/sales/subsections/household_characteristics_spec.rb @@ -49,7 +49,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model gender_2_buyer_retirement_value_check buyer_2_working_situation working_situation_2_retirement_value_check_joint_purchase - working_situation_buyer_2_income_value_check + working_situation_buyer_2_income_min_value_check buyer_2_working_situation_student_not_child_value_check buyer_2_live_in_property number_of_others_in_property @@ -158,7 +158,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model buyer_2_nationality buyer_2_working_situation working_situation_2_retirement_value_check_joint_purchase - working_situation_buyer_2_income_value_check + working_situation_buyer_2_income_min_value_check buyer_2_working_situation_student_not_child_value_check buyer_2_live_in_property number_of_others_in_property diff --git a/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb b/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb index 4fa5aa6fe..eadcfb87b 100644 --- a/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb +++ b/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb @@ -28,7 +28,8 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model buyer_1_mortgage_value_check buyer_2_income buyer_2_income_mortgage_value_check - buyer_2_income_value_check + buyer_2_income_min_value_check + buyer_2_income_max_value_check buyer_2_mortgage buyer_2_mortgage_value_check housing_benefits_joint_purchase @@ -57,7 +58,8 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model buyer_1_mortgage_value_check buyer_2_income buyer_2_income_mortgage_value_check - buyer_2_income_value_check + buyer_2_income_min_value_check + buyer_2_income_max_value_check buyer_2_mortgage buyer_2_mortgage_value_check housing_benefits_joint_purchase diff --git a/spec/models/form/sales/subsections/property_information_spec.rb b/spec/models/form/sales/subsections/property_information_spec.rb index 4c9e5b475..dae216968 100644 --- a/spec/models/form/sales/subsections/property_information_spec.rb +++ b/spec/models/form/sales/subsections/property_information_spec.rb @@ -28,6 +28,7 @@ RSpec.describe Form::Sales::Subsections::PropertyInformation, type: :model do property_postcode property_local_authority local_authority_buyer_1_income_max_value_check + local_authority_buyer_2_income_max_value_check about_price_la_value_check property_wheelchair_accessible ], @@ -47,6 +48,7 @@ RSpec.describe Form::Sales::Subsections::PropertyInformation, type: :model do address property_local_authority local_authority_buyer_1_income_max_value_check + local_authority_buyer_2_income_max_value_check property_number_of_bedrooms about_price_bedrooms_value_check property_unit_type