From bf83b79ac1aac1ba5a1fe81fc82985c21aaf8bde Mon Sep 17 00:00:00 2001 From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com> Date: Thu, 14 Nov 2024 12:54:57 +0000 Subject: [PATCH] Remove depends_on companybuy which has been removed --- .../subsections/household_characteristics.rb | 11 +++- .../household_characteristics_spec.rb | 60 ++++++++++--------- 2 files changed, 42 insertions(+), 29 deletions(-) diff --git a/app/models/form/sales/subsections/household_characteristics.rb b/app/models/form/sales/subsections/household_characteristics.rb index 07f998edb..e839b1979 100644 --- a/app/models/form/sales/subsections/household_characteristics.rb +++ b/app/models/form/sales/subsections/household_characteristics.rb @@ -3,7 +3,14 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection super @id = "household_characteristics" @label = "Household characteristics" - @depends_on = [{ "setup_completed?" => true, "company_buyer?" => false }] + end + + def depends_on + if form.start_year_2025_or_later? + [{ "setup_completed?" => true }] + else + [{ "setup_completed?" => true, "company_buyer?" => false }] + end end def pages @@ -143,6 +150,8 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection end def displayed_in_tasklist?(log) + return true if form.start_year_2025_or_later? + !log.company_buyer? 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 8f9e8ea01..3cd856eb3 100644 --- a/spec/models/form/sales/subsections/household_characteristics_spec.rb +++ b/spec/models/form/sales/subsections/household_characteristics_spec.rb @@ -16,6 +16,14 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model expect(household_characteristics.section).to eq(section) end + it "has the correct id" do + expect(household_characteristics.id).to eq("household_characteristics") + end + + it "has the correct label" do + expect(household_characteristics.label).to eq("Household characteristics") + end + context "with 2022/23 form" do before do allow(form).to receive(:start_date).and_return(Time.zone.local(2022, 4, 1)) @@ -234,6 +242,26 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model allow(form).to receive(:start_year_2025_or_later?).and_return(false) end + it "has correct depends on" do + expect(household_characteristics.depends_on).to eq([{ "setup_completed?" => true, "company_buyer?" => false }]) + end + + context "when the sale is to a company buyer" do + let(:log) { FactoryBot.build(:sales_log, ownershipsch: 3, companybuy: 1) } + + it "is not displayed in tasklist" do + expect(household_characteristics.displayed_in_tasklist?(log)).to eq(false) + end + end + + context "when the sale is not to a company buyer" do + let(:log) { FactoryBot.build(:sales_log, ownershipsch: 3, companybuy: 2) } + + it "is displayed in tasklist" do + expect(household_characteristics.displayed_in_tasklist?(log)).to eq(true) + end + end + it "has correct pages" do expect(household_characteristics.pages.map(&:id)).to eq( %w[ @@ -368,6 +396,10 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model allow(form).to receive(:start_year_2025_or_later?).and_return(true) end + it "has correct depends on" do + expect(household_characteristics.depends_on).to eq([{ "setup_completed?" => true }]) + end + it "has correct pages" do expect(household_characteristics.pages.map(&:id)).to eq( %w[ @@ -494,32 +526,4 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model ) end end - - it "has the correct id" do - expect(household_characteristics.id).to eq("household_characteristics") - end - - it "has the correct label" do - expect(household_characteristics.label).to eq("Household characteristics") - end - - it "has correct depends on" do - expect(household_characteristics.depends_on).to eq([{ "setup_completed?" => true, "company_buyer?" => false }]) - end - - context "when the sale is to a company buyer" do - let(:log) { FactoryBot.build(:sales_log, ownershipsch: 3, companybuy: 1) } - - it "is not displayed in tasklist" do - expect(household_characteristics.displayed_in_tasklist?(log)).to eq(false) - end - end - - context "when the sale is not to a company buyer" do - let(:log) { FactoryBot.build(:sales_log, ownershipsch: 3, companybuy: 2) } - - it "is displayed in tasklist" do - expect(household_characteristics.displayed_in_tasklist?(log)).to eq(true) - end - end end