From b87c107f25703e4befeaf23422f362d8c9b27ff3 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Thu, 14 Nov 2024 08:55:41 +0000 Subject: [PATCH] Route only to buyer questions for staircase transactions (#2765) --- .../form/sales/pages/buyer1_ethnic_group.rb | 18 +-- .../sales/pages/buyer1_live_in_property.rb | 37 +++--- .../form/sales/pages/buyer1_nationality.rb | 18 +-- .../sales/pages/buyer1_working_situation.rb | 10 ++ .../form/sales/pages/buyer2_ethnic_group.rb | 21 +-- .../sales/pages/buyer2_live_in_property.rb | 39 +++--- .../form/sales/pages/buyer2_nationality.rb | 21 +-- .../sales/pages/buyer2_working_situation.rb | 21 +-- .../pages/number_of_others_in_property.rb | 21 +-- .../sales/pages/buyer1_ethnic_group_spec.rb | 71 +++++++++- .../pages/buyer1_live_in_property_spec.rb | 106 +++++++++++---- .../sales/pages/buyer1_nationality_spec.rb | 75 +++++++++-- .../pages/buyer1_working_situation_spec.rb | 71 +++++++++- .../sales/pages/buyer2_ethnic_group_spec.rb | 88 +++++++++++-- .../pages/buyer2_live_in_property_spec.rb | 108 ++++++++++++---- .../sales/pages/buyer2_nationality_spec.rb | 96 ++++++++++---- .../pages/buyer2_working_situation_spec.rb | 88 +++++++++++-- .../number_of_others_in_property_spec.rb | 121 ++++++++++++++---- 18 files changed, 802 insertions(+), 228 deletions(-) diff --git a/app/models/form/sales/pages/buyer1_ethnic_group.rb b/app/models/form/sales/pages/buyer1_ethnic_group.rb index afd5a69f3..a545c95a8 100644 --- a/app/models/form/sales/pages/buyer1_ethnic_group.rb +++ b/app/models/form/sales/pages/buyer1_ethnic_group.rb @@ -2,14 +2,6 @@ class Form::Sales::Pages::Buyer1EthnicGroup < ::Form::Page def initialize(id, hsh, subsection) super @id = "buyer_1_ethnic_group" - @depends_on = [ - { - "buyer_has_seen_privacy_notice?" => true, - }, - { - "buyer_not_interviewed?" => true, - }, - ] end def questions @@ -17,4 +9,14 @@ class Form::Sales::Pages::Buyer1EthnicGroup < ::Form::Page Form::Sales::Questions::Buyer1EthnicGroup.new(nil, nil, self), ] end + + def routed_to?(log, _current_user) + super && page_routed_to?(log) + end + + def page_routed_to?(log) + return false if log.form.start_year_2025_or_later? && log.is_staircase? + + log.buyer_has_seen_privacy_notice? || log.buyer_not_interviewed? + end end diff --git a/app/models/form/sales/pages/buyer1_live_in_property.rb b/app/models/form/sales/pages/buyer1_live_in_property.rb index 8ee63d26c..eede7b282 100644 --- a/app/models/form/sales/pages/buyer1_live_in_property.rb +++ b/app/models/form/sales/pages/buyer1_live_in_property.rb @@ -2,26 +2,6 @@ class Form::Sales::Pages::Buyer1LiveInProperty < ::Form::Page def initialize(id, hsh, subsection) super @id = "buyer_1_live_in_property" - @depends_on = [ - { - "buyer_has_seen_privacy_notice?" => true, - "outright_sale?" => false, - }, - { - "buyer_not_interviewed?" => true, - "outright_sale?" => false, - }, - { - "buyer_has_seen_privacy_notice?" => true, - "joint_purchase?" => true, - "buyers_will_live_in?" => true, - }, - { - "buyer_not_interviewed?" => true, - "joint_purchase?" => true, - "buyers_will_live_in?" => true, - }, - ] end def questions @@ -29,4 +9,21 @@ class Form::Sales::Pages::Buyer1LiveInProperty < ::Form::Page Form::Sales::Questions::Buyer1LiveInProperty.new(nil, nil, self), ] end + + def routed_to?(log, _current_user) + super && page_routed_to?(log) + end + + def page_routed_to?(log) + return false if log.form.start_year_2025_or_later? && log.is_staircase? + + privacy_notice_seen_or_not_interviewed = log.buyer_has_seen_privacy_notice? || log.buyer_not_interviewed? + not_outright_sale = !log.outright_sale? + joint_purchase_and_live_in = log.joint_purchase? && log.buyers_will_live_in? + + return true if privacy_notice_seen_or_not_interviewed && not_outright_sale + return true if privacy_notice_seen_or_not_interviewed && joint_purchase_and_live_in + + false + end end diff --git a/app/models/form/sales/pages/buyer1_nationality.rb b/app/models/form/sales/pages/buyer1_nationality.rb index 791ecafac..7c87421ca 100644 --- a/app/models/form/sales/pages/buyer1_nationality.rb +++ b/app/models/form/sales/pages/buyer1_nationality.rb @@ -2,14 +2,6 @@ class Form::Sales::Pages::Buyer1Nationality < ::Form::Page def initialize(id, hsh, subsection) super @id = "buyer_1_nationality" - @depends_on = [ - { - "buyer_has_seen_privacy_notice?" => true, - }, - { - "buyer_not_interviewed?" => true, - }, - ] end def questions @@ -22,4 +14,14 @@ class Form::Sales::Pages::Buyer1Nationality < ::Form::Page [Form::Sales::Questions::Buyer1Nationality.new(nil, nil, self)] end end + + def routed_to?(log, _current_user) + super && page_routed_to?(log) + end + + def page_routed_to?(log) + return false if log.form.start_year_2025_or_later? && log.is_staircase? + + log.buyer_has_seen_privacy_notice? || log.buyer_not_interviewed? + end end diff --git a/app/models/form/sales/pages/buyer1_working_situation.rb b/app/models/form/sales/pages/buyer1_working_situation.rb index d9f33f8e9..911bc2a70 100644 --- a/app/models/form/sales/pages/buyer1_working_situation.rb +++ b/app/models/form/sales/pages/buyer1_working_situation.rb @@ -17,4 +17,14 @@ class Form::Sales::Pages::Buyer1WorkingSituation < ::Form::Page Form::Sales::Questions::Buyer1WorkingSituation.new(nil, nil, self), ] end + + def routed_to?(log, _current_user) + super && page_routed_to?(log) + end + + def page_routed_to?(log) + return false if log.form.start_year_2025_or_later? && log.is_staircase? + + log.buyer_has_seen_privacy_notice? || log.buyer_not_interviewed? + end end diff --git a/app/models/form/sales/pages/buyer2_ethnic_group.rb b/app/models/form/sales/pages/buyer2_ethnic_group.rb index 196063985..8c1dc59e3 100644 --- a/app/models/form/sales/pages/buyer2_ethnic_group.rb +++ b/app/models/form/sales/pages/buyer2_ethnic_group.rb @@ -2,16 +2,6 @@ class Form::Sales::Pages::Buyer2EthnicGroup < ::Form::Page def initialize(id, hsh, subsection) super @id = "buyer_2_ethnic_group" - @depends_on = [ - { - "joint_purchase?" => true, - "buyer_has_seen_privacy_notice?" => true, - }, - { - "joint_purchase?" => true, - "buyer_not_interviewed?" => true, - }, - ] end def questions @@ -19,4 +9,15 @@ class Form::Sales::Pages::Buyer2EthnicGroup < ::Form::Page Form::Sales::Questions::Buyer2EthnicGroup.new(nil, nil, self), ] end + + def routed_to?(log, _current_user) + super && page_routed_to?(log) + end + + def page_routed_to?(log) + return false unless log.joint_purchase? + return false if log.form.start_year_2025_or_later? && log.is_staircase? + + log.buyer_has_seen_privacy_notice? || log.buyer_not_interviewed? + end end 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 a16638c0d..b38f0ec3b 100644 --- a/app/models/form/sales/pages/buyer2_live_in_property.rb +++ b/app/models/form/sales/pages/buyer2_live_in_property.rb @@ -2,28 +2,6 @@ class Form::Sales::Pages::Buyer2LiveInProperty < ::Form::Page def initialize(id, hsh, subsection) super @id = "buyer_2_live_in_property" - @depends_on = [ - { - "buyer_has_seen_privacy_notice?" => true, - "outright_sale?" => false, - "joint_purchase?" => true, - }, - { - "buyer_not_interviewed?" => true, - "outright_sale?" => false, - "joint_purchase?" => true, - }, - { - "buyer_has_seen_privacy_notice?" => true, - "joint_purchase?" => true, - "buyers_will_live_in?" => true, - }, - { - "buyer_not_interviewed?" => true, - "joint_purchase?" => true, - "buyers_will_live_in?" => true, - }, - ] end def questions @@ -31,4 +9,21 @@ class Form::Sales::Pages::Buyer2LiveInProperty < ::Form::Page Form::Sales::Questions::Buyer2LiveInProperty.new(nil, nil, self), ] end + + def routed_to?(log, _current_user) + super && page_routed_to?(log) + end + + def page_routed_to?(log) + return false if log.form.start_year_2025_or_later? && log.is_staircase? + return false unless log.joint_purchase? + + privacy_notice_seen_or_not_interviewed = log.buyer_has_seen_privacy_notice? || log.buyer_not_interviewed? + not_outright_sale = !log.outright_sale? + + return true if privacy_notice_seen_or_not_interviewed && not_outright_sale + return true if privacy_notice_seen_or_not_interviewed && log.buyers_will_live_in? + + false + end end diff --git a/app/models/form/sales/pages/buyer2_nationality.rb b/app/models/form/sales/pages/buyer2_nationality.rb index 30790fd63..8cbf32980 100644 --- a/app/models/form/sales/pages/buyer2_nationality.rb +++ b/app/models/form/sales/pages/buyer2_nationality.rb @@ -2,16 +2,6 @@ class Form::Sales::Pages::Buyer2Nationality < ::Form::Page def initialize(id, hsh, subsection) super @id = "buyer_2_nationality" - @depends_on = [ - { - "joint_purchase?" => true, - "buyer_has_seen_privacy_notice?" => true, - }, - { - "joint_purchase?" => true, - "buyer_not_interviewed?" => true, - }, - ] end def questions @@ -24,4 +14,15 @@ class Form::Sales::Pages::Buyer2Nationality < ::Form::Page [Form::Sales::Questions::Buyer2Nationality.new(nil, nil, self)] end end + + def routed_to?(log, _current_user) + super && page_routed_to?(log) + end + + def page_routed_to?(log) + return false unless log.joint_purchase? + return false if log.form.start_year_2025_or_later? && log.is_staircase? + + log.buyer_has_seen_privacy_notice? || log.buyer_not_interviewed? + end end diff --git a/app/models/form/sales/pages/buyer2_working_situation.rb b/app/models/form/sales/pages/buyer2_working_situation.rb index 4e73c09cf..264d720f2 100644 --- a/app/models/form/sales/pages/buyer2_working_situation.rb +++ b/app/models/form/sales/pages/buyer2_working_situation.rb @@ -3,16 +3,6 @@ class Form::Sales::Pages::Buyer2WorkingSituation < ::Form::Page super @id = "buyer_2_working_situation" @copy_key = "sales.household_characteristics.ecstat2.buyer" - @depends_on = [ - { - "joint_purchase?" => true, - "buyer_has_seen_privacy_notice?" => true, - }, - { - "joint_purchase?" => true, - "buyer_not_interviewed?" => true, - }, - ] end def questions @@ -20,4 +10,15 @@ class Form::Sales::Pages::Buyer2WorkingSituation < ::Form::Page Form::Sales::Questions::Buyer2WorkingSituation.new(nil, nil, self), ] end + + def routed_to?(log, _current_user) + super && page_routed_to?(log) + end + + def page_routed_to?(log) + return false unless log.joint_purchase? + return false if log.form.start_year_2025_or_later? && log.is_staircase? + + log.buyer_has_seen_privacy_notice? || log.buyer_not_interviewed? + end end diff --git a/app/models/form/sales/pages/number_of_others_in_property.rb b/app/models/form/sales/pages/number_of_others_in_property.rb index 23d670f93..1bf454b9c 100644 --- a/app/models/form/sales/pages/number_of_others_in_property.rb +++ b/app/models/form/sales/pages/number_of_others_in_property.rb @@ -1,16 +1,6 @@ class Form::Sales::Pages::NumberOfOthersInProperty < ::Form::Page def initialize(id, hsh, subsection, joint_purchase:) super(id, hsh, subsection) - @depends_on = [ - { - "buyer_has_seen_privacy_notice?" => true, - "joint_purchase?" => joint_purchase, - }, - { - "buyer_not_interviewed?" => true, - "joint_purchase?" => joint_purchase, - }, - ] @joint_purchase = joint_purchase end @@ -19,4 +9,15 @@ class Form::Sales::Pages::NumberOfOthersInProperty < ::Form::Page Form::Sales::Questions::NumberOfOthersInProperty.new(nil, nil, self, joint_purchase: @joint_purchase), ] end + + def routed_to?(log, _current_user) + super && page_routed_to?(log) + end + + def page_routed_to?(log) + return false unless log.joint_purchase? == @joint_purchase + return false if log.form.start_year_2025_or_later? && log.is_staircase? + + log.buyer_has_seen_privacy_notice? || log.buyer_not_interviewed? + end end diff --git a/spec/models/form/sales/pages/buyer1_ethnic_group_spec.rb b/spec/models/form/sales/pages/buyer1_ethnic_group_spec.rb index 9a94fc0fd..c1cbb1dff 100644 --- a/spec/models/form/sales/pages/buyer1_ethnic_group_spec.rb +++ b/spec/models/form/sales/pages/buyer1_ethnic_group_spec.rb @@ -5,7 +5,8 @@ RSpec.describe Form::Sales::Pages::Buyer1EthnicGroup, type: :model do 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), start_year_2024_or_later?: false)) } + let(:form) { Form.new(nil, 2023, [], "sales") } + let(:subsection) { instance_double(Form::Subsection, form:, depends_on: nil) } it "has correct subsection" do expect(page.subsection).to eq(subsection) @@ -23,7 +24,71 @@ RSpec.describe Form::Sales::Pages::Buyer1EthnicGroup, type: :model do expect(page.description).to be_nil end - it "has correct depends_on" do - expect(page.depends_on).to eq([{ "buyer_has_seen_privacy_notice?" => true }, { "buyer_not_interviewed?" => true }]) + context "with year 2024" do + let(:form) { Form.new(nil, 2024, [], "sales") } + + context "when routing" do + before do + allow(log).to receive(:form).and_return(form) + end + + context "when buyer has seen privacy notice and buyer interviewed" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 0, staircase: 2) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "when buyer has seen privacy notice and buyer not interviewed" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 1, staircase: 2) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "and buyer has not seen privacy notice and buyer interviewed" do + let(:log) { build(:sales_log, privacynotice: nil, jointpur: 1, noint: 0, staircase: 2) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + + context "and buyer has not seen privacy notice and buyer not interviewed" do + let(:log) { build(:sales_log, privacynotice: nil, jointpur: 1, noint: 1, staircase: 2) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + end + end + + context "with year 2025" do + let(:form) { Form.new(nil, 2025, [], "sales") } + + before do + allow(log).to receive(:form).and_return(form) + end + + context "when routing" do + context "and staircase is not 1" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 0, staircase: 2) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "and staircase is 1" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 0, staircase: 1) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + end end end diff --git a/spec/models/form/sales/pages/buyer1_live_in_property_spec.rb b/spec/models/form/sales/pages/buyer1_live_in_property_spec.rb index edc53bd79..76cb612eb 100644 --- a/spec/models/form/sales/pages/buyer1_live_in_property_spec.rb +++ b/spec/models/form/sales/pages/buyer1_live_in_property_spec.rb @@ -5,7 +5,8 @@ RSpec.describe Form::Sales::Pages::Buyer1LiveInProperty, type: :model do 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), start_year_2024_or_later?: false)) } + let(:form) { Form.new(nil, 2023, [], "sales") } + let(:subsection) { instance_double(Form::Subsection, form:, enabled?: true, depends_on: nil) } it "has correct subsection" do expect(page.subsection).to eq(subsection) @@ -23,26 +24,87 @@ RSpec.describe Form::Sales::Pages::Buyer1LiveInProperty, type: :model do expect(page.description).to be_nil end - it "has correct depends_on" do - expect(page.depends_on).to eq([ - { - "buyer_has_seen_privacy_notice?" => true, - "outright_sale?" => false, - }, - { - "buyer_not_interviewed?" => true, - "outright_sale?" => false, - }, - { - "buyer_has_seen_privacy_notice?" => true, - "joint_purchase?" => true, - "buyers_will_live_in?" => true, - }, - { - "buyer_not_interviewed?" => true, - "joint_purchase?" => true, - "buyers_will_live_in?" => true, - }, - ]) + context "with year 2024" do + let(:form) { Form.new(nil, 2024, [], "sales") } + + context "when routing" do + before do + allow(log).to receive(:form).and_return(form) + end + + context "when privacy notice seen and not outright sale" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 2, noint: nil, staircase: 2, ownershipsch: 1, buylivein: nil) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "when buyer not interviewed and not outright sale" do + let(:log) { build(:sales_log, privacynotice: nil, jointpur: 2, noint: 1, staircase: 2, ownershipsch: 1, buylivein: nil) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "when privacy notice seen, joint purchase and live in" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 0, staircase: 2, ownershipsch: 1, buylivein: 1) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "when buyer not interviewed, joint purchase and live in" do + let(:log) { build(:sales_log, privacynotice: nil, jointpur: 1, noint: 1, staircase: 2, ownershipsch: 1, buylivein: 1) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "when buyer has seen privacy notice and buyer interviewed and it's outright sale" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 2, noint: 0, staircase: 2, ownershipsch: 3, buylivein: nil) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + + context "and buyer has not seen privacy notice and buyer interviewed" do + let(:log) { build(:sales_log, privacynotice: nil, jointpur: 2, noint: 0, staircase: 2, ownershipsch: 1, buylivein: nil) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + end + end + + context "with year 2025" do + let(:form) { Form.new(nil, 2025, [], "sales") } + + before do + allow(log).to receive(:form).and_return(form) + end + + context "when routing" do + context "and staircase is not 1" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 2, noint: 1, staircase: 2, ownershipsch: 1, buylivein: nil) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "and staircase is 1" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 2, noint: 1, ownershipsch: 1, buylivein: nil, staircase: 1) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + end end end diff --git a/spec/models/form/sales/pages/buyer1_nationality_spec.rb b/spec/models/form/sales/pages/buyer1_nationality_spec.rb index a84a44009..ad09ee526 100644 --- a/spec/models/form/sales/pages/buyer1_nationality_spec.rb +++ b/spec/models/form/sales/pages/buyer1_nationality_spec.rb @@ -3,12 +3,11 @@ require "rails_helper" RSpec.describe Form::Sales::Pages::Buyer1Nationality, type: :model do subject(:page) { described_class.new(nil, nil, subsection) } - let(:subsection) { instance_double(Form::Subsection) } - let(:form) { instance_double(Form, start_date: Time.zone.local(2023, 4, 1)) } + let(:subsection) { instance_double(Form::Subsection, depends_on: nil) } + let(:form) { Form.new(nil, 2023, [], "sales") } before do allow(subsection).to receive(:form).and_return(form) - allow(form).to receive(:start_year_2024_or_later?).and_return(false) end it "has correct subsection" do @@ -27,17 +26,75 @@ RSpec.describe Form::Sales::Pages::Buyer1Nationality, type: :model do expect(page.description).to be_nil end - it "has correct depends_on" do - expect(page.depends_on).to eq [{ "buyer_has_seen_privacy_notice?" => true }, { "buyer_not_interviewed?" => true }] + context "with year 2024" do + let(:form) { Form.new(nil, 2024, [], "sales") } + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq %w[nationality_all_group nationality_all] + end + + context "when routing" do + before do + allow(log).to receive(:form).and_return(form) + end + + context "when buyer has seen privacy notice and buyer interviewed" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 0, staircase: 2) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "when buyer has seen privacy notice and buyer not interviewed" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 1, staircase: 2) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "and buyer has not seen privacy notice and buyer interviewed" do + let(:log) { build(:sales_log, privacynotice: nil, jointpur: 1, noint: 0, staircase: 2) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + + context "and buyer has not seen privacy notice and buyer not interviewed" do + let(:log) { build(:sales_log, privacynotice: nil, jointpur: 1, noint: 1, staircase: 2) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + end end - context "with year 2024" do + context "with year 2025" do + let(:form) { Form.new(nil, 2025, [], "sales") } + before do - allow(form).to receive(:start_year_2024_or_later?).and_return(true) + allow(log).to receive(:form).and_return(form) end - it "has correct questions" do - expect(page.questions.map(&:id)).to eq %w[nationality_all_group nationality_all] + context "when routing" do + context "and staircase is not 1" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 0, staircase: 2) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "and staircase is 1" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 0, staircase: 1) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end end end end diff --git a/spec/models/form/sales/pages/buyer1_working_situation_spec.rb b/spec/models/form/sales/pages/buyer1_working_situation_spec.rb index 182da0a82..47a997623 100644 --- a/spec/models/form/sales/pages/buyer1_working_situation_spec.rb +++ b/spec/models/form/sales/pages/buyer1_working_situation_spec.rb @@ -5,7 +5,8 @@ RSpec.describe Form::Sales::Pages::Buyer1WorkingSituation, type: :model do 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), start_year_2024_or_later?: true, start_year_2025_or_later?: false)) } + let(:form) { Form.new(nil, 2023, [], "sales") } + let(:subsection) { instance_double(Form::Subsection, form:, enabled?: true) } it "has correct subsection" do expect(page.subsection).to eq(subsection) @@ -18,4 +19,72 @@ RSpec.describe Form::Sales::Pages::Buyer1WorkingSituation, type: :model do it "has the correct id" do expect(page.id).to eq("buyer_1_working_situation") end + + context "with year 2024" do + let(:form) { Form.new(nil, 2024, [], "sales") } + + context "when routing" do + before do + allow(log).to receive(:form).and_return(form) + end + + context "when buyer has seen privacy notice and buyer interviewed" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 0, staircase: 2) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "when buyer has seen privacy notice and buyer not interviewed" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 1, staircase: 2) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "and buyer has not seen privacy notice and buyer interviewed" do + let(:log) { build(:sales_log, privacynotice: nil, jointpur: 1, noint: 0, staircase: 2) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + + context "and buyer has not seen privacy notice and buyer not interviewed" do + let(:log) { build(:sales_log, privacynotice: nil, jointpur: 1, noint: 1, staircase: 2) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + end + end + + context "with year 2025" do + let(:form) { Form.new(nil, 2025, [], "sales") } + + before do + allow(log).to receive(:form).and_return(form) + end + + context "when routing" do + context "and staircase is not 1" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 0, staircase: 2) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "and staircase is 1" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 0, staircase: 1) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + end + end end diff --git a/spec/models/form/sales/pages/buyer2_ethnic_group_spec.rb b/spec/models/form/sales/pages/buyer2_ethnic_group_spec.rb index d129508ee..d12138682 100644 --- a/spec/models/form/sales/pages/buyer2_ethnic_group_spec.rb +++ b/spec/models/form/sales/pages/buyer2_ethnic_group_spec.rb @@ -5,7 +5,8 @@ RSpec.describe Form::Sales::Pages::Buyer2EthnicGroup, type: :model do 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))) } + let(:form) { Form.new(nil, 2023, [], "sales") } + let(:subsection) { instance_double(Form::Subsection, form:, depends_on: nil) } it "has correct subsection" do expect(page.subsection).to eq(subsection) @@ -23,16 +24,79 @@ RSpec.describe Form::Sales::Pages::Buyer2EthnicGroup, type: :model do expect(page.description).to be_nil end - it "has correct depends_on" do - expect(page.depends_on).to eq([ - { - "joint_purchase?" => true, - "buyer_has_seen_privacy_notice?" => true, - }, - { - "joint_purchase?" => true, - "buyer_not_interviewed?" => true, - }, - ]) + context "with year 2024" do + let(:form) { Form.new(nil, 2024, [], "sales") } + + context "when routing" do + before do + allow(log).to receive(:form).and_return(form) + end + + context "when buyer has seen privacy notice and buyer interviewed" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 0, staircase: 2) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "when buyer has seen privacy notice and buyer not interviewed" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 1, staircase: 2) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "and buyer has not seen privacy notice and buyer interviewed" do + let(:log) { build(:sales_log, privacynotice: nil, jointpur: 1, noint: 0, staircase: 2) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + + context "and buyer has not seen privacy notice and buyer not interviewed" do + let(:log) { build(:sales_log, privacynotice: nil, jointpur: 1, noint: 1, staircase: 2) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "when it's not a joint purchase" do + let(:log) { build(:sales_log, privacynotice: nil, jointpur: 2, noint: 1, staircase: 2) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + end + end + + context "with year 2025" do + let(:form) { Form.new(nil, 2025, [], "sales") } + + before do + allow(log).to receive(:form).and_return(form) + end + + context "when routing" do + context "and staircase is not 1" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 0, staircase: 2) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "and staircase is 1" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 0, staircase: 1) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + end end end 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 b2eb2386b..73a56be00 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 @@ -5,7 +5,8 @@ RSpec.describe Form::Sales::Pages::Buyer2LiveInProperty, type: :model do 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))) } + let(:form) { Form.new(nil, 2023, [], "sales") } + let(:subsection) { instance_double(Form::Subsection, form:, depends_on: nil, enabled?: true) } it "has correct subsection" do expect(page.subsection).to eq(subsection) @@ -23,28 +24,87 @@ RSpec.describe Form::Sales::Pages::Buyer2LiveInProperty, type: :model do expect(page.description).to be_nil end - it "has correct depends_on" do - expect(page.depends_on).to eq([ - { - "buyer_has_seen_privacy_notice?" => true, - "outright_sale?" => false, - "joint_purchase?" => true, - }, - { - "buyer_not_interviewed?" => true, - "outright_sale?" => false, - "joint_purchase?" => true, - }, - { - "buyer_has_seen_privacy_notice?" => true, - "joint_purchase?" => true, - "buyers_will_live_in?" => true, - }, - { - "buyer_not_interviewed?" => true, - "joint_purchase?" => true, - "buyers_will_live_in?" => true, - }, - ]) + context "with year 2024" do + let(:form) { Form.new(nil, 2024, [], "sales") } + + context "when routing" do + before do + allow(log).to receive(:form).and_return(form) + end + + context "when privacy notice seen and not outright sale" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: nil, staircase: 2, ownershipsch: 1, buylivein: nil) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "when buyer not interviewed and not outright sale" do + let(:log) { build(:sales_log, privacynotice: nil, jointpur: 1, noint: 1, staircase: 2, ownershipsch: 1, buylivein: nil) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "when privacy notice seen, joint purchase and live in" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 0, staircase: 2, ownershipsch: 1, buylivein: 1) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "when buyer not interviewed, joint purchase and live in" do + let(:log) { build(:sales_log, privacynotice: nil, jointpur: 1, noint: 1, staircase: 2, ownershipsch: 1, buylivein: 1) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "when buyer has seen privacy notice and buyer interviewed and it's outright sale" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 0, staircase: 2, ownershipsch: 3, buylivein: nil) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + + context "and buyer has not seen privacy notice and buyer interviewed" do + let(:log) { build(:sales_log, privacynotice: nil, jointpur: 1, noint: 0, staircase: 2, ownershipsch: 1, buylivein: nil) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + end + end + + context "with year 2025" do + let(:form) { Form.new(nil, 2025, [], "sales") } + + before do + allow(log).to receive(:form).and_return(form) + end + + context "when routing" do + context "and staircase is not 1" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 1, staircase: 2, ownershipsch: 1, buylivein: nil) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "and staircase is 1" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 1, ownershipsch: 1, buylivein: nil, staircase: 1) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + end end end diff --git a/spec/models/form/sales/pages/buyer2_nationality_spec.rb b/spec/models/form/sales/pages/buyer2_nationality_spec.rb index e01215d21..fa9270ec7 100644 --- a/spec/models/form/sales/pages/buyer2_nationality_spec.rb +++ b/spec/models/form/sales/pages/buyer2_nationality_spec.rb @@ -3,13 +3,8 @@ require "rails_helper" RSpec.describe Form::Sales::Pages::Buyer2Nationality, type: :model do subject(:page) { described_class.new(nil, nil, subsection) } - let(:subsection) { instance_double(Form::Subsection) } - let(:form) { instance_double(Form, start_date: Time.zone.local(2023, 4, 1)) } - - before do - allow(subsection).to receive(:form).and_return(form) - allow(form).to receive(:start_year_2024_or_later?).and_return(false) - end + let(:form) { Form.new(nil, 2023, [], "sales") } + let(:subsection) { instance_double(Form::Subsection, form:, enabled?: true, depends_on: nil) } it "has correct subsection" do expect(page.subsection).to be subsection @@ -27,26 +22,83 @@ RSpec.describe Form::Sales::Pages::Buyer2Nationality, type: :model do expect(page.description).to be_nil end - it "has correct depends_on" do - expect(page.depends_on).to eq [ - { - "joint_purchase?" => true, - "buyer_has_seen_privacy_notice?" => true, - }, - { - "joint_purchase?" => true, - "buyer_not_interviewed?" => true, - }, - ] + context "with year 2024" do + let(:form) { Form.new(nil, 2024, [], "sales") } + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq %w[nationality_all_buyer2_group nationality_all_buyer2] + end + + context "when routing" do + before do + allow(log).to receive(:form).and_return(form) + end + + context "when buyer has seen privacy notice and buyer interviewed" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 0, staircase: 2) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "when buyer has seen privacy notice and buyer not interviewed" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 1, staircase: 2) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "and buyer has not seen privacy notice and buyer interviewed" do + let(:log) { build(:sales_log, privacynotice: nil, jointpur: 1, noint: 0, staircase: 2) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + + context "and buyer has not seen privacy notice and buyer not interviewed" do + let(:log) { build(:sales_log, privacynotice: nil, jointpur: 1, noint: 1, staircase: 2) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "when it's not a joint purchase" do + let(:log) { build(:sales_log, privacynotice: nil, jointpur: 2, noint: 1, staircase: 2) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + end end - context "with year 2024" do + context "with year 2025" do + let(:form) { Form.new(nil, 2025, [], "sales") } + before do - allow(form).to receive(:start_year_2024_or_later?).and_return(true) + allow(log).to receive(:form).and_return(form) end - it "has correct questions" do - expect(page.questions.map(&:id)).to eq %w[nationality_all_buyer2_group nationality_all_buyer2] + context "when routing" do + context "and staircase is not 1" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 0, staircase: 2) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "and staircase is 1" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 0, staircase: 1) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end end end end diff --git a/spec/models/form/sales/pages/buyer2_working_situation_spec.rb b/spec/models/form/sales/pages/buyer2_working_situation_spec.rb index 6c9915903..f0022006e 100644 --- a/spec/models/form/sales/pages/buyer2_working_situation_spec.rb +++ b/spec/models/form/sales/pages/buyer2_working_situation_spec.rb @@ -5,7 +5,8 @@ RSpec.describe Form::Sales::Pages::Buyer2WorkingSituation, type: :model do 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), start_year_2025_or_later?: false)) } + let(:form) { Form.new(nil, 2023, [], "sales") } + let(:subsection) { instance_double(Form::Subsection, form:, depends_on: nil) } it "has correct subsection" do expect(page.subsection).to eq(subsection) @@ -23,16 +24,79 @@ RSpec.describe Form::Sales::Pages::Buyer2WorkingSituation, type: :model do expect(page.description).to be_nil end - it "has correct depends_on" do - expect(page.depends_on).to eq([ - { - "joint_purchase?" => true, - "buyer_has_seen_privacy_notice?" => true, - }, - { - "joint_purchase?" => true, - "buyer_not_interviewed?" => true, - }, - ]) + context "with year 2024" do + let(:form) { Form.new(nil, 2024, [], "sales") } + + context "when routing" do + before do + allow(log).to receive(:form).and_return(form) + end + + context "when buyer has seen privacy notice and buyer interviewed" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 0, staircase: 2) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "when buyer has seen privacy notice and buyer not interviewed" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 1, staircase: 2) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "and buyer has not seen privacy notice and buyer interviewed" do + let(:log) { build(:sales_log, privacynotice: nil, jointpur: 1, noint: 0, staircase: 2) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + + context "and buyer has not seen privacy notice and buyer not interviewed" do + let(:log) { build(:sales_log, privacynotice: nil, jointpur: 1, noint: 1, staircase: 2) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "when it's not a joint purchase" do + let(:log) { build(:sales_log, privacynotice: nil, jointpur: 2, noint: 1, staircase: 2) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + end + end + + context "with year 2025" do + let(:form) { Form.new(nil, 2025, [], "sales") } + + before do + allow(log).to receive(:form).and_return(form) + end + + context "when routing" do + context "and staircase is not 1" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 0, staircase: 2) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "and staircase is 1" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 0, staircase: 1) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + end end end diff --git a/spec/models/form/sales/pages/number_of_others_in_property_spec.rb b/spec/models/form/sales/pages/number_of_others_in_property_spec.rb index 859aff8e0..b4e5f8ea9 100644 --- a/spec/models/form/sales/pages/number_of_others_in_property_spec.rb +++ b/spec/models/form/sales/pages/number_of_others_in_property_spec.rb @@ -6,7 +6,8 @@ RSpec.describe Form::Sales::Pages::NumberOfOthersInProperty, type: :model do let(:page_id) { "number_of_others_in_property" } let(:page_definition) { nil } let(:joint_purchase) { false } - let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1))) } + let(:form) { Form.new(nil, 2024, [], "sales") } + let(:subsection) { instance_double(Form::Subsection, form:, enabled?: true, depends_on: nil) } it "has correct subsection" do expect(page.subsection).to eq(subsection) @@ -24,19 +25,6 @@ RSpec.describe Form::Sales::Pages::NumberOfOthersInProperty, type: :model do expect(page.description).to be_nil end - it "has the correct depends_on" do - expect(page.depends_on).to eq([ - { - "buyer_has_seen_privacy_notice?" => true, - "joint_purchase?" => joint_purchase, - }, - { - "buyer_not_interviewed?" => true, - "joint_purchase?" => joint_purchase, - }, - ]) - end - context "with joint purchase" do let(:page_id) { "number_of_others_in_property_joint_purchase" } let(:joint_purchase) { true } @@ -45,17 +33,100 @@ RSpec.describe Form::Sales::Pages::NumberOfOthersInProperty, type: :model do expect(page.id).to eq("number_of_others_in_property_joint_purchase") end - it "has the correct depends_on" do - expect(page.depends_on).to eq([ - { - "buyer_has_seen_privacy_notice?" => true, - "joint_purchase?" => joint_purchase, - }, - { - "buyer_not_interviewed?" => true, - "joint_purchase?" => joint_purchase, - }, - ]) + context "when routing" do + before do + allow(log).to receive(:form).and_return(form) + end + + context "with 2024 logs" do + context "with joint purchase" do + context "when buyer has seen privacy notice and buyer interviewed" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 0) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "when buyer has seen privacy notice and buyer not interviewed" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 1) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "and buyer has not seen privacy notice and buyer interviewed" do + let(:log) { build(:sales_log, privacynotice: nil, jointpur: 1, noint: 0) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + + context "and buyer has not seen privacy notice and buyer not interviewed" do + let(:log) { build(:sales_log, privacynotice: nil, jointpur: 1, noint: 1) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + end + + context "with non joint purchase" do + context "when buyer has seen privacy notice and buyer interviewed" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 2, noint: 0) } + + it "routes to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + + context "when buyer has seen privacy notice and buyer not interviewed" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 2, noint: 1) } + + it "routes to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + + context "and buyer has not seen privacy notice and buyer interviewed" do + let(:log) { build(:sales_log, privacynotice: nil, jointpur: 2, noint: 0) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + + context "and buyer has not seen privacy notice and buyer not interviewed" do + let(:log) { build(:sales_log, privacynotice: nil, jointpur: 2, noint: 1) } + + it "routes to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + end + end + + context "with 2025 logs" do + let(:form) { Form.new(nil, 2025, [], "sales") } + + context "and staircase is not 1" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 0, staircase: 2) } + + it "routes to the page" do + expect(page.routed_to?(log, nil)).to eq(true) + end + end + + context "and staircase is 1" do + let(:log) { build(:sales_log, privacynotice: 1, jointpur: 1, noint: 0, staircase: 1) } + + it "does not route to the page" do + expect(page).not_to be_routed_to(log, nil) + end + end + end end end end