Browse Source

CLDC-870 Update mortgage amount validations (#1240)

* Add mortgage value check after mortgage used and mortgage amount pages

* Run the mortgage amount validation on non joint purchases as well

* Add validation to disounted and outright sales

* only show buyer 2 checks if it's a jjoint purchase
pull/1264/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
fca8a852d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      app/models/form/sales/pages/mortgage_value_check.rb
  2. 2
      app/models/form/sales/subsections/discounted_ownership_scheme.rb
  3. 8
      app/models/form/sales/subsections/income_benefits_and_savings.rb
  4. 2
      app/models/form/sales/subsections/outright_sale.rb
  5. 2
      app/models/form/sales/subsections/shared_ownership_scheme.rb
  6. 2
      app/models/validations/sales/soft_validations.rb
  7. 16
      spec/models/form/sales/pages/mortgage_value_check_spec.rb
  8. 2
      spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
  9. 2
      spec/models/form/sales/subsections/outright_sale_spec.rb
  10. 2
      spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb
  11. 4
      spec/models/form_handler_spec.rb
  12. 16
      spec/models/validations/sales/soft_validations_spec.rb

28
app/models/form/sales/pages/mortgage_value_check.rb

@ -1,12 +1,9 @@
class Form::Sales::Pages::MortgageValueCheck < ::Form::Page class Form::Sales::Pages::MortgageValueCheck < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection, person_index = nil)
super super(id, hsh, subsection)
@depends_on = [ @depends_on = depends_on
{
"mortgage_over_soft_max?" => true,
},
]
@informative_text = {} @informative_text = {}
@person_index = person_index
end end
def questions def questions
@ -14,4 +11,21 @@ class Form::Sales::Pages::MortgageValueCheck < ::Form::Page
Form::Sales::Questions::MortgageValueCheck.new(nil, nil, self), Form::Sales::Questions::MortgageValueCheck.new(nil, nil, self),
] ]
end end
def depends_on
if @person_index == 2
[
{
"mortgage_over_soft_max?" => true,
"jointpur" => 1,
},
]
else
[
{
"mortgage_over_soft_max?" => true,
},
]
end
end
end end

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

@ -16,7 +16,9 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection
Form::Sales::Pages::PurchasePrice.new("purchase_price_discounted_ownership", nil, self), Form::Sales::Pages::PurchasePrice.new("purchase_price_discounted_ownership", nil, self),
Form::Sales::Pages::DepositAndMortgageValueCheck.new("discounted_ownership_deposit_and_mortgage_value_check_after_value_and_discount", nil, self), Form::Sales::Pages::DepositAndMortgageValueCheck.new("discounted_ownership_deposit_and_mortgage_value_check_after_value_and_discount", nil, self),
Form::Sales::Pages::Mortgageused.new("mortgage_used_discounted_ownership", nil, self), Form::Sales::Pages::Mortgageused.new("mortgage_used_discounted_ownership", nil, self),
Form::Sales::Pages::MortgageValueCheck.new("discounted_ownership_mortgage_used_mortgage_value_check", nil, self),
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_discounted_ownership", nil, self), Form::Sales::Pages::MortgageAmount.new("mortgage_amount_discounted_ownership", nil, self),
Form::Sales::Pages::MortgageValueCheck.new("discounted_ownership_mortgage_amount_mortgage_value_check", nil, self),
Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_mortgage_value_check", nil, self), Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_mortgage_value_check", nil, self),
Form::Sales::Pages::DepositAndMortgageValueCheck.new("discounted_ownership_deposit_and_mortgage_value_check_after_mortgage", nil, self), Form::Sales::Pages::DepositAndMortgageValueCheck.new("discounted_ownership_deposit_and_mortgage_value_check_after_mortgage", nil, self),
Form::Sales::Pages::MortgageLender.new("mortgage_lender_discounted_ownership", nil, self), Form::Sales::Pages::MortgageLender.new("mortgage_lender_discounted_ownership", nil, self),

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

@ -10,13 +10,13 @@ class Form::Sales::Subsections::IncomeBenefitsAndSavings < ::Form::Subsection
@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::Buyer1IncomeValueCheck.new("buyer_1_income_value_check", nil, self),
Form::Sales::Pages::MortgageValueCheck.new("buyer_1_income_mortgage_value_check", nil, self), 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), Form::Sales::Pages::MortgageValueCheck.new("buyer_1_mortgage_value_check", nil, self, 1),
Form::Sales::Pages::Buyer2Income.new(nil, nil, self), Form::Sales::Pages::Buyer2Income.new(nil, nil, self),
Form::Sales::Pages::MortgageValueCheck.new("buyer_2_income_mortgage_value_check", nil, self), Form::Sales::Pages::MortgageValueCheck.new("buyer_2_income_mortgage_value_check", nil, self, 2),
Form::Sales::Pages::Buyer2Mortgage.new(nil, nil, self), Form::Sales::Pages::Buyer2Mortgage.new(nil, nil, self),
Form::Sales::Pages::MortgageValueCheck.new("buyer_2_mortgage_value_check", nil, self), Form::Sales::Pages::MortgageValueCheck.new("buyer_2_mortgage_value_check", nil, self, 2),
Form::Sales::Pages::HousingBenefits.new(nil, nil, self), Form::Sales::Pages::HousingBenefits.new(nil, nil, self),
Form::Sales::Pages::Savings.new(nil, nil, self), Form::Sales::Pages::Savings.new(nil, nil, self),
Form::Sales::Pages::SavingsValueCheck.new("savings_value_check", nil, self), Form::Sales::Pages::SavingsValueCheck.new("savings_value_check", nil, self),

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

