From 7d2c92144ee21b4ddc07a7057d33eea3c5ec54e4 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Mon, 5 Aug 2024 12:34:58 +0100 Subject: [PATCH] CLDC-3569 Update social homebuy errors (#2541) * Split questions * Update the error message * Add guidance * Add back the headers * Refactor depends_on * Refactor further --- .../pages/about_deposit_without_discount.rb | 26 -- app/models/form/sales/pages/deposit.rb | 21 ++ ...t_deposit_with_discount.rb => discount.rb} | 5 +- ...ut_price_shared_ownership.rb => equity.rb} | 5 +- .../sales/pages/value_shared_ownership.rb | 13 + .../form/sales/questions/deposit_amount.rb | 1 + .../form/sales/questions/deposit_discount.rb | 1 + app/models/form/sales/questions/equity.rb | 1 + .../form/sales/questions/mortgage_amount.rb | 1 + app/models/form/sales/questions/value.rb | 1 + .../discounted_ownership_scheme.rb | 2 +- .../form/sales/subsections/outright_sale.rb | 2 +- .../subsections/shared_ownership_scheme.rb | 13 +- .../sales/sale_information_validations.rb | 18 +- app/views/form/_numeric_question.html.erb | 2 +- ...ial_calculations_shared_ownership.html.erb | 10 + config/locales/en.yml | 2 +- .../about_deposit_without_discount_spec.rb | 79 ------ spec/models/form/sales/pages/deposit_spec.rb | 235 ++++++++++++++++++ ...with_discount_spec.rb => discount_spec.rb} | 8 +- ...hared_ownership_spec.rb => equity_spec.rb} | 6 +- .../pages/value_shared_ownership_spec.rb | 33 +++ .../discounted_ownership_scheme_spec.rb | 2 +- .../sales/subsections/outright_sale_spec.rb | 6 +- .../shared_ownership_scheme_spec.rb | 8 +- .../sale_information_validations_spec.rb | 12 +- 26 files changed, 371 insertions(+), 142 deletions(-) delete mode 100644 app/models/form/sales/pages/about_deposit_without_discount.rb create mode 100644 app/models/form/sales/pages/deposit.rb rename app/models/form/sales/pages/{about_deposit_with_discount.rb => discount.rb} (72%) rename app/models/form/sales/pages/{about_price_shared_ownership.rb => equity.rb} (56%) create mode 100644 app/models/form/sales/pages/value_shared_ownership.rb create mode 100644 app/views/form/guidance/_financial_calculations_shared_ownership.html.erb delete mode 100644 spec/models/form/sales/pages/about_deposit_without_discount_spec.rb create mode 100644 spec/models/form/sales/pages/deposit_spec.rb rename spec/models/form/sales/pages/{about_deposit_with_discount_spec.rb => discount_spec.rb} (87%) rename spec/models/form/sales/pages/{about_price_shared_ownership_spec.rb => equity_spec.rb} (78%) create mode 100644 spec/models/form/sales/pages/value_shared_ownership_spec.rb diff --git a/app/models/form/sales/pages/about_deposit_without_discount.rb b/app/models/form/sales/pages/about_deposit_without_discount.rb deleted file mode 100644 index 5747c3ed4..000000000 --- a/app/models/form/sales/pages/about_deposit_without_discount.rb +++ /dev/null @@ -1,26 +0,0 @@ -class Form::Sales::Pages::AboutDepositWithoutDiscount < ::Form::Page - def initialize(id, hsh, subsection, ownershipsch:, optional:) - super(id, hsh, subsection) - @header = "About the deposit" - @ownershipsch = ownershipsch - @optional = optional - end - - def questions - @questions ||= [ - Form::Sales::Questions::DepositAmount.new(nil, nil, self, ownershipsch: @ownershipsch, optional: @optional), - ] - end - - def depends_on - if form.start_year_after_2024? - [{ "social_homebuy?" => false, "ownershipsch" => 1, "stairowned_100?" => @optional }, - { "ownershipsch" => 2 }, - { "ownershipsch" => 3, "mortgageused" => 1 }] - else - [{ "social_homebuy?" => false, "ownershipsch" => 1 }, - { "ownershipsch" => 2 }, - { "ownershipsch" => 3, "mortgageused" => 1 }] - end - end -end diff --git a/app/models/form/sales/pages/deposit.rb b/app/models/form/sales/pages/deposit.rb new file mode 100644 index 000000000..72e6d163c --- /dev/null +++ b/app/models/form/sales/pages/deposit.rb @@ -0,0 +1,21 @@ +class Form::Sales::Pages::Deposit < ::Form::Page + def initialize(id, hsh, subsection, ownershipsch:, optional:) + super(id, hsh, subsection) + @ownershipsch = ownershipsch + @optional = optional + @header = "About the deposit" + end + + def questions + @questions ||= [ + Form::Sales::Questions::DepositAmount.new(nil, nil, self, ownershipsch: @ownershipsch, optional: @optional), + ] + end + + def routed_to?(log, _user) + return true if log.ownershipsch == 2 || (log.ownershipsch == 3 && log.mortgageused == 1) + return false if log.stairowned_100? != @optional && form.start_year_after_2024? + + log.ownershipsch == 1 + end +end diff --git a/app/models/form/sales/pages/about_deposit_with_discount.rb b/app/models/form/sales/pages/discount.rb similarity index 72% rename from app/models/form/sales/pages/about_deposit_with_discount.rb rename to app/models/form/sales/pages/discount.rb index 4f1eed451..267fda711 100644 --- a/app/models/form/sales/pages/about_deposit_with_discount.rb +++ b/app/models/form/sales/pages/discount.rb @@ -1,13 +1,12 @@ -class Form::Sales::Pages::AboutDepositWithDiscount < ::Form::Page +class Form::Sales::Pages::Discount < ::Form::Page def initialize(id, hsh, subsection, optional:) super(id, hsh, subsection) - @header = "About the deposit" @optional = optional + @header = "About the deposit" end def questions @questions ||= [ - Form::Sales::Questions::DepositAmount.new(nil, nil, self, ownershipsch: 1, optional: @optional), Form::Sales::Questions::DepositDiscount.new(nil, nil, self), ] end diff --git a/app/models/form/sales/pages/about_price_shared_ownership.rb b/app/models/form/sales/pages/equity.rb similarity index 56% rename from app/models/form/sales/pages/about_price_shared_ownership.rb rename to app/models/form/sales/pages/equity.rb index 1f65a7d19..018ba6f79 100644 --- a/app/models/form/sales/pages/about_price_shared_ownership.rb +++ b/app/models/form/sales/pages/equity.rb @@ -1,13 +1,12 @@ -class Form::Sales::Pages::AboutPriceSharedOwnership < ::Form::Page +class Form::Sales::Pages::Equity < ::Form::Page def initialize(id, hsh, subsection) super - @id = "about_price_shared_ownership" + @id = "equity" @header = "About the price of the property" end def questions @questions ||= [ - Form::Sales::Questions::Value.new(nil, nil, self), Form::Sales::Questions::Equity.new(nil, nil, self), ] end diff --git a/app/models/form/sales/pages/value_shared_ownership.rb b/app/models/form/sales/pages/value_shared_ownership.rb new file mode 100644 index 000000000..a4f6dbe1c --- /dev/null +++ b/app/models/form/sales/pages/value_shared_ownership.rb @@ -0,0 +1,13 @@ +class Form::Sales::Pages::ValueSharedOwnership < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "value_shared_ownership" + @header = "About the price of the property" + end + + def questions + @questions ||= [ + Form::Sales::Questions::Value.new(nil, nil, self), + ] + end +end diff --git a/app/models/form/sales/questions/deposit_amount.rb b/app/models/form/sales/questions/deposit_amount.rb index 3cef0db8d..86bb456f3 100644 --- a/app/models/form/sales/questions/deposit_amount.rb +++ b/app/models/form/sales/questions/deposit_amount.rb @@ -13,6 +13,7 @@ class Form::Sales::Questions::DepositAmount < ::Form::Question @ownershipsch = ownershipsch @question_number = QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.fetch(form.start_date.year, QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.max_by { |k, _v| k }.last)[ownershipsch] @optional = optional + @top_guidance_partial = "financial_calculations_shared_ownership" if ownershipsch == 1 end def derived?(log) diff --git a/app/models/form/sales/questions/deposit_discount.rb b/app/models/form/sales/questions/deposit_discount.rb index 52a7e90c7..faf8d76f7 100644 --- a/app/models/form/sales/questions/deposit_discount.rb +++ b/app/models/form/sales/questions/deposit_discount.rb @@ -12,6 +12,7 @@ class Form::Sales::Questions::DepositDiscount < ::Form::Question @prefix = "£" @hint_text = "Enter the total cash discount given on the property being purchased through the Social HomeBuy scheme" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @top_guidance_partial = "financial_calculations_shared_ownership" end QUESTION_NUMBER_FROM_YEAR = { 2023 => 96, 2024 => 97 }.freeze diff --git a/app/models/form/sales/questions/equity.rb b/app/models/form/sales/questions/equity.rb index 6ee8d692f..2e1ad4dee 100644 --- a/app/models/form/sales/questions/equity.rb +++ b/app/models/form/sales/questions/equity.rb @@ -12,6 +12,7 @@ class Form::Sales::Questions::Equity < ::Form::Question @suffix = "%" @hint_text = "Enter the amount of initial equity held by the purchaser (for example, 25% or 50%)" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @top_guidance_partial = "financial_calculations_shared_ownership" end QUESTION_NUMBER_FROM_YEAR = { 2023 => 89, 2024 => 90 }.freeze diff --git a/app/models/form/sales/questions/mortgage_amount.rb b/app/models/form/sales/questions/mortgage_amount.rb index f3ec338ee..e38737c89 100644 --- a/app/models/form/sales/questions/mortgage_amount.rb +++ b/app/models/form/sales/questions/mortgage_amount.rb @@ -12,6 +12,7 @@ class Form::Sales::Questions::MortgageAmount < ::Form::Question @hint_text = "Enter the amount of mortgage agreed with the mortgage lender. Exclude any deposits or cash payments. Numeric in pounds. Rounded to the nearest pound." @ownershipsch = ownershipsch @question_number = QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.fetch(form.start_date.year, QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.max_by { |k, _v| k }.last)[ownershipsch] + @top_guidance_partial = "financial_calculations_shared_ownership" if ownershipsch == 1 end QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP = { diff --git a/app/models/form/sales/questions/value.rb b/app/models/form/sales/questions/value.rb index 61668aa83..3ec96e76e 100644 --- a/app/models/form/sales/questions/value.rb +++ b/app/models/form/sales/questions/value.rb @@ -11,6 +11,7 @@ class Form::Sales::Questions::Value < ::Form::Question @prefix = "£" @hint_text = "Enter the full purchase price of the property before any discounts are applied. For shared ownership, enter the full purchase price paid for 100% equity (this is equal to the value of the share owned by the PRP plus the value bought by the purchaser)" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @top_guidance_partial = "financial_calculations_shared_ownership" end QUESTION_NUMBER_FROM_YEAR = { 2023 => 88, 2024 => 89 }.freeze diff --git a/app/models/form/sales/subsections/discounted_ownership_scheme.rb b/app/models/form/sales/subsections/discounted_ownership_scheme.rb index dd115786f..e8af859cf 100644 --- a/app/models/form/sales/subsections/discounted_ownership_scheme.rb +++ b/app/models/form/sales/subsections/discounted_ownership_scheme.rb @@ -32,7 +32,7 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection Form::Sales::Pages::MortgageLength.new("mortgage_length_discounted_ownership", nil, self, ownershipsch: 2), Form::Sales::Pages::ExtraBorrowing.new("extra_borrowing_discounted_ownership", nil, self, ownershipsch: 2), Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_value_check", nil, self), - Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_discounted_ownership", nil, self, ownershipsch: 2, optional: false), + Form::Sales::Pages::Deposit.new("deposit_discounted_ownership", nil, self, ownershipsch: 2, optional: false), Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_deposit_value_check", nil, self), Form::Sales::Pages::DepositValueCheck.new("discounted_ownership_deposit_joint_purchase_value_check", nil, self, joint_purchase: true), Form::Sales::Pages::DepositValueCheck.new("discounted_ownership_deposit_value_check", nil, self, joint_purchase: false), diff --git a/app/models/form/sales/subsections/outright_sale.rb b/app/models/form/sales/subsections/outright_sale.rb index 15d95f4b7..6b29313a1 100644 --- a/app/models/form/sales/subsections/outright_sale.rb +++ b/app/models/form/sales/subsections/outright_sale.rb @@ -18,7 +18,7 @@ class Form::Sales::Subsections::OutrightSale < ::Form::Subsection (Form::Sales::Pages::MortgageLenderOther.new("mortgage_lender_other_outright_sale", nil, self, ownershipsch: 3) unless form.start_year_after_2024?), Form::Sales::Pages::MortgageLength.new("mortgage_length_outright_sale", nil, self, ownershipsch: 3), Form::Sales::Pages::ExtraBorrowing.new("extra_borrowing_outright_sale", nil, self, ownershipsch: 3), - Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_outright_sale", nil, self, ownershipsch: 3, optional: false), + Form::Sales::Pages::Deposit.new("deposit_outright_sale", nil, self, ownershipsch: 3, optional: false), Form::Sales::Pages::DepositValueCheck.new("outright_sale_deposit_joint_purchase_value_check", nil, self, joint_purchase: true), Form::Sales::Pages::DepositValueCheck.new("outright_sale_deposit_value_check", nil, self, joint_purchase: false), leasehold_charge_pages, diff --git a/app/models/form/sales/subsections/shared_ownership_scheme.rb b/app/models/form/sales/subsections/shared_ownership_scheme.rb index 01697baff..0d9f363a0 100644 --- a/app/models/form/sales/subsections/shared_ownership_scheme.rb +++ b/app/models/form/sales/subsections/shared_ownership_scheme.rb @@ -26,8 +26,9 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection Form::Sales::Pages::PreviousBedrooms.new(nil, nil, self), Form::Sales::Pages::PreviousPropertyType.new(nil, nil, self), Form::Sales::Pages::PreviousTenure.new(nil, nil, self), - Form::Sales::Pages::AboutPriceSharedOwnership.new(nil, nil, self), + Form::Sales::Pages::ValueSharedOwnership.new(nil, nil, self), Form::Sales::Pages::AboutPriceValueCheck.new("about_price_shared_ownership_value_check", nil, self), + Form::Sales::Pages::Equity.new(nil, 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), @@ -38,10 +39,12 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection Form::Sales::Pages::MortgageLenderOther.new("mortgage_lender_other_shared_ownership", nil, self, ownershipsch: 1), Form::Sales::Pages::MortgageLength.new("mortgage_length_shared_ownership", nil, self, ownershipsch: 1), Form::Sales::Pages::ExtraBorrowing.new("extra_borrowing_shared_ownership", nil, self, ownershipsch: 1), - Form::Sales::Pages::AboutDepositWithDiscount.new("about_deposit_with_discount", nil, self, optional: false), - (Form::Sales::Pages::AboutDepositWithDiscount.new("about_deposit_with_discount_optional", nil, self, optional: true) if form.start_year_after_2024?), - Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_shared_ownership", nil, self, ownershipsch: 1, optional: false), - (Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_shared_ownership_optional", nil, self, ownershipsch: 1, optional: true) if form.start_year_after_2024?), + Form::Sales::Pages::Deposit.new("deposit", nil, self, optional: false, ownershipsch: 1), + Form::Sales::Pages::Discount.new("discount", nil, self, optional: false), + (Form::Sales::Pages::Deposit.new("deposit_optional", nil, self, optional: true, ownershipsch: 1) if form.start_year_after_2024?), + (Form::Sales::Pages::Discount.new("discount_optional", nil, self, optional: true) if form.start_year_after_2024?), + Form::Sales::Pages::Deposit.new("deposit_shared_ownership", nil, self, ownershipsch: 1, optional: false), + (Form::Sales::Pages::Deposit.new("deposit_shared_ownership_optional", nil, self, ownershipsch: 1, optional: true) if form.start_year_after_2024?), Form::Sales::Pages::DepositValueCheck.new("deposit_joint_purchase_value_check", nil, self, joint_purchase: true), Form::Sales::Pages::DepositValueCheck.new("deposit_value_check", nil, self, joint_purchase: false), Form::Sales::Pages::SharedOwnershipDepositValueCheck.new("shared_ownership_deposit_value_check", nil, self), diff --git a/app/models/validations/sales/sale_information_validations.rb b/app/models/validations/sales/sale_information_validations.rb index c8083156c..92a1cd172 100644 --- a/app/models/validations/sales/sale_information_validations.rb +++ b/app/models/validations/sales/sale_information_validations.rb @@ -155,9 +155,23 @@ module Validations::Sales::SaleInformationValidations if over_tolerance?(record.mortgage_deposit_and_discount_total, record.expected_shared_ownership_deposit_value, 1) %i[mortgage value deposit cashdis equity].each do |field| - record.errors.add field, I18n.t("validations.sale_information.non_staircasing_mortgage.mortgage_used_socialhomebuy", mortgage_deposit_and_discount_total: record.field_formatted_as_currency("mortgage_deposit_and_discount_total"), expected_shared_ownership_deposit_value: record.field_formatted_as_currency("expected_shared_ownership_deposit_value")) + record.errors.add field, I18n.t("validations.sale_information.non_staircasing_mortgage.mortgage_used_socialhomebuy", + mortgage: record.field_formatted_as_currency("mortgage"), + value: record.field_formatted_as_currency("value"), + deposit: record.field_formatted_as_currency("deposit"), + cashdis: record.field_formatted_as_currency("cashdis"), + equity: "#{record.equity}%", + mortgage_deposit_and_discount_total: record.field_formatted_as_currency("mortgage_deposit_and_discount_total"), + expected_shared_ownership_deposit_value: record.field_formatted_as_currency("expected_shared_ownership_deposit_value")).html_safe end - record.errors.add :type, :skip_bu_error, message: I18n.t("validations.sale_information.non_staircasing_mortgage.mortgage_used_socialhomebuy", mortgage_deposit_and_discount_total: record.field_formatted_as_currency("mortgage_deposit_and_discount_total"), expected_shared_ownership_deposit_value: record.field_formatted_as_currency("expected_shared_ownership_deposit_value")) + record.errors.add :type, :skip_bu_error, message: I18n.t("validations.sale_information.non_staircasing_mortgage.mortgage_used_socialhomebuy", + mortgage: record.field_formatted_as_currency("mortgage"), + value: record.field_formatted_as_currency("value"), + deposit: record.field_formatted_as_currency("deposit"), + cashdis: record.field_formatted_as_currency("cashdis"), + equity: "#{record.equity}%", + mortgage_deposit_and_discount_total: record.field_formatted_as_currency("mortgage_deposit_and_discount_total"), + expected_shared_ownership_deposit_value: record.field_formatted_as_currency("expected_shared_ownership_deposit_value")) end elsif record.mortgage_not_used? if over_tolerance?(record.deposit_and_discount_total, record.expected_shared_ownership_deposit_value, 1) diff --git a/app/views/form/_numeric_question.html.erb b/app/views/form/_numeric_question.html.erb index aa147767b..8bd2ce7bc 100644 --- a/app/views/form/_numeric_question.html.erb +++ b/app/views/form/_numeric_question.html.erb @@ -1,4 +1,4 @@ -<%= render partial: "form/guidance/#{question.top_guidance_partial}" if question.top_guidance? %> +<%= render partial: "form/guidance/#{question.top_guidance_partial}", locals: { log: @log } if question.top_guidance? %> <%= f.govuk_text_field( question.id.to_sym, diff --git a/app/views/form/guidance/_financial_calculations_shared_ownership.html.erb b/app/views/form/guidance/_financial_calculations_shared_ownership.html.erb new file mode 100644 index 000000000..8edbbd375 --- /dev/null +++ b/app/views/form/guidance/_financial_calculations_shared_ownership.html.erb @@ -0,0 +1,10 @@ +<%= govuk_details(summary_text: "How the financial values are calculated’") do %> +
+ The mortgage amount (<%= govuk_link_to "Q92", send("#{log.class.name.underscore}_#{log.form.get_question('mortgage', log).page.id}_path", log) %>), + cash deposit (<%= govuk_link_to "Q95", send("#{log.class.name.underscore}_#{log.form.get_question('deposit', log).page.id}_path", log) %>) + and cash discount (<%= govuk_link_to "Q97", send("#{log.class.name.underscore}_#{log.form.get_question('cashdis', log).page.id}_path", log) %>) + added together must equal + the purchase price (<%= govuk_link_to "Q88", send("#{log.class.name.underscore}_#{log.form.get_question('value', log).page.id}_path", log) %>) + multiplied by the percentage equity stake (<%= govuk_link_to "Q89", send("#{log.class.name.underscore}_#{log.form.get_question('equity', log).page.id}_path", log) %>) +
+<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index a53b375fe..e4cc52ecf 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -658,7 +658,7 @@ en: non_staircasing_mortgage: mortgage_used: "The mortgage and deposit added together is %{mortgage_and_deposit_total}. The value multiplied by the percentage bought is %{expected_shared_ownership_deposit_value}. These figures should be the same." mortgage_not_used: "The deposit is %{deposit} and the value multiplied by the percentage bought is %{expected_shared_ownership_deposit_value}. These figures should be the same." - mortgage_used_socialhomebuy: "The mortgage, deposit, and cash discount added together is %{mortgage_deposit_and_discount_total}. The value multiplied by the percentage bought is %{expected_shared_ownership_deposit_value}. These figures should be the same." + mortgage_used_socialhomebuy: "The mortgage amount (%{mortgage}), deposit (%{deposit}), and cash discount (%{cashdis}) added together is %{mortgage_deposit_and_discount_total}. The full purchase price (%{value}) multiplied by the percentage equity stake purchased (%{equity}) is %{expected_shared_ownership_deposit_value}. These two amounts should be the same." mortgage_not_used_socialhomebuy: "The deposit and cash discount added together is %{deposit_and_discount_total}. The value multiplied by the percentage bought is %{expected_shared_ownership_deposit_value}. These figures should be the same." staircasing_mortgage: mortgage_used: "The mortgage and deposit added together is %{mortgage_and_deposit_total}. The value multiplied by the percentage bought is %{stairbought_part_of_value}. These figures should be the same." diff --git a/spec/models/form/sales/pages/about_deposit_without_discount_spec.rb b/spec/models/form/sales/pages/about_deposit_without_discount_spec.rb deleted file mode 100644 index 003313353..000000000 --- a/spec/models/form/sales/pages/about_deposit_without_discount_spec.rb +++ /dev/null @@ -1,79 +0,0 @@ -require "rails_helper" - -RSpec.describe Form::Sales::Pages::AboutDepositWithoutDiscount, type: :model do - subject(:page) { described_class.new(page_id, page_definition, subsection, ownershipsch: 1, optional: false) } - - let(:page_id) { nil } - let(:page_definition) { nil } - let(:subsection) { instance_double(Form::Subsection) } - - before do - allow(subsection).to receive(:form).and_return(instance_double(Form, start_year_after_2024?: false, start_date: Time.zone.local(2023, 4, 1))) - end - - 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]) - end - - it "has the correct id" do - expect(page.id).to eq(nil) - end - - it "has the correct header" do - expect(page.header).to eq("About the deposit") - end - - it "has the correct description" do - expect(page.description).to be_nil - end - - it "has correct depends_on" do - expect(page.depends_on).to eq( - [{ "social_homebuy?" => false, "ownershipsch" => 1 }, - { "ownershipsch" => 2 }, - { "ownershipsch" => 3, "mortgageused" => 1 }], - ) - end - - context "when optional is true" do - subject(:page) { described_class.new(page_id, page_definition, subsection, ownershipsch: 1, optional: true) } - - it "has correct depends_on" do - expect(page.depends_on).to eq( - [{ "social_homebuy?" => false, "ownershipsch" => 1 }, - { "ownershipsch" => 2 }, - { "ownershipsch" => 3, "mortgageused" => 1 }], - ) - end - end - - context "when it's a 2024 form" do - before do - allow(subsection).to receive(:form).and_return(instance_double(Form, start_year_after_2024?: true, start_date: Time.zone.local(2024, 4, 1))) - end - - it "has correct depends_on" do - expect(page.depends_on).to eq( - [{ "social_homebuy?" => false, "ownershipsch" => 1, "stairowned_100?" => false }, - { "ownershipsch" => 2 }, - { "ownershipsch" => 3, "mortgageused" => 1 }], - ) - end - - context "and optional is true" do - subject(:page) { described_class.new(page_id, page_definition, subsection, ownershipsch: 1, optional: true) } - - it "has correct depends_on" do - expect(page.depends_on).to eq( - [{ "social_homebuy?" => false, "ownershipsch" => 1, "stairowned_100?" => true }, - { "ownershipsch" => 2 }, - { "ownershipsch" => 3, "mortgageused" => 1 }], - ) - end - end - end -end diff --git a/spec/models/form/sales/pages/deposit_spec.rb b/spec/models/form/sales/pages/deposit_spec.rb new file mode 100644 index 000000000..af314a95a --- /dev/null +++ b/spec/models/form/sales/pages/deposit_spec.rb @@ -0,0 +1,235 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::Deposit, type: :model do + subject(:page) { described_class.new(page_id, page_definition, subsection, ownershipsch: 1, optional:) } + + let(:page_id) { nil } + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection, enabled?: true) } + let(:form) { instance_double(Form, start_year_after_2024?: false, start_date: Time.zone.local(2023, 4, 1)) } + let(:optional) { false } + + before do + allow(subsection).to receive(:form).and_return(form) + end + + 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]) + end + + it "has the correct id" do + expect(page.id).to eq(nil) + end + + it "has the correct header" do + expect(page.header).to eq("About the deposit") + end + + it "has the correct description" do + expect(page.description).to be_nil + end + + context "when routing with start year after 2024" do + before do + allow(form).to receive(:start_year_after_2024?).and_return(true) + end + + context "and optional is false" do + context "and the log is shared ownership, not social homembuy and stairowned is not 100" do + let(:log) { build(:sales_log, ownershipsch: 1, type: 16, stairowned: 70) } + + it "routes to the page" do + expect(page).to be_routed_to(log, nil) + end + end + + context "and the log is shared ownership, not social homembuy and stairowned is 100" do + let(:log) { build(:sales_log, ownershipsch: 1, type: 16, stairowned: 100) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + + context "and the log is shared ownership, social homebuy and stairowned is not 100" do + let(:log) { build(:sales_log, ownershipsch: 1, type: 18, stairowned: 80) } + + it "routes to the page" do + expect(page).to be_routed_to(log, nil) + end + end + + context "and the log is shared ownership, social homebuy and stairowned is 100" do + let(:log) { build(:sales_log, ownershipsch: 1, type: 18, stairowned: 100) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + + context "and the log is discounted ownership" do + let(:log) { build(:sales_log, ownershipsch: 2, type: 18) } + + it "routes to the page" do + expect(page).to be_routed_to(log, nil) + end + end + + context "and the log is outright ownership and mortgage used is yes" do + let(:log) { build(:sales_log, ownershipsch: 3, mortgageused: 1) } + + it "routes to the page" do + expect(page).to be_routed_to(log, nil) + end + end + + context "and ownership is outright sale and mortgage used is not yes" do + let(:log) { build(:sales_log, ownershipsch: 3, mortgageused: 2) } + + it "doesn't route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + end + + context "and optional is true" do + let(:optional) { true } + + context "and the log is shared ownership, not social homembuy and stairowned is not 100" do + let(:log) { build(:sales_log, ownershipsch: 1, type: 16, stairowned: 70) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + + context "and the log is shared ownership, not social homembuy and stairowned is 100" do + let(:log) { build(:sales_log, ownershipsch: 1, type: 16, stairowned: 100) } + + it "routes to the page" do + expect(page).to be_routed_to(log, nil) + end + end + + context "and the log is shared ownership, social homebuy and stairowned is not 100" do + let(:log) { build(:sales_log, ownershipsch: 1, type: 18, stairowned: 80) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + + context "and the log is shared ownership, social homebuy and stairowned is 100" do + let(:log) { build(:sales_log, ownershipsch: 1, type: 18, stairowned: 100) } + + it "routes to the page" do + expect(page).to be_routed_to(log, nil) + end + end + end + end + + context "when routing with start year before 2024" do + before do + allow(form).to receive(:start_year_after_2024?).and_return(false) + end + + context "and optional is false" do + context "and the log is shared ownership, not social homembuy and stairowned is not 100" do + let(:log) { build(:sales_log, ownershipsch: 1, type: 16, stairowned: 70) } + + it "routes to the page" do + expect(page).to be_routed_to(log, nil) + end + end + + context "and the log is shared ownership, not social homembuy and stairowned is 100" do + let(:log) { build(:sales_log, ownershipsch: 1, type: 16, stairowned: 100) } + + it "routes to the page" do + expect(page).to be_routed_to(log, nil) + end + end + + context "and the log is shared ownership, social homebuy and stairowned is not 100" do + let(:log) { build(:sales_log, ownershipsch: 1, type: 18, stairowned: 80) } + + it "routes to the page" do + expect(page).to be_routed_to(log, nil) + end + end + + context "and the log is shared ownership, social homebuy and stairowned is 100" do + let(:log) { build(:sales_log, ownershipsch: 1, type: 18, stairowned: 100) } + + it "routes to the page" do + expect(page).to be_routed_to(log, nil) + end + end + + context "and the log is discounted ownership" do + let(:log) { build(:sales_log, ownershipsch: 2, type: 18) } + + it "routes to the page" do + expect(page).to be_routed_to(log, nil) + end + end + + context "and the log is outright ownership and mortgage used is yes" do + let(:log) { build(:sales_log, ownershipsch: 3, mortgageused: 1) } + + it "routes to the page" do + expect(page).to be_routed_to(log, nil) + end + end + + context "and ownership is outright sale and mortgage used is not yes" do + let(:log) { build(:sales_log, ownershipsch: 3, mortgageused: 2) } + + it "doesn't route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + end + + context "and optional is true" do + let(:optional) { true } + + context "and the log is shared ownership, not social homembuy and stairowned is not 100" do + let(:log) { build(:sales_log, ownershipsch: 1, type: 16, stairowned: 70) } + + it "does routes to the page" do + expect(page).to be_routed_to(log, nil) + end + end + + context "and the log is shared ownership, not social homembuy and stairowned is 100" do + let(:log) { build(:sales_log, ownershipsch: 1, type: 16, stairowned: 100) } + + it "routes to the page" do + expect(page).to be_routed_to(log, nil) + end + end + + context "and the log is shared ownership, social homebuy and stairowned is not 100" do + let(:log) { build(:sales_log, ownershipsch: 1, type: 18, stairowned: 80) } + + it "does routes to the page" do + expect(page).to be_routed_to(log, nil) + end + end + + context "and the log is shared ownership, social homebuy and stairowned is 100" do + let(:log) { build(:sales_log, ownershipsch: 1, type: 18, stairowned: 100) } + + it "routes to the page" do + expect(page).to be_routed_to(log, nil) + end + end + end + end +end diff --git a/spec/models/form/sales/pages/about_deposit_with_discount_spec.rb b/spec/models/form/sales/pages/discount_spec.rb similarity index 87% rename from spec/models/form/sales/pages/about_deposit_with_discount_spec.rb rename to spec/models/form/sales/pages/discount_spec.rb index fabfb7836..bb65f1d6d 100644 --- a/spec/models/form/sales/pages/about_deposit_with_discount_spec.rb +++ b/spec/models/form/sales/pages/discount_spec.rb @@ -1,9 +1,9 @@ require "rails_helper" -RSpec.describe Form::Sales::Pages::AboutDepositWithDiscount, type: :model do +RSpec.describe Form::Sales::Pages::Discount, type: :model do subject(:page) { described_class.new(page_id, page_definition, subsection, optional: false) } - let(:page_id) { "about_deposit_with_discount" } + let(:page_id) { "discount" } let(:page_definition) { nil } let(:subsection) { instance_double(Form::Subsection) } @@ -16,11 +16,11 @@ RSpec.describe Form::Sales::Pages::AboutDepositWithDiscount, type: :model do end it "has correct questions" do - expect(page.questions.map(&:id)).to eq(%w[deposit cashdis]) + expect(page.questions.map(&:id)).to eq(%w[cashdis]) end it "has the correct id" do - expect(page.id).to eq("about_deposit_with_discount") + expect(page.id).to eq("discount") end it "has the correct header" do diff --git a/spec/models/form/sales/pages/about_price_shared_ownership_spec.rb b/spec/models/form/sales/pages/equity_spec.rb similarity index 78% rename from spec/models/form/sales/pages/about_price_shared_ownership_spec.rb rename to spec/models/form/sales/pages/equity_spec.rb index 7074a3ca9..bf620269e 100644 --- a/spec/models/form/sales/pages/about_price_shared_ownership_spec.rb +++ b/spec/models/form/sales/pages/equity_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.describe Form::Sales::Pages::AboutPriceSharedOwnership, type: :model do +RSpec.describe Form::Sales::Pages::Equity, type: :model do subject(:page) { described_class.new(page_id, page_definition, subsection) } let(:page_id) { nil } @@ -12,11 +12,11 @@ RSpec.describe Form::Sales::Pages::AboutPriceSharedOwnership, type: :model do end it "has correct questions" do - expect(page.questions.map(&:id)).to eq(%w[value equity]) + expect(page.questions.map(&:id)).to eq(%w[equity]) end it "has the correct id" do - expect(page.id).to eq("about_price_shared_ownership") + expect(page.id).to eq("equity") end it "has the correct header" do diff --git a/spec/models/form/sales/pages/value_shared_ownership_spec.rb b/spec/models/form/sales/pages/value_shared_ownership_spec.rb new file mode 100644 index 000000000..58a40b2cd --- /dev/null +++ b/spec/models/form/sales/pages/value_shared_ownership_spec.rb @@ -0,0 +1,33 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::ValueSharedOwnership, type: :model do + subject(:page) { described_class.new(page_id, page_definition, subsection) } + + let(:page_id) { nil } + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1))) } + + 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[value]) + end + + it "has the correct id" do + expect(page.id).to eq("value_shared_ownership") + end + + it "has the correct header" do + expect(page.header).to eq("About the price of the property") + end + + it "has the correct description" do + expect(page.description).to be_nil + end + + it "has correct depends_on" do + expect(page.depends_on).to be_nil + 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 5f20cbb91..9bb428569 100644 --- a/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb +++ b/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb @@ -38,7 +38,7 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model mortgage_length_discounted_ownership extra_borrowing_discounted_ownership extra_borrowing_value_check - about_deposit_discounted_ownership + deposit_discounted_ownership extra_borrowing_deposit_value_check discounted_ownership_deposit_joint_purchase_value_check discounted_ownership_deposit_value_check diff --git a/spec/models/form/sales/subsections/outright_sale_spec.rb b/spec/models/form/sales/subsections/outright_sale_spec.rb index efb2aaad6..0d28330f2 100644 --- a/spec/models/form/sales/subsections/outright_sale_spec.rb +++ b/spec/models/form/sales/subsections/outright_sale_spec.rb @@ -38,7 +38,7 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do mortgage_lender_other_outright_sale mortgage_length_outright_sale extra_borrowing_outright_sale - about_deposit_outright_sale + deposit_outright_sale outright_sale_deposit_joint_purchase_value_check outright_sale_deposit_value_check monthly_charges_outright_sale_value_check @@ -67,7 +67,7 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do mortgage_lender_other_outright_sale mortgage_length_outright_sale extra_borrowing_outright_sale - about_deposit_outright_sale + deposit_outright_sale outright_sale_deposit_joint_purchase_value_check outright_sale_deposit_value_check leasehold_charges_outright_sale @@ -94,7 +94,7 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do outright_sale_mortgage_amount_mortgage_value_check mortgage_length_outright_sale extra_borrowing_outright_sale - about_deposit_outright_sale + deposit_outright_sale outright_sale_deposit_joint_purchase_value_check outright_sale_deposit_value_check leasehold_charges_outright_sale 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 59e7bfbfb..685e92877 100644 --- a/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb +++ b/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb @@ -36,8 +36,9 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do previous_bedrooms previous_property_type shared_ownership_previous_tenure - about_price_shared_ownership + value_shared_ownership about_price_shared_ownership_value_check + equity shared_ownership_equity_value_check mortgage_used_shared_ownership mortgage_used_mortgage_value_check @@ -48,8 +49,9 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do mortgage_lender_other_shared_ownership mortgage_length_shared_ownership extra_borrowing_shared_ownership - about_deposit_with_discount - about_deposit_shared_ownership + deposit + discount + deposit_shared_ownership deposit_joint_purchase_value_check deposit_value_check shared_ownership_deposit_value_check diff --git a/spec/models/validations/sales/sale_information_validations_spec.rb b/spec/models/validations/sales/sale_information_validations_spec.rb index 44245f73f..d1becd432 100644 --- a/spec/models/validations/sales/sale_information_validations_spec.rb +++ b/spec/models/validations/sales/sale_information_validations_spec.rb @@ -882,12 +882,12 @@ RSpec.describe Validations::Sales::SaleInformationValidations do it "adds an error" do sale_information_validator.validate_non_staircasing_mortgage(record) - expect(record.errors["mortgage"]).to include("The mortgage, deposit, and cash discount added together is £15,200.00. The value multiplied by the percentage bought is £8,400.00. These figures should be the same.") - expect(record.errors["value"]).to include("The mortgage, deposit, and cash discount added together is £15,200.00. The value multiplied by the percentage bought is £8,400.00. These figures should be the same.") - expect(record.errors["deposit"]).to include("The mortgage, deposit, and cash discount added together is £15,200.00. The value multiplied by the percentage bought is £8,400.00. These figures should be the same.") - expect(record.errors["equity"]).to include("The mortgage, deposit, and cash discount added together is £15,200.00. The value multiplied by the percentage bought is £8,400.00. These figures should be the same.") - expect(record.errors["cashdis"]).to include("The mortgage, deposit, and cash discount added together is £15,200.00. The value multiplied by the percentage bought is £8,400.00. These figures should be the same.") - expect(record.errors["type"]).to include("The mortgage, deposit, and cash discount added together is £15,200.00. The value multiplied by the percentage bought is £8,400.00. These figures should be the same.") + expect(record.errors["mortgage"]).to include("The mortgage amount (£10,000.00), deposit (£5,000.00), and cash discount (£200.00) added together is £15,200.00. The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00. These two amounts should be the same.") + expect(record.errors["value"]).to include("The mortgage amount (£10,000.00), deposit (£5,000.00), and cash discount (£200.00) added together is £15,200.00. The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00. These two amounts should be the same.") + expect(record.errors["deposit"]).to include("The mortgage amount (£10,000.00), deposit (£5,000.00), and cash discount (£200.00) added together is £15,200.00. The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00. These two amounts should be the same.") + expect(record.errors["equity"]).to include("The mortgage amount (£10,000.00), deposit (£5,000.00), and cash discount (£200.00) added together is £15,200.00. The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00. These two amounts should be the same.") + expect(record.errors["cashdis"]).to include("The mortgage amount (£10,000.00), deposit (£5,000.00), and cash discount (£200.00) added together is £15,200.00. The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00. These two amounts should be the same.") + expect(record.errors["type"]).to include("The mortgage amount (£10,000.00), deposit (£5,000.00), and cash discount (£200.00) added together is £15,200.00. The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00. These two amounts should be the same.") end end