Browse Source

Cldc 855 savings validation (#1102)

* Add savings soft validation page and question

* Add savings saof validation page to the income subsection

* add savings_over_soft_max? soft validation

* Add deposit value check soft validation page and question

* Add deposit soft validation page to the income and benefits subsection

* Add deposit, savings and deposit value check fields to the db

* Add deposit over soft max validation

* Add the value check to the new sections
pull/1096/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
09e4a55bbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      app/models/form/sales/pages/deposit_value_check.rb
  2. 20
      app/models/form/sales/pages/savings_value_check.rb
  3. 25
      app/models/form/sales/questions/deposit_value_check.rb
  4. 25
      app/models/form/sales/questions/savings_value_check.rb
  5. 1
      app/models/form/sales/subsections/discounted_ownership_scheme.rb
  6. 2
      app/models/form/sales/subsections/income_benefits_and_savings.rb
  7. 1
      app/models/form/sales/subsections/outright_sale.rb
  8. 1
      app/models/form/sales/subsections/shared_ownership_scheme.rb
  9. 10
      app/models/validations/sales/soft_validations.rb
  10. 8
      db/migrate/20221216151616_add_savings_value_check.rb
  11. 2
      db/schema.rb
  12. 33
      spec/models/form/sales/pages/deposit_value_check_spec.rb
  13. 33
      spec/models/form/sales/pages/savings_value_check_spec.rb
  14. 61
      spec/models/form/sales/questions/deposit_value_check_spec.rb
  15. 61
      spec/models/form/sales/questions/savings_value_check_spec.rb
  16. 1
      spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
  17. 2
      spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb
  18. 3
      spec/models/form/sales/subsections/outright_sale_spec.rb
  19. 1
      spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb
  20. 4
      spec/models/form_handler_spec.rb
  21. 54
      spec/models/validations/sales/soft_validations_spec.rb

20
app/models/form/sales/pages/deposit_value_check.rb

@ -0,0 +1,20 @@
class Form::Sales::Pages::DepositValueCheck < ::Form::Page
def initialize(id, hsh, subsection)
super
@header = ""
@description = ""
@subsection = subsection
@depends_on = [
{
"deposit_over_soft_max?" => true,
},
]
@informative_text = {}
end
def questions
@questions ||= [
Form::Sales::Questions::DepositValueCheck.new(nil, nil, self),
]
end
end

20
app/models/form/sales/pages/savings_value_check.rb

@ -0,0 +1,20 @@
class Form::Sales::Pages::SavingsValueCheck < ::Form::Page
def initialize(id, hsh, subsection)
super
@header = ""
@description = ""
@subsection = subsection
@depends_on = [
{
"savings_over_soft_max?" => true,
},
]
@informative_text = {}
end
def questions
@questions ||= [
Form::Sales::Questions::SavingsValueCheck.new(nil, nil, self),
]
end
end

25
app/models/form/sales/questions/deposit_value_check.rb

@ -0,0 +1,25 @@
class Form::Sales::Questions::DepositValueCheck < ::Form::Question
def initialize(id, hsh, page)
super
@id = "deposit_value_check"
@check_answer_label = "Deposit confirmation"
@header = "Are you sure that the deposit is this much higher than the buyer's savings?"
@type = "interruption_screen"
@answer_options = {
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
}
@hidden_in_check_answers = {
"depends_on" => [
{
"deposit_value_check" => 0,
},
{
"deposit_value_check" => 1,
},
],
}
@check_answers_card_number = 0
@page = page
end
end

25
app/models/form/sales/questions/savings_value_check.rb

@ -0,0 +1,25 @@
class Form::Sales::Questions::SavingsValueCheck < ::Form::Question
def initialize(id, hsh, page)
super
@id = "savings_value_check"
@check_answer_label = "Savings confirmation"
@header = "Are you sure the savings are higher than £100,000?"
@type = "interruption_screen"
@answer_options = {
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
}
@hidden_in_check_answers = {
"depends_on" => [
{
"savings_value_check" => 0,
},
{
"savings_value_check" => 1,
},
],
}
@check_answers_card_number = 0
@page = page
end
end

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

@ -14,6 +14,7 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection
Form::Sales::Pages::AboutPriceNotRtb.new(nil, nil, self),
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_discounted_ownership", nil, self),
Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_discounted_ownership", nil, self),
Form::Sales::Pages::DepositValueCheck.new("discounted_ownership_deposit_value_check", nil, self),
]
end

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

@ -19,6 +19,8 @@ class Form::Sales::Subsections::IncomeBenefitsAndSavings < ::Form::Subsection
Form::Sales::Pages::Buyer2Mortgage.new(nil, nil, self),
Form::Sales::Pages::MortgageValueCheck.new("buyer_2_mortgage_value_check", nil, self),
Form::Sales::Pages::Savings.new(nil, nil, self),
Form::Sales::Pages::SavingsValueCheck.new("savings_value_check", nil, self),
Form::Sales::Pages::DepositValueCheck.new("savings_deposit_value_check", nil, self),
Form::Sales::Pages::PreviousOwnership.new(nil, nil, self),
]
end

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

@ -12,6 +12,7 @@ class Form::Sales::Subsections::OutrightSale < ::Form::Subsection
Form::Sales::Pages::PurchasePrice.new(nil, nil, self),
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_outright_sale", nil, self),
Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_outright_sale", nil, self),
Form::Sales::Pages::DepositValueCheck.new("outright_sale_deposit_value_check", nil, self),
]
end

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

