diff --git a/app/models/form/lettings/pages/rent_4_weekly.rb b/app/models/form/lettings/pages/rent_4_weekly.rb index aa6441f6e..4bfaf28ff 100644 --- a/app/models/form/lettings/pages/rent_4_weekly.rb +++ b/app/models/form/lettings/pages/rent_4_weekly.rb @@ -3,10 +3,7 @@ class Form::Lettings::Pages::Rent4Weekly < ::Form::Page super @id = "rent_4_weekly" @copy_key = "lettings.income_and_benefits.rent_and_charges" - @depends_on = [ - { "household_charge" => 0, "rent_and_charges_paid_every_4_weeks?" => true, "is_carehome?" => false }, - { "household_charge" => nil, "rent_and_charges_paid_every_4_weeks?" => true, "is_carehome?" => false }, - ] + @depends_on = depends_on end def questions @@ -18,4 +15,18 @@ class Form::Lettings::Pages::Rent4Weekly < ::Form::Page Form::Lettings::Questions::Tcharge4Weekly.new(nil, nil, self), ] end + + def depends_on + if form.start_year_2025_or_later? + [ + { "household_charge" => 0, "rent_and_charges_paid_every_4_weeks?" => true }, + { "household_charge" => nil, "rent_and_charges_paid_every_4_weeks?" => true }, + ] + else + [ + { "household_charge" => 0, "rent_and_charges_paid_every_4_weeks?" => true, "is_carehome?" => false }, + { "household_charge" => nil, "rent_and_charges_paid_every_4_weeks?" => true, "is_carehome?" => false }, + ] + end + end end diff --git a/app/models/form/lettings/pages/rent_bi_weekly.rb b/app/models/form/lettings/pages/rent_bi_weekly.rb index 7eab8daf4..aad9e9312 100644 --- a/app/models/form/lettings/pages/rent_bi_weekly.rb +++ b/app/models/form/lettings/pages/rent_bi_weekly.rb @@ -3,10 +3,7 @@ class Form::Lettings::Pages::RentBiWeekly < ::Form::Page super @id = "rent_bi_weekly" @copy_key = "lettings.income_and_benefits.rent_and_charges" - @depends_on = [ - { "household_charge" => nil, "rent_and_charges_paid_every_2_weeks?" => true, "is_carehome?" => false }, - { "household_charge" => 0, "rent_and_charges_paid_every_2_weeks?" => true, "is_carehome?" => false }, - ] + @depends_on = depends_on end def questions @@ -18,4 +15,18 @@ class Form::Lettings::Pages::RentBiWeekly < ::Form::Page Form::Lettings::Questions::TchargeBiWeekly.new(nil, nil, self), ] end + + def depends_on + if form.start_year_2025_or_later? + [ + { "household_charge" => nil, "rent_and_charges_paid_every_2_weeks?" => true }, + { "household_charge" => 0, "rent_and_charges_paid_every_2_weeks?" => true }, + ] + else + [ + { "household_charge" => nil, "rent_and_charges_paid_every_2_weeks?" => true, "is_carehome?" => false }, + { "household_charge" => 0, "rent_and_charges_paid_every_2_weeks?" => true, "is_carehome?" => false }, + ] + end + end end diff --git a/app/models/form/lettings/pages/rent_monthly.rb b/app/models/form/lettings/pages/rent_monthly.rb index 9a3cd6a7e..1fcc21b17 100644 --- a/app/models/form/lettings/pages/rent_monthly.rb +++ b/app/models/form/lettings/pages/rent_monthly.rb @@ -3,10 +3,7 @@ class Form::Lettings::Pages::RentMonthly < ::Form::Page super @id = "rent_monthly" @copy_key = "lettings.income_and_benefits.rent_and_charges" - @depends_on = [ - { "household_charge" => nil, "rent_and_charges_paid_monthly?" => true, "is_carehome?" => false }, - { "household_charge" => 0, "rent_and_charges_paid_monthly?" => true, "is_carehome?" => false }, - ] + @depends_on = depends_on end def questions @@ -18,4 +15,18 @@ class Form::Lettings::Pages::RentMonthly < ::Form::Page Form::Lettings::Questions::TchargeMonthly.new(nil, nil, self), ] end + + def depends_on + if form.start_year_2025_or_later? + [ + { "household_charge" => nil, "rent_and_charges_paid_monthly?" => true }, + { "household_charge" => 0, "rent_and_charges_paid_monthly?" => true }, + ] + else + [ + { "household_charge" => nil, "rent_and_charges_paid_monthly?" => true, "is_carehome?" => false }, + { "household_charge" => 0, "rent_and_charges_paid_monthly?" => true, "is_carehome?" => false }, + ] + end + end end diff --git a/app/models/form/lettings/pages/rent_weekly.rb b/app/models/form/lettings/pages/rent_weekly.rb index 86106cfe3..b40641ebe 100644 --- a/app/models/form/lettings/pages/rent_weekly.rb +++ b/app/models/form/lettings/pages/rent_weekly.rb @@ -3,10 +3,7 @@ class Form::Lettings::Pages::RentWeekly < ::Form::Page super @id = "rent_weekly" @copy_key = "lettings.income_and_benefits.rent_and_charges" - @depends_on = [ - { "rent_and_charges_paid_weekly?" => true, "household_charge" => 0, "is_carehome?" => false }, - { "rent_and_charges_paid_weekly?" => true, "household_charge" => nil, "is_carehome?" => false }, - ] + @depends_on = depends_on end def questions @@ -18,4 +15,18 @@ class Form::Lettings::Pages::RentWeekly < ::Form::Page Form::Lettings::Questions::TchargeWeekly.new(nil, nil, self), ] end + + def depends_on + if form.start_year_2025_or_later? + [ + { "rent_and_charges_paid_weekly?" => true, "household_charge" => 0 }, + { "rent_and_charges_paid_weekly?" => true, "household_charge" => nil }, + ] + else + [ + { "rent_and_charges_paid_weekly?" => true, "household_charge" => 0, "is_carehome?" => false }, + { "rent_and_charges_paid_weekly?" => true, "household_charge" => nil, "is_carehome?" => false }, + ] + end + end end diff --git a/app/models/form/lettings/subsections/income_and_benefits.rb b/app/models/form/lettings/subsections/income_and_benefits.rb index 2be2fb9a5..4ad3003cb 100644 --- a/app/models/form/lettings/subsections/income_and_benefits.rb +++ b/app/models/form/lettings/subsections/income_and_benefits.rb @@ -15,11 +15,7 @@ class Form::Lettings::Subsections::IncomeAndBenefits < ::Form::Subsection Form::Lettings::Pages::BenefitsProportion.new("benefits_proportion", nil, self), Form::Lettings::Pages::RentOrOtherCharges.new(nil, nil, self), Form::Lettings::Pages::RentPeriod.new(nil, nil, self), - Form::Lettings::Pages::CareHomeWeekly.new(nil, nil, self), - Form::Lettings::Pages::CareHomeBiWeekly.new(nil, nil, self), - Form::Lettings::Pages::CareHome4Weekly.new(nil, nil, self), - Form::Lettings::Pages::CareHomeMonthly.new(nil, nil, self), - Form::Lettings::Pages::CareHomeChargesValueCheck.new(nil, nil, self), + carehome_questions, Form::Lettings::Pages::RentWeekly.new(nil, nil, self), Form::Lettings::Pages::RentBiWeekly.new(nil, nil, self), Form::Lettings::Pages::Rent4Weekly.new(nil, nil, self), @@ -30,6 +26,20 @@ class Form::Lettings::Subsections::IncomeAndBenefits < ::Form::Subsection Form::Lettings::Pages::SupchargValueCheck.new(nil, nil, self), Form::Lettings::Pages::Outstanding.new(nil, nil, self), Form::Lettings::Pages::OutstandingAmount.new(nil, nil, self), - ].compact + ].flatten.compact + end + +private + + def carehome_questions + return [] if form.start_year_2025_or_later? + + [ + Form::Lettings::Pages::CareHomeWeekly.new(nil, nil, self), + Form::Lettings::Pages::CareHomeBiWeekly.new(nil, nil, self), + Form::Lettings::Pages::CareHome4Weekly.new(nil, nil, self), + Form::Lettings::Pages::CareHomeMonthly.new(nil, nil, self), + Form::Lettings::Pages::CareHomeChargesValueCheck.new(nil, nil, self), + ] end end diff --git a/spec/models/form/lettings/pages/rent4_weekly_spec.rb b/spec/models/form/lettings/pages/rent4_weekly_spec.rb new file mode 100644 index 000000000..8a8527d6a --- /dev/null +++ b/spec/models/form/lettings/pages/rent4_weekly_spec.rb @@ -0,0 +1,44 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Pages::Rent4Weekly, type: :model do + subject(:page) { described_class.new(nil, page_definition, subsection) } + + let(:page_definition) { nil } + let(:start_date) { Time.zone.local(2024, 4, 1) } + let(:start_year_2025_or_later) { false } + let(:form) { instance_double(Form, start_date:) } + let(:subsection) { instance_double(Form::Subsection, form:) } + let(:person_index) { 2 } + + before do + allow(form).to receive(:start_year_2025_or_later?).and_return(start_year_2025_or_later) + end + + context "with form before 2025" do + let(:start_date) { Time.zone.local(2024, 4, 1) } + let(:start_year_2025_or_later) { false } + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [ + { "rent_and_charges_paid_every_4_weeks?" => true, "household_charge" => 0, "is_carehome?" => false }, + { "rent_and_charges_paid_every_4_weeks?" => true, "household_charge" => nil, "is_carehome?" => false }, + ], + ) + end + end + + context "with form on or after 2025" do + let(:start_date) { Time.zone.local(2025, 4, 1) } + let(:start_year_2025_or_later) { true } + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [ + { "rent_and_charges_paid_every_4_weeks?" => true, "household_charge" => 0 }, + { "rent_and_charges_paid_every_4_weeks?" => true, "household_charge" => nil }, + ], + ) + end + end +end diff --git a/spec/models/form/lettings/pages/rent_bi_weekly_spec.rb b/spec/models/form/lettings/pages/rent_bi_weekly_spec.rb new file mode 100644 index 000000000..a1975f766 --- /dev/null +++ b/spec/models/form/lettings/pages/rent_bi_weekly_spec.rb @@ -0,0 +1,44 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Pages::RentBiWeekly, type: :model do + subject(:page) { described_class.new(nil, page_definition, subsection) } + + let(:page_definition) { nil } + let(:start_date) { Time.zone.local(2024, 4, 1) } + let(:start_year_2025_or_later) { false } + let(:form) { instance_double(Form, start_date:) } + let(:subsection) { instance_double(Form::Subsection, form:) } + let(:person_index) { 2 } + + before do + allow(form).to receive(:start_year_2025_or_later?).and_return(start_year_2025_or_later) + end + + context "with form before 2025" do + let(:start_date) { Time.zone.local(2024, 4, 1) } + let(:start_year_2025_or_later) { false } + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [ + { "rent_and_charges_paid_every_2_weeks?" => true, "household_charge" => nil, "is_carehome?" => false }, + { "rent_and_charges_paid_every_2_weeks?" => true, "household_charge" => 0, "is_carehome?" => false }, + ], + ) + end + end + + context "with form on or after 2025" do + let(:start_date) { Time.zone.local(2025, 4, 1) } + let(:start_year_2025_or_later) { true } + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [ + { "rent_and_charges_paid_every_2_weeks?" => true, "household_charge" => nil }, + { "rent_and_charges_paid_every_2_weeks?" => true, "household_charge" => 0 }, + ], + ) + end + end +end diff --git a/spec/models/form/lettings/pages/rent_monthly_spec.rb b/spec/models/form/lettings/pages/rent_monthly_spec.rb new file mode 100644 index 000000000..619fc254e --- /dev/null +++ b/spec/models/form/lettings/pages/rent_monthly_spec.rb @@ -0,0 +1,44 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Pages::RentMonthly, type: :model do + subject(:page) { described_class.new(nil, page_definition, subsection) } + + let(:page_definition) { nil } + let(:start_date) { Time.zone.local(2024, 4, 1) } + let(:start_year_2025_or_later) { false } + let(:form) { instance_double(Form, start_date:) } + let(:subsection) { instance_double(Form::Subsection, form:) } + let(:person_index) { 2 } + + before do + allow(form).to receive(:start_year_2025_or_later?).and_return(start_year_2025_or_later) + end + + context "with form before 2025" do + let(:start_date) { Time.zone.local(2024, 4, 1) } + let(:start_year_2025_or_later) { false } + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [ + { "rent_and_charges_paid_monthly?" => true, "household_charge" => nil, "is_carehome?" => false }, + { "rent_and_charges_paid_monthly?" => true, "household_charge" => 0, "is_carehome?" => false }, + ], + ) + end + end + + context "with form on or after 2025" do + let(:start_date) { Time.zone.local(2025, 4, 1) } + let(:start_year_2025_or_later) { true } + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [ + { "rent_and_charges_paid_monthly?" => true, "household_charge" => nil }, + { "rent_and_charges_paid_monthly?" => true, "household_charge" => 0 }, + ], + ) + end + end +end diff --git a/spec/models/form/lettings/pages/rent_weekly_spec.rb b/spec/models/form/lettings/pages/rent_weekly_spec.rb new file mode 100644 index 000000000..89bbae37a --- /dev/null +++ b/spec/models/form/lettings/pages/rent_weekly_spec.rb @@ -0,0 +1,44 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Pages::RentWeekly, type: :model do + subject(:page) { described_class.new(nil, page_definition, subsection) } + + let(:page_definition) { nil } + let(:start_date) { Time.zone.local(2024, 4, 1) } + let(:start_year_2025_or_later) { false } + let(:form) { instance_double(Form, start_date:) } + let(:subsection) { instance_double(Form::Subsection, form:) } + let(:person_index) { 2 } + + before do + allow(form).to receive(:start_year_2025_or_later?).and_return(start_year_2025_or_later) + end + + context "with form before 2025" do + let(:start_date) { Time.zone.local(2024, 4, 1) } + let(:start_year_2025_or_later) { false } + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [ + { "rent_and_charges_paid_weekly?" => true, "household_charge" => 0, "is_carehome?" => false }, + { "rent_and_charges_paid_weekly?" => true, "household_charge" => nil, "is_carehome?" => false }, + ], + ) + end + end + + context "with form on or after 2025" do + let(:start_date) { Time.zone.local(2025, 4, 1) } + let(:start_year_2025_or_later) { true } + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [ + { "rent_and_charges_paid_weekly?" => true, "household_charge" => 0 }, + { "rent_and_charges_paid_weekly?" => true, "household_charge" => nil }, + ], + ) + end + end +end diff --git a/spec/models/form/lettings/subsections/income_and_benefits_spec.rb b/spec/models/form/lettings/subsections/income_and_benefits_spec.rb index 7bdc26bfa..9d78b3216 100644 --- a/spec/models/form/lettings/subsections/income_and_benefits_spec.rb +++ b/spec/models/form/lettings/subsections/income_and_benefits_spec.rb @@ -5,40 +5,77 @@ RSpec.describe Form::Lettings::Subsections::IncomeAndBenefits, type: :model do let(:subsection_id) { nil } let(:subsection_definition) { nil } - let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) } + let(:start_date) { Time.zone.local(2024, 4, 1) } + let(:start_year_2025_or_later) { false } + let(:form) { instance_double(Form, start_date:) } let(:section) { instance_double(Form::Lettings::Sections::RentAndCharges, form:) } + before do + allow(form).to receive(:start_year_2025_or_later?).and_return(start_year_2025_or_later) + end + it "has correct section" do expect(income_and_benefits.section).to eq(section) end - it "has correct pages" do - expect(income_and_benefits.pages.map(&:id)).to eq( - %w[ - income_known - income_amount - net_income_value_check - housing_benefit - benefits_proportion - rent_or_other_charges - rent_period - care_home_weekly - care_home_bi_weekly - care_home_4_weekly - care_home_monthly - care_home_charges_value_check - rent_weekly - rent_bi_weekly - rent_4_weekly - rent_monthly - brent_rent_value_check - scharge_value_check - pscharge_value_check - supcharg_value_check - outstanding - outstanding_amount - ], - ) + context "with 2024 form" do + it "has correct pages" do + expect(income_and_benefits.pages.map(&:id)).to eq( + %w[ + income_known + income_amount + net_income_value_check + housing_benefit + benefits_proportion + rent_or_other_charges + rent_period + care_home_weekly + care_home_bi_weekly + care_home_4_weekly + care_home_monthly + care_home_charges_value_check + rent_weekly + rent_bi_weekly + rent_4_weekly + rent_monthly + brent_rent_value_check + scharge_value_check + pscharge_value_check + supcharg_value_check + outstanding + outstanding_amount + ], + ) + end + end + + context "with 2025 form" do + let(:start_date) { Time.zone.local(2025, 4, 1) } + let(:start_year_2025_or_later) { true } + + it "has correct pages" do + expect(income_and_benefits.pages.map(&:id)).to eq( + %w[ + income_known + income_amount + net_income_value_check + housing_benefit + benefits_proportion + rent_or_other_charges + rent_period + rent_weekly + rent_bi_weekly + rent_4_weekly + rent_monthly + brent_rent_value_check + scharge_value_check + pscharge_value_check + supcharg_value_check + outstanding + outstanding_amount + ], + ) + end end it "has the correct id" do