From 8f89c1e3f7aeb4b3b858e4de8b9cec8b0d5b5b9c Mon Sep 17 00:00:00 2001 From: samyou-softwire Date: Wed, 22 Apr 2026 12:20:35 +0100 Subject: [PATCH] CLDC-3676: sales deposit value soft validation --- .../shared_ownership_deposit_value_check.rb | 35 ----- .../shared_ownership_deposit_value_check.rb | 22 --- .../shared_ownership_initial_purchase.rb | 3 - .../subsections/shared_ownership_scheme.rb | 3 - ...hared_ownership_staircasing_transaction.rb | 1 - .../validations/sales/soft_validations.rb | 9 -- ...ared_ownership_deposit_value_check_spec.rb | 44 ------ ...ared_ownership_deposit_value_check_spec.rb | 45 ------ .../shared_ownership_initial_purchase_spec.rb | 9 -- .../shared_ownership_scheme_spec.rb | 3 - ..._ownership_staircasing_transaction_spec.rb | 2 - .../sales/soft_validations_spec.rb | 143 ------------------ 12 files changed, 319 deletions(-) delete mode 100644 app/models/form/sales/pages/shared_ownership_deposit_value_check.rb delete mode 100644 app/models/form/sales/questions/shared_ownership_deposit_value_check.rb delete mode 100644 spec/models/form/sales/pages/shared_ownership_deposit_value_check_spec.rb delete mode 100644 spec/models/form/sales/questions/shared_ownership_deposit_value_check_spec.rb diff --git a/app/models/form/sales/pages/shared_ownership_deposit_value_check.rb b/app/models/form/sales/pages/shared_ownership_deposit_value_check.rb deleted file mode 100644 index e56db3e38..000000000 --- a/app/models/form/sales/pages/shared_ownership_deposit_value_check.rb +++ /dev/null @@ -1,35 +0,0 @@ -class Form::Sales::Pages::SharedOwnershipDepositValueCheck < ::Form::Page - def initialize(id, hsh, subsection) - super - @depends_on = [ - { - "shared_ownership_deposit_invalid?" => true, - }, - ] - @copy_key = "sales.soft_validations.shared_ownership_deposit_value_check" - @title_text = { - "translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text", - "arguments" => [ - { - "key" => "mortgage_deposit_and_discount_error_fields", - "i18n_template" => "mortgage_deposit_and_discount_error_fields", - }, - { - "key" => "field_formatted_as_currency", - "arguments_for_key" => "mortgage_deposit_and_discount_total", - "i18n_template" => "mortgage_deposit_and_discount_total", - }, - ], - } - end - - def questions - @questions ||= [ - Form::Sales::Questions::SharedOwnershipDepositValueCheck.new(nil, nil, self), - ] - end - - def interruption_screen_question_ids - %w[mortgage mortgageused cashdis type deposit value equity] - end -end diff --git a/app/models/form/sales/questions/shared_ownership_deposit_value_check.rb b/app/models/form/sales/questions/shared_ownership_deposit_value_check.rb deleted file mode 100644 index e7f520b43..000000000 --- a/app/models/form/sales/questions/shared_ownership_deposit_value_check.rb +++ /dev/null @@ -1,22 +0,0 @@ -class Form::Sales::Questions::SharedOwnershipDepositValueCheck < ::Form::Question - def initialize(id, hsh, page) - super - @id = "shared_ownership_deposit_value_check" - @copy_key = "sales.soft_validations.shared_ownership_deposit_value_check" - @type = "interruption_screen" - @answer_options = { - "0" => { "value" => "Yes" }, - "1" => { "value" => "No" }, - } - @hidden_in_check_answers = { - "depends_on" => [ - { - "shared_ownership_deposit_value_check" => 0, - }, - { - "shared_ownership_deposit_value_check" => 1, - }, - ], - } - end -end diff --git a/app/models/form/sales/subsections/shared_ownership_initial_purchase.rb b/app/models/form/sales/subsections/shared_ownership_initial_purchase.rb index 462f4b14c..c7a25b13b 100644 --- a/app/models/form/sales/subsections/shared_ownership_initial_purchase.rb +++ b/app/models/form/sales/subsections/shared_ownership_initial_purchase.rb @@ -22,11 +22,9 @@ class Form::Sales::Subsections::SharedOwnershipInitialPurchase < ::Form::Subsect Form::Sales::Pages::ValueSharedOwnership.new("value_shared_ownership", nil, self), Form::Sales::Pages::AboutPriceValueCheck.new("about_price_shared_ownership_value_check", nil, self), Form::Sales::Pages::Equity.new("initial_equity", 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, ownershipsch: 1), Form::Sales::Pages::MortgageValueCheck.new("mortgage_used_mortgage_value_check", nil, self), Form::Sales::Pages::MortgageAmount.new("mortgage_amount_shared_ownership", nil, self, ownershipsch: 1), - 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::MortgageLength.new("mortgage_length_shared_ownership", nil, self, ownershipsch: 1) unless form.start_year_2026_or_later?), (Form::Sales::Pages::MortgageLengthNotInterviewed.new("mortgage_length_shared_ownership_not_interviewed", nil, self, ownershipsch: 1) if form.start_year_2026_or_later?), @@ -37,7 +35,6 @@ class Form::Sales::Subsections::SharedOwnershipInitialPurchase < ::Form::Subsect Form::Sales::Pages::DepositValueCheck.new("deposit_value_check", nil, self, joint_purchase: false), Form::Sales::Pages::DepositDiscount.new("deposit_discount", nil, self, optional: false), Form::Sales::Pages::DepositDiscount.new("deposit_discount_optional", nil, self, optional: true), - Form::Sales::Pages::SharedOwnershipDepositValueCheck.new("shared_ownership_deposit_value_check", nil, self), Form::Sales::Pages::MonthlyRent.new(nil, nil, self), Form::Sales::Pages::ServiceCharge.new("service_charge", nil, self), Form::Sales::Pages::MonthlyChargesValueCheck.new("monthly_charges_initial_purchase_value_check", nil, self), diff --git a/app/models/form/sales/subsections/shared_ownership_scheme.rb b/app/models/form/sales/subsections/shared_ownership_scheme.rb index c0718e009..9b26b6ec8 100644 --- a/app/models/form/sales/subsections/shared_ownership_scheme.rb +++ b/app/models/form/sales/subsections/shared_ownership_scheme.rb @@ -30,11 +30,9 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection Form::Sales::Pages::ValueSharedOwnership.new("value_shared_ownership", nil, self), Form::Sales::Pages::AboutPriceValueCheck.new("about_price_shared_ownership_value_check", nil, self), Form::Sales::Pages::Equity.new("equity", 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, ownershipsch: 1), Form::Sales::Pages::MortgageValueCheck.new("mortgage_used_mortgage_value_check", nil, self), Form::Sales::Pages::MortgageAmount.new("mortgage_amount_shared_ownership", nil, self, ownershipsch: 1), - 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, ownershipsch: 1), Form::Sales::Pages::MortgageLenderOther.new("mortgage_lender_other_shared_ownership", nil, self, ownershipsch: 1), @@ -46,7 +44,6 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection Form::Sales::Pages::DepositValueCheck.new("deposit_value_check", nil, self, joint_purchase: false), Form::Sales::Pages::DepositDiscount.new("deposit_discount", nil, self, optional: false), (Form::Sales::Pages::DepositDiscount.new("deposit_discount_optional", nil, self, optional: true) if form.start_year_2024_or_later?), - Form::Sales::Pages::SharedOwnershipDepositValueCheck.new("shared_ownership_deposit_value_check", nil, self), Form::Sales::Pages::MonthlyRent.new(nil, nil, self), Form::Sales::Pages::LeaseholdCharges.new("leasehold_charges_shared_ownership", nil, self, ownershipsch: 1), Form::Sales::Pages::MonthlyChargesValueCheck.new("monthly_charges_shared_ownership_value_check", nil, self), diff --git a/app/models/form/sales/subsections/shared_ownership_staircasing_transaction.rb b/app/models/form/sales/subsections/shared_ownership_staircasing_transaction.rb index 0ff054f18..fd426e3ff 100644 --- a/app/models/form/sales/subsections/shared_ownership_staircasing_transaction.rb +++ b/app/models/form/sales/subsections/shared_ownership_staircasing_transaction.rb @@ -21,7 +21,6 @@ class Form::Sales::Subsections::SharedOwnershipStaircasingTransaction < ::Form:: Form::Sales::Pages::ValueSharedOwnership.new("value_shared_ownership_staircase", nil, self), Form::Sales::Pages::AboutPriceValueCheck.new("about_price_shared_ownership_value_check_staircasing", nil, self), Form::Sales::Pages::Equity.new("staircase_equity", nil, self), - Form::Sales::Pages::SharedOwnershipDepositValueCheck.new("shared_ownership_equity_value_check_staircasing", nil, self), Form::Sales::Pages::Mortgageused.new("staircase_mortgage_used_shared_ownership", nil, self, ownershipsch: 1), Form::Sales::Pages::MonthlyRentStaircasingOwned.new(nil, nil, self), Form::Sales::Pages::MonthlyRentStaircasing.new(nil, nil, self), diff --git a/app/models/validations/sales/soft_validations.rb b/app/models/validations/sales/soft_validations.rb index 40f29cdf5..50d451f17 100644 --- a/app/models/validations/sales/soft_validations.rb +++ b/app/models/validations/sales/soft_validations.rb @@ -90,15 +90,6 @@ module Validations::Sales::SoftValidations type == 24 && stairowned.between?(76, 100) end - def shared_ownership_deposit_invalid? - return unless saledate && collection_start_year <= 2023 - return unless mortgage || mortgageused == 2 || mortgageused == 3 - return unless cashdis || !social_homebuy? - return unless deposit && value && equity - - over_tolerance?(mortgage_deposit_and_discount_total, value * equity / 100, 1) - end - def mortgage_plus_deposit_less_than_discounted_value? return unless mortgage && deposit && value && discount return if form.start_year_2026_or_later? diff --git a/spec/models/form/sales/pages/shared_ownership_deposit_value_check_spec.rb b/spec/models/form/sales/pages/shared_ownership_deposit_value_check_spec.rb deleted file mode 100644 index bca971fe5..000000000 --- a/spec/models/form/sales/pages/shared_ownership_deposit_value_check_spec.rb +++ /dev/null @@ -1,44 +0,0 @@ -require "rails_helper" - -RSpec.describe Form::Sales::Pages::SharedOwnershipDepositValueCheck, type: :model do - subject(:page) { described_class.new(page_id, page_definition, subsection) } - - let(:page_id) { "shared_ownership_deposit_value_check" } - let(:page_definition) { nil } - let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) } - let(:subsection) { instance_double(Form::Subsection, form:) } - - 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[shared_ownership_deposit_value_check]) - end - - it "has the correct id" do - expect(page.id).to eq("shared_ownership_deposit_value_check") - end - - it "has correct depends_on" do - expect(page.depends_on).to eq([ - { - "shared_ownership_deposit_invalid?" => true, - }, - ]) - end - - it "has the correct title_text" do - expect(page.title_text).to eq({ - "translation" => "forms.2024.sales.soft_validations.shared_ownership_deposit_value_check.title_text", - "arguments" => [ - { "i18n_template" => "mortgage_deposit_and_discount_error_fields", "key" => "mortgage_deposit_and_discount_error_fields" }, - { "arguments_for_key" => "mortgage_deposit_and_discount_total", "i18n_template" => "mortgage_deposit_and_discount_total", "key" => "field_formatted_as_currency" }, - ], - }) - end - - it "has the correct interruption_screen_question_ids" do - expect(page.interruption_screen_question_ids).to eq(%w[mortgage mortgageused cashdis type deposit value equity]) - end -end diff --git a/spec/models/form/sales/questions/shared_ownership_deposit_value_check_spec.rb b/spec/models/form/sales/questions/shared_ownership_deposit_value_check_spec.rb deleted file mode 100644 index 0c8a37dad..000000000 --- a/spec/models/form/sales/questions/shared_ownership_deposit_value_check_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -require "rails_helper" - -RSpec.describe Form::Sales::Questions::SharedOwnershipDepositValueCheck, 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("shared_ownership_deposit_value_check") - 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?(nil)).to be false - 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" => [ - { - "shared_ownership_deposit_value_check" => 0, - }, - { - "shared_ownership_deposit_value_check" => 1, - }, - ], - }) - end -end diff --git a/spec/models/form/sales/subsections/shared_ownership_initial_purchase_spec.rb b/spec/models/form/sales/subsections/shared_ownership_initial_purchase_spec.rb index ce154af3d..63dd73726 100644 --- a/spec/models/form/sales/subsections/shared_ownership_initial_purchase_spec.rb +++ b/spec/models/form/sales/subsections/shared_ownership_initial_purchase_spec.rb @@ -43,11 +43,9 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipInitialPurchase, type: : value_shared_ownership about_price_shared_ownership_value_check initial_equity - shared_ownership_equity_value_check mortgage_used_shared_ownership mortgage_used_mortgage_value_check mortgage_amount_shared_ownership - shared_ownership_mortgage_amount_value_check mortgage_amount_mortgage_value_check mortgage_length_shared_ownership deposit_shared_ownership @@ -56,7 +54,6 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipInitialPurchase, type: : deposit_value_check deposit_discount deposit_discount_optional - shared_ownership_deposit_value_check monthly_rent service_charge monthly_charges_initial_purchase_value_check @@ -86,11 +83,9 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipInitialPurchase, type: : value_shared_ownership about_price_shared_ownership_value_check initial_equity - shared_ownership_equity_value_check mortgage_used_shared_ownership mortgage_used_mortgage_value_check mortgage_amount_shared_ownership - shared_ownership_mortgage_amount_value_check mortgage_amount_mortgage_value_check mortgage_length_shared_ownership deposit_shared_ownership @@ -99,7 +94,6 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipInitialPurchase, type: : deposit_value_check deposit_discount deposit_discount_optional - shared_ownership_deposit_value_check monthly_rent service_charge monthly_charges_initial_purchase_value_check @@ -128,11 +122,9 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipInitialPurchase, type: : value_shared_ownership about_price_shared_ownership_value_check initial_equity - shared_ownership_equity_value_check mortgage_used_shared_ownership mortgage_used_mortgage_value_check mortgage_amount_shared_ownership - shared_ownership_mortgage_amount_value_check mortgage_amount_mortgage_value_check mortgage_length_shared_ownership_not_interviewed mortgage_length_shared_ownership_interviewed @@ -142,7 +134,6 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipInitialPurchase, type: : deposit_value_check deposit_discount deposit_discount_optional - shared_ownership_deposit_value_check monthly_rent service_charge monthly_charges_initial_purchase_value_check 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 0b6904508..2887d2565 100644 --- a/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb +++ b/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb @@ -39,11 +39,9 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do value_shared_ownership about_price_shared_ownership_value_check equity - shared_ownership_equity_value_check mortgage_used_shared_ownership mortgage_used_mortgage_value_check mortgage_amount_shared_ownership - shared_ownership_mortgage_amount_value_check mortgage_amount_mortgage_value_check mortgage_lender_shared_ownership mortgage_lender_other_shared_ownership @@ -53,7 +51,6 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do deposit_joint_purchase_value_check deposit_value_check deposit_discount - shared_ownership_deposit_value_check monthly_rent leasehold_charges_shared_ownership monthly_charges_shared_ownership_value_check diff --git a/spec/models/form/sales/subsections/shared_ownership_staircasing_transaction_spec.rb b/spec/models/form/sales/subsections/shared_ownership_staircasing_transaction_spec.rb index e70e4b613..31715aee2 100644 --- a/spec/models/form/sales/subsections/shared_ownership_staircasing_transaction_spec.rb +++ b/spec/models/form/sales/subsections/shared_ownership_staircasing_transaction_spec.rb @@ -44,7 +44,6 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipStaircasingTransaction, value_shared_ownership_staircase about_price_shared_ownership_value_check_staircasing staircase_equity - shared_ownership_equity_value_check_staircasing staircase_mortgage_used_shared_ownership monthly_rent_staircasing_owned monthly_rent_staircasing @@ -72,7 +71,6 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipStaircasingTransaction, value_shared_ownership_staircase about_price_shared_ownership_value_check_staircasing staircase_equity - shared_ownership_equity_value_check_staircasing staircase_mortgage_used_shared_ownership monthly_rent_staircasing_owned monthly_rent_staircasing diff --git a/spec/models/validations/sales/soft_validations_spec.rb b/spec/models/validations/sales/soft_validations_spec.rb index a800b5b54..07c438ca8 100644 --- a/spec/models/validations/sales/soft_validations_spec.rb +++ b/spec/models/validations/sales/soft_validations_spec.rb @@ -465,149 +465,6 @@ RSpec.describe Validations::Sales::SoftValidations do .not_to be_deposit_over_soft_max end end - - context "when validating shared ownership deposit" do - before do - record.saledate = Time.zone.local(2023, 4, 3) - end - - it "returns false if MORTGAGE + DEPOSIT + CASHDIS are equal VALUE * EQUITY/100" do - record.mortgage = 1000 - record.deposit = 1000 - record.cashdis = 1000 - record.value = 3000 - record.equity = 100 - - expect(record) - .not_to be_shared_ownership_deposit_invalid - end - - it "returns false if MORTGAGE + DEPOSIT + CASHDIS are within 1£ of VALUE * EQUITY/100" do - record.mortgage = 500 - record.deposit = 500 - record.cashdis = 500 - record.value = 3001 - record.equity = 50 - - expect(record) - .not_to be_shared_ownership_deposit_invalid - end - - it "returns false if mortgage is used and no mortgage is given" do - record.mortgage = nil - record.deposit = 1000 - record.cashdis = 1000 - record.value = 3000 - record.equity = 100 - - expect(record) - .not_to be_shared_ownership_deposit_invalid - end - - it "returns true if mortgage is not used and no mortgage is given" do - record.mortgage = nil - record.mortgageused = 2 - record.deposit = 1000 - record.cashdis = 1000 - record.value = 3000 - record.equity = 100 - - expect(record) - .to be_shared_ownership_deposit_invalid - end - - it "returns false if no deposit is given" do - record.mortgage = 1000 - record.deposit = nil - record.cashdis = 1000 - record.value = 3000 - record.equity = 100 - - expect(record) - .not_to be_shared_ownership_deposit_invalid - end - - it "returns false if no cashdis is given and cashdis is routed to" do - record.mortgage = 1000 - record.deposit = 1000 - record.type = 18 - record.cashdis = nil - record.value = 3000 - record.equity = 100 - - expect(record) - .not_to be_shared_ownership_deposit_invalid - end - - it "returns true if no cashdis is given and cashdis is not routed to" do - record.mortgage = 1000 - record.deposit = 1000 - record.type = 2 - record.cashdis = nil - record.value = 3000 - record.equity = 100 - - expect(record) - .to be_shared_ownership_deposit_invalid - end - - it "returns false if no cashdis not routed to and MORTGAGE + DEPOSIT are within 1£ of VALUE * EQUITY/100" do - record.mortgage = 500 - record.deposit = 500 - record.type = 2 - record.cashdis = nil - record.value = 1999 - record.equity = 50 - - expect(record) - .not_to be_shared_ownership_deposit_invalid - end - - it "returns false if no value is given" do - record.mortgage = 1000 - record.deposit = 1000 - record.cashdis = 1000 - record.value = nil - record.equity = 100 - - expect(record) - .not_to be_shared_ownership_deposit_invalid - end - - it "returns false if no equity is given" do - record.mortgage = 1000 - record.deposit = 1000 - record.cashdis = 1000 - record.value = 3000 - record.equity = nil - - expect(record) - .not_to be_shared_ownership_deposit_invalid - end - - it "returns true if MORTGAGE + DEPOSIT + CASHDIS are not equal VALUE * EQUITY/100" do - record.mortgage = 1000 - record.deposit = 1000 - record.cashdis = 1000 - record.value = 4323 - record.equity = 100 - - expect(record) - .to be_shared_ownership_deposit_invalid - end - - it "returns false if startyear is after 2024" do - record.saledate = Time.zone.local(2025, 1, 1) - record.mortgage = 1000 - record.deposit = 1000 - record.cashdis = 1000 - record.value = 4323 - record.equity = 100 - - expect(record) - .not_to be_shared_ownership_deposit_invalid - end - end end describe "hodate_more_than_3_years_before_saledate" do