Browse Source

feat: add max value check for buyer 1

pull/1518/head
natdeanlewissoftwire 3 years ago
parent
commit
755b61d342
  1. 27
      app/models/form/sales/pages/buyer1_income_max_value_check.rb
  2. 2
      app/models/form/sales/pages/buyer1_income_min_value_check.rb
  3. 2
      app/models/form/sales/subsections/household_characteristics.rb
  4. 3
      app/models/form/sales/subsections/income_benefits_and_savings.rb
  5. 2
      app/models/form/sales/subsections/property_information.rb
  6. 6
      app/models/validations/sales/soft_validations.rb
  7. 1
      config/locales/en.yml
  8. 6
      spec/models/form/sales/pages/buyer1_income_min_value_check_spec.rb
  9. 2
      spec/models/form/sales/questions/buyer1_income_min_value_check_spec.rb
  10. 4
      spec/models/form/sales/subsections/household_characteristics_spec.rb
  11. 4
      spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb

27
app/models/form/sales/pages/buyer1_income_max_value_check.rb

@ -0,0 +1,27 @@
class Form::Sales::Pages::Buyer1IncomeMaxValueCheck < ::Form::Page
def initialize(id, hsh, subsection)
super
@depends_on = [
{
"income1_over_soft_max?" => true,
},
]
@title_text = {
"translation" => "soft_validations.income.over_soft_max_for_la",
"arguments" => [
{
"key" => "field_formatted_as_currency",
"arguments_for_key" => "income1",
"i18n_template" => "income",
}
],
}
@informative_text = {}
end
def questions
@questions ||= [
Form::Sales::Questions::Buyer1IncomeValueCheck.new(nil, nil, self),
]
end
end

2
app/models/form/sales/pages/buyer1_income_value_check.rb → app/models/form/sales/pages/buyer1_income_min_value_check.rb

@ -1,4 +1,4 @@
class Form::Sales::Pages::Buyer1IncomeValueCheck < ::Form::Page class Form::Sales::Pages::Buyer1IncomeMinValueCheck < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@depends_on = [ @depends_on = [

2
app/models/form/sales/subsections/household_characteristics.rb

@ -24,7 +24,7 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Sales::Pages::Nationality1.new(nil, nil, self), Form::Sales::Pages::Nationality1.new(nil, nil, self),
Form::Sales::Pages::Buyer1WorkingSituation.new(nil, nil, self), Form::Sales::Pages::Buyer1WorkingSituation.new(nil, nil, self),
Form::Sales::Pages::RetirementValueCheck.new("working_situation_1_retirement_value_check", nil, self, person_index: 1), Form::Sales::Pages::RetirementValueCheck.new("working_situation_1_retirement_value_check", nil, self, person_index: 1),
Form::Sales::Pages::Buyer1IncomeValueCheck.new("working_situation_buyer_1_income_value_check", nil, self), Form::Sales::Pages::Buyer1IncomeMinValueCheck.new("working_situation_buyer_1_income_min_value_check", nil, self),
Form::Sales::Pages::Buyer1LiveInProperty.new(nil, nil, self), Form::Sales::Pages::Buyer1LiveInProperty.new(nil, nil, self),
Form::Sales::Pages::Buyer2RelationshipToBuyer1.new(nil, nil, self), Form::Sales::Pages::Buyer2RelationshipToBuyer1.new(nil, nil, self),
Form::Sales::Pages::PersonStudentNotChildValueCheck.new("buyer_2_relationship_student_not_child_value_check", nil, self, person_index: 2), Form::Sales::Pages::PersonStudentNotChildValueCheck.new("buyer_2_relationship_student_not_child_value_check", nil, self, person_index: 2),

3
app/models/form/sales/subsections/income_benefits_and_savings.rb

@ -9,7 +9,8 @@ class Form::Sales::Subsections::IncomeBenefitsAndSavings < ::Form::Subsection
def pages def pages
@pages ||= [ @pages ||= [
Form::Sales::Pages::Buyer1Income.new(nil, nil, self), Form::Sales::Pages::Buyer1Income.new(nil, nil, self),
Form::Sales::Pages::Buyer1IncomeValueCheck.new("buyer_1_income_value_check", nil, self), Form::Sales::Pages::Buyer1IncomeMinValueCheck.new("buyer_1_income_min_value_check", nil, self),
Form::Sales::Pages::Buyer1IncomeMaxValueCheck.new("buyer_1_income_max_value_check", nil, self),
Form::Sales::Pages::MortgageValueCheck.new("buyer_1_income_mortgage_value_check", nil, self, 1), Form::Sales::Pages::MortgageValueCheck.new("buyer_1_income_mortgage_value_check", nil, self, 1),
Form::Sales::Pages::Buyer1Mortgage.new(nil, nil, self), Form::Sales::Pages::Buyer1Mortgage.new(nil, nil, self),
Form::Sales::Pages::MortgageValueCheck.new("buyer_1_mortgage_value_check", nil, self, 1), Form::Sales::Pages::MortgageValueCheck.new("buyer_1_mortgage_value_check", nil, self, 1),

2
app/models/form/sales/subsections/property_information.rb

@ -28,6 +28,7 @@ class Form::Sales::Subsections::PropertyInformation < ::Form::Subsection
Form::Sales::Pages::UprnConfirmation.new(nil, nil, self), Form::Sales::Pages::UprnConfirmation.new(nil, nil, self),
Form::Sales::Pages::Address.new(nil, nil, self), Form::Sales::Pages::Address.new(nil, nil, self),
Form::Sales::Pages::PropertyLocalAuthority.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),
] ]
end end
end end
@ -37,6 +38,7 @@ class Form::Sales::Subsections::PropertyInformation < ::Form::Subsection
[ [
Form::Sales::Pages::Postcode.new(nil, nil, self), Form::Sales::Pages::Postcode.new(nil, nil, self),
Form::Sales::Pages::PropertyLocalAuthority.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),
] ]
end end
end end

