diff --git a/app/models/form/sales/pages/deposit_value_check.rb b/app/models/form/sales/pages/deposit_value_check.rb new file mode 100644 index 000000000..7c0fc9fef --- /dev/null +++ b/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 diff --git a/app/models/form/sales/pages/savings_value_check.rb b/app/models/form/sales/pages/savings_value_check.rb new file mode 100644 index 000000000..7f31097f9 --- /dev/null +++ b/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 diff --git a/app/models/form/sales/questions/deposit_value_check.rb b/app/models/form/sales/questions/deposit_value_check.rb new file mode 100644 index 000000000..86bc0d226 --- /dev/null +++ b/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 diff --git a/app/models/form/sales/questions/savings_value_check.rb b/app/models/form/sales/questions/savings_value_check.rb new file mode 100644 index 000000000..6af93ee03 --- /dev/null +++ b/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 diff --git a/app/models/form/sales/subsections/discounted_ownership_scheme.rb b/app/models/form/sales/subsections/discounted_ownership_scheme.rb index 4e317618e..c0d65522f 100644 --- a/app/models/form/sales/subsections/discounted_ownership_scheme.rb +++ b/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 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 9232b9318..318095373 100644 --- a/app/models/form/sales/subsections/income_benefits_and_savings.rb +++ b/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 diff --git a/app/models/form/sales/subsections/outright_sale.rb b/app/models/form/sales/subsections/outright_sale.rb index c9c6bbf85..4c7f5263f 100644 --- a/app/models/form/sales/subsections/outright_sale.rb +++ b/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 diff --git a/app/models/form/sales/subsections/shared_ownership_scheme.rb b/app/models/form/sales/subsections/shared_ownership_scheme.rb index 89a438487..aaf789ff8 100644 --- a/app/models/form/sales/subsections/shared_ownership_scheme.rb +++ b/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 diff --git a/app/models/validations/sales/soft_validations.rb b/app/models/validations/sales/soft_validations.rb index d52d5cf9c..db061704d 100644 --- a/app/models/validations/sales/soft_validations.rb +++ b/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 diff --git a/db/migrate/20221216151616_add_savings_value_check.rb b/db/migrate/20221216151616_add_savings_value_check.rb new file mode 100644 index 000000000..e5facd5e8 --- /dev/null +++ b/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 diff --git a/db/schema.rb b/db/schema.rb index f0351dba5..8418104e8 100644 --- a/db/schema.rb +++ b/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" diff --git a/spec/models/form/sales/pages/deposit_value_check_spec.rb b/spec/models/form/sales/pages/deposit_value_check_spec.rb new file mode 100644 index 000000000..909215f2c --- /dev/null +++ b/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 diff --git a/spec/models/form/sales/pages/savings_value_check_spec.rb b/spec/models/form/sales/pages/savings_value_check_spec.rb new file mode 100644 index 000000000..d40862da9 --- /dev/null +++ b/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 diff --git a/spec/models/form/sales/questions/deposit_value_check_spec.rb b/spec/models/form/sales/questions/deposit_value_check_spec.rb new file mode 100644 index 000000000..70baafbef --- /dev/null +++ b/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 diff --git a/spec/models/form/sales/questions/savings_value_check_spec.rb b/spec/models/form/sales/questions/savings_value_check_spec.rb new file mode 100644 index 000000000..3794147de --- /dev/null +++ b/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 diff --git a/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb b/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb index 0adb25d3c..02b31541c 100644 --- a/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb +++ b/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 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 02d58622a..d568c8f99 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 @@ -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 ], ) diff --git a/spec/models/form/sales/subsections/outright_sale_spec.rb b/spec/models/form/sales/subsections/outright_sale_spec.rb index 96a26ff93..c19337d16 100644 --- a/spec/models/form/sales/subsections/outright_sale_spec.rb +++ b/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 diff --git a/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb b/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb index 4cdf0c468..b2bfc41e8 100644 --- a/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb +++ b/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 ], ) diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index d9bee9a52..1dc26e32b 100644 --- a/spec/models/form_handler_spec.rb +++ b/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 diff --git a/spec/models/validations/sales/soft_validations_spec.rb b/spec/models/validations/sales/soft_validations_spec.rb index 6eb454e07..132701356 100644 --- a/spec/models/validations/sales/soft_validations_spec.rb +++ b/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