Browse Source

CLDC-1583 Add extra borrowing validation (#1201)

* feat: add condition-less soft validation and update db

* feat: add validation condition and update tests

* feat: update validation

* feat: update validation

* feat: add tests

* db: update

* test: update

* refactor: linting

* test: update

* feat: update text, remove separate redundant function, add value check page everywhere

* feat: leave value check at end

* test: update

* feat: add value check everywhere

* tests: update

* db:update

* feat: only appear at end

* test: update

* feat: add soft validation everywhere smoothly

* test: update
pull/1169/head
natdeanlewissoftwire 2 years ago committed by GitHub
parent
commit
a4fbb99a3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      app/models/form/sales/pages/extra_borrowing_value_check.rb
  2. 23
      app/models/form/sales/questions/extra_borrowing_value_check.rb
  3. 4
      app/models/form/sales/subsections/discounted_ownership_scheme.rb
  4. 4
      app/models/validations/sales/household_validations.rb
  5. 6
      app/models/validations/sales/soft_validations.rb
  6. 2
      config/locales/en.yml
  7. 7
      db/migrate/20230118170602_add_extra_borrowing_value_check_to_sales.rb
  8. 5
      db/schema.rb
  9. 2
      db/seeds.rb
  10. 4
      spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
  11. 4
      spec/models/form_handler_spec.rb
  12. 83
      spec/models/validations/sales/soft_validations_spec.rb

21
app/models/form/sales/pages/extra_borrowing_value_check.rb

@ -0,0 +1,21 @@
class Form::Sales::Pages::ExtraBorrowingValueCheck < Form::Page
def initialize(id, hsh, subsection)
super
@depends_on = [
{
"extra_borrowing_expected_but_not_reported?" => true,
},
]
@title_text = {
"translation" => "soft_validations.extra_borrowing.title",
}
@informative_text = {
}
end
def questions
@questions ||= [
Form::Sales::Questions::ExtraBorrowingValueCheck.new(nil, nil, self),
]
end
end

23
app/models/form/sales/questions/extra_borrowing_value_check.rb

@ -0,0 +1,23 @@
class Form::Sales::Questions::ExtraBorrowingValueCheck < ::Form::Question
def initialize(id, hsh, page)
super(id, hsh, page)
@id = "extrabor_value_check"
@check_answer_label = "Extra borrowing confirmation"
@type = "interruption_screen"
@answer_options = {
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
}
@hidden_in_check_answers = {
"depends_on" => [
{
"extrabor_value_check" => 0,
},
{
"extrabor_value_check" => 1,
},
],
}
@header = "Are you sure there is no extra borrowing?"
end
end

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

@ -10,15 +10,19 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection
@pages ||= [
Form::Sales::Pages::LivingBeforePurchase.new("living_before_purchase_discounted_ownership", nil, self),
Form::Sales::Pages::AboutPriceRtb.new(nil, nil, self),
Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_price_value_check", nil, self),
Form::Sales::Pages::AboutPriceNotRtb.new(nil, nil, self),
Form::Sales::Pages::PurchasePrice.new("purchase_price_discounted_ownership", nil, self),
Form::Sales::Pages::Mortgageused.new("mortgage_used_discounted_ownership", nil, self),
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_discounted_ownership", nil, self),
Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_mortgage_value_check", nil, self),
Form::Sales::Pages::MortgageLender.new("mortgage_lender_discounted_ownership", nil, self),
Form::Sales::Pages::MortgageLenderOther.new("mortgage_lender_other_discounted_ownership", nil, self),
Form::Sales::Pages::MortgageLength.new("mortgage_length_discounted_ownership", nil, self),
Form::Sales::Pages::ExtraBorrowing.new("extra_borrowing_discounted_ownership", nil, self),
Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_value_check", nil, self),
Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_discounted_ownership", nil, self),
Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_deposit_value_check", nil, self),
Form::Sales::Pages::DepositValueCheck.new("discounted_ownership_deposit_value_check", nil, self),
Form::Sales::Pages::LeaseholdCharges.new("leasehold_charges_discounted_ownership", nil, self),
]

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

@ -109,10 +109,6 @@ private
economic_status == 7
end
def person_economic_status_refused?(economic_status)
economic_status == 10
end
def person_is_child?(relationship)
relationship == "C"
end

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

@ -37,6 +37,12 @@ module Validations::Sales::SoftValidations
deposit > savings * 4 / 3
end
def extra_borrowing_expected_but_not_reported?
return unless extrabor && mortgage && deposit && value && discount
extrabor != 1 && mortgage + deposit > value - value * discount / 100
end
def hodate_3_years_or_more_saledate?
return unless hodate && saledate

2
config/locales/en.yml

@ -448,6 +448,8 @@ en:
max:
title: "You told us this person is %{age} or over and not retired"
hint_text: "The minimum expected retirement age for %{gender} in England is %{age}."
extra_borrowing:
title: "The mortgage and deposit are higher than the purchase minus the discount"
pregnancy:
title: "You told us somebody in the household is pregnant"
no_females: "You also told us there are no female tenants living at the property."

7
db/migrate/20230118170602_add_extra_borrowing_value_check_to_sales.rb

@ -0,0 +1,7 @@
class AddExtraBorrowingValueCheckToSales < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :extrabor_value_check, :integer
end
end
end

5
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_01_16_151942) do
ActiveRecord::Schema[7.0].define(version: 2023_01_18_170602) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -502,8 +502,9 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_16_151942) do
t.integer "hhtype"
t.integer "hodate_check"
t.bigint "bulk_upload_id"
t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id"
t.integer "retirement_value_check"
t.integer "extrabor_value_check"
t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id"
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id"
t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"

