diff --git a/app/helpers/guidance_helper.rb b/app/helpers/guidance_helper.rb new file mode 100644 index 000000000..00d699cd2 --- /dev/null +++ b/app/helpers/guidance_helper.rb @@ -0,0 +1,11 @@ +module GuidanceHelper + include GovukLinkHelper + include GovukVisuallyHiddenHelper + + def question_link(question_id, log, user) + question = log.form.get_question(question_id, log) + return "" unless question.page.routed_to?(log, user) + + "(#{govuk_link_to "Q#{question.question_number}", send("#{log.class.name.underscore}_#{question.page.id}_path", log)})".html_safe + end +end 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..3e298e4f6 --- /dev/null +++ b/app/models/form/sales/pages/deposit.rb @@ -0,0 +1,22 @@ +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 false unless super + 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/deposit_discount.rb similarity index 72% rename from app/models/form/sales/pages/about_deposit_with_discount.rb rename to app/models/form/sales/pages/deposit_discount.rb index 4f1eed451..6931a7510 100644 --- a/app/models/form/sales/pages/about_deposit_with_discount.rb +++ b/app/models/form/sales/pages/deposit_discount.rb @@ -1,13 +1,12 @@ -class Form::Sales::Pages::AboutDepositWithDiscount < ::Form::Page +class Form::Sales::Pages::DepositDiscount < ::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_rtb.rb b/app/models/form/sales/pages/discount.rb similarity index 62% rename from app/models/form/sales/pages/about_price_rtb.rb rename to app/models/form/sales/pages/discount.rb index d8d20398f..56670075b 100644 --- a/app/models/form/sales/pages/about_price_rtb.rb +++ b/app/models/form/sales/pages/discount.rb @@ -1,7 +1,7 @@ -class Form::Sales::Pages::AboutPriceRtb < ::Form::Page +class Form::Sales::Pages::Discount < ::Form::Page def initialize(id, hsh, subsection) super - @id = "about_price_rtb" + @id = "discount" @header = "About the price of the property" @depends_on = [{ "right_to_buy?" => true, @@ -10,7 +10,6 @@ class Form::Sales::Pages::AboutPriceRtb < ::Form::Page def questions @questions ||= [ - Form::Sales::Questions::PurchasePrice.new(nil, nil, self, ownershipsch: 2), Form::Sales::Questions::Discount.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/about_price_not_rtb.rb b/app/models/form/sales/pages/grant.rb similarity index 64% rename from app/models/form/sales/pages/about_price_not_rtb.rb rename to app/models/form/sales/pages/grant.rb index 2f30548c7..7c7d2a625 100644 --- a/app/models/form/sales/pages/about_price_not_rtb.rb +++ b/app/models/form/sales/pages/grant.rb @@ -1,7 +1,7 @@ -class Form::Sales::Pages::AboutPriceNotRtb < ::Form::Page +class Form::Sales::Pages::Grant < ::Form::Page def initialize(id, hsh, subsection) super - @id = "about_price_not_rtb" + @id = "grant" @header = "About the price of the property" @depends_on = [{ "right_to_buy?" => false, @@ -11,7 +11,6 @@ class Form::Sales::Pages::AboutPriceNotRtb < ::Form::Page def questions @questions ||= [ - Form::Sales::Questions::PurchasePrice.new(nil, nil, self, ownershipsch: 2), Form::Sales::Questions::Grant.new(nil, nil, self), ] end diff --git a/app/models/form/sales/pages/mortgageused.rb b/app/models/form/sales/pages/mortgageused.rb index f9d8eae2e..a4912b12d 100644 --- a/app/models/form/sales/pages/mortgageused.rb +++ b/app/models/form/sales/pages/mortgageused.rb @@ -1,6 +1,7 @@ class Form::Sales::Pages::Mortgageused < ::Form::Page def initialize(id, hsh, subsection, ownershipsch:) super(id, hsh, subsection) + @header = "Mortgage Amount" @ownershipsch = ownershipsch end diff --git a/app/models/form/sales/pages/purchase_price.rb b/app/models/form/sales/pages/purchase_price.rb new file mode 100644 index 000000000..2203375ef --- /dev/null +++ b/app/models/form/sales/pages/purchase_price.rb @@ -0,0 +1,18 @@ +class Form::Sales::Pages::PurchasePrice < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "purchase_price" + @header = "About the price of the property" + @depends_on = [{ "right_to_buy?" => true }, + { + "right_to_buy?" => false, + "rent_to_buy_full_ownership?" => false, + }] + end + + def questions + @questions ||= [ + Form::Sales::Questions::PurchasePrice.new(nil, nil, self, ownershipsch: 2), + ] + end +end diff --git a/app/models/form/sales/pages/purchase_price_outright_ownership.rb b/app/models/form/sales/pages/purchase_price_outright_ownership.rb index a5e995ed6..897a19c2e 100644 --- a/app/models/form/sales/pages/purchase_price_outright_ownership.rb +++ b/app/models/form/sales/pages/purchase_price_outright_ownership.rb @@ -4,6 +4,8 @@ class Form::Sales::Pages::PurchasePriceOutrightOwnership < ::Form::Page @depends_on = [ { "outright_sale_or_discounted_with_full_ownership?" => true }, ] + @header = "About the price of the property" + @top_guidance_partial = "financial_calculations_outright_sale" @ownershipsch = ownershipsch 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..c1d91cc12 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 = top_guidance_partial end def derived?(log) @@ -31,4 +32,10 @@ class Form::Sales::Questions::DepositAmount < ::Form::Question "Enter the total cash sum paid by the buyer towards the property that was not funded by the mortgage. This excludes any grant or loan" end end + + def top_guidance_partial + return "financial_calculations_shared_ownership" if @ownershipsch == 1 + return "financial_calculations_discounted_ownership" if @ownershipsch == 2 + return "financial_calculations_outright_sale" if @ownershipsch == 3 + end end 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/discount.rb b/app/models/form/sales/questions/discount.rb index fdee1e11c..f99203ebe 100644 --- a/app/models/form/sales/questions/discount.rb +++ b/app/models/form/sales/questions/discount.rb @@ -14,6 +14,7 @@ class Form::Sales::Questions::Discount < ::Form::Question If discount capped, enter capped %

