Browse Source

CLDC-3569 Update social homebuy errors (#2541)

* Split questions

* Update the error message

* Add guidance

* Add back the headers

* Refactor depends_on

* Refactor further
pull/2582/head
kosiakkatrina 2 years ago committed by Kat
parent
commit
0ba98a756f
  1. 26
      app/models/form/sales/pages/about_deposit_without_discount.rb
  2. 21
      app/models/form/sales/pages/deposit.rb
  3. 5
      app/models/form/sales/pages/discount.rb
  4. 5
      app/models/form/sales/pages/equity.rb
  5. 13
      app/models/form/sales/pages/value_shared_ownership.rb
  6. 1
      app/models/form/sales/questions/deposit_amount.rb
  7. 1
      app/models/form/sales/questions/deposit_discount.rb
  8. 1
      app/models/form/sales/questions/equity.rb
  9. 1
      app/models/form/sales/questions/mortgage_amount.rb
  10. 1
      app/models/form/sales/questions/value.rb
  11. 2
      app/models/form/sales/subsections/discounted_ownership_scheme.rb
  12. 2
      app/models/form/sales/subsections/outright_sale.rb
  13. 13
      app/models/form/sales/subsections/shared_ownership_scheme.rb
  14. 18
      app/models/validations/sales/sale_information_validations.rb
  15. 2
      app/views/form/_numeric_question.html.erb
  16. 10
      app/views/form/guidance/_financial_calculations_shared_ownership.html.erb
  17. 2
      config/locales/en.yml
  18. 79
      spec/models/form/sales/pages/about_deposit_without_discount_spec.rb
  19. 235
      spec/models/form/sales/pages/deposit_spec.rb
  20. 8
      spec/models/form/sales/pages/discount_spec.rb
  21. 6
      spec/models/form/sales/pages/equity_spec.rb
  22. 33
      spec/models/form/sales/pages/value_shared_ownership_spec.rb
  23. 2
      spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
  24. 6
      spec/models/form/sales/subsections/outright_sale_spec.rb
  25. 8
      spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb
  26. 12
      spec/models/validations/sales/sale_information_validations_spec.rb

26
app/models/form/sales/pages/about_deposit_without_discount.rb

@ -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

21
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

5
app/models/form/sales/pages/about_deposit_with_discount.rb → 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:) def initialize(id, hsh, subsection, optional:)
super(id, hsh, subsection) super(id, hsh, subsection)
@header = "About the deposit"
@optional = optional @optional = optional
@header = "About the deposit"
end end
def questions def questions
@questions ||= [ @questions ||= [
Form::Sales::Questions::DepositAmount.new(nil, nil, self, ownershipsch: 1, optional: @optional),
Form::Sales::Questions::DepositDiscount.new(nil, nil, self), Form::Sales::Questions::DepositDiscount.new(nil, nil, self),
] ]
end end

5
app/models/form/sales/pages/about_price_shared_ownership.rb → 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) def initialize(id, hsh, subsection)
super super
@id = "about_price_shared_ownership" @id = "equity"
@header = "About the price of the property" @header = "About the price of the property"
end end
def questions def questions
@questions ||= [ @questions ||= [
Form::Sales::Questions::Value.new(nil, nil, self),
Form::Sales::Questions::Equity.new(nil, nil, self), Form::Sales::Questions::Equity.new(nil, nil, self),
] ]
end end

13
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

1
app/models/form/sales/questions/deposit_amount.rb

@ -13,6 +13,7 @@ class Form::Sales::Questions::DepositAmount < ::Form::Question
@ownershipsch = ownershipsch @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] @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 @optional = optional
@top_guidance_partial = "financial_calculations_shared_ownership" if ownershipsch == 1
end end
def derived?(log) def derived?(log)

1
app/models/form/sales/questions/deposit_discount.rb

@ -12,6 +12,7 @@ class Form::Sales::Questions::DepositDiscount < ::Form::Question
@prefix = "£" @prefix = "£"
@hint_text = "Enter the total cash discount given on the property being purchased through the Social HomeBuy scheme" @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] @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 end
QUESTION_NUMBER_FROM_YEAR = { 2023 => 96, 2024 => 97 }.freeze QUESTION_NUMBER_FROM_YEAR = { 2023 => 96, 2024 => 97 }.freeze

1
app/models/form/sales/questions/equity.rb

@ -12,6 +12,7 @@ class Form::Sales::Questions::Equity < ::Form::Question
@suffix = "%" @suffix = "%"
@hint_text = "Enter the amount of initial equity held by the purchaser (for example, 25% or 50%)" @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] @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 end
QUESTION_NUMBER_FROM_YEAR = { 2023 => 89, 2024 => 90 }.freeze QUESTION_NUMBER_FROM_YEAR = { 2023 => 89, 2024 => 90 }.freeze