@ -10,7 +10,9 @@ class Form::Sales::Subsections::OutrightSale < ::Form::Subsection
@pages ||= [ @pages ||= [
Form::Sales::Pages::PurchasePrice.new("purchase_price_outright_sale", nil, self), Form::Sales::Pages::PurchasePrice.new("purchase_price_outright_sale", nil, self),
Form::Sales::Pages::Mortgageused.new("mortgage_used_outright_sale", nil, self), Form::Sales::Pages::Mortgageused.new("mortgage_used_outright_sale", nil, self),
Form::Sales::Pages::MortgageValueCheck.new("outright_sale_mortgage_used_mortgage_value_check", nil, self),
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_outright_sale", nil, self), Form::Sales::Pages::MortgageAmount.new("mortgage_amount_outright_sale", nil, self),
Form::Sales::Pages::MortgageValueCheck.new("outright_sale_mortgage_amount_mortgage_value_check", nil, self),
Form::Sales::Pages::MortgageLender.new("mortgage_lender_outright_sale", nil, self), Form::Sales::Pages::MortgageLender.new("mortgage_lender_outright_sale", nil, self),
Form::Sales::Pages::MortgageLenderOther.new("mortgage_lender_other_outright_sale", nil, self), Form::Sales::Pages::MortgageLenderOther.new("mortgage_lender_other_outright_sale", nil, self),
Form::Sales::Pages::MortgageLength.new("mortgage_length_outright_sale", nil, self), Form::Sales::Pages::MortgageLength.new("mortgage_length_outright_sale", nil, self),

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

@ -24,8 +24,10 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection
Form::Sales::Pages::AboutPriceSharedOwnership.new(nil, nil, self), Form::Sales::Pages::AboutPriceSharedOwnership.new(nil, nil, self),
Form::Sales::Pages::SharedOwnershipDepositValueCheck.new("shared_ownership_equity_value_check", nil, self), Form::Sales::Pages::SharedOwnershipDepositValueCheck.new("shared_ownership_equity_value_check", nil, self),
Form::Sales::Pages::Mortgageused.new("mortgage_used_shared_ownership", nil, self), Form::Sales::Pages::Mortgageused.new("mortgage_used_shared_ownership", nil, self),
Form::Sales::Pages::MortgageValueCheck.new("mortgage_used_mortgage_value_check", nil, self),
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_shared_ownership", nil, self), Form::Sales::Pages::MortgageAmount.new("mortgage_amount_shared_ownership", nil, self),
Form::Sales::Pages::SharedOwnershipDepositValueCheck.new("shared_ownership_mortgage_amount_value_check", nil, self), Form::Sales::Pages::SharedOwnershipDepositValueCheck.new("shared_ownership_mortgage_amount_value_check", nil, self),
Form::Sales::Pages::MortgageValueCheck.new("mortgage_amount_mortgage_value_check", nil, self),
Form::Sales::Pages::MortgageLender.new("mortgage_lender_shared_ownership", nil, self), Form::Sales::Pages::MortgageLender.new("mortgage_lender_shared_ownership", nil, self),
Form::Sales::Pages::MortgageLenderOther.new("mortgage_lender_other_shared_ownership", nil, self), Form::Sales::Pages::MortgageLenderOther.new("mortgage_lender_other_shared_ownership", nil, self),
Form::Sales::Pages::MortgageLength.new("mortgage_length_shared_ownership", nil, self), Form::Sales::Pages::MortgageLength.new("mortgage_length_shared_ownership", nil, self),

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

@ -18,7 +18,7 @@ module Validations::Sales::SoftValidations
end end
def mortgage_over_soft_max? def mortgage_over_soft_max?
return false unless mortgage && inc1mort && inc2mort return false unless mortgage && inc1mort && (inc2mort || not_joint_purchase?)
return false if income1_used_for_mortgage? && income1.blank? || income2_used_for_mortgage? && income2.blank? return false if income1_used_for_mortgage? && income1.blank? || income2_used_for_mortgage? && income2.blank?
income_used_for_mortgage = (income1_used_for_mortgage? ? income1 : 0) + (income2_used_for_mortgage? ? income2 : 0) income_used_for_mortgage = (income1_used_for_mortgage? ? income1 : 0) + (income2_used_for_mortgage? ? income2 : 0)

16
spec/models/form/sales/pages/mortgage_value_check_spec.rb

@ -1,10 +1,11 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Pages::MortgageValueCheck, type: :model do RSpec.describe Form::Sales::Pages::MortgageValueCheck, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) } subject(:page) { described_class.new(page_id, page_definition, subsection, index) }
let(:page_id) { "buyer_1_income_mortgage_value_check" } let(:page_id) { "buyer_1_income_mortgage_value_check" }
let(:page_definition) { nil } let(:page_definition) { nil }
let(:index) { 1 }
let(:subsection) { instance_double(Form::Subsection) } let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do it "has correct subsection" do
@ -34,4 +35,17 @@ RSpec.describe Form::Sales::Pages::MortgageValueCheck, type: :model do
}, },
]) ])
end end
context "when checking buyer 2" do
let(:index) { 2 }
it "has correct depends_on" do
expect(page.depends_on).to eq([
{
"mortgage_over_soft_max?" => true,
"jointpur" => 1,
},
])
end
end
end end