If the property is being sold to an existing tenant under the RTB, PRTB, or VRTB schemes, enter the % discount from the full market value that is being given." @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_discounted_ownership" end QUESTION_NUMBER_FROM_YEAR = { 2023 => 102, 2024 => 103 }.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/grant.rb b/app/models/form/sales/questions/grant.rb index 00b54e8d2..45b70d61f 100644 --- a/app/models/form/sales/questions/grant.rb +++ b/app/models/form/sales/questions/grant.rb @@ -12,6 +12,7 @@ class Form::Sales::Questions::Grant < ::Form::Question @prefix = "£" @hint_text = "For all schemes except Right to Buy (RTB), Preserved Right to Buy (PRTB), Voluntary Right to Buy (VRTB) and Rent to Buy" @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_discounted_ownership" end QUESTION_NUMBER_FROM_YEAR = { 2023 => 101, 2024 => 102 }.freeze diff --git a/app/models/form/sales/questions/mortgage_amount.rb b/app/models/form/sales/questions/mortgage_amount.rb index f3ec338ee..cfd031f27 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 = top_guidance_partial end QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP = { @@ -22,4 +23,10 @@ class Form::Sales::Questions::MortgageAmount < ::Form::Question def derived?(log) log&.mortgage_not_used? end + + def top_guidance_partial + return "financial_calculations_shared_ownership" if @ownershipsch == 1 + return "financial_calculations_discounted_ownership" if @ownershipsch == 2 + return "financial_calculations_outright_sale" if @ownershipsch == 3 + end end diff --git a/app/models/form/sales/questions/mortgageused.rb b/app/models/form/sales/questions/mortgageused.rb index 8dbe3a650..4ece2544e 100644 --- a/app/models/form/sales/questions/mortgageused.rb +++ b/app/models/form/sales/questions/mortgageused.rb @@ -8,6 +8,7 @@ class Form::Sales::Questions::Mortgageused < ::Form::Question @answer_options = ANSWER_OPTIONS @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 = top_guidance_partial end def displayed_answer_options(log, _user = nil) @@ -34,4 +35,10 @@ class Form::Sales::Questions::Mortgageused < ::Form::Question 2023 => { 1 => 90, 2 => 103, 3 => 111 }, 2024 => { 1 => 91, 2 => 104, 3 => 112 }, }.freeze + + def top_guidance_partial + return "financial_calculations_shared_ownership" if @ownershipsch == 1 + return "financial_calculations_discounted_ownership" if @ownershipsch == 2 + return "financial_calculations_outright_sale" if @ownershipsch == 3 + end end diff --git a/app/models/form/sales/questions/purchase_price.rb b/app/models/form/sales/questions/purchase_price.rb index 428d0cce0..3a9bd4ee7 100644 --- a/app/models/form/sales/questions/purchase_price.rb +++ b/app/models/form/sales/questions/purchase_price.rb @@ -12,6 +12,7 @@ class Form::Sales::Questions::PurchasePrice < ::Form::Question @hint_text = hint_text @ownership_sch = 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 = top_guidance_partial end QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP = { @@ -24,4 +25,9 @@ class Form::Sales::Questions::PurchasePrice < ::Form::Question "For all schemes, including Right to Acquire (RTA), Right to Buy (RTB), Voluntary Right to Buy (VRTB) or Preserved Right to Buy (PRTB) sales, enter the full price of the property without any discount" end + + def top_guidance_partial + return "financial_calculations_discounted_ownership" if @ownership_sch == 2 + return "financial_calculations_outright_sale" if @ownership_sch == 3 + end end diff --git a/app/models/form/sales/questions/staircase_bought.rb b/app/models/form/sales/questions/staircase_bought.rb index 3836daba6..0a6343db4 100644 --- a/app/models/form/sales/questions/staircase_bought.rb +++ b/app/models/form/sales/questions/staircase_bought.rb @@ -11,6 +11,7 @@ class Form::Sales::Questions::StaircaseBought < ::Form::Question @step = 1 @suffix = "%" @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 => 77, 2024 => 79 }.freeze 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..8131df4a7 100644 --- a/app/models/form/sales/subsections/discounted_ownership_scheme.rb +++ b/app/models/form/sales/subsections/discounted_ownership_scheme.rb @@ -10,10 +10,11 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection @pages ||= [ Form::Sales::Pages::LivingBeforePurchase.new("living_before_purchase_discounted_ownership_joint_purchase", nil, self, ownershipsch: 2, joint_purchase: true), Form::Sales::Pages::LivingBeforePurchase.new("living_before_purchase_discounted_ownership", nil, self, ownershipsch: 2, joint_purchase: false), - Form::Sales::Pages::AboutPriceRtb.new(nil, nil, self), + Form::Sales::Pages::PurchasePrice.new(nil, nil, self), + Form::Sales::Pages::Discount.new(nil, nil, self), Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_price_value_check", nil, self), Form::Sales::Pages::PercentageDiscountValueCheck.new("percentage_discount_value_check", nil, self), - Form::Sales::Pages::AboutPriceNotRtb.new(nil, nil, self), + Form::Sales::Pages::Grant.new(nil, nil, self), Form::Sales::Pages::GrantValueCheck.new(nil, nil, self), Form::Sales::Pages::PurchasePriceOutrightOwnership.new("purchase_price_discounted_ownership", nil, self, ownershipsch: 2), Form::Sales::Pages::DiscountedSaleValueCheck.new("discounted_sale_grant_value_check", nil, self), @@ -32,7 +33,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..c955929dc 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,12 +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_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::DepositDiscount.new("deposit_discount", nil, self, optional: false), + (Form::Sales::Pages::DepositDiscount.new("deposit_discount_optional", nil, self, optional: true) if form.start_year_after_2024?), 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), diff --git a/app/models/validations/sales/sale_information_validations.rb b/app/models/validations/sales/sale_information_validations.rb index c8083156c..42c6a6172 100644 --- a/app/models/validations/sales/sale_information_validations.rb +++ b/app/models/validations/sales/sale_information_validations.rb @@ -51,8 +51,15 @@ module Validations::Sales::SaleInformationValidations tolerance = record.discount ? record.value * 0.05 / 100 : 1 if over_tolerance?(record.mortgage_deposit_and_grant_total, record.value_with_discount, tolerance, strict: !record.discount.nil?) && record.discounted_ownership_sale? + deposit_and_grant_sentence = record.grant.present? ? ", cash deposit (#{record.field_formatted_as_currency('deposit')}), and grant (#{record.field_formatted_as_currency('grant')})" : " and cash deposit (#{record.field_formatted_as_currency('deposit')})" + discount_sentence = record.discount.present? ? " (#{record.field_formatted_as_currency('value')}) subtracted by the sum of the full purchase price (#{record.field_formatted_as_currency('value')}) multiplied by the percentage discount (#{record.discount}%)" : "" %i[mortgageused mortgage value deposit ownershipsch discount grant].each do |field| - record.errors.add field, I18n.t("validations.sale_information.discounted_ownership_value", mortgage_deposit_and_grant_total: record.field_formatted_as_currency("mortgage_deposit_and_grant_total"), value_with_discount: record.field_formatted_as_currency("value_with_discount")) + record.errors.add field, I18n.t("validations.sale_information.discounted_ownership_value", + mortgage: record.mortgage&.positive? ? " (#{record.field_formatted_as_currency('mortgage')})" : "", + deposit_and_grant_sentence:, + mortgage_deposit_and_grant_total: record.field_formatted_as_currency("mortgage_deposit_and_grant_total"), + discount_sentence:, + value_with_discount: record.field_formatted_as_currency("value_with_discount")).html_safe end end end @@ -65,9 +72,17 @@ module Validations::Sales::SaleInformationValidations if over_tolerance?(record.mortgage_and_deposit_total, record.value, 1) %i[mortgageused mortgage value deposit].each do |field| - record.errors.add field, I18n.t("validations.sale_information.outright_sale_value", mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_total"), value: record.field_formatted_as_currency("value")) + record.errors.add field, I18n.t("validations.sale_information.outright_sale_value", + mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_total"), + mortgage: record.mortgage&.positive? ? " (#{record.field_formatted_as_currency('mortgage')})" : "", + deposit: record.field_formatted_as_currency("deposit"), + value: record.field_formatted_as_currency("value")).html_safe end - record.errors.add :ownershipsch, :skip_bu_error, message: I18n.t("validations.sale_information.outright_sale_value", mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_total"), value: record.field_formatted_as_currency("value")) + record.errors.add :ownershipsch, :skip_bu_error, message: I18n.t("validations.sale_information.outright_sale_value", + mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_total"), + mortgage: record.mortgage&.positive? ? " (#{record.field_formatted_as_currency('mortgage')})" : "", + deposit: record.field_formatted_as_currency("deposit"), + value: record.field_formatted_as_currency("value")).html_safe end end @@ -155,16 +170,42 @@ 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")).html_safe end elsif record.mortgage_not_used? if over_tolerance?(record.deposit_and_discount_total, record.expected_shared_ownership_deposit_value, 1) %i[mortgageused value deposit cashdis equity].each do |field| - record.errors.add field, I18n.t("validations.sale_information.non_staircasing_mortgage.mortgage_not_used_socialhomebuy", deposit_and_discount_total: record.field_formatted_as_currency("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_not_used_socialhomebuy", + deposit_and_discount_total: record.field_formatted_as_currency("deposit_and_discount_total"), + expected_shared_ownership_deposit_value: record.field_formatted_as_currency("expected_shared_ownership_deposit_value"), + value: record.field_formatted_as_currency("value"), + deposit: record.field_formatted_as_currency("deposit"), + cashdis: record.field_formatted_as_currency("cashdis"), + equity: "#{record.equity}%").html_safe end - record.errors.add :type, :skip_bu_error, message: I18n.t("validations.sale_information.non_staircasing_mortgage.mortgage_not_used_socialhomebuy", deposit_and_discount_total: record.field_formatted_as_currency("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_not_used_socialhomebuy", + deposit_and_discount_total: record.field_formatted_as_currency("deposit_and_discount_total"), + expected_shared_ownership_deposit_value: record.field_formatted_as_currency("expected_shared_ownership_deposit_value"), + value: record.field_formatted_as_currency("value"), + deposit: record.field_formatted_as_currency("deposit"), + cashdis: record.field_formatted_as_currency("cashdis"), + equity: "#{record.equity}%").html_safe end end end @@ -175,16 +216,34 @@ module Validations::Sales::SaleInformationValidations if over_tolerance?(record.mortgage_and_deposit_total, record.expected_shared_ownership_deposit_value, 1) %i[mortgage value deposit equity].each do |field| - record.errors.add field, I18n.t("validations.sale_information.non_staircasing_mortgage.mortgage_used", mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_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", + mortgage: record.field_formatted_as_currency("mortgage"), + deposit: record.field_formatted_as_currency("deposit"), + value: record.field_formatted_as_currency("value"), + equity: "#{record.equity}%", + mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_total"), + expected_shared_ownership_deposit_value: record.field_formatted_as_currency("expected_shared_ownership_deposit_value")) end - record.errors.add :type, :skip_bu_error, message: I18n.t("validations.sale_information.non_staircasing_mortgage.mortgage_used", mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_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", + mortgage: record.field_formatted_as_currency("mortgage"), + deposit: record.field_formatted_as_currency("deposit"), + value: record.field_formatted_as_currency("value"), + equity: "#{record.equity}%", + mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_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, record.expected_shared_ownership_deposit_value, 1) %i[mortgageused value deposit equity].each do |field| - record.errors.add field, I18n.t("validations.sale_information.non_staircasing_mortgage.mortgage_not_used", deposit: record.field_formatted_as_currency("deposit"), 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_not_used", + deposit: record.field_formatted_as_currency("deposit"), + value: record.field_formatted_as_currency("value"), + 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_not_used", deposit: record.field_formatted_as_currency("deposit"), 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_not_used", + deposit: record.field_formatted_as_currency("deposit"), + value: record.field_formatted_as_currency("value"), + expected_shared_ownership_deposit_value: record.field_formatted_as_currency("expected_shared_ownership_deposit_value")).html_safe end end end @@ -197,15 +256,41 @@ module Validations::Sales::SaleInformationValidations if over_tolerance?(record.mortgage_deposit_and_discount_total, record.stairbought_part_of_value, 1) %i[mortgage value deposit cashdis stairbought].each do |field| - record.errors.add field, I18n.t("validations.sale_information.staircasing_mortgage.mortgage_used_socialhomebuy", mortgage_deposit_and_discount_total: record.field_formatted_as_currency("mortgage_deposit_and_discount_total"), stairbought_part_of_value: record.field_formatted_as_currency("stairbought_part_of_value")) + record.errors.add field, I18n.t("validations.sale_information.staircasing_mortgage.mortgage_used_socialhomebuy", + mortgage_deposit_and_discount_total: record.field_formatted_as_currency("mortgage_deposit_and_discount_total"), + stairbought_part_of_value: record.field_formatted_as_currency("stairbought_part_of_value"), + 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"), + stairbought: "#{record.stairbought}%").html_safe end - record.errors.add :type, :skip_bu_error, message: I18n.t("validations.sale_information.staircasing_mortgage.mortgage_used_socialhomebuy", mortgage_deposit_and_discount_total: record.field_formatted_as_currency("mortgage_deposit_and_discount_total"), stairbought_part_of_value: record.field_formatted_as_currency("stairbought_part_of_value")) + record.errors.add :type, :skip_bu_error, message: I18n.t("validations.sale_information.staircasing_mortgage.mortgage_used_socialhomebuy", + mortgage_deposit_and_discount_total: record.field_formatted_as_currency("mortgage_deposit_and_discount_total"), + stairbought_part_of_value: record.field_formatted_as_currency("stairbought_part_of_value"), + 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"), + stairbought: "#{record.stairbought}%").html_safe end elsif over_tolerance?(record.deposit_and_discount_total, record.stairbought_part_of_value, 1) %i[mortgageused value deposit cashdis stairbought].each do |field| - record.errors.add field, I18n.t("validations.sale_information.staircasing_mortgage.mortgage_not_used_socialhomebuy", deposit_and_discount_total: record.field_formatted_as_currency("deposit_and_discount_total"), stairbought_part_of_value: record.field_formatted_as_currency("stairbought_part_of_value")) + record.errors.add field, I18n.t("validations.sale_information.staircasing_mortgage.mortgage_not_used_socialhomebuy", + deposit_and_discount_total: record.field_formatted_as_currency("deposit_and_discount_total"), + stairbought_part_of_value: record.field_formatted_as_currency("stairbought_part_of_value"), + value: record.field_formatted_as_currency("value"), + deposit: record.field_formatted_as_currency("deposit"), + cashdis: record.field_formatted_as_currency("cashdis"), + stairbought: "#{record.stairbought}%").html_safe end - record.errors.add :type, :skip_bu_error, message: I18n.t("validations.sale_information.staircasing_mortgage.mortgage_not_used_socialhomebuy", deposit_and_discount_total: record.field_formatted_as_currency("deposit_and_discount_total"), stairbought_part_of_value: record.field_formatted_as_currency("stairbought_part_of_value")) + record.errors.add :type, :skip_bu_error, message: I18n.t("validations.sale_information.staircasing_mortgage.mortgage_not_used_socialhomebuy", + deposit_and_discount_total: record.field_formatted_as_currency("deposit_and_discount_total"), + stairbought_part_of_value: record.field_formatted_as_currency("stairbought_part_of_value"), + value: record.field_formatted_as_currency("value"), + deposit: record.field_formatted_as_currency("deposit"), + cashdis: record.field_formatted_as_currency("cashdis"), + stairbought: "#{record.stairbought}%").html_safe end end @@ -215,15 +300,31 @@ module Validations::Sales::SaleInformationValidations if over_tolerance?(record.mortgage_and_deposit_total, record.stairbought_part_of_value, 1) %i[mortgage value deposit stairbought type].each do |field| - record.errors.add field, I18n.t("validations.sale_information.staircasing_mortgage.mortgage_used", mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_total"), stairbought_part_of_value: record.field_formatted_as_currency("stairbought_part_of_value")) + record.errors.add field, I18n.t("validations.sale_information.staircasing_mortgage.mortgage_used", + mortgage: record.field_formatted_as_currency("mortgage"), + deposit: record.field_formatted_as_currency("deposit"), + mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_total"), + value: record.field_formatted_as_currency("value"), + stairbought_part_of_value: record.field_formatted_as_currency("stairbought_part_of_value")).html_safe end - record.errors.add :type, :skip_bu_error, message: I18n.t("validations.sale_information.staircasing_mortgage.mortgage_used", mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_total"), stairbought_part_of_value: record.field_formatted_as_currency("stairbought_part_of_value")) + record.errors.add :type, :skip_bu_error, message: I18n.t("validations.sale_information.staircasing_mortgage.mortgage_used", + mortgage: record.field_formatted_as_currency("mortgage"), + deposit: record.field_formatted_as_currency("deposit"), + mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_total"), + value: record.field_formatted_as_currency("value"), + stairbought_part_of_value: record.field_formatted_as_currency("stairbought_part_of_value")).html_safe end elsif over_tolerance?(record.deposit, record.stairbought_part_of_value, 1) %i[mortgageused value deposit stairbought type].each do |field| - record.errors.add field, I18n.t("validations.sale_information.staircasing_mortgage.mortgage_not_used", deposit: record.field_formatted_as_currency("deposit"), stairbought_part_of_value: record.field_formatted_as_currency("stairbought_part_of_value")) + record.errors.add field, I18n.t("validations.sale_information.staircasing_mortgage.mortgage_not_used", + deposit: record.field_formatted_as_currency("deposit"), + value: record.field_formatted_as_currency("value"), + stairbought_part_of_value: record.field_formatted_as_currency("stairbought_part_of_value")).html_safe end - record.errors.add :type, :skip_bu_error, message: I18n.t("validations.sale_information.staircasing_mortgage.mortgage_not_used", deposit: record.field_formatted_as_currency("deposit"), stairbought_part_of_value: record.field_formatted_as_currency("stairbought_part_of_value")) + record.errors.add :type, :skip_bu_error, message: I18n.t("validations.sale_information.staircasing_mortgage.mortgage_not_used", + deposit: record.field_formatted_as_currency("deposit"), + value: record.field_formatted_as_currency("value"), + stairbought_part_of_value: record.field_formatted_as_currency("stairbought_part_of_value")).html_safe end end diff --git a/app/views/form/_numeric_question.html.erb b/app/views/form/_numeric_question.html.erb index aa147767b..6a7446db6 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, @@ -14,7 +14,7 @@ suffix_text: question.suffix_label(@log), value: format_money_input(log: @log, question:), inputmode: "numeric", - pattern: "\d*\.?\d*", + pattern: "\\d*\\.?\\d*", **stimulus_html_attributes(question), ) %> diff --git a/app/views/form/_radio_question.html.erb b/app/views/form/_radio_question.html.erb index c15b31b58..41e98a1cc 100644 --- a/app/views/form/_radio_question.html.erb +++ b/app/views/form/_radio_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? %> <% banner = question.notification_banner(@log) %> <% if banner %> <%= govuk_notification_banner( diff --git a/app/views/form/guidance/_financial_calculations_discounted_ownership.html.erb b/app/views/form/guidance/_financial_calculations_discounted_ownership.html.erb new file mode 100644 index 000000000..f87f9ba7f --- /dev/null +++ b/app/views/form/guidance/_financial_calculations_discounted_ownership.html.erb @@ -0,0 +1,29 @@ +<% discount_question_link = question_link("discount", log, current_user) %> +<% grant_question_link = question_link("grant", log, current_user) %> +<% value_question_link = question_link("value", log, current_user) %> +<%= govuk_details(summary_text: "How the financial values are calculated") do %> +

