From 83492b10ca694cdeb91e37c204450f342bc439e9 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Tue, 30 Jan 2024 17:16:39 +0000 Subject: [PATCH] feat: remove pages from 2024 and test (#2191) --- .../form/sales/subsections/outright_sale.rb | 6 +-- .../sales/subsections/outright_sale_spec.rb | 44 +++++++++++++++++-- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/app/models/form/sales/subsections/outright_sale.rb b/app/models/form/sales/subsections/outright_sale.rb index 4af89d317..245cbcb10 100644 --- a/app/models/form/sales/subsections/outright_sale.rb +++ b/app/models/form/sales/subsections/outright_sale.rb @@ -14,15 +14,15 @@ class Form::Sales::Subsections::OutrightSale < ::Form::Subsection Form::Sales::Pages::MortgageValueCheck.new("outright_sale_mortgage_used_mortgage_value_check", nil, self), Form::Sales::Pages::MortgageAmount.new("mortgage_amount_outright_sale", nil, self, ownershipsch: 3), Form::Sales::Pages::MortgageValueCheck.new("outright_sale_mortgage_amount_mortgage_value_check", nil, self), - Form::Sales::Pages::MortgageLender.new("mortgage_lender_outright_sale", nil, self, ownershipsch: 3), - Form::Sales::Pages::MortgageLenderOther.new("mortgage_lender_other_outright_sale", nil, self, ownershipsch: 3), + (Form::Sales::Pages::MortgageLender.new("mortgage_lender_outright_sale", nil, self, ownershipsch: 3) unless form.start_year_after_2024?), + (Form::Sales::Pages::MortgageLenderOther.new("mortgage_lender_other_outright_sale", nil, self, ownershipsch: 3) unless form.start_year_after_2024?), Form::Sales::Pages::MortgageLength.new("mortgage_length_outright_sale", nil, self, ownershipsch: 3), Form::Sales::Pages::ExtraBorrowing.new("extra_borrowing_outright_sale", nil, self, ownershipsch: 3), Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_outright_sale", nil, self, ownershipsch: 3), Form::Sales::Pages::DepositValueCheck.new("outright_sale_deposit_value_check", nil, self), leasehold_charge_pages, Form::Sales::Pages::MonthlyChargesValueCheck.new("monthly_charges_outright_sale_value_check", nil, self), - ].compact + ].flatten.compact end def displayed_in_tasklist?(log) diff --git a/spec/models/form/sales/subsections/outright_sale_spec.rb b/spec/models/form/sales/subsections/outright_sale_spec.rb index ee659b83d..4e4b50655 100644 --- a/spec/models/form/sales/subsections/outright_sale_spec.rb +++ b/spec/models/form/sales/subsections/outright_sale_spec.rb @@ -6,16 +6,24 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do let(:subsection_id) { nil } let(:subsection_definition) { nil } let(:section) { instance_double(Form::Sales::Sections::SaleInformation) } + let(:form) { instance_double(Form) } + + before do + allow(section).to receive(:form).and_return(form) + end it "has correct section" do expect(outright_sale.section).to eq(section) end describe "pages" do - let(:section) { instance_double(described_class, form: instance_double(Form, start_date:)) } + let(:section) { instance_double(described_class, form: instance_double(Form)) } context "when 2022" do - let(:start_date) { Time.utc(2022, 2, 8) } + before do + allow(form).to receive(:start_date).and_return(Time.zone.local(2022, 2, 8)) + allow(form).to receive(:start_year_after_2024?).and_return(false) + end it "has correct pages" do expect(outright_sale.pages.compact.map(&:id)).to eq( @@ -39,7 +47,11 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do end context "when 2023" do - let(:start_date) { Time.utc(2023, 2, 8) } + before do + allow(form).to receive(:start_date).and_return(Time.zone.local(2023, 2, 8)) + + allow(form).to receive(:start_year_after_2024?).and_return(false) + end it "has correct pages" do expect(outright_sale.pages.map(&:id)).to eq( @@ -62,6 +74,32 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do ) end end + + context "when 2024" do + before do + allow(form).to receive(:start_date).and_return(Time.zone.local(2024, 2, 8)) + allow(form).to receive(:start_year_after_2024?).and_return(true) + end + + it "has correct pages" do + expect(outright_sale.pages.map(&:id)).to eq( + %w[ + purchase_price_outright_sale + about_price_outright_sale_value_check + mortgage_used_outright_sale + outright_sale_mortgage_used_mortgage_value_check + mortgage_amount_outright_sale + outright_sale_mortgage_amount_mortgage_value_check + mortgage_length_outright_sale + extra_borrowing_outright_sale + about_deposit_outright_sale + outright_sale_deposit_value_check + leasehold_charges_outright_sale + monthly_charges_outright_sale_value_check + ], + ) + end + end end it "has the correct id" do