diff --git a/app/models/form/sales/pages/buyer2_live_in_property.rb b/app/models/form/sales/pages/buyer2_live_in_property.rb index 9ba67080b..3c0ce7b3b 100644 --- a/app/models/form/sales/pages/buyer2_live_in_property.rb +++ b/app/models/form/sales/pages/buyer2_live_in_property.rb @@ -4,12 +4,12 @@ class Form::Sales::Pages::Buyer2LiveInProperty < ::Form::Page @id = "buyer_2_live_in_property" @depends_on = [ { - "jointpur" => 1, + "joint_purchase?" => true, "privacynotice" => 1, }, { - "jointpur" => 1, - "noint" => 1, + "joint_purchase?" => true, + "buyer_not_interviewed?" => true, }, ] end diff --git a/app/models/form/sales/pages/buyer2_living_in.rb b/app/models/form/sales/pages/buyer2_living_in.rb new file mode 100644 index 000000000..b8d32ffdc --- /dev/null +++ b/app/models/form/sales/pages/buyer2_living_in.rb @@ -0,0 +1,11 @@ +class Form::Sales::Pages::Buyer2LivingIn < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "buyer_2_living_in" + @depends_on = [{ "buyer_two_will_live_in_property?" => true }] + end + + def questions + @questions = [Form::Sales::Questions::Buyer2LivingIn.new(nil, nil, self)] + end +end diff --git a/app/models/form/sales/pages/buyer2_previous_housing_situation.rb b/app/models/form/sales/pages/buyer2_previous_housing_situation.rb new file mode 100644 index 000000000..c6a511243 --- /dev/null +++ b/app/models/form/sales/pages/buyer2_previous_housing_situation.rb @@ -0,0 +1,11 @@ +class Form::Sales::Pages::Buyer2PreviousHousingSituation < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "buyer_2_previous_housing_situation" + @depends_on = [{ "buyer_two_not_already_living_in_property?" => true }] + end + + def questions + @questions = [Form::Sales::Questions::PreviousTenureBuyer2.new(nil, nil, self)] + end +end diff --git a/app/models/form/sales/questions/buyer2_living_in.rb b/app/models/form/sales/questions/buyer2_living_in.rb new file mode 100644 index 000000000..1494e61a2 --- /dev/null +++ b/app/models/form/sales/questions/buyer2_living_in.rb @@ -0,0 +1,17 @@ +class Form::Sales::Questions::Buyer2LivingIn < ::Form::Question + def initialize(id, hsh, page) + super + @id = "buy2living" + @check_answer_label = "Buyer 2 living at the same address" + @header = "At the time of purchase, was buyer 2 living at the same address as buyer 1?" + @type = "radio" + @hint_text = "" + @answer_options = ANSWER_OPTIONS + end + + ANSWER_OPTIONS = { + "1" => { "value" => "Yes" }, + "2" => { "value" => "No" }, + "3" => { "value" => "Don't know" }, + }.freeze +end diff --git a/app/models/form/sales/questions/previous_tenure_buyer2.rb b/app/models/form/sales/questions/previous_tenure_buyer2.rb new file mode 100644 index 000000000..6de2ed8c5 --- /dev/null +++ b/app/models/form/sales/questions/previous_tenure_buyer2.rb @@ -0,0 +1,23 @@ +class Form::Sales::Questions::PreviousTenureBuyer2 < ::Form::Question + def initialize(id, hsh, page) + super + @id = "prevtenbuy2" + @check_answer_label = "Buyer 2’s previous tenure" + @header = "What was buyer 2’s previous tenure?" + @type = "radio" + @hint_text = "" + @answer_options = ANSWER_OPTIONS + end + + ANSWER_OPTIONS = { + "1" => { "value" => "Local Authority" }, + "2" => { "value" => "Private registered provider or housing association tenant" }, + "3" => { "value" => "Private tenant" }, + "5" => { "value" => "Owner occupier" }, + "4" => { "value" => "Tied home or renting with job" }, + "6" => { "value" => "Living with family or friends" }, + "7" => { "value" => "Temporary accomodation" }, + "9" => { "value" => "Other" }, + "0" => { "value" => "Don't know" }, + }.freeze +end diff --git a/app/models/form/sales/subsections/household_situation.rb b/app/models/form/sales/subsections/household_situation.rb index a9d9306d6..225b1ae43 100644 --- a/app/models/form/sales/subsections/household_situation.rb +++ b/app/models/form/sales/subsections/household_situation.rb @@ -12,6 +12,16 @@ class Form::Sales::Subsections::HouseholdSituation < ::Form::Subsection Form::Sales::Pages::LastAccommodation.new(nil, nil, self), Form::Sales::Pages::LastAccommodationLa.new(nil, nil, self), Form::Sales::Pages::BuyersOrganisations.new(nil, nil, self), - ] + buyer_2_situation_pages, + ].flatten.compact + end + + def buyer_2_situation_pages + if form.start_date.year >= 2023 + [ + Form::Sales::Pages::Buyer2LivingIn.new(nil, nil, self), + Form::Sales::Pages::Buyer2PreviousHousingSituation.new(nil, nil, self), + ] + end end end diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb index 90f130c04..e15b9c610 100644 --- a/app/models/sales_log.rb +++ b/app/models/sales_log.rb @@ -151,6 +151,14 @@ class SalesLog < Log inc1mort == 1 end + def buyer_two_will_live_in_property? + buy2livein == 1 + end + + def buyer_two_not_already_living_in_property? + buy2living == 2 + end + def income2_used_for_mortgage? inc2mort == 1 end @@ -250,6 +258,10 @@ class SalesLog < Log jointpur == 2 end + def buyer_not_interviewed? + noint == 1 + end + def old_persons_shared_ownership? type == 24 end diff --git a/db/migrate/20230224083552_add_columns_to_sales_log.rb b/db/migrate/20230224083552_add_columns_to_sales_log.rb new file mode 100644 index 000000000..f4fbc91df --- /dev/null +++ b/db/migrate/20230224083552_add_columns_to_sales_log.rb @@ -0,0 +1,8 @@ +class AddColumnsToSalesLog < ActiveRecord::Migration[7.0] + def change + change_table :sales_logs, bulk: true do |t| + t.column :buy2living, :integer + t.column :prevtenbuy2, :integer + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 3b26fde33..385d565c7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -543,6 +543,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_08_101826) do t.integer "proplen_asked" t.string "old_id" t.integer "pregblank" + t.integer "buy2living" + t.integer "prevtenbuy2" t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id" t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id" t.index ["old_id"], name: "index_sales_logs_on_old_id", unique: true diff --git a/spec/models/form/sales/pages/buyer2_live_in_property_spec.rb b/spec/models/form/sales/pages/buyer2_live_in_property_spec.rb index 258e37462..555e78927 100644 --- a/spec/models/form/sales/pages/buyer2_live_in_property_spec.rb +++ b/spec/models/form/sales/pages/buyer2_live_in_property_spec.rb @@ -30,12 +30,12 @@ RSpec.describe Form::Sales::Pages::Buyer2LiveInProperty, type: :model do it "has correct depends_on" do expect(page.depends_on).to eq([ { - "jointpur" => 1, + "joint_purchase?" => true, "privacynotice" => 1, }, { - "jointpur" => 1, - "noint" => 1, + "joint_purchase?" => true, + "buyer_not_interviewed?" => true, }, ]) end diff --git a/spec/models/form/sales/pages/buyer2_living_in_spec.rb b/spec/models/form/sales/pages/buyer2_living_in_spec.rb new file mode 100644 index 000000000..9bfef1ff4 --- /dev/null +++ b/spec/models/form/sales/pages/buyer2_living_in_spec.rb @@ -0,0 +1,31 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::Buyer2LivingIn, type: :model do + subject(:page) { described_class.new(nil, nil, subsection) } + + let(:subsection) { instance_double(Form::Subsection) } + + 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[buy2living]) + end + + it "has the correct id" do + expect(page.id).to eq("buyer_2_living_in") + end + + it "has the correct header" do + expect(page.header).to be_nil + 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([{ "buyer_two_will_live_in_property?" => true }]) + end +end diff --git a/spec/models/form/sales/pages/buyer2_previous_housing_situation_spec.rb b/spec/models/form/sales/pages/buyer2_previous_housing_situation_spec.rb new file mode 100644 index 000000000..ac5611a8f --- /dev/null +++ b/spec/models/form/sales/pages/buyer2_previous_housing_situation_spec.rb @@ -0,0 +1,31 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::Buyer2PreviousHousingSituation, type: :model do + subject(:page) { described_class.new(nil, nil, subsection) } + + let(:subsection) { instance_double(Form::Subsection) } + + 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[prevtenbuy2]) + end + + it "has the correct id" do + expect(page.id).to eq("buyer_2_previous_housing_situation") + end + + it "has the correct header" do + expect(page.header).to be_nil + 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([{ "buyer_two_not_already_living_in_property?" => true }]) + end +end diff --git a/spec/models/form/sales/questions/buyer2_living_in_spec.rb b/spec/models/form/sales/questions/buyer2_living_in_spec.rb new file mode 100644 index 000000000..4fca65f3f --- /dev/null +++ b/spec/models/form/sales/questions/buyer2_living_in_spec.rb @@ -0,0 +1,43 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::Buyer2LivingIn, type: :model do + subject(:question) { described_class.new(nil, nil, page) } + + let(:page) { instance_double(Form::Page) } + + it "has correct page" do + expect(question.page).to eq page + end + + it "has the correct id" do + expect(question.id).to eq "buy2living" + end + + it "has the correct header" do + expect(question.header).to eq "At the time of purchase, was buyer 2 living at the same address as buyer 1?" + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq "Buyer 2 living at the same address" + end + + it "has the correct type" do + expect(question.type).to eq "radio" + end + + it "is not marked as derived" do + expect(question.derived?).to be false + end + + it "has the correct hint_text" do + expect(question.hint_text).to eq "" + end + + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "1" => { "value" => "Yes" }, + "2" => { "value" => "No" }, + "3" => { "value" => "Don't know" }, + }) + end +end diff --git a/spec/models/form/sales/questions/previous_tenure_buyer2_spec.rb b/spec/models/form/sales/questions/previous_tenure_buyer2_spec.rb new file mode 100644 index 000000000..1ab7a86de --- /dev/null +++ b/spec/models/form/sales/questions/previous_tenure_buyer2_spec.rb @@ -0,0 +1,49 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::PreviousTenureBuyer2, type: :model do + subject(:question) { described_class.new(nil, nil, page) } + + let(:page) { instance_double(Form::Page) } + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("prevtenbuy2") + end + + it "has the correct header" do + expect(question.header).to eq("What was buyer 2’s previous tenure?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Buyer 2’s previous tenure") + end + + it "has the correct type" do + expect(question.type).to eq("radio") + end + + it "is not marked as derived" do + expect(question.derived?).to be false + end + + it "has the correct hint_text" do + expect(question.hint_text).to eq("") + end + + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "1" => { "value" => "Local Authority" }, + "2" => { "value" => "Private registered provider or housing association tenant" }, + "3" => { "value" => "Private tenant" }, + "5" => { "value" => "Owner occupier" }, + "4" => { "value" => "Tied home or renting with job" }, + "6" => { "value" => "Living with family or friends" }, + "7" => { "value" => "Temporary accomodation" }, + "9" => { "value" => "Other" }, + "0" => { "value" => "Don't know" }, + }) + end +end diff --git a/spec/models/form/sales/subsections/household_situation_spec.rb b/spec/models/form/sales/subsections/household_situation_spec.rb index e88dda99f..10898b27c 100644 --- a/spec/models/form/sales/subsections/household_situation_spec.rb +++ b/spec/models/form/sales/subsections/household_situation_spec.rb @@ -1,25 +1,44 @@ require "rails_helper" RSpec.describe Form::Sales::Subsections::HouseholdSituation, type: :model do - subject(:household_characteristics) { described_class.new(subsection_id, subsection_definition, section) } + subject(:household_characteristics) { described_class.new(nil, nil, section) } - let(:subsection_id) { nil } - let(:subsection_definition) { nil } - let(:section) { instance_double(Form::Sales::Sections::Household) } + let(:start_date) { Time.utc(2023, 4, 1) } + let(:form) { instance_double(Form, start_date:) } + let(:section) { instance_double(Form::Sales::Sections::Household, form:) } it "has correct section" do expect(household_characteristics.section).to eq(section) end - it "has correct pages" do - expect(household_characteristics.pages.map(&:id)).to eq( - %w[ - buyer1_previous_tenure - last_accommodation - last_accommodation_la - buyers_organisations - ], - ) + context "when the log belongs to the 22/23 collection" do + let(:start_date) { Time.utc(2022, 4, 1) } + + it "has correct pages" do + expect(household_characteristics.pages.map(&:id)).to eq( + %w[ + buyer1_previous_tenure + last_accommodation + last_accommodation_la + buyers_organisations + ], + ) + end + end + + context "when the log belongs to the 23/24 collection" do + it "has correct pages" do + expect(household_characteristics.pages.map(&:id)).to eq( + %w[ + buyer1_previous_tenure + last_accommodation + last_accommodation_la + buyers_organisations + buyer_2_living_in + buyer_2_previous_housing_situation + ], + ) + end end it "has the correct id" do