+ <% if log.mortgage_used? || log.mortgageused.blank? %> + <% mortgage_question_link = log.mortgageused.blank? ? question_link("mortgageused", log, current_user) : question_link("mortgage", log, current_user) %> + The mortgage amount <%= mortgage_question_link %><% if grant_question_link.blank? %> + and cash deposit <%= question_link("deposit", log, current_user) %> + <% else %>, cash deposit <%= question_link("deposit", log, current_user) %> + and grant <%= grant_question_link %> + <% end %> + added together must equal + <% else %> + <% if grant_question_link.blank? %> + Cash deposit <%= question_link("deposit", log, current_user) %> must equal + <% else %> + Cash deposit <%= question_link("deposit", log, current_user) %> + and grant <%= grant_question_link %> + added together must equal + <% end %> + <% end %> + the purchase price <%= value_question_link %> + <% if discount_question_link.present? %> + subtracted by the sum of the purchase price <%= value_question_link %> + multiplied by the discount <%= discount_question_link %> + <% end %> +

+<% end %> diff --git a/app/views/form/guidance/_financial_calculations_outright_sale.html.erb b/app/views/form/guidance/_financial_calculations_outright_sale.html.erb new file mode 100644 index 000000000..ae5ebd50f --- /dev/null +++ b/app/views/form/guidance/_financial_calculations_outright_sale.html.erb @@ -0,0 +1,13 @@ +<%= govuk_details(summary_text: "How the financial values are calculated") do %> +

+ <% if log.mortgage_used? || log.mortgageused.blank? %> + <% mortgage_question_link = log.mortgageused.blank? ? question_link("mortgageused", log, current_user) : question_link("mortgage", log, current_user) %> + The mortgage amount <%= mortgage_question_link %> + and cash deposit <%= question_link("deposit", log, current_user) %> + added together must equal + <% else %> + Cash deposit <%= question_link("deposit", log, current_user) %> must equal + <% end %> + the purchase price <%= question_link("value", log, current_user) %> +

+<% end %> 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..0741e6afa --- /dev/null +++ b/app/views/form/guidance/_financial_calculations_shared_ownership.html.erb @@ -0,0 +1,30 @@ +<%= govuk_details(summary_text: "How the financial values are calculated") do %> +