@ -21,6 +21,7 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_shared_ownership", nil, self),
Form::Sales::Pages::AboutDepositWithDiscount.new(nil, nil, self),
Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_shared_ownership", nil, self),
Form::Sales::Pages::DepositValueCheck.new("shared_ownership_deposit_value_check", nil, self),
Form::Sales::Pages::MonthlyRent.new(nil, nil, self),
]
end

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

@ -26,4 +26,14 @@ module Validations::Sales::SoftValidations
wheel == 1
end
def savings_over_soft_max?
savings && savings > 100_000
end
def deposit_over_soft_max?
return unless savings && deposit
deposit > savings * 4 / 3
end
end

8
db/migrate/20221216151616_add_savings_value_check.rb

@ -0,0 +1,8 @@
class AddSavingsValueCheck < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :savings_value_check, :integer
t.column :deposit_value_check, :integer
end
end
end

2
db/schema.rb

@ -455,6 +455,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_04_164318) do
t.integer "hhregresstill"
t.integer "proplen"
t.integer "prevten"
t.integer "savings_value_check"
t.integer "deposit_value_check"
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"

33
spec/models/form/sales/pages/deposit_value_check_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::DepositValueCheck, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { "deposit_value_check" }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[deposit_value_check])
end
it "has the correct id" do
expect(page.id).to eq("deposit_value_check")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([
{
"deposit_over_soft_max?" => true,
},
])
end
end

33
spec/models/form/sales/pages/savings_value_check_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::SavingsValueCheck, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { "savings_value_check" }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[savings_value_check])
end
it "has the correct id" do
expect(page.id).to eq("savings_value_check")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([
{
"savings_over_soft_max?" => true,
},
])
end
end

61
spec/models/form/sales/questions/deposit_value_check_spec.rb

@ -0,0 +1,61 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::DepositValueCheck, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("deposit_value_check")
end
it "has the correct header" do
expect(question.header).to eq("Are you sure that the deposit is this much higher than the buyer's savings?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Deposit confirmation")
end
it "has the correct type" do
expect(question.type).to eq("interruption_screen")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint" do
expect(question.hint_text).to be_nil
end
it "has a correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(0)
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
})
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq({
"depends_on" => [
{
"deposit_value_check" => 0,
},
{
"deposit_value_check" => 1,
},
],
})
end
end

61
spec/models/form/sales/questions/savings_value_check_spec.rb

@ -0,0 +1,61 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::SavingsValueCheck, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("savings_value_check")
end
it "has the correct header" do
expect(question.header).to eq("Are you sure the savings are higher than £100,000?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Savings confirmation")
end
it "has the correct type" do
expect(question.type).to eq("interruption_screen")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint" do
expect(question.hint_text).to be_nil
end
it "has a correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(0)
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
})
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq({
"depends_on" => [
{
"savings_value_check" => 0,
},
{
"savings_value_check" => 1,
},
],
})
end
end

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

@ -19,6 +19,7 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
about_price_not_rtb
mortgage_amount_discounted_ownership
about_deposit_discounted_ownership
discounted_ownership_deposit_value_check
],
)
end

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

@ -24,6 +24,8 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model
buyer_2_mortgage
buyer_2_mortgage_value_check
savings
savings_value_check
savings_deposit_value_check
previous_ownership
],
)

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

@ -15,7 +15,8 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do
expect(outright_sale.pages.map(&:id)).to eq(
%w[purchase_price
mortgage_amount_outright_sale
about_deposit_outright_sale],
about_deposit_outright_sale
outright_sale_deposit_value_check],
)
end

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

@ -26,6 +26,7 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do
mortgage_amount_shared_ownership
about_deposit_with_discount
about_deposit_shared_ownership
shared_ownership_deposit_value_check
monthly_rent
],
)

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(107)
expect(form.pages.count).to eq(112)
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(107)
expect(form.pages.count).to eq(112)
expect(form.name).to eq("2021_2022_sales")
end
end

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

@ -201,4 +201,58 @@ RSpec.describe Validations::Sales::SoftValidations do
end
end
end
describe "savings amount validations" do
context "when validating soft max" do
it "returns false if no savings is given" do
record.savings = nil
expect(record)
.not_to be_savings_over_soft_max
end
it "savings is over 100_000" do
record.savings = 100_001
expect(record)
.to be_savings_over_soft_max
end
it "savings is under 100_000" do
record.savings = 99_999
expect(record)
.not_to be_mortgage_over_soft_max
end
end
end
describe "deposit amount validations" do
context "when validating soft max" do
it "returns false if no savings is given" do
record.savings = nil
record.deposit = 8_001
expect(record)
.not_to be_deposit_over_soft_max
end
it "returns false if no deposit is given" do
record.deposit = nil
record.savings = 6_000
expect(record)
.not_to be_deposit_over_soft_max
end
it "returns true if deposit is more than 4/3 of savings" do
record.deposit = 8_001
record.savings = 6_000
expect(record)
.to be_deposit_over_soft_max
end
it "returns fals if deposit is less than 4/3 of savings" do
record.deposit = 7_999
record.savings = 6_000
expect(record)
.not_to be_deposit_over_soft_max
end
end
end
end

Loading…
Cancel
Save