1
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." @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 @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] @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 end
QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP = { QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP = {

1
app/models/form/sales/questions/value.rb

@ -11,6 +11,7 @@ class Form::Sales::Questions::Value < ::Form::Question
@prefix = "£" @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)" @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] @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 end
QUESTION_NUMBER_FROM_YEAR = { 2023 => 88, 2024 => 89 }.freeze QUESTION_NUMBER_FROM_YEAR = { 2023 => 88, 2024 => 89 }.freeze

2
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::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::ExtraBorrowing.new("extra_borrowing_discounted_ownership", nil, self, ownershipsch: 2),
Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_value_check", nil, self), 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::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_joint_purchase_value_check", nil, self, joint_purchase: true),
Form::Sales::Pages::DepositValueCheck.new("discounted_ownership_deposit_value_check", nil, self, joint_purchase: false), Form::Sales::Pages::DepositValueCheck.new("discounted_ownership_deposit_value_check", nil, self, joint_purchase: false),

2
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::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::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::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_joint_purchase_value_check", nil, self, joint_purchase: true),
Form::Sales::Pages::DepositValueCheck.new("outright_sale_deposit_value_check", nil, self, joint_purchase: false), Form::Sales::Pages::DepositValueCheck.new("outright_sale_deposit_value_check", nil, self, joint_purchase: false),
leasehold_charge_pages, leasehold_charge_pages,

13
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::PreviousBedrooms.new(nil, nil, self),
Form::Sales::Pages::PreviousPropertyType.new(nil, nil, self), Form::Sales::Pages::PreviousPropertyType.new(nil, nil, self),
Form::Sales::Pages::PreviousTenure.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::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::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::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::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::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::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::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::Deposit.new("deposit", nil, self, optional: false, ownershipsch: 1),
(Form::Sales::Pages::AboutDepositWithDiscount.new("about_deposit_with_discount_optional", nil, self, optional: true) if form.start_year_after_2024?), Form::Sales::Pages::Discount.new("discount", nil, self, optional: false),
Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_shared_ownership", nil, self, ownershipsch: 1, optional: false), (Form::Sales::Pages::Deposit.new("deposit_optional", nil, self, optional: true, ownershipsch: 1) if form.start_year_after_2024?),
(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::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_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::DepositValueCheck.new("deposit_value_check", nil, self, joint_purchase: false),
Form::Sales::Pages::SharedOwnershipDepositValueCheck.new("shared_ownership_deposit_value_check", nil, self), Form::Sales::Pages::SharedOwnershipDepositValueCheck.new("shared_ownership_deposit_value_check", nil, self),

18
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) 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| %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 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 end
elsif record.mortgage_not_used? elsif record.mortgage_not_used?
if over_tolerance?(record.deposit_and_discount_total, record.expected_shared_ownership_deposit_value, 1) if over_tolerance?(record.deposit_and_discount_total, record.expected_shared_ownership_deposit_value, 1)

2
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( <%= f.govuk_text_field(
question.id.to_sym, question.id.to_sym,

10
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 %>
<p class="govuk-body">
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) %>)
</p>
<% end %>

2
config/locales/en.yml

@ -658,7 +658,7 @@ en:
non_staircasing_mortgage: 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_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_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}.</br></br> The full purchase price (%{value}) multiplied by the percentage equity stake purchased (%{equity}) is %{expected_shared_ownership_deposit_value}.</br></br> 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." 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: 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." 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."

79
spec/models/form/sales/pages/about_deposit_without_discount_spec.rb

@ -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

235
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

8
spec/models/form/sales/pages/about_deposit_with_discount_spec.rb → spec/models/form/sales/pages/discount_spec.rb

@ -1,9 +1,9 @@
require "rails_helper" 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) } 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(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) } let(:subsection) { instance_double(Form::Subsection) }
@ -16,11 +16,11 @@ RSpec.describe Form::Sales::Pages::AboutDepositWithDiscount, type: :model do
end end
it "has correct questions" do 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 end
it "has the correct id" do it "has the correct id" do
expect(page.id).to eq("about_deposit_with_discount") expect(page.id).to eq("discount")
end end
it "has the correct header" do it "has the correct header" do

6
spec/models/form/sales/pages/about_price_shared_ownership_spec.rb → spec/models/form/sales/pages/equity_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" 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) } subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil } let(:page_id) { nil }
@ -12,11 +12,11 @@ RSpec.describe Form::Sales::Pages::AboutPriceSharedOwnership, type: :model do
end end
it "has correct questions" do 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 end
it "has the correct id" do it "has the correct id" do
expect(page.id).to eq("about_price_shared_ownership") expect(page.id).to eq("equity")
end end
it "has the correct header" do it "has the correct header" do