+ <% if log.mortgage_used? || log.mortgageused.blank? %> + <% mortgage_question_link = log.mortgageused.blank? ? question_link("mortgageused", log, current_user) : question_link("mortgage", log, current_user) %> + The mortgage amount <%= mortgage_question_link %><% if log.type == 18 %>, cash deposit <%= question_link("deposit", log, current_user) %>, + and cash discount <%= question_link("cashdis", log, current_user) %> + added together + <% else %> + and cash deposit <%= question_link("deposit", log, current_user) %> + added together + <% end %> + <% elsif log.mortgage_not_used? || log.mortgage_use_unknown? %> + <% if log.type == 18 %> + The cash deposit <%= question_link("deposit", log, current_user) %>, + and cash discount <%= question_link("cashdis", log, current_user) %> + added together + <% else %> + Cash deposit <%= question_link("deposit", log, current_user) %> + <% end %> + <% end %> + must equal + the purchase price <%= question_link("value", log, current_user) %> + <% stairbought_page = log.form.get_question("stairbought", log).page %> + <% if stairbought_page.routed_to?(log, current_user) %> + multiplied by the percentage bought <%= question_link("stairbought", log, current_user) %> + <% else %> + multiplied by the percentage equity stake <%= question_link("equity", log, current_user) %> + <% end %> +

+<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index a53b375fe..bae5e568d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -644,8 +644,8 @@ en: must_be_after_hodate: "Sale completion date must be after practical completion or handover date" previous_property_type: property_type_bedsit: "A bedsit cannot have more than 1 bedroom" - discounted_ownership_value: "The mortgage, deposit, and grant when added together is %{mortgage_deposit_and_grant_total}, and the purchase price times by the discount is %{value_with_discount}. These figures should be the same" - outright_sale_value: "The mortgage and deposit when added together is %{mortgage_and_deposit_total}, and the purchase price is %{value}. These figures should be the same." + discounted_ownership_value: "The mortgage%{mortgage}%{deposit_and_grant_sentence} added together is %{mortgage_deposit_and_grant_total}.

The full purchase price%{discount_sentence} is %{value_with_discount}.

These two amounts should be the same." + outright_sale_value: "The mortgage%{mortgage} and cash deposit (%{deposit}) when added together is %{mortgage_and_deposit_total}.

The full purchase price is %{value}.

