diff --git a/app/models/form/sales/pages/buyer_interview.rb b/app/models/form/sales/pages/buyer_interview.rb index ebd2e387a..2d20a9490 100644 --- a/app/models/form/sales/pages/buyer_interview.rb +++ b/app/models/form/sales/pages/buyer_interview.rb @@ -1,12 +1,20 @@ class Form::Sales::Pages::BuyerInterview < ::Form::Page - def initialize(id, hsh, subsection) - super - @id = "buyer_interview" + def initialize(id, hsh, subsection, joint_purchase:) + super(id, hsh, subsection) + @joint_purchase = joint_purchase end def questions @questions ||= [ - Form::Sales::Questions::BuyerInterview.new(nil, nil, self), + Form::Sales::Questions::BuyerInterview.new(nil, nil, self, joint_purchase: @joint_purchase), ] end + + def depends_on + if @joint_purchase + [{ "joint_purchase?" => true }] + else + [{ "not_joint_purchase?" => true }] + end + end end diff --git a/app/models/form/sales/pages/old_persons_shared_ownership_value_check.rb b/app/models/form/sales/pages/old_persons_shared_ownership_value_check.rb index 537a6679f..101f30f88 100644 --- a/app/models/form/sales/pages/old_persons_shared_ownership_value_check.rb +++ b/app/models/form/sales/pages/old_persons_shared_ownership_value_check.rb @@ -1,19 +1,15 @@ class Form::Sales::Pages::OldPersonsSharedOwnershipValueCheck < ::Form::Page - def initialize(id, hsh, subsection) - super - @depends_on = [ - { - "buyers_age_for_old_persons_shared_ownership_invalid?" => true, - }, - ] + def initialize(id, hsh, subsection, joint_purchase:) + super(id, hsh, subsection) @title_text = { - "translation" => "soft_validations.old_persons_shared_ownership.title_text", + "translation" => "soft_validations.old_persons_shared_ownership.title_text.#{joint_purchase ? 'two' : 'one'}", "arguments" => [], } @informative_text = { "translation" => "soft_validations.old_persons_shared_ownership.hint_text", "arguments" => [], } + @joint_purchase = joint_purchase end def questions @@ -25,4 +21,12 @@ class Form::Sales::Pages::OldPersonsSharedOwnershipValueCheck < ::Form::Page def interruption_screen_question_ids %w[type jointpur age1 age2] end + + def depends_on + if @joint_purchase + [{ "joint_purchase?" => true, "buyers_age_for_old_persons_shared_ownership_invalid?" => true }] + else + [{ "not_joint_purchase?" => true, "buyers_age_for_old_persons_shared_ownership_invalid?" => true }] + end + end end diff --git a/app/models/form/sales/pages/privacy_notice.rb b/app/models/form/sales/pages/privacy_notice.rb index dc4bfa70d..818baaa02 100644 --- a/app/models/form/sales/pages/privacy_notice.rb +++ b/app/models/form/sales/pages/privacy_notice.rb @@ -1,13 +1,21 @@ class Form::Sales::Pages::PrivacyNotice < ::Form::Page - def initialize(id, hsh, subsection) - super - @id = "privacy_notice" + def initialize(id, hsh, subsection, joint_purchase:) + super(id, hsh, subsection) @header = "Department for Levelling Up, Housing and Communities privacy notice" + @joint_purchase = joint_purchase end def questions @questions ||= [ - Form::Sales::Questions::PrivacyNotice.new(nil, nil, self), + Form::Sales::Questions::PrivacyNotice.new(nil, nil, self, joint_purchase: @joint_purchase), ] end + + def depends_on + if @joint_purchase + [{ "joint_purchase?" => true }] + else + [{ "not_joint_purchase?" => true }] + end + end end diff --git a/app/models/form/sales/questions/buyer_interview.rb b/app/models/form/sales/questions/buyer_interview.rb index aa737171f..f957b392a 100644 --- a/app/models/form/sales/questions/buyer_interview.rb +++ b/app/models/form/sales/questions/buyer_interview.rb @@ -1,11 +1,11 @@ class Form::Sales::Questions::BuyerInterview < ::Form::Question - def initialize(id, hsh, page) - super + def initialize(id, hsh, page, joint_purchase:) + super(id, hsh, page) @id = "noint" - @check_answer_label = "Buyer interviewed in person?" - @header = "Was the buyer interviewed for any of the answers you will provide on this log?" + @check_answer_label = "#{joint_purchase ? 'Buyers' : 'Buyer'} interviewed in person?" + @header = "#{joint_purchase ? 'Were the buyers' : 'Was the buyer'} interviewed for any of the answers you will provide on this log?" @type = "radio" - @hint_text = "You should still try to answer all questions even if the buyer wasn't interviewed in person" + @hint_text = "You should still try to answer all questions even if the #{joint_purchase ? "buyers weren't" : "buyer wasn't"} interviewed in person" @answer_options = ANSWER_OPTIONS @question_number = 18 end diff --git a/app/models/form/sales/questions/privacy_notice.rb b/app/models/form/sales/questions/privacy_notice.rb index 62eab5d8f..84bfbb8f2 100644 --- a/app/models/form/sales/questions/privacy_notice.rb +++ b/app/models/form/sales/questions/privacy_notice.rb @@ -1,19 +1,20 @@ class Form::Sales::Questions::PrivacyNotice < ::Form::Question - def initialize(id, hsh, page) - super + def initialize(id, hsh, page, joint_purchase:) + super(id, hsh, page) @id = "privacynotice" - @check_answer_label = "Buyer has seen the privacy notice?" + @check_answer_label = "#{joint_purchase ? 'Buyers have' : 'Buyer has'} seen the privacy notice?" @header = "Declaration" @type = "checkbox" @top_guidance_partial = form.start_year_after_2024? ? "privacy_notice_buyer_2024" : "privacy_notice_buyer" @question_number = 19 + @joint_purchase = joint_purchase end def answer_options declaration_text = if form.start_year_after_2024? - "The buyer has seen or been given access to the DLUHC privacy notice" + "The #{@joint_purchase ? 'buyers have' : 'buyer has'} seen or been given access to the DLUHC privacy notice" else - "The buyer has seen the DLUHC privacy notice" + "The #{@joint_purchase ? 'buyers have' : 'buyer has'} seen the DLUHC privacy notice" end { "privacynotice" => { "value" => declaration_text } }.freeze diff --git a/app/models/form/sales/subsections/household_characteristics.rb b/app/models/form/sales/subsections/household_characteristics.rb index ac006b453..eeb8dbea3 100644 --- a/app/models/form/sales/subsections/household_characteristics.rb +++ b/app/models/form/sales/subsections/household_characteristics.rb @@ -8,11 +8,14 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection def pages @pages ||= [ - (Form::Sales::Pages::BuyerInterview.new(nil, nil, self) unless form.start_year_after_2024?), - (Form::Sales::Pages::PrivacyNotice.new(nil, nil, self) unless form.start_year_after_2024?), + (Form::Sales::Pages::BuyerInterview.new("buyer_interview_joint_purchase", nil, self, joint_purchase: true) unless form.start_year_after_2024?), + (Form::Sales::Pages::BuyerInterview.new("buyer_interview", nil, self, joint_purchase: false) unless form.start_year_after_2024?), + (Form::Sales::Pages::PrivacyNotice.new("privacy_notice_joint_purchase", nil, self, joint_purchase: true) unless form.start_year_after_2024?), + (Form::Sales::Pages::PrivacyNotice.new("privacy_notice", nil, self, joint_purchase: false) unless form.start_year_after_2024?), Form::Sales::Pages::Age1.new(nil, nil, self), Form::Sales::Pages::RetirementValueCheck.new("age_1_retirement_value_check", nil, self, person_index: 1), - Form::Sales::Pages::OldPersonsSharedOwnershipValueCheck.new("age_1_old_persons_shared_ownership_value_check", nil, self), + Form::Sales::Pages::OldPersonsSharedOwnershipValueCheck.new("age_1_old_persons_shared_ownership_joint_purchase_value_check", nil, self, joint_purchase: true), + Form::Sales::Pages::OldPersonsSharedOwnershipValueCheck.new("age_1_old_persons_shared_ownership_value_check", nil, self, joint_purchase: false), Form::Sales::Pages::GenderIdentity1.new(nil, nil, self), Form::Sales::Pages::RetirementValueCheck.new("gender_1_retirement_value_check", nil, self, person_index: 1), Form::Sales::Pages::Buyer1EthnicGroup.new(nil, nil, self), @@ -30,7 +33,8 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Sales::Pages::Buyer2RelationshipToBuyer1.new(nil, nil, self), Form::Sales::Pages::PersonStudentNotChildValueCheck.new("buyer_2_relationship_student_not_child_value_check", nil, self, person_index: 2), Form::Sales::Pages::Age2.new(nil, nil, self), - Form::Sales::Pages::OldPersonsSharedOwnershipValueCheck.new("age_2_old_persons_shared_ownership_value_check", nil, self), + Form::Sales::Pages::OldPersonsSharedOwnershipValueCheck.new("age_2_old_persons_shared_ownership_joint_purchase_value_check", nil, self, joint_purchase: true), + Form::Sales::Pages::OldPersonsSharedOwnershipValueCheck.new("age_2_old_persons_shared_ownership_value_check", nil, self, joint_purchase: false), Form::Sales::Pages::RetirementValueCheck.new("age_2_buyer_retirement_value_check", nil, self, person_index: 2), Form::Sales::Pages::PersonStudentNotChildValueCheck.new("buyer_2_age_student_not_child_value_check", nil, self, person_index: 2), Form::Sales::Pages::GenderIdentity2.new(nil, nil, self), diff --git a/app/models/form/sales/subsections/setup.rb b/app/models/form/sales/subsections/setup.rb index 49e9392bb..f954e24e6 100644 --- a/app/models/form/sales/subsections/setup.rb +++ b/app/models/form/sales/subsections/setup.rb @@ -20,8 +20,10 @@ class Form::Sales::Subsections::Setup < ::Form::Subsection Form::Sales::Pages::BuyerLive.new(nil, nil, self), Form::Sales::Pages::JointPurchase.new(nil, nil, self), Form::Sales::Pages::NumberJointBuyers.new(nil, nil, self), - (Form::Sales::Pages::BuyerInterview.new(nil, nil, self) if form.start_year_after_2024?), - (Form::Sales::Pages::PrivacyNotice.new(nil, nil, self) if form.start_year_after_2024?), + (Form::Sales::Pages::BuyerInterview.new("buyer_interview_joint_purchase", nil, self, joint_purchase: true) if form.start_year_after_2024?), + (Form::Sales::Pages::BuyerInterview.new("buyer_interview", nil, self, joint_purchase: false) if form.start_year_after_2024?), + (Form::Sales::Pages::PrivacyNotice.new("privacy_notice_joint_purchase", nil, self, joint_purchase: true) if form.start_year_after_2024?), + (Form::Sales::Pages::PrivacyNotice.new("privacy_notice", nil, self, joint_purchase: false) if form.start_year_after_2024?), ].flatten.compact end end diff --git a/spec/models/form/sales/pages/buyer_interview_spec.rb b/spec/models/form/sales/pages/buyer_interview_spec.rb index ffc4c9a3a..5d02332e0 100644 --- a/spec/models/form/sales/pages/buyer_interview_spec.rb +++ b/spec/models/form/sales/pages/buyer_interview_spec.rb @@ -1,9 +1,9 @@ require "rails_helper" RSpec.describe Form::Sales::Pages::BuyerInterview, type: :model do - subject(:page) { described_class.new(page_id, page_definition, subsection) } + subject(:page) { described_class.new(page_id, page_definition, subsection, joint_purchase: false) } - let(:page_id) { nil } + let(:page_id) { "buyer_interview" } let(:page_definition) { nil } let(:subsection) { instance_double(Form::Subsection) } diff --git a/spec/models/form/sales/pages/old_persons_shared_ownership_value_check_spec.rb b/spec/models/form/sales/pages/old_persons_shared_ownership_value_check_spec.rb index d9c4beed9..0f4649ea8 100644 --- a/spec/models/form/sales/pages/old_persons_shared_ownership_value_check_spec.rb +++ b/spec/models/form/sales/pages/old_persons_shared_ownership_value_check_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" RSpec.describe Form::Sales::Pages::OldPersonsSharedOwnershipValueCheck, type: :model do - subject(:page) { described_class.new(page_id, page_definition, subsection) } + subject(:page) { described_class.new(page_id, page_definition, subsection, joint_purchase: false) } let(:page_id) { "old_persons_shared_ownership_value_check" } let(:page_definition) { nil } @@ -27,13 +27,14 @@ RSpec.describe Form::Sales::Pages::OldPersonsSharedOwnershipValueCheck, type: :m expect(page.depends_on).to eq([ { "buyers_age_for_old_persons_shared_ownership_invalid?" => true, + "not_joint_purchase?" => true, }, ]) end it "has the correct title_text" do expect(page.title_text).to eq({ - "translation" => "soft_validations.old_persons_shared_ownership.title_text", + "translation" => "soft_validations.old_persons_shared_ownership.title_text.one", "arguments" => [], }) end @@ -45,4 +46,24 @@ RSpec.describe Form::Sales::Pages::OldPersonsSharedOwnershipValueCheck, type: :m it "has the correct interruption_screen_question_ids" do expect(page.interruption_screen_question_ids).to eq(%w[type jointpur age1 age2]) end + + context "with joint purchase" do + subject(:page) { described_class.new(page_id, page_definition, subsection, joint_purchase: true) } + + it "has the correct title_text" do + expect(page.title_text).to eq({ + "translation" => "soft_validations.old_persons_shared_ownership.title_text.two", + "arguments" => [], + }) + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([ + { + "buyers_age_for_old_persons_shared_ownership_invalid?" => true, + "joint_purchase?" => true, + }, + ]) + end + end end diff --git a/spec/models/form/sales/pages/privacy_notice_spec.rb b/spec/models/form/sales/pages/privacy_notice_spec.rb index 9c2ce1a64..0a3d389cf 100644 --- a/spec/models/form/sales/pages/privacy_notice_spec.rb +++ b/spec/models/form/sales/pages/privacy_notice_spec.rb @@ -1,9 +1,9 @@ require "rails_helper" RSpec.describe Form::Sales::Pages::PrivacyNotice, type: :model do - subject(:page) { described_class.new(page_id, page_definition, subsection) } + subject(:page) { described_class.new(page_id, page_definition, subsection, joint_purchase: false) } - let(:page_id) { nil } + let(:page_id) { "privacy_notice" } let(:page_definition) { nil } let(:subsection) { instance_double(Form::Subsection) } let(:form) { instance_double(Form) } @@ -34,6 +34,20 @@ RSpec.describe Form::Sales::Pages::PrivacyNotice, type: :model do end it "has correct depends_on" do - expect(page.depends_on).to be_nil + expect(page.depends_on).to eq([{ "not_joint_purchase?" => true }]) + end + + context "with joint purchase" do + subject(:page) { described_class.new(page_id, page_definition, subsection, joint_purchase: true) } + + let(:page_id) { "privacy_notice_joint_purchase" } + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ "joint_purchase?" => true }]) + end + + it "has the correct id" do + expect(page.id).to eq("privacy_notice_joint_purchase") + end end end diff --git a/spec/models/form/sales/questions/buyer_interview_spec.rb b/spec/models/form/sales/questions/buyer_interview_spec.rb index 433d46f8b..0dc25978f 100644 --- a/spec/models/form/sales/questions/buyer_interview_spec.rb +++ b/spec/models/form/sales/questions/buyer_interview_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" RSpec.describe Form::Sales::Questions::BuyerInterview, type: :model do - subject(:question) { described_class.new(question_id, question_definition, page) } + subject(:question) { described_class.new(question_id, question_definition, page, joint_purchase: false) } let(:question_id) { nil } let(:question_definition) { nil } @@ -41,4 +41,20 @@ RSpec.describe Form::Sales::Questions::BuyerInterview, type: :model do "1" => { "value" => "No" }, }) end + + context "with joint purchase" do + subject(:question) { described_class.new(question_id, question_definition, page, joint_purchase: true) } + + it "has the correct header" do + expect(question.header).to eq("Were the buyers interviewed for any of the answers you will provide on this log?") + end + + it "has the correct hint_text" do + expect(question.hint_text).to eq("You should still try to answer all questions even if the buyers weren't interviewed in person") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Buyers interviewed in person?") + end + end end diff --git a/spec/models/form/sales/subsections/household_characteristics_spec.rb b/spec/models/form/sales/subsections/household_characteristics_spec.rb index 842dec8bc..3deddf001 100644 --- a/spec/models/form/sales/subsections/household_characteristics_spec.rb +++ b/spec/models/form/sales/subsections/household_characteristics_spec.rb @@ -25,10 +25,13 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model it "has correct pages" do expect(household_characteristics.pages.map(&:id)).to eq( %w[ + buyer_interview_joint_purchase buyer_interview + privacy_notice_joint_purchase privacy_notice buyer_1_age age_1_retirement_value_check + age_1_old_persons_shared_ownership_joint_purchase_value_check age_1_old_persons_shared_ownership_value_check buyer_1_gender_identity gender_1_retirement_value_check @@ -47,6 +50,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model buyer_2_relationship_to_buyer_1 buyer_2_relationship_student_not_child_value_check buyer_2_age + age_2_old_persons_shared_ownership_joint_purchase_value_check age_2_old_persons_shared_ownership_value_check age_2_buyer_retirement_value_check buyer_2_age_student_not_child_value_check @@ -129,10 +133,13 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model it "has correct pages" do expect(household_characteristics.pages.map(&:id)).to eq( %w[ + buyer_interview_joint_purchase buyer_interview + privacy_notice_joint_purchase privacy_notice buyer_1_age age_1_retirement_value_check + age_1_old_persons_shared_ownership_joint_purchase_value_check age_1_old_persons_shared_ownership_value_check buyer_1_gender_identity gender_1_retirement_value_check @@ -151,6 +158,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model buyer_2_relationship_to_buyer_1 buyer_2_relationship_student_not_child_value_check buyer_2_age + age_2_old_persons_shared_ownership_joint_purchase_value_check age_2_old_persons_shared_ownership_value_check age_2_buyer_retirement_value_check buyer_2_age_student_not_child_value_check @@ -242,6 +250,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model %w[ buyer_1_age age_1_retirement_value_check + age_1_old_persons_shared_ownership_joint_purchase_value_check age_1_old_persons_shared_ownership_value_check buyer_1_gender_identity gender_1_retirement_value_check @@ -260,6 +269,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model buyer_2_relationship_to_buyer_1 buyer_2_relationship_student_not_child_value_check buyer_2_age + age_2_old_persons_shared_ownership_joint_purchase_value_check age_2_old_persons_shared_ownership_value_check age_2_buyer_retirement_value_check buyer_2_age_student_not_child_value_check diff --git a/spec/models/form/sales/subsections/setup_spec.rb b/spec/models/form/sales/subsections/setup_spec.rb index eb92e3753..d1964930e 100644 --- a/spec/models/form/sales/subsections/setup_spec.rb +++ b/spec/models/form/sales/subsections/setup_spec.rb @@ -67,7 +67,9 @@ RSpec.describe Form::Sales::Subsections::Setup, type: :model do buyer_live joint_purchase number_joint_buyers + buyer_interview_joint_purchase buyer_interview + privacy_notice_joint_purchase privacy_notice ], )