@ -1,17 +1,61 @@
require " rails_helper "
require " rails_helper "
RSpec . describe Form :: Sales :: Subsections :: DiscountedOwnershipScheme , type : :model do
RSpec . describe Form :: Sales :: Subsections :: DiscountedOwnershipScheme , type : :model do
include CollectionTimeHelper
subject ( :discounted_ownership_scheme ) { described_class . new ( subsection_id , subsection_definition , section ) }
subject ( :discounted_ownership_scheme ) { described_class . new ( subsection_id , subsection_definition , section ) }
let ( :subsection_id ) { nil }
let ( :subsection_id ) { nil }
let ( :subsection_definition ) { nil }
let ( :subsection_definition ) { nil }
let ( :form ) { instance_double ( Form , start_date : Time . zone . local ( 2024 , 4 , 1 ) , start_year_2025_or_later? : false ) }
let ( :start_year_2025_or_later? ) { true }
let ( :start_year_2026_or_later? ) { true }
let ( :form ) { instance_double ( Form , start_date : current_collection_start_date , start_year_2025_or_later? : start_year_2025_or_later? , start_year_2026_or_later? : start_year_2026_or_later? ) }
let ( :section ) { instance_double ( Form :: Sales :: Sections :: SaleInformation , form : ) }
let ( :section ) { instance_double ( Form :: Sales :: Sections :: SaleInformation , form : ) }
it " has correct section " do
it " has correct section " do
expect ( discounted_ownership_scheme . section ) . to eq ( section )
expect ( discounted_ownership_scheme . section ) . to eq ( section )
end
end
it " has the correct id " do
expect ( discounted_ownership_scheme . id ) . to eq ( " discounted_ownership_scheme " )
end
it " has the correct copy key " do
expect ( discounted_ownership_scheme . copy_key ) . to eq ( " sale_information " )
end
it " has the correct label " do
expect ( discounted_ownership_scheme . label ) . to eq ( " Discounted ownership scheme " )
end
it " has the correct depends_on " do
expect ( discounted_ownership_scheme . depends_on ) . to eq ( [
{
" ownershipsch " = > 2 , " setup_completed? " = > true
} ,
] )
end
context " when it is a discounted ownership scheme " do
let ( :log ) { FactoryBot . build ( :sales_log , ownershipsch : 2 ) }
it " is displayed in tasklist " do
expect ( discounted_ownership_scheme . displayed_in_tasklist? ( log ) ) . to be ( true )
end
end
context " when it is not a discounted ownership scheme " do
let ( :log ) { FactoryBot . build ( :sales_log , ownershipsch : 1 ) }
it " is displayed in tasklist " do
expect ( discounted_ownership_scheme . displayed_in_tasklist? ( log ) ) . to be ( false )
end
end
context " when 2024 " , metadata : { year : 24 } do
let ( :start_year_2025_or_later? ) { false }
let ( :start_year_2026_or_later? ) { false }
it " has correct pages " do
it " has correct pages " do
expect ( discounted_ownership_scheme . pages . map ( & :id ) ) . to eq (
expect ( discounted_ownership_scheme . pages . map ( & :id ) ) . to eq (
%w[
%w[
@ -51,46 +95,51 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
] ,
] ,
)
)
end
end
it " has the correct id " do
expect ( discounted_ownership_scheme . id ) . to eq ( " discounted_ownership_scheme " )
end
end
it " has the correct copy key " do
context " when 2025 " , metadata : { year : 25 } do
expect ( discounted_ownership_scheme . copy_key ) . to eq ( " sale_information " )
let ( :start_year_2026_or_later? ) { false }
end
it " has the correct label " do
expect ( discounted_ownership_scheme . label ) . to eq ( " Discounted ownership scheme " )
end
it " has the correct depends_on " do
it " has correct pages " do
expect ( discounted_ownership_scheme . depends_on ) . to eq ( [
expect ( discounted_ownership_scheme . pages . map ( & :id ) ) . to eq (
{
%w[
" ownershipsch " = > 2 , " setup_completed? " = > true
living_before_purchase_discounted_ownership_joint_purchase
} ,
living_before_purchase_discounted_ownership
] )
purchase_price
end
discount
extra_borrowing_price_value_check
context " when it is a discounted ownership scheme " do
percentage_discount_value_check
let ( :log ) { FactoryBot . build ( :sales_log , ownershipsch : 2 ) }
grant
grant_value_check
it " is displayed in tasklist " do
purchase_price_discounted_ownership
expect ( discounted_ownership_scheme . displayed_in_tasklist? ( log ) ) . to be ( true )
discounted_sale_grant_value_check
end
about_price_discounted_ownership_value_check
end
discounted_ownership_deposit_and_mortgage_value_check_after_value_and_discount
mortgage_used_discounted_ownership
context " when it is not a discounted ownership scheme " do
discounted_ownership_mortgage_used_mortgage_value_check
let ( :log ) { FactoryBot . build ( :sales_log , ownershipsch : 1 ) }
discounted_sale_mortgage_used_value_check
mortgage_amount_discounted_ownership
it " is displayed in tasklist " do
discounted_ownership_mortgage_amount_mortgage_value_check
expect ( discounted_ownership_scheme . displayed_in_tasklist? ( log ) ) . to be ( false )
discounted_sale_mortgage_value_check
extra_borrowing_mortgage_value_check
discounted_ownership_deposit_and_mortgage_value_check_after_mortgage
mortgage_length_discounted_ownership
extra_borrowing_discounted_ownership
extra_borrowing_value_check
deposit_discounted_ownership
extra_borrowing_deposit_value_check
discounted_ownership_deposit_joint_purchase_value_check
discounted_ownership_deposit_value_check
discounted_ownership_deposit_and_mortgage_value_check_after_deposit
discounted_sale_deposit_value_check
leasehold_charges_discounted_ownership
monthly_charges_discounted_ownership_value_check
] ,
)
end
end
end
end
context " with form on or after 2025 " do
context " when 2026 " , metadata : { year : 26 } do
let ( :form ) { instance_double ( Form , start_date : Time . zone . local ( 2025 , 4 , 1 ) , start_year_2025_or_later? : true ) }
it " has correct pages " do
it " has correct pages " do
expect ( discounted_ownership_scheme . pages . map ( & :id ) ) . to eq (
expect ( discounted_ownership_scheme . pages . map ( & :id ) ) . to eq (
%w[
%w[
@ -114,7 +163,8 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
discounted_sale_mortgage_value_check
discounted_sale_mortgage_value_check
extra_borrowing_mortgage_value_check
extra_borrowing_mortgage_value_check
discounted_ownership_deposit_and_mortgage_value_check_after_mortgage
discounted_ownership_deposit_and_mortgage_value_check_after_mortgage
mortgage_length_discounted_ownership
mortgage_length_discounted_ownership_not_interviewed
mortgage_length_discounted_ownership_interviewed
extra_borrowing_discounted_ownership
extra_borrowing_discounted_ownership
extra_borrowing_value_check
extra_borrowing_value_check
deposit_discounted_ownership
deposit_discounted_ownership