These two amounts should be the same." monthly_rent: higher_than_expected: "Basic monthly rent must be between £0.00 and £9,999.00" grant: @@ -656,15 +656,15 @@ en: over_discounted_london_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £136,400 for properties in London." over_discounted_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £102,400 for properties outside of London." 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_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_used: "The mortgage (%{mortgage}) and cash deposit (%{deposit}) added together is %{mortgage_and_deposit_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: "The cash deposit is %{deposit}.

The full purchase price (%{value}) multiplied by the percentage bought is %{expected_shared_ownership_deposit_value}.

These two amounts should be the same." + mortgage_used_socialhomebuy: "The mortgage amount (%{mortgage}), cash 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 cash deposit (%{deposit}) and cash discount (%{cashdis}) added together is %{deposit_and_discount_total}.

The full purchase price (%{value}) multiplied by the percentage bought (%{equity}) is %{expected_shared_ownership_deposit_value}.

These two amounts 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." - mortgage_not_used: "The deposit is %{deposit} and the value multiplied by the percentage bought is %{stairbought_part_of_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 %{stairbought_part_of_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 %{stairbought_part_of_value}. These figures should be the same." + mortgage_used: "The mortgage (%{mortgage}) and cash deposit (%{deposit}) added together is %{mortgage_and_deposit_total}.

The full purchase price (%{value}) multiplied by the percentage bought is %{stairbought_part_of_value}.

These two amounts should be the same." + mortgage_not_used: "The cash deposit is %{deposit}.

The full purchase price (%{value}) multiplied by the percentage bought is %{stairbought_part_of_value}.

These two amounts should be the same." + mortgage_used_socialhomebuy: "The mortgage amount (%{mortgage}), cash deposit (%{deposit}), and cash discount (%{cashdis}) added together is %{mortgage_deposit_and_discount_total}.

The full purchase price (%{value}) multiplied by the percentage bought (%{stairbought}) is %{stairbought_part_of_value}.

These two amounts should be the same." + mortgage_not_used_socialhomebuy: "The cash deposit (%{deposit}) and cash discount (%{cashdis}) added together is %{deposit_and_discount_total}.

The full purchase price (%{value}) multiplied by the percentage bought (%{stairbought}) is %{stairbought_part_of_value}.

These two amounts should be the same." stairowned: mortgageused_dont_know: "The percentage owned has to be 100% if the mortgage used is 'Don’t know'" merge_request: diff --git a/spec/helpers/guidance_helper_spec.rb b/spec/helpers/guidance_helper_spec.rb new file mode 100644 index 000000000..c1b900fac --- /dev/null +++ b/spec/helpers/guidance_helper_spec.rb @@ -0,0 +1,21 @@ +require "rails_helper" + +RSpec.describe GuidanceHelper do + describe "#question_link" do + context "when question page is routed to" do + let(:log) { create(:sales_log, :shared_ownership_setup_complete, mortgageused: 2) } + + it "returns an empty string if question is not routed to" do + expect(question_link("mortgage", log, log.assigned_to)).to eq("") + end + end + + context "when question page is not routed to" do + let(:log) { create(:sales_log, :shared_ownership_setup_complete, mortgageused: 1) } + + it "returns a link to the question with correct question number in brakets" do + expect(question_link("mortgage", log, log.assigned_to)).to eq("(Q92)") + end + end + end +end 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/about_deposit_with_discount_spec.rb b/spec/models/form/sales/pages/deposit_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/deposit_discount_spec.rb index fabfb7836..f4ffb85e5 100644 --- a/spec/models/form/sales/pages/about_deposit_with_discount_spec.rb +++ b/spec/models/form/sales/pages/deposit_discount_spec.rb @@ -1,9 +1,9 @@ require "rails_helper" -RSpec.describe Form::Sales::Pages::AboutDepositWithDiscount, type: :model do +RSpec.describe Form::Sales::Pages::DepositDiscount, 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/deposit_spec.rb b/spec/models/form/sales/pages/deposit_spec.rb new file mode 100644 index 000000000..3a3746ac6 --- /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, depends_on: true) } + let(:form) { instance_double(Form, start_year_after_2024?: false, start_date: Time.zone.local(2023, 4, 1), depends_on_met: true) } + 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_price_rtb_spec.rb b/spec/models/form/sales/pages/discount_spec.rb similarity index 83% rename from spec/models/form/sales/pages/about_price_rtb_spec.rb rename to spec/models/form/sales/pages/discount_spec.rb index c7ce5c233..1a38bd634 100644 --- a/spec/models/form/sales/pages/about_price_rtb_spec.rb +++ b/spec/models/form/sales/pages/discount_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.describe Form::Sales::Pages::AboutPriceRtb, type: :model do +RSpec.describe Form::Sales::Pages::Discount, type: :model do subject(:page) { described_class.new(page_id, page_definition, subsection) } let(:page_id) { nil } @@ -16,11 +16,11 @@ RSpec.describe Form::Sales::Pages::AboutPriceRtb, type: :model do end it "has correct questions" do - expect(page.questions.map(&:id)).to eq(%w[value discount]) + expect(page.questions.map(&:id)).to eq(%w[discount]) end it "has the correct id" do - expect(page.id).to eq("about_price_rtb") + 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/about_price_not_rtb_spec.rb b/spec/models/form/sales/pages/grant_spec.rb similarity index 81% rename from spec/models/form/sales/pages/about_price_not_rtb_spec.rb rename to spec/models/form/sales/pages/grant_spec.rb index 95ed0fdb7..f88cdf9ae 100644 --- a/spec/models/form/sales/pages/about_price_not_rtb_spec.rb +++ b/spec/models/form/sales/pages/grant_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.describe Form::Sales::Pages::AboutPriceNotRtb, type: :model do +RSpec.describe Form::Sales::Pages::Grant, 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::AboutPriceNotRtb, type: :model do end it "has correct questions" do - expect(page.questions.map(&:id)).to eq(%w[value grant]) + expect(page.questions.map(&:id)).to eq(%w[grant]) end it "has the correct id" do - expect(page.id).to eq("about_price_not_rtb") + expect(page.id).to eq("grant") end it "has the correct header" do diff --git a/spec/models/form/sales/pages/purchase_price_outright_ownership_spec.rb b/spec/models/form/sales/pages/purchase_price_outright_ownership_spec.rb index 83342c9b0..1aefb1e43 100644 --- a/spec/models/form/sales/pages/purchase_price_outright_ownership_spec.rb +++ b/spec/models/form/sales/pages/purchase_price_outright_ownership_spec.rb @@ -20,7 +20,7 @@ RSpec.describe Form::Sales::Pages::PurchasePriceOutrightOwnership, type: :model end it "has the correct header" do - expect(page.header).to be_nil + expect(page.header).to eq("About the price of the property") end it "has the correct description" do diff --git a/spec/models/form/sales/pages/purchase_price_spec.rb b/spec/models/form/sales/pages/purchase_price_spec.rb new file mode 100644 index 000000000..57cf526ad --- /dev/null +++ b/spec/models/form/sales/pages/purchase_price_spec.rb @@ -0,0 +1,38 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::PurchasePrice, 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) } + + 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[value]) + end + + it "has the correct id" do + expect(page.id).to eq("purchase_price") + 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 eq([{ "right_to_buy?" => true }, + { "rent_to_buy_full_ownership?" => false, "right_to_buy?" => false }]) + end +end 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..e703e713a 100644 --- a/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb +++ b/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb @@ -16,10 +16,11 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model %w[ living_before_purchase_discounted_ownership_joint_purchase living_before_purchase_discounted_ownership - about_price_rtb + purchase_price + discount extra_borrowing_price_value_check percentage_discount_value_check - about_price_not_rtb + grant grant_value_check purchase_price_discounted_ownership discounted_sale_grant_value_check @@ -38,7 +39,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..ea3fcd40e 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,10 +49,10 @@ 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_shared_ownership deposit_joint_purchase_value_check deposit_value_check + deposit_discount shared_ownership_deposit_value_check monthly_rent leasehold_charges_shared_ownership diff --git a/spec/models/validations/sales/sale_information_validations_spec.rb b/spec/models/validations/sales/sale_information_validations_spec.rb index 44245f73f..6cfa71d21 100644 --- a/spec/models/validations/sales/sale_information_validations_spec.rb +++ b/spec/models/validations/sales/sale_information_validations_spec.rb @@ -235,13 +235,13 @@ RSpec.describe Validations::Sales::SaleInformationValidations do sale_information_validator.validate_discounted_ownership_value(record) - expect(record.errors["mortgageused"]).to include("The mortgage, deposit, and grant when added together is £50,000.00, and the purchase price times by the discount is £49,999.00. These figures should be the same") - expect(record.errors["mortgage"]).to include("The mortgage, deposit, and grant when added together is £50,000.00, and the purchase price times by the discount is £49,999.00. These figures should be the same") - expect(record.errors["value"]).to include("The mortgage, deposit, and grant when added together is £50,000.00, and the purchase price times by the discount is £49,999.00. These figures should be the same") - expect(record.errors["deposit"]).to include("The mortgage, deposit, and grant when added together is £50,000.00, and the purchase price times by the discount is £49,999.00. These figures should be the same") - expect(record.errors["ownershipsch"]).to include("The mortgage, deposit, and grant when added together is £50,000.00, and the purchase price times by the discount is £49,999.00. These figures should be the same") - expect(record.errors["discount"]).to include("The mortgage, deposit, and grant when added together is £50,000.00, and the purchase price times by the discount is £49,999.00. These figures should be the same") - expect(record.errors["grant"]).to include("The mortgage, deposit, and grant when added together is £50,000.00, and the purchase price times by the discount is £49,999.00. These figures should be the same") + expect(record.errors["mortgageused"]).to include("The mortgage (£30,000.00), cash deposit (£5,000.00), and grant (£15,000.00) added together is £50,000.00.

The full purchase price is £49,999.00.

These two amounts should be the same.") + expect(record.errors["mortgage"]).to include("The mortgage (£30,000.00), cash deposit (£5,000.00), and grant (£15,000.00) added together is £50,000.00.

The full purchase price is £49,999.00.

These two amounts should be the same.") + expect(record.errors["value"]).to include("The mortgage (£30,000.00), cash deposit (£5,000.00), and grant (£15,000.00) added together is £50,000.00.

The full purchase price is £49,999.00.

These two amounts should be the same.") + expect(record.errors["deposit"]).to include("The mortgage (£30,000.00), cash deposit (£5,000.00), and grant (£15,000.00) added together is £50,000.00.

The full purchase price is £49,999.00.

These two amounts should be the same.") + expect(record.errors["ownershipsch"]).to include("The mortgage (£30,000.00), cash deposit (£5,000.00), and grant (£15,000.00) added together is £50,000.00.

The full purchase price is £49,999.00.

These two amounts should be the same.") + expect(record.errors["discount"]).to include("The mortgage (£30,000.00), cash deposit (£5,000.00), and grant (£15,000.00) added together is £50,000.00.

The full purchase price is £49,999.00.

These two amounts should be the same.") + expect(record.errors["grant"]).to include("The mortgage (£30,000.00), cash deposit (£5,000.00), and grant (£15,000.00) added together is £50,000.00.

The full purchase price is £49,999.00.

These two amounts should be the same.") end it "adds an error if mortgage, deposit and grant at least 1 less than discounted value" do @@ -252,13 +252,13 @@ RSpec.describe Validations::Sales::SaleInformationValidations do sale_information_validator.validate_discounted_ownership_value(record) - expect(record.errors["mortgageused"]).to include("The mortgage, deposit, and grant when added together is £50,000.00, and the purchase price times by the discount is £50,001.00. These figures should be the same") - expect(record.errors["mortgage"]).to include("The mortgage, deposit, and grant when added together is £50,000.00, and the purchase price times by the discount is £50,001.00. These figures should be the same") - expect(record.errors["value"]).to include("The mortgage, deposit, and grant when added together is £50,000.00, and the purchase price times by the discount is £50,001.00. These figures should be the same") - expect(record.errors["deposit"]).to include("The mortgage, deposit, and grant when added together is £50,000.00, and the purchase price times by the discount is £50,001.00. These figures should be the same") - expect(record.errors["ownershipsch"]).to include("The mortgage, deposit, and grant when added together is £50,000.00, and the purchase price times by the discount is £50,001.00. These figures should be the same") - expect(record.errors["discount"]).to include("The mortgage, deposit, and grant when added together is £50,000.00, and the purchase price times by the discount is £50,001.00. These figures should be the same") - expect(record.errors["grant"]).to include("The mortgage, deposit, and grant when added together is £50,000.00, and the purchase price times by the discount is £50,001.00. These figures should be the same") + expect(record.errors["mortgageused"]).to include("The mortgage (£30,000.00), cash deposit (£5,000.00), and grant (£15,000.00) added together is £50,000.00.

The full purchase price is £50,001.00.

These two amounts should be the same.") + expect(record.errors["mortgage"]).to include("The mortgage (£30,000.00), cash deposit (£5,000.00), and grant (£15,000.00) added together is £50,000.00.

The full purchase price is £50,001.00.

These two amounts should be the same.") + expect(record.errors["value"]).to include("The mortgage (£30,000.00), cash deposit (£5,000.00), and grant (£15,000.00) added together is £50,000.00.

The full purchase price is £50,001.00.

These two amounts should be the same.") + expect(record.errors["deposit"]).to include("The mortgage (£30,000.00), cash deposit (£5,000.00), and grant (£15,000.00) added together is £50,000.00.

The full purchase price is £50,001.00.

These two amounts should be the same.") + expect(record.errors["ownershipsch"]).to include("The mortgage (£30,000.00), cash deposit (£5,000.00), and grant (£15,000.00) added together is £50,000.00.

The full purchase price is £50,001.00.

These two amounts should be the same.") + expect(record.errors["discount"]).to include("The mortgage (£30,000.00), cash deposit (£5,000.00), and grant (£15,000.00) added together is £50,000.00.

The full purchase price is £50,001.00.

These two amounts should be the same.") + expect(record.errors["grant"]).to include("The mortgage (£30,000.00), cash deposit (£5,000.00), and grant (£15,000.00) added together is £50,000.00.

The full purchase price is £50,001.00.

These two amounts should be the same.") end it "does not add an error if mortgage, deposit and grant total equals discounted value" do @@ -345,13 +345,13 @@ RSpec.describe Validations::Sales::SaleInformationValidations do sale_information_validator.validate_discounted_ownership_value(record) - expect(record.errors["mortgageused"]).to include("The mortgage, deposit, and grant when added together is £66,113.00, and the purchase price times by the discount is £66,051.00. These figures should be the same") - expect(record.errors["mortgage"]).to include("The mortgage, deposit, and grant when added together is £66,113.00, and the purchase price times by the discount is £66,051.00. These figures should be the same") - expect(record.errors["value"]).to include("The mortgage, deposit, and grant when added together is £66,113.00, and the purchase price times by the discount is £66,051.00. These figures should be the same") - expect(record.errors["deposit"]).to include("The mortgage, deposit, and grant when added together is £66,113.00, and the purchase price times by the discount is £66,051.00. These figures should be the same") - expect(record.errors["ownershipsch"]).to include("The mortgage, deposit, and grant when added together is £66,113.00, and the purchase price times by the discount is £66,051.00. These figures should be the same") - expect(record.errors["discount"]).to include("The mortgage, deposit, and grant when added together is £66,113.00, and the purchase price times by the discount is £66,051.00. These figures should be the same") - expect(record.errors["grant"]).to include("The mortgage, deposit, and grant when added together is £66,113.00, and the purchase price times by the discount is £66,051.00. These figures should be the same") + expect(record.errors["mortgageused"]).to include("The mortgage (£66,113.00) and cash deposit (£0.00) added together is £66,113.00.

The full purchase price (£123,000.00) subtracted by the sum of the full purchase price (£123,000.00) multiplied by the percentage discount (46.3%) is £66,051.00.

These two amounts should be the same.") + expect(record.errors["mortgage"]).to include("The mortgage (£66,113.00) and cash deposit (£0.00) added together is £66,113.00.

The full purchase price (£123,000.00) subtracted by the sum of the full purchase price (£123,000.00) multiplied by the percentage discount (46.3%) is £66,051.00.

These two amounts should be the same.") + expect(record.errors["value"]).to include("The mortgage (£66,113.00) and cash deposit (£0.00) added together is £66,113.00.

The full purchase price (£123,000.00) subtracted by the sum of the full purchase price (£123,000.00) multiplied by the percentage discount (46.3%) is £66,051.00.

These two amounts should be the same.") + expect(record.errors["deposit"]).to include("The mortgage (£66,113.00) and cash deposit (£0.00) added together is £66,113.00.

The full purchase price (£123,000.00) subtracted by the sum of the full purchase price (£123,000.00) multiplied by the percentage discount (46.3%) is £66,051.00.

These two amounts should be the same.") + expect(record.errors["ownershipsch"]).to include("The mortgage (£66,113.00) and cash deposit (£0.00) added together is £66,113.00.

The full purchase price (£123,000.00) subtracted by the sum of the full purchase price (£123,000.00) multiplied by the percentage discount (46.3%) is £66,051.00.

These two amounts should be the same.") + expect(record.errors["discount"]).to include("The mortgage (£66,113.00) and cash deposit (£0.00) added together is £66,113.00.

The full purchase price (£123,000.00) subtracted by the sum of the full purchase price (£123,000.00) multiplied by the percentage discount (46.3%) is £66,051.00.

These two amounts should be the same.") + expect(record.errors["grant"]).to include("The mortgage (£66,113.00) and cash deposit (£0.00) added together is £66,113.00.

The full purchase price (£123,000.00) subtracted by the sum of the full purchase price (£123,000.00) multiplied by the percentage discount (46.3%) is £66,051.00.

These two amounts should be the same.") end it "does not add errors if mortgage and deposit total is exactly 0.05% x market value away from market value - discount" do @@ -379,13 +379,14 @@ RSpec.describe Validations::Sales::SaleInformationValidations do it "returns true if mortgage and deposit total does not equal market value" do record.deposit = 2_000 sale_information_validator.validate_discounted_ownership_value(record) - expect(record.errors["mortgageused"]).to include("The mortgage, deposit, and grant when added together is £12,000.00, and the purchase price times by the discount is £30,000.00. These figures should be the same") - expect(record.errors["mortgage"]).to include("The mortgage, deposit, and grant when added together is £12,000.00, and the purchase price times by the discount is £30,000.00. These figures should be the same") - expect(record.errors["value"]).to include("The mortgage, deposit, and grant when added together is £12,000.00, and the purchase price times by the discount is £30,000.00. These figures should be the same") - expect(record.errors["deposit"]).to include("The mortgage, deposit, and grant when added together is £12,000.00, and the purchase price times by the discount is £30,000.00. These figures should be the same") - expect(record.errors["ownershipsch"]).to include("The mortgage, deposit, and grant when added together is £12,000.00, and the purchase price times by the discount is £30,000.00. These figures should be the same") - expect(record.errors["discount"]).to include("The mortgage, deposit, and grant when added together is £12,000.00, and the purchase price times by the discount is £30,000.00. These figures should be the same") - expect(record.errors["grant"]).to include("The mortgage, deposit, and grant when added together is £12,000.00, and the purchase price times by the discount is £30,000.00. These figures should be the same") + + expect(record.errors["mortgageused"]).to include("The mortgage (£10,000.00) and cash deposit (£2,000.00) added together is £12,000.00.

The full purchase price is £30,000.00.

These two amounts should be the same.") + expect(record.errors["mortgage"]).to include("The mortgage (£10,000.00) and cash deposit (£2,000.00) added together is £12,000.00.

The full purchase price is £30,000.00.

These two amounts should be the same.") + expect(record.errors["value"]).to include("The mortgage (£10,000.00) and cash deposit (£2,000.00) added together is £12,000.00.

The full purchase price is £30,000.00.

These two amounts should be the same.") + expect(record.errors["deposit"]).to include("The mortgage (£10,000.00) and cash deposit (£2,000.00) added together is £12,000.00.

The full purchase price is £30,000.00.

These two amounts should be the same.") + expect(record.errors["ownershipsch"]).to include("The mortgage (£10,000.00) and cash deposit (£2,000.00) added together is £12,000.00.

The full purchase price is £30,000.00.

These two amounts should be the same.") + expect(record.errors["discount"]).to include("The mortgage (£10,000.00) and cash deposit (£2,000.00) added together is £12,000.00.

The full purchase price is £30,000.00.

These two amounts should be the same.") + expect(record.errors["grant"]).to include("The mortgage (£10,000.00) and cash deposit (£2,000.00) added together is £12,000.00.

The full purchase price is £30,000.00.

These two amounts should be the same.") end it "returns false if mortgage and deposit total equals market value" do @@ -425,13 +426,13 @@ RSpec.describe Validations::Sales::SaleInformationValidations do it "returns true if mortgage, grant and deposit total does not equal market value - discount" do record.mortgage = 10 sale_information_validator.validate_discounted_ownership_value(record) - expect(record.errors["mortgageused"]).to include("The mortgage, deposit, and grant when added together is £8,010.00, and the purchase price times by the discount is £18,000.00. These figures should be the same") - expect(record.errors["mortgage"]).to include("The mortgage, deposit, and grant when added together is £8,010.00, and the purchase price times by the discount is £18,000.00. These figures should be the same") - expect(record.errors["value"]).to include("The mortgage, deposit, and grant when added together is £8,010.00, and the purchase price times by the discount is £18,000.00. These figures should be the same") - expect(record.errors["deposit"]).to include("The mortgage, deposit, and grant when added together is £8,010.00, and the purchase price times by the discount is £18,000.00. These figures should be the same") - expect(record.errors["ownershipsch"]).to include("The mortgage, deposit, and grant when added together is £8,010.00, and the purchase price times by the discount is £18,000.00. These figures should be the same") - expect(record.errors["discount"]).to include("The mortgage, deposit, and grant when added together is £8,010.00, and the purchase price times by the discount is £18,000.00. These figures should be the same") - expect(record.errors["grant"]).to include("The mortgage, deposit, and grant when added together is £8,010.00, and the purchase price times by the discount is £18,000.00. These figures should be the same") + expect(record.errors["mortgageused"]).to include("The mortgage (£10.00), cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,010.00.

The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.

These two amounts should be the same.") + expect(record.errors["mortgage"]).to include("The mortgage (£10.00), cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,010.00.

The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.

These two amounts should be the same.") + expect(record.errors["value"]).to include("The mortgage (£10.00), cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,010.00.

The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.

These two amounts should be the same.") + expect(record.errors["deposit"]).to include("The mortgage (£10.00), cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,010.00.

The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.

These two amounts should be the same.") + expect(record.errors["ownershipsch"]).to include("The mortgage (£10.00), cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,010.00.

The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.

These two amounts should be the same.") + expect(record.errors["discount"]).to include("The mortgage (£10.00), cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,010.00.

The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.

These two amounts should be the same.") + expect(record.errors["grant"]).to include("The mortgage (£10.00), cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,010.00.

The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.

These two amounts should be the same.") end it "returns false if mortgage, grant and deposit total equals market value - discount" do @@ -453,13 +454,14 @@ RSpec.describe Validations::Sales::SaleInformationValidations do it "returns true if grant and deposit total does not equal market value - discount" do sale_information_validator.validate_discounted_ownership_value(record) - expect(record.errors["mortgageused"]).to include("The mortgage, deposit, and grant when added together is £8,000.00, and the purchase price times by the discount is £18,000.00. These figures should be the same") - expect(record.errors["mortgage"]).to include("The mortgage, deposit, and grant when added together is £8,000.00, and the purchase price times by the discount is £18,000.00. These figures should be the same") - expect(record.errors["value"]).to include("The mortgage, deposit, and grant when added together is £8,000.00, and the purchase price times by the discount is £18,000.00. These figures should be the same") - expect(record.errors["deposit"]).to include("The mortgage, deposit, and grant when added together is £8,000.00, and the purchase price times by the discount is £18,000.00. These figures should be the same") - expect(record.errors["ownershipsch"]).to include("The mortgage, deposit, and grant when added together is £8,000.00, and the purchase price times by the discount is £18,000.00. These figures should be the same") - expect(record.errors["discount"]).to include("The mortgage, deposit, and grant when added together is £8,000.00, and the purchase price times by the discount is £18,000.00. These figures should be the same") - expect(record.errors["grant"]).to include("The mortgage, deposit, and grant when added together is £8,000.00, and the purchase price times by the discount is £18,000.00. These figures should be the same") + + expect(record.errors["mortgageused"]).to include("The mortgage, cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,000.00.

The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.

These two amounts should be the same.") + expect(record.errors["mortgage"]).to include("The mortgage, cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,000.00.

The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.

These two amounts should be the same.") + expect(record.errors["value"]).to include("The mortgage, cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,000.00.

The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.

These two amounts should be the same.") + expect(record.errors["deposit"]).to include("The mortgage, cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,000.00.

The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.

These two amounts should be the same.") + expect(record.errors["ownershipsch"]).to include("The mortgage, cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,000.00.

The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.

These two amounts should be the same.") + expect(record.errors["discount"]).to include("The mortgage, cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,000.00.

The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.

These two amounts should be the same.") + expect(record.errors["grant"]).to include("The mortgage, cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,000.00.

The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.

These two amounts should be the same.") end it "returns false if mortgage, grant and deposit total equals market value - discount" do @@ -536,11 +538,11 @@ RSpec.describe Validations::Sales::SaleInformationValidations do it "adds errors" do sale_information_validator.validate_outright_sale_value_matches_mortgage_plus_deposit(record) - expect(record.errors["mortgageused"]).to include("The mortgage and deposit when added together is £200,000.00, and the purchase price is £300,000.00. These figures should be the same.") - expect(record.errors["mortgage"]).to include("The mortgage and deposit when added together is £200,000.00, and the purchase price is £300,000.00. These figures should be the same.") - expect(record.errors["deposit"]).to include("The mortgage and deposit when added together is £200,000.00, and the purchase price is £300,000.00. These figures should be the same.") - expect(record.errors["value"]).to include("The mortgage and deposit when added together is £200,000.00, and the purchase price is £300,000.00. These figures should be the same.") - expect(record.errors["ownershipsch"]).to include("The mortgage and deposit when added together is £200,000.00, and the purchase price is £300,000.00. These figures should be the same.") + expect(record.errors["mortgageused"]).to include("The mortgage (£100,000.00) and cash deposit (£100,000.00) when added together is £200,000.00.

The full purchase price is £300,000.00.

These two amounts should be the same.") + expect(record.errors["mortgage"]).to include("The mortgage (£100,000.00) and cash deposit (£100,000.00) when added together is £200,000.00.

The full purchase price is £300,000.00.

These two amounts should be the same.") + expect(record.errors["deposit"]).to include("The mortgage (£100,000.00) and cash deposit (£100,000.00) when added together is £200,000.00.

The full purchase price is £300,000.00.

These two amounts should be the same.") + expect(record.errors["value"]).to include("The mortgage (£100,000.00) and cash deposit (£100,000.00) when added together is £200,000.00.

The full purchase price is £300,000.00.

These two amounts should be the same.") + expect(record.errors["ownershipsch"]).to include("The mortgage (£100,000.00) and cash deposit (£100,000.00) when added together is £200,000.00.

The full purchase price is £300,000.00.

These two amounts should be the same.") end end @@ -866,12 +868,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 and deposit added together is £15,000.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 and deposit added together is £15,000.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 and deposit added together is £15,000.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 and deposit added together is £15,000.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 and deposit added together is £15,000.00. The value multiplied by the percentage bought is £8,400.00. These figures should be the same.") - expect(record.errors["cashdis"]).not_to include("The mortgage and deposit added together is £15,000.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 (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.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 (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.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 (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.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 (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.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 (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.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"]).not_to include("The mortgage (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.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 context "and it is a social homebuy" do @@ -882,12 +884,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), cash 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), cash 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), cash 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), cash 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), cash 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), cash 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 @@ -966,12 +968,12 @@ RSpec.describe Validations::Sales::SaleInformationValidations do it "adds an error" do sale_information_validator.validate_non_staircasing_mortgage(record) - expect(record.errors["mortgageused"]).to include("The deposit is £5,000.00 and the value multiplied by the percentage bought is £8,400.00. These figures should be the same.") - expect(record.errors["value"]).to include("The deposit is £5,000.00 and the value multiplied by the percentage bought is £8,400.00. These figures should be the same.") - expect(record.errors["deposit"]).to include("The deposit is £5,000.00 and the value multiplied by the percentage bought is £8,400.00. These figures should be the same.") - expect(record.errors["equity"]).to include("The deposit is £5,000.00 and the value multiplied by the percentage bought is £8,400.00. These figures should be the same.") - expect(record.errors["type"]).to include("The deposit is £5,000.00 and the value multiplied by the percentage bought is £8,400.00. These figures should be the same.") - expect(record.errors["cashdis"]).not_to include("The deposit is £5,000.00 and the value multiplied by the percentage bought is £8,400.00. These figures should be the same.") + expect(record.errors["mortgageused"]).to include("The cash deposit is £5,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") + expect(record.errors["value"]).to include("The cash deposit is £5,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") + expect(record.errors["deposit"]).to include("The cash deposit is £5,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") + expect(record.errors["equity"]).to include("The cash deposit is £5,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") + expect(record.errors["type"]).to include("The cash deposit is £5,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") + expect(record.errors["cashdis"]).not_to include("The cash deposit is £5,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") end context "and it is a social homebuy" do @@ -982,12 +984,12 @@ RSpec.describe Validations::Sales::SaleInformationValidations do it "adds an error" do sale_information_validator.validate_non_staircasing_mortgage(record) - expect(record.errors["mortgageused"]).to include("The deposit and cash discount added together is £5,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 deposit and cash discount added together is £5,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 deposit and cash discount added together is £5,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 deposit and cash discount added together is £5,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 deposit and cash discount added together is £5,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 deposit and cash discount added together is £5,200.00. The value multiplied by the percentage bought is £8,400.00. These figures should be the same.") + expect(record.errors["mortgageused"]).to include("The cash deposit (£5,000.00) and cash discount (£200.00) added together is £5,200.00.

The full purchase price (£30,000.00) multiplied by the percentage bought (28.0%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["value"]).to include("The cash deposit (£5,000.00) and cash discount (£200.00) added together is £5,200.00.

The full purchase price (£30,000.00) multiplied by the percentage bought (28.0%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["deposit"]).to include("The cash deposit (£5,000.00) and cash discount (£200.00) added together is £5,200.00.

The full purchase price (£30,000.00) multiplied by the percentage bought (28.0%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["equity"]).to include("The cash deposit (£5,000.00) and cash discount (£200.00) added together is £5,200.00.

The full purchase price (£30,000.00) multiplied by the percentage bought (28.0%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["cashdis"]).to include("The cash deposit (£5,000.00) and cash discount (£200.00) added together is £5,200.00.

The full purchase price (£30,000.00) multiplied by the percentage bought (28.0%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["type"]).to include("The cash deposit (£5,000.00) and cash discount (£200.00) added together is £5,200.00.

The full purchase price (£30,000.00) multiplied by the percentage bought (28.0%) is £8,400.00.

These two amounts should be the same.") end end @@ -1085,12 +1087,12 @@ RSpec.describe Validations::Sales::SaleInformationValidations do it "adds an error" do sale_information_validator.validate_staircasing_mortgage(record) - expect(record.errors["mortgage"]).to include("The mortgage and deposit added together is £15,000.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 and deposit added together is £15,000.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 and deposit added together is £15,000.00. The value multiplied by the percentage bought is £8,400.00. These figures should be the same.") - expect(record.errors["stairbought"]).to include("The mortgage and deposit added together is £15,000.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 and deposit added together is £15,000.00. The value multiplied by the percentage bought is £8,400.00. These figures should be the same.") - expect(record.errors["cashdis"]).not_to include("The mortgage and deposit added together is £15,000.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 (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") + expect(record.errors["value"]).to include("The mortgage (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") + expect(record.errors["deposit"]).to include("The mortgage (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") + expect(record.errors["stairbought"]).to include("The mortgage (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") + expect(record.errors["type"]).to include("The mortgage (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") + expect(record.errors["cashdis"]).not_to include("The mortgage (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") end context "and it is a social homebuy" do @@ -1101,12 +1103,12 @@ RSpec.describe Validations::Sales::SaleInformationValidations do it "adds an error" do sale_information_validator.validate_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["stairbought"]).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), cash 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 bought (28%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["value"]).to include("The mortgage amount (£10,000.00), cash 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 bought (28%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["deposit"]).to include("The mortgage amount (£10,000.00), cash 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 bought (28%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["stairbought"]).to include("The mortgage amount (£10,000.00), cash 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 bought (28%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["cashdis"]).to include("The mortgage amount (£10,000.00), cash 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 bought (28%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["type"]).to include("The mortgage amount (£10,000.00), cash 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 bought (28%) is £8,400.00.

These two amounts should be the same.") end end @@ -1204,12 +1206,12 @@ RSpec.describe Validations::Sales::SaleInformationValidations do it "adds an error" do sale_information_validator.validate_staircasing_mortgage(record) - expect(record.errors["mortgageused"]).to include("The deposit is £5,000.00 and the value multiplied by the percentage bought is £8,400.00. These figures should be the same.") - expect(record.errors["value"]).to include("The deposit is £5,000.00 and the value multiplied by the percentage bought is £8,400.00. These figures should be the same.") - expect(record.errors["deposit"]).to include("The deposit is £5,000.00 and the value multiplied by the percentage bought is £8,400.00. These figures should be the same.") - expect(record.errors["stairbought"]).to include("The deposit is £5,000.00 and the value multiplied by the percentage bought is £8,400.00. These figures should be the same.") - expect(record.errors["type"]).to include("The deposit is £5,000.00 and the value multiplied by the percentage bought is £8,400.00. These figures should be the same.") - expect(record.errors["cashdis"]).not_to include("The deposit is £5,000.00 and the value multiplied by the percentage bought is £8,400.00. These figures should be the same.") + expect(record.errors["mortgageused"]).to include("The cash deposit is £5,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") + expect(record.errors["value"]).to include("The cash deposit is £5,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") + expect(record.errors["deposit"]).to include("The cash deposit is £5,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") + expect(record.errors["stairbought"]).to include("The cash deposit is £5,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") + expect(record.errors["type"]).to include("The cash deposit is £5,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") + expect(record.errors["cashdis"]).not_to include("The cash deposit is £5,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") end context "and it is a social homebuy" do @@ -1220,12 +1222,12 @@ RSpec.describe Validations::Sales::SaleInformationValidations do it "adds an error" do sale_information_validator.validate_staircasing_mortgage(record) - expect(record.errors["mortgageused"]).to include("The deposit and cash discount added together is £5,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 deposit and cash discount added together is £5,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 deposit and cash discount added together is £5,200.00. The value multiplied by the percentage bought is £8,400.00. These figures should be the same.") - expect(record.errors["stairbought"]).to include("The deposit and cash discount added together is £5,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 deposit and cash discount added together is £5,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 deposit and cash discount added together is £5,200.00. The value multiplied by the percentage bought is £8,400.00. These figures should be the same.") + expect(record.errors["mortgageused"]).to include("The cash deposit (£5,000.00) and cash discount (£200.00) added together is £5,200.00.

The full purchase price (£30,000.00) multiplied by the percentage bought (28%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["value"]).to include("The cash deposit (£5,000.00) and cash discount (£200.00) added together is £5,200.00.

The full purchase price (£30,000.00) multiplied by the percentage bought (28%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["deposit"]).to include("The cash deposit (£5,000.00) and cash discount (£200.00) added together is £5,200.00.

The full purchase price (£30,000.00) multiplied by the percentage bought (28%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["stairbought"]).to include("The cash deposit (£5,000.00) and cash discount (£200.00) added together is £5,200.00.

The full purchase price (£30,000.00) multiplied by the percentage bought (28%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["cashdis"]).to include("The cash deposit (£5,000.00) and cash discount (£200.00) added together is £5,200.00.

The full purchase price (£30,000.00) multiplied by the percentage bought (28%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["type"]).to include("The cash deposit (£5,000.00) and cash discount (£200.00) added together is £5,200.00.

The full purchase price (£30,000.00) multiplied by the percentage bought (28%) is £8,400.00.

These two amounts should be the same.") end end diff --git a/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb index 656ff7a2f..f19a61d78 100644 --- a/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb @@ -1341,10 +1341,10 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do it "includes errors on other related fields" do parser.valid? - expect(parser.errors[:field_104]).to include("The mortgage and deposit added together is £15,000.00. The value multiplied by the percentage bought is £8,400.00. These figures should be the same.") - expect(parser.errors[:field_109]).to include("The mortgage and deposit added together is £15,000.00. The value multiplied by the percentage bought is £8,400.00. These figures should be the same.") - expect(parser.errors[:field_101]).to include("The mortgage and deposit added together is £15,000.00. The value multiplied by the percentage bought is £8,400.00. These figures should be the same.") - expect(parser.errors[:field_102]).to include("The mortgage and deposit added together is £15,000.00. The value multiplied by the percentage bought is £8,400.00. These figures should be the same.") + expect(parser.errors[:field_104]).to include("The mortgage (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.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(parser.errors[:field_109]).to include("The mortgage (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.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(parser.errors[:field_101]).to include("The mortgage (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.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(parser.errors[:field_102]).to include("The mortgage (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.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 it "does not add errors to other ownership type fields" do @@ -1379,7 +1379,7 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do it "only adds errors to the discounted ownership field" do parser.valid? expect(parser.errors[:field_103]).to be_empty - expect(parser.errors[:field_117]).to include("The mortgage, deposit, and grant when added together is £100.00, and the purchase price times by the discount is £90.00. These figures should be the same") + expect(parser.errors[:field_117]).to include("The mortgage and cash deposit (£100.00) added together is £100.00.

The full purchase price (£100.00) subtracted by the sum of the full purchase price (£100.00) multiplied by the percentage discount (10.0%) is £90.00.

These two amounts should be the same.") expect(parser.errors[:field_126]).to be_empty end end diff --git a/spec/views/form/guidance/_financial_calculations_discounted_ownership_spec.rb b/spec/views/form/guidance/_financial_calculations_discounted_ownership_spec.rb new file mode 100644 index 000000000..5b40f2fc3 --- /dev/null +++ b/spec/views/form/guidance/_financial_calculations_discounted_ownership_spec.rb @@ -0,0 +1,85 @@ +require "rails_helper" + +RSpec.describe "form/guidance/_financial_calculations_discounted_ownership.html.erb" do + let(:log) { create(:sales_log) } + + let(:fragment) { Capybara::Node::Simple.new(rendered) } + + context "when mortgage used is not answered" do + let(:log) { create(:sales_log, :completed, ownershipsch: 2, type: 9, mortgageused: nil, discount: 30) } + + it "renders correct content" do + render partial: "form/guidance/financial_calculations_discounted_ownership", locals: { log:, current_user: log.assigned_to } + expect(fragment).to have_content("The mortgage amount") + expect(fragment).to have_content("and cash deposit") + expect(fragment).to have_content("added together must equal") + expect(fragment).to have_content("the purchase price") + expect(fragment).to have_content("subtracted by the sum of the purchase price") + expect(fragment).to have_content("multiplied by the discount") + end + end + + context "when mortgage used is no" do + let(:log) { create(:sales_log, :completed, ownershipsch: 2, type: 9, mortgageused: 2, discount: nil) } + + it "renders correct content" do + render partial: "form/guidance/financial_calculations_discounted_ownership", locals: { log:, current_user: log.assigned_to } + expect(fragment).to have_content("Cash deposit") + expect(fragment).to have_content("must equal") + expect(fragment).to have_content("the purchase price") + expect(fragment).to have_content("subtracted by the sum of the purchase price") + expect(fragment).to have_content("multiplied by the discount") + + expect(fragment).not_to have_content("The mortgage amount") + expect(fragment).not_to have_content("added together must equal") + end + end + + context "when mortgage used is yes" do + let(:log) { create(:sales_log, :completed, ownershipsch: 2, type: 9, mortgageused: 1, mortgage: nil, discount: 30) } + + it "renders correct content" do + render partial: "form/guidance/financial_calculations_discounted_ownership", locals: { log:, current_user: log.assigned_to } + expect(fragment).to have_content("The mortgage amount") + expect(fragment).to have_content("and cash deposit") + expect(fragment).to have_content("added together must equal") + expect(fragment).to have_content("the purchase price") + expect(fragment).to have_content("subtracted by the sum of the purchase price") + expect(fragment).to have_content("multiplied by the discount") + end + end + + context "when grant is routed to" do + context "and morgage used" do + let(:log) { create(:sales_log, :completed, ownershipsch: 2, type: 22, mortgageused: 1, mortgage: nil, discount: 30) } + + it "renders correct content" do + render partial: "form/guidance/financial_calculations_discounted_ownership", locals: { log:, current_user: log.assigned_to } + expect(fragment).to have_content("The mortgage amount") + expect(fragment).to have_content("cash deposit") + expect(fragment).to have_content("and grant") + expect(fragment).to have_content("added together must equal") + expect(fragment).to have_content("the purchase price") + + expect(fragment).not_to have_content("subtracted by the sum of the purchase price") + expect(fragment).not_to have_content("multiplied by the discount") + end + end + + context "and morgage not used" do + let(:log) { create(:sales_log, :completed, ownershipsch: 2, type: 22, mortgageused: 2, grant: nil) } + + it "renders correct content" do + render partial: "form/guidance/financial_calculations_discounted_ownership", locals: { log:, current_user: log.assigned_to } + expect(fragment).to have_content("Cash deposit") + expect(fragment).to have_content("and grant") + expect(fragment).to have_content("added together must equal") + expect(fragment).to have_content("the purchase price") + + expect(fragment).not_to have_content("The mortgage amount") + expect(fragment).not_to have_content("subtracted by the sum of the purchase price") + expect(fragment).not_to have_content("multiplied by the discount") + end + end + end +end diff --git a/spec/views/form/guidance/_financial_calculations_outright_sale_spec.rb b/spec/views/form/guidance/_financial_calculations_outright_sale_spec.rb new file mode 100644 index 000000000..343239e80 --- /dev/null +++ b/spec/views/form/guidance/_financial_calculations_outright_sale_spec.rb @@ -0,0 +1,45 @@ +require "rails_helper" + +RSpec.describe "form/guidance/_financial_calculations_outright_sale.html.erb" do + let(:log) { create(:sales_log) } + + let(:fragment) { Capybara::Node::Simple.new(rendered) } + + context "when mortgage used is not answered" do + let(:log) { create(:sales_log, :outright_sale_setup_complete, ownershipsch: 3, type: 10, mortgageused: nil, discount: 30) } + + it "renders correct content" do + render partial: "form/guidance/financial_calculations_outright_sale", locals: { log:, current_user: log.assigned_to } + expect(fragment).to have_content("The mortgage amount") + expect(fragment).to have_content("and cash deposit") + expect(fragment).to have_content("added together must equal") + expect(fragment).to have_content("the purchase price") + end + end + + context "when mortgage used is no" do + let(:log) { create(:sales_log, :outright_sale_setup_complete, ownershipsch: 3, type: 10, mortgageused: 2, discount: nil) } + + it "renders correct content" do + render partial: "form/guidance/financial_calculations_outright_sale", locals: { log:, current_user: log.assigned_to } + expect(fragment).to have_content("Cash deposit") + expect(fragment).to have_content("must equal") + expect(fragment).to have_content("the purchase price") + + expect(fragment).not_to have_content("The mortgage amount") + expect(fragment).not_to have_content("added together must equal") + end + end + + context "when mortgage used is yes" do + let(:log) { create(:sales_log, :outright_sale_setup_complete, ownershipsch: 3, type: 10, mortgageused: 1, mortgage: nil, discount: 30) } + + it "renders correct content" do + render partial: "form/guidance/financial_calculations_outright_sale", locals: { log:, current_user: log.assigned_to } + expect(fragment).to have_content("The mortgage amount") + expect(fragment).to have_content("and cash deposit") + expect(fragment).to have_content("added together must equal") + expect(fragment).to have_content("the purchase price") + end + end +end