2
db/seeds.rb

@ -160,7 +160,7 @@ unless Rails.env.test?
saledate: Date.new(1, 1, 1),
purchid: "1",
ownershipsch: 2,
type: 8,
type: 9,
jointpur: 1,
jointmore: 1,
)

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

@ -16,15 +16,19 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
%w[
living_before_purchase_discounted_ownership
about_price_rtb
extra_borrowing_price_value_check
about_price_not_rtb
purchase_price_discounted_ownership
mortgage_used_discounted_ownership
mortgage_amount_discounted_ownership
extra_borrowing_mortgage_value_check
mortgage_lender_discounted_ownership
mortgage_lender_other_discounted_ownership
mortgage_length_discounted_ownership
extra_borrowing_discounted_ownership
extra_borrowing_value_check
about_deposit_discounted_ownership
extra_borrowing_deposit_value_check
discounted_ownership_deposit_value_check
leasehold_charges_discounted_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
form = form_handler.get_form("current_sales")
expect(form).to be_a(Form)
expect(form.pages.count).to eq(183)
expect(form.pages.count).to eq(187)
expect(form.name).to eq("2022_2023_sales")
end
it "is able to load a previous sales form" do
form = form_handler.get_form("previous_sales")
expect(form).to be_a(Form)
expect(form.pages.count).to eq(183)
expect(form.pages.count).to eq(187)
expect(form.name).to eq("2021_2022_sales")
end
end

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

@ -128,7 +128,7 @@ RSpec.describe Validations::Sales::SoftValidations do
.not_to be_mortgage_over_soft_max
end
it "returns true if only income1 is used for morgage and it is less than 1/5 of the morgage" do
it "returns true if only income1 is used for mortgage and it is less than 1/5 of the mortgage" do
record.inc1mort = 1
record.income1 = 10_000
record.mortgage = 51_000
@ -137,7 +137,7 @@ RSpec.describe Validations::Sales::SoftValidations do
.to be_mortgage_over_soft_max
end
it "returns false if only income1 is used for morgage and it is more than 1/5 of the morgage" do
it "returns false if only income1 is used for mortgage and it is more than 1/5 of the mortgage" do
record.inc1mort = 1
record.income1 = 10_000
record.mortgage = 44_000
@ -146,7 +146,7 @@ RSpec.describe Validations::Sales::SoftValidations do
.not_to be_mortgage_over_soft_max
end
it "returns true if only income2 is used for morgage and it is less than 1/5 of the morgage" do
it "returns true if only income2 is used for mortgage and it is less than 1/5 of the mortgage" do
record.inc1mort = 2
record.inc2mort = 1
record.income2 = 10_000
@ -155,7 +155,7 @@ RSpec.describe Validations::Sales::SoftValidations do
.to be_mortgage_over_soft_max
end
it "returns false if only income2 is used for morgage and it is more than 1/5 of the morgage" do
it "returns false if only income2 is used for mortgage and it is more than 1/5 of the mortgage" do
record.inc1mort = 2
record.inc2mort = 1
record.income2 = 10_000
@ -164,7 +164,7 @@ RSpec.describe Validations::Sales::SoftValidations do
.not_to be_mortgage_over_soft_max
end
it "returns true if income1 and income2 are used for morgage and their sum is less than 1/5 of the morgage" do
it "returns true if income1 and income2 are used for mortgage and their sum is less than 1/5 of the mortgage" do
record.inc1mort = 1
record.inc2mort = 1
record.income1 = 10_000
@ -174,7 +174,7 @@ RSpec.describe Validations::Sales::SoftValidations do
.to be_mortgage_over_soft_max
end
it "returns false if income1 and income2 are used for morgage and their sum is more than 1/5 of the morgage" do
it "returns false if income1 and income2 are used for mortgage and their sum is more than 1/5 of the mortgage" do
record.inc1mort = 1
record.inc2mort = 1
record.income1 = 8_000
@ -184,7 +184,7 @@ RSpec.describe Validations::Sales::SoftValidations do
.not_to be_mortgage_over_soft_max
end
it "returns true if neither of the incomes are used for morgage and the morgage is more than 0" do
it "returns true if neither of the incomes are used for mortgage and the mortgage is more than 0" do
record.inc1mort = 2
record.inc2mort = 2
record.mortgage = 124_000
@ -192,7 +192,7 @@ RSpec.describe Validations::Sales::SoftValidations do
.to be_mortgage_over_soft_max
end
it "returns true if neither of the incomes are used for morgage and the morgage is 0" do
it "returns false if neither of the incomes are used for mortgage and the mortgage is 0" do
record.inc1mort = 2
record.inc2mort = 2
record.mortgage = 0
@ -200,6 +200,73 @@ RSpec.describe Validations::Sales::SoftValidations do
.not_to be_mortgage_over_soft_max
end
end
context "when validating extra borrowing" do
it "returns false if extrabor not present" do
record.mortgage = 50_000
record.deposit = 40_000
record.value = 100_000
record.discount = 11
expect(record)
.not_to be_extra_borrowing_expected_but_not_reported
end
it "returns false if mortgage not present" do
record.extrabor = 2
record.deposit = 40_000
record.value = 100_000
record.discount = 11
expect(record)
.not_to be_extra_borrowing_expected_but_not_reported
end
it "returns false if deposit not present" do
record.extrabor = 2
record.mortgage = 50_000
record.value = 100_000
record.discount = 11
expect(record)
.not_to be_extra_borrowing_expected_but_not_reported
end
it "returns false if value not present" do
record.extrabor = 2
record.mortgage = 50_000
record.deposit = 40_000
record.discount = 11
expect(record)
.not_to be_extra_borrowing_expected_but_not_reported
end
it "returns false if discount not present" do
record.extrabor = 2
record.mortgage = 50_000
record.deposit = 40_000
record.value = 100_000
expect(record)
.not_to be_extra_borrowing_expected_but_not_reported
end
it "returns false if extra borrowing expected and reported" do
record.extrabor = 1
record.mortgage = 50_000
record.deposit = 40_000
record.value = 100_000
record.discount = 11
expect(record)
.not_to be_extra_borrowing_expected_but_not_reported
end
it "returns true if extra borrowing expected but not reported" do
record.extrabor = 2
record.mortgage = 50_000
record.deposit = 40_000
record.value = 100_000
record.discount = 11
expect(record)
.to be_extra_borrowing_expected_but_not_reported
end
end
end
describe "savings amount validations" do

Loading…
Cancel
Save