@ -1,6 +1,8 @@
require " rails_helper "
require " rails_helper "
RSpec . describe Form :: Sales :: Questions :: Mortgageused , type : :model do
RSpec . describe Form :: Sales :: Questions :: Mortgageused , type : :model do
include CollectionTimeHelper
subject ( :question ) { described_class . new ( question_id , question_definition , page , ownershipsch : ) }
subject ( :question ) { described_class . new ( question_id , question_definition , page , ownershipsch : ) }
let ( :question_id ) { nil }
let ( :question_id ) { nil }
@ -9,26 +11,42 @@ RSpec.describe Form::Sales::Questions::Mortgageused, type: :model do
let ( :staircase ) { nil }
let ( :staircase ) { nil }
let ( :saledate ) { Time . zone . today }
let ( :saledate ) { Time . zone . today }
let ( :log ) { build ( :sales_log , :in_progress , ownershipsch : , stairowned : , staircase : ) }
let ( :log ) { build ( :sales_log , :in_progress , ownershipsch : , stairowned : , staircase : ) }
let ( :start_year_2024_or_later? ) { true }
let ( :start_year_2025_or_later? ) { true }
let ( :start_year_2026_or_later? ) { true }
let ( :subsection_id ) { " shared_ownership_initial_purchase " }
let ( :form ) { instance_double ( Form , start_date : saledate , start_year_2024_or_later? : start_year_2024_or_later? , start_year_2025_or_later? : start_year_2025_or_later? , start_year_2026_or_later? : start_year_2026_or_later? ) }
let ( :page ) { instance_double ( Form :: Page , subsection : instance_double ( Form :: Subsection , form : , id : subsection_id ) ) }
context " when the form start year is 2024 " do
context " when it is a shared ownership scheme " do
let ( :form ) { instance_double ( Form , start_date : Time . zone . local ( 2024 , 4 , 1 ) , start_year_2026_or_later? : false ) }
let ( :page ) { instance_double ( Form :: Page , subsection : instance_double ( Form :: Subsection , form : , id : " shared_ownership " ) ) }
let ( :saledate ) { Time . zone . local ( 2024 , 5 , 1 ) }
let ( :ownershipsch ) { 1 }
let ( :ownershipsch ) { 1 }
before do
it " has the correct top_guidance_partial " do
allow ( form ) . to receive_messages ( start_year_2024_or_later? : true , start_year_2025_or_later? : false )
expect ( question . top_guidance_partial ) . to eq ( " financial_calculations_shared_ownership " )
end
end
end
it " has the correct answer_options " do
context " when it is a discounted ownership sale " do
expect ( question . answer_options ) . to eq ( {
let ( :ownershipsch ) { 2 }
" 1 " = > { " value " = > " Yes " } ,
" 2 " = > { " value " = > " No " } ,
it " has the correct top_guidance_partial " do
" divider " = > { " value " = > true } ,
expect ( question . top_guidance_partial ) . to eq ( " financial_calculations_discounted_ownership " )
" 3 " = > { " value " = > " Don’t know " } ,
end
} )
end
context " when it is an outright sale " do
let ( :ownershipsch ) { 3 }
it " has the correct top_guidance_partial " do
expect ( question . top_guidance_partial ) . to eq ( " financial_calculations_outright_sale " )
end
end
end
context " when the form start year is 2024 " , metadata : { year : 24 } do
let ( :saledate ) { collection_start_date_for_year ( 2024 ) }
let ( :start_year_2025_or_later? ) { false }
let ( :start_year_2026_or_later? ) { false }
context " when it is a discounted ownership sale " do
context " when it is a discounted ownership sale " do
let ( :ownershipsch ) { 2 }
let ( :ownershipsch ) { 2 }
@ -44,24 +62,22 @@ RSpec.describe Form::Sales::Questions::Mortgageused, type: :model do
context " when it is an outright sale " do
context " when it is an outright sale " do
let ( :ownershipsch ) { 3 }
let ( :ownershipsch ) { 3 }
context " and the saledate is before 24/25 " do
it " shows the correct question number " do
let ( :saledate ) { Time . zone . local ( 2023 , 5 , 1 ) } \
expect ( question . question_number ) . to eq 112
it " does show the don't know option " do
expect_the_question_to_show_dont_know
end
end
end
context " and the saledate is 24/25 " do
it " shows the don't know option " do
it " shows the don't know option " do
expect_the_question_to_show_dont_know
expect_the_question_to_show_dont_know
end
end
end
end
end
context " when it is a shared ownership scheme " do
context " when it is a shared ownership scheme " do
let ( :ownershipsch ) { 1 }
let ( :ownershipsch ) { 1 }
it " shows the correct question number " do
expect ( question . question_number ) . to eq 91
end
context " and it is a staircasing transaction " do
context " and it is a staircasing transaction " do
let ( :staircase ) { 1 }
let ( :staircase ) { 1 }
@ -92,15 +108,9 @@ RSpec.describe Form::Sales::Questions::Mortgageused, type: :model do
end
end
end
end
context " when the form start year is 2025 " do
context " when the form start year is 2025 " , metadata : { year : 25 } do
let ( :form ) { instance_double ( Form , start_date : Time . zone . local ( 2025 , 4 , 1 ) , start_year_2026_or_later? : false ) }
let ( :saledate ) { collection_start_date_for_year ( 2025 ) }
let ( :page ) { instance_double ( Form :: Page , subsection : instance_double ( Form :: Subsection , form : , id : subsection_id ) ) }
let ( :start_year_2026_or_later? ) { false }
let ( :saledate ) { Time . zone . local ( 2025 , 5 , 1 ) }
let ( :subsection_id ) { " shared_ownership_initial_purchase " }
before do
allow ( form ) . to receive_messages ( start_year_2024_or_later? : true , start_year_2025_or_later? : true )
end
context " when it is a discounted ownership sale " do
context " when it is a discounted ownership sale " do
let ( :ownershipsch ) { 2 }
let ( :ownershipsch ) { 2 }
@ -118,10 +128,14 @@ RSpec.describe Form::Sales::Questions::Mortgageused, type: :model do
context " when it is a shared ownership scheme " do
context " when it is a shared ownership scheme " do
let ( :ownershipsch ) { 1 }
let ( :ownershipsch ) { 1 }
it " shows the correct question number " do
expect ( question . question_number ) . to eq 82
end
context " and it is a staircasing transaction " do
context " and it is a staircasing transaction " do
let ( :staircase ) { 1 }
let ( :staircase ) { 1 }
it " does show the don't know option " do
it " shows the don't know option " do
expect_the_question_to_show_dont_know
expect_the_question_to_show_dont_know
end
end
@ -144,6 +158,53 @@ RSpec.describe Form::Sales::Questions::Mortgageused, type: :model do
end
end
end
end
context " when the form start year is 2026 " , metadata : { year : 26 } do
let ( :saledate ) { collection_start_date_for_year ( 2026 ) }
context " when it is a discounted ownership sale " do
let ( :ownershipsch ) { 2 }
let ( :subsection_id ) { " discounted_ownership_scheme " }
it " shows the correct question number " do
expect ( question . question_number ) . to eq 116
end
it " shows the don't know option " do
expect_the_question_to_show_dont_know
end
end
context " when it is a shared ownership scheme " do
let ( :ownershipsch ) { 1 }
context " and it is a staircasing transaction " do
let ( :staircase ) { 1 }
let ( :subsection_id ) { " shared_ownership_staircasing_transaction " }
it " shows the correct question number " do
expect ( question . question_number ) . to eq 107
end
it " shows the don't know option " do
expect_the_question_to_show_dont_know
end
end
context " and it is not a staircasing transaction " do
let ( :staircase ) { 2 }
let ( :subsection_id ) { " shared_ownership_initial_purchase " }
it " shows the correct question number " do
expect ( question . question_number ) . to eq 90
end
it " shows the don't know option " do
expect_the_question_to_show_dont_know
end
end
end
end
private
private
def expect_the_question_not_to_show_dont_know
def expect_the_question_not_to_show_dont_know