2
spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb

@ -22,7 +22,9 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
purchase_price_discounted_ownership purchase_price_discounted_ownership
discounted_ownership_deposit_and_mortgage_value_check_after_value_and_discount discounted_ownership_deposit_and_mortgage_value_check_after_value_and_discount
mortgage_used_discounted_ownership mortgage_used_discounted_ownership
discounted_ownership_mortgage_used_mortgage_value_check
mortgage_amount_discounted_ownership mortgage_amount_discounted_ownership
discounted_ownership_mortgage_amount_mortgage_value_check
extra_borrowing_mortgage_value_check extra_borrowing_mortgage_value_check
discounted_ownership_deposit_and_mortgage_value_check_after_mortgage discounted_ownership_deposit_and_mortgage_value_check_after_mortgage
mortgage_lender_discounted_ownership mortgage_lender_discounted_ownership

2
spec/models/form/sales/subsections/outright_sale_spec.rb

@ -16,7 +16,9 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do
%w[ %w[
purchase_price_outright_sale purchase_price_outright_sale
mortgage_used_outright_sale mortgage_used_outright_sale
outright_sale_mortgage_used_mortgage_value_check
mortgage_amount_outright_sale mortgage_amount_outright_sale
outright_sale_mortgage_amount_mortgage_value_check
mortgage_lender_outright_sale mortgage_lender_outright_sale
mortgage_lender_other_outright_sale mortgage_lender_other_outright_sale
mortgage_length_outright_sale mortgage_length_outright_sale

2
spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb

@ -30,8 +30,10 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do
about_price_shared_ownership about_price_shared_ownership
shared_ownership_equity_value_check shared_ownership_equity_value_check
mortgage_used_shared_ownership mortgage_used_shared_ownership
mortgage_used_mortgage_value_check
mortgage_amount_shared_ownership mortgage_amount_shared_ownership
shared_ownership_mortgage_amount_value_check shared_ownership_mortgage_amount_value_check
mortgage_amount_mortgage_value_check
mortgage_lender_shared_ownership mortgage_lender_shared_ownership
mortgage_lender_other_shared_ownership mortgage_lender_other_shared_ownership
mortgage_length_shared_ownership mortgage_length_shared_ownership

4
spec/models/form_handler_spec.rb

@ -52,14 +52,14 @@ RSpec.describe FormHandler do
it "is able to load a current sales form" do it "is able to load a current sales form" do
form = form_handler.get_form("current_sales") form = form_handler.get_form("current_sales")
expect(form).to be_a(Form) expect(form).to be_a(Form)
expect(form.pages.count).to eq(203) expect(form.pages.count).to eq(209)
expect(form.name).to eq("2022_2023_sales") expect(form.name).to eq("2022_2023_sales")
end end
it "is able to load a previous sales form" do it "is able to load a previous sales form" do
form = form_handler.get_form("previous_sales") form = form_handler.get_form("previous_sales")
expect(form).to be_a(Form) expect(form).to be_a(Form)
expect(form.pages.count).to eq(203) expect(form.pages.count).to eq(209)
expect(form.name).to eq("2021_2022_sales") expect(form.name).to eq("2021_2022_sales")
end end
end end

16
spec/models/validations/sales/soft_validations_spec.rb

@ -102,14 +102,26 @@ RSpec.describe Validations::Sales::SoftValidations do
.not_to be_mortgage_over_soft_max .not_to be_mortgage_over_soft_max
end end
it "returns false if no inc2mort is given" do it "returns false if no inc2mort is given and it's a joint purchase" do
record.inc1mort = 2 record.jointpur = 1
record.inc1mort = 1
record.income1 = 10
record.inc2mort = nil record.inc2mort = nil
record.mortgage = 20_000 record.mortgage = 20_000
expect(record) expect(record)
.not_to be_mortgage_over_soft_max .not_to be_mortgage_over_soft_max
end end
it "returns true if no inc2mort is given and it's not a joint purchase" do
record.jointpur = 2
record.inc1mort = 1
record.income1 = 10
record.inc2mort = nil
record.mortgage = 20_000
expect(record)
.to be_mortgage_over_soft_max
end
it "returns false if no income1 is given and inc1mort is yes" do it "returns false if no income1 is given and inc1mort is yes" do
record.inc1mort = 1 record.inc1mort = 1
record.inc2mort = 2 record.inc2mort = 2

Loading…
Cancel
Save