33
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

2
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 mortgage_length_discounted_ownership
extra_borrowing_discounted_ownership extra_borrowing_discounted_ownership
extra_borrowing_value_check extra_borrowing_value_check
about_deposit_discounted_ownership deposit_discounted_ownership
extra_borrowing_deposit_value_check extra_borrowing_deposit_value_check
discounted_ownership_deposit_joint_purchase_value_check discounted_ownership_deposit_joint_purchase_value_check
discounted_ownership_deposit_value_check discounted_ownership_deposit_value_check

6
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_lender_other_outright_sale
mortgage_length_outright_sale mortgage_length_outright_sale
extra_borrowing_outright_sale extra_borrowing_outright_sale
about_deposit_outright_sale deposit_outright_sale
outright_sale_deposit_joint_purchase_value_check outright_sale_deposit_joint_purchase_value_check
outright_sale_deposit_value_check outright_sale_deposit_value_check
monthly_charges_outright_sale_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_lender_other_outright_sale
mortgage_length_outright_sale mortgage_length_outright_sale
extra_borrowing_outright_sale extra_borrowing_outright_sale
about_deposit_outright_sale deposit_outright_sale
outright_sale_deposit_joint_purchase_value_check outright_sale_deposit_joint_purchase_value_check
outright_sale_deposit_value_check outright_sale_deposit_value_check
leasehold_charges_outright_sale leasehold_charges_outright_sale
@ -94,7 +94,7 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do
outright_sale_mortgage_amount_mortgage_value_check outright_sale_mortgage_amount_mortgage_value_check
mortgage_length_outright_sale mortgage_length_outright_sale
extra_borrowing_outright_sale extra_borrowing_outright_sale
about_deposit_outright_sale deposit_outright_sale
outright_sale_deposit_joint_purchase_value_check outright_sale_deposit_joint_purchase_value_check
outright_sale_deposit_value_check outright_sale_deposit_value_check
leasehold_charges_outright_sale leasehold_charges_outright_sale

8
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_bedrooms
previous_property_type previous_property_type
shared_ownership_previous_tenure shared_ownership_previous_tenure
about_price_shared_ownership value_shared_ownership
about_price_shared_ownership_value_check about_price_shared_ownership_value_check
equity
shared_ownership_equity_value_check shared_ownership_equity_value_check
mortgage_used_shared_ownership mortgage_used_shared_ownership
mortgage_used_mortgage_value_check mortgage_used_mortgage_value_check
@ -48,8 +49,9 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do
mortgage_lender_other_shared_ownership mortgage_lender_other_shared_ownership
mortgage_length_shared_ownership mortgage_length_shared_ownership
extra_borrowing_shared_ownership extra_borrowing_shared_ownership
about_deposit_with_discount deposit
about_deposit_shared_ownership discount
deposit_shared_ownership
deposit_joint_purchase_value_check deposit_joint_purchase_value_check
deposit_value_check deposit_value_check
shared_ownership_deposit_value_check shared_ownership_deposit_value_check

12
spec/models/validations/sales/sale_information_validations_spec.rb

@ -882,12 +882,12 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
it "adds an error" do it "adds an error" do
sale_information_validator.validate_non_staircasing_mortgage(record) 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["mortgage"]).to include("The mortgage amount (£10,000.00), deposit (£5,000.00), and cash discount (£200.00) added together is £15,200.00.</br></br> The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.</br></br> These two amounts 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["value"]).to include("The mortgage amount (£10,000.00), deposit (£5,000.00), and cash discount (£200.00) added together is £15,200.00.</br></br> The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.</br></br> These two amounts 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["deposit"]).to include("The mortgage amount (£10,000.00), deposit (£5,000.00), and cash discount (£200.00) added together is £15,200.00.</br></br> The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.</br></br> These two amounts 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["equity"]).to include("The mortgage amount (£10,000.00), deposit (£5,000.00), and cash discount (£200.00) added together is £15,200.00.</br></br> The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.</br></br> These two amounts 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["cashdis"]).to include("The mortgage amount (£10,000.00), deposit (£5,000.00), and cash discount (£200.00) added together is £15,200.00.</br></br> The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.</br></br> These two amounts 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["type"]).to include("The mortgage amount (£10,000.00), deposit (£5,000.00), and cash discount (£200.00) added together is £15,200.00.</br></br> The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.</br></br> These two amounts should be the same.")
end end
end end

Loading…
Cancel
Save