6
app/models/validations/sales/soft_validations.rb

@ -19,6 +19,12 @@ module Validations::Sales::SoftValidations
income2 < ALLOWED_INCOME_RANGES_SALES[ecstat2][:soft_min] income2 < ALLOWED_INCOME_RANGES_SALES[ecstat2][:soft_min]
end end
def income1_over_soft_max?
return unless income1 && la && discounted_ownership_sale?
(london_property? && income1 > 90_000) || (property_not_in_london? && income1 > 80_000)
end
def staircase_bought_above_fifty? def staircase_bought_above_fifty?
stairbought && stairbought > 50 stairbought && stairbought > 50
end end

1
config/locales/en.yml

@ -510,6 +510,7 @@ en:
message: "Net income is higher than expected based on the lead tenant’s working situation. Are you sure this is correct?" message: "Net income is higher than expected based on the lead tenant’s working situation. Are you sure this is correct?"
income: income:
under_soft_min_for_economic_status: "You said income was %{income}, which is below this working situation's minimum (%{minimum})" 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."
rent: rent:
outside_range_title: "You told us the rent is %{brent}" 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}." min_hint_text: "The minimum rent expected for this type of property in this local authority is £%{soft_min_for_period}."

6
spec/models/form/sales/pages/buyer1_income_value_check_spec.rb → spec/models/form/sales/pages/buyer1_income_min_value_check_spec.rb

@ -1,9 +1,9 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Pages::Buyer1IncomeValueCheck, type: :model do RSpec.describe Form::Sales::Pages::Buyer1IncomeMinValueCheck, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) } subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { "prefix_buyer_1_income_value_check" } let(:page_id) { "prefix_buyer_1_income_min_value_check" }
let(:page_definition) { nil } let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) } let(:subsection) { instance_double(Form::Subsection) }
@ -16,7 +16,7 @@ RSpec.describe Form::Sales::Pages::Buyer1IncomeValueCheck, type: :model do
end end
it "has the correct id" do it "has the correct id" do
expect(page.id).to eq("prefix_buyer_1_income_value_check") expect(page.id).to eq("prefix_buyer_1_income_min_value_check")
end end
it "has the correct header" do it "has the correct header" do

2
spec/models/form/sales/questions/buyer1_income_value_check_spec.rb → spec/models/form/sales/questions/buyer1_income_min_value_check_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Questions::Buyer1IncomeValueCheck, type: :model do RSpec.describe Form::Sales::Questions::Buyer1IncomeMinValueCheck, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) } subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil } let(:question_id) { nil }

4
spec/models/form/sales/subsections/household_characteristics_spec.rb

@ -37,7 +37,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
buyer_1_nationality buyer_1_nationality
buyer_1_working_situation buyer_1_working_situation
working_situation_1_retirement_value_check working_situation_1_retirement_value_check
working_situation_buyer_1_income_value_check working_situation_buyer_1_income_min_value_check
buyer_1_live_in_property buyer_1_live_in_property
buyer_2_relationship_to_buyer_1 buyer_2_relationship_to_buyer_1
buyer_2_relationship_student_not_child_value_check buyer_2_relationship_student_not_child_value_check
@ -139,7 +139,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
buyer_1_nationality buyer_1_nationality
buyer_1_working_situation buyer_1_working_situation
working_situation_1_retirement_value_check working_situation_1_retirement_value_check
working_situation_buyer_1_income_value_check working_situation_buyer_1_income_min_value_check
buyer_1_live_in_property buyer_1_live_in_property
buyer_2_relationship_to_buyer_1 buyer_2_relationship_to_buyer_1
buyer_2_relationship_student_not_child_value_check buyer_2_relationship_student_not_child_value_check

4
spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb

@ -21,7 +21,7 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model
expect(subsection.pages.compact.map(&:id)).to eq( expect(subsection.pages.compact.map(&:id)).to eq(
%w[ %w[
buyer_1_income buyer_1_income
buyer_1_income_value_check buyer_1_income_min_value_check
buyer_1_income_mortgage_value_check buyer_1_income_mortgage_value_check
buyer_1_mortgage buyer_1_mortgage
buyer_1_mortgage_value_check buyer_1_mortgage_value_check
@ -49,7 +49,7 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model
expect(subsection.pages.map(&:id)).to eq( expect(subsection.pages.map(&:id)).to eq(
%w[ %w[
buyer_1_income buyer_1_income
buyer_1_income_value_check buyer_1_income_min_value_check
buyer_1_income_mortgage_value_check buyer_1_income_mortgage_value_check
buyer_1_mortgage buyer_1_mortgage
buyer_1_mortgage_value_check buyer_1_mortgage_value_check

Loading…
Cancel
Save