Browse Source

CLDC-4402: simplify p3

CLDC-4402-audit-start-year-2024-or-later-usage-2
Rebecca Jesson 4 weeks ago
parent
commit
f34d893489
  1. 1
      app/models/form/lettings/subsections/household_characteristics.rb
  2. 2
      app/models/form/lettings/subsections/tenancy_information.rb
  3. 2
      app/models/form/sales/subsections/outright_sale.rb
  4. 6
      app/models/form/sales/subsections/shared_ownership_scheme.rb
  5. 24
      spec/models/form/lettings/subsections/tenancy_information_spec.rb
  6. 59
      spec/models/form/sales/subsections/outright_sale_spec.rb
  7. 4
      spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb

1
app/models/form/lettings/subsections/household_characteristics.rb

@ -8,7 +8,6 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
def pages
@pages ||= [
(Form::Lettings::Pages::Declaration.new(nil, nil, self) unless form.start_year_2024_or_later?),
Form::Lettings::Pages::HouseholdMembers.new(nil, nil, self),
(Form::Lettings::Pages::NoFemalesPregnantHouseholdLeadHhmembValueCheck.new(nil, nil, self) unless form.start_year_2026_or_later?),
(Form::Lettings::Pages::FemalesInSoftAgeRangeInPregnantHouseholdLeadHhmembValueCheck.new(nil, nil, self) unless form.start_year_2026_or_later?),

2
app/models/form/lettings/subsections/tenancy_information.rb

@ -16,7 +16,7 @@ class Form::Lettings::Subsections::TenancyInformation < ::Form::Subsection
Form::Lettings::Pages::TenancyLength.new(nil, nil, self),
Form::Lettings::Pages::TenancyLengthAffordableRent.new(nil, nil, self),
Form::Lettings::Pages::TenancyLengthIntermediateRent.new(nil, nil, self),
(Form::Lettings::Pages::TenancyLengthPeriodic.new(nil, nil, self) if form.start_year_2024_or_later?),
Form::Lettings::Pages::TenancyLengthPeriodic.new(nil, nil, self),
(Form::Lettings::Pages::ShelteredAccommodation.new(nil, nil, self) unless form.start_year_2025_or_later?),
].flatten.compact
end

2
app/models/form/sales/subsections/outright_sale.rb

@ -17,8 +17,6 @@ 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) unless form.start_year_2024_or_later?),
(Form::Sales::Pages::MortgageLenderOther.new("mortgage_lender_other_outright_sale", nil, self, ownershipsch: 3) unless form.start_year_2024_or_later?),
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::Deposit.new("deposit_outright_sale", nil, self, ownershipsch: 3, optional: false),

6
app/models/form/sales/subsections/shared_ownership_scheme.rb

@ -37,15 +37,15 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection
Form::Sales::Pages::MortgageLength.new("mortgage_length_shared_ownership", nil, self, ownershipsch: 1),
Form::Sales::Pages::ExtraBorrowing.new("extra_borrowing_shared_ownership", nil, self, ownershipsch: 1),
Form::Sales::Pages::Deposit.new("deposit_shared_ownership", nil, self, ownershipsch: 1, optional: false),
(Form::Sales::Pages::Deposit.new("deposit_shared_ownership_optional", nil, self, ownershipsch: 1, optional: true) if form.start_year_2024_or_later?),
Form::Sales::Pages::Deposit.new("deposit_shared_ownership_optional", nil, self, ownershipsch: 1, optional: true),
Form::Sales::Pages::DepositValueCheck.new("deposit_joint_purchase_value_check", nil, self, joint_purchase: true),
Form::Sales::Pages::DepositValueCheck.new("deposit_value_check", nil, self, joint_purchase: false),
Form::Sales::Pages::DepositDiscount.new("deposit_discount", nil, self, optional: false),
(Form::Sales::Pages::DepositDiscount.new("deposit_discount_optional", nil, self, optional: true) if form.start_year_2024_or_later?),
Form::Sales::Pages::DepositDiscount.new("deposit_discount_optional", nil, self, optional: true),
Form::Sales::Pages::MonthlyRent.new(nil, nil, self),
Form::Sales::Pages::LeaseholdCharges.new("leasehold_charges_shared_ownership", nil, self, ownershipsch: 1),
Form::Sales::Pages::MonthlyChargesValueCheck.new("monthly_charges_shared_ownership_value_check", nil, self),
].compact
]
end
def displayed_in_tasklist?(log)

24
spec/models/form/lettings/subsections/tenancy_information_spec.rb

@ -16,30 +16,12 @@ RSpec.describe Form::Lettings::Subsections::TenancyInformation, type: :model do
let(:form) { instance_double(Form, start_date:) }
before do
allow(form).to receive_messages(start_year_2024_or_later?: true, start_year_2025_or_later?: false, start_year_2026_or_later?: false)
end
context "when 2023" do
let(:start_date) { Time.utc(2023, 2, 8) }
before do
allow(form).to receive_messages(start_year_2024_or_later?: false, start_year_2025_or_later?: false, start_year_2026_or_later?: false)
end
it "has correct pages" do
expect(tenancy_information.pages.map(&:id)).to eq(
%w[joint starter_tenancy tenancy_type starter_tenancy_type tenancy_length tenancy_length_affordable_rent tenancy_length_intermediate_rent sheltered_accommodation],
)
end
allow(form).to receive_messages(start_year_2025_or_later?: false, start_year_2026_or_later?: false)
end
context "when 2024" do
let(:start_date) { Time.utc(2024, 2, 8) }
before do
allow(form).to receive_messages(start_year_2024_or_later?: true, start_year_2025_or_later?: false, start_year_2026_or_later?: false)
end
it "has correct pages" do
expect(tenancy_information.pages.map(&:id)).to eq(
%w[joint starter_tenancy tenancy_type starter_tenancy_type tenancy_length tenancy_length_affordable_rent tenancy_length_intermediate_rent tenancy_length_periodic sheltered_accommodation],
@ -51,7 +33,7 @@ RSpec.describe Form::Lettings::Subsections::TenancyInformation, type: :model do
let(:start_date) { Time.utc(2025, 2, 8) }
before do
allow(form).to receive_messages(start_year_2024_or_later?: true, start_year_2025_or_later?: true, start_year_2026_or_later?: false)
allow(form).to receive_messages(start_year_2025_or_later?: true, start_year_2026_or_later?: false)
end
it "has correct pages" do
@ -65,7 +47,7 @@ RSpec.describe Form::Lettings::Subsections::TenancyInformation, type: :model do
let(:start_date) { Time.utc(2026, 2, 8) }
before do
allow(form).to receive_messages(start_year_2024_or_later?: true, start_year_2025_or_later?: true, start_year_2026_or_later?: true)
allow(form).to receive_messages(start_year_2025_or_later?: true, start_year_2026_or_later?: true)
end
it "has correct pages" do

59
spec/models/form/sales/subsections/outright_sale_spec.rb

@ -19,36 +19,8 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do
describe "pages" do
let(:section) { instance_double(described_class, form: instance_double(Form)) }
context "when 2022" do
before do
allow(form).to receive_messages(start_date: Time.zone.local(2022, 2, 8), start_year_2024_or_later?: false)
end
it "has correct pages" do
expect(outright_sale.pages.compact.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_lender_outright_sale
mortgage_lender_other_outright_sale
mortgage_length_outright_sale
extra_borrowing_outright_sale
deposit_outright_sale
outright_sale_deposit_joint_purchase_value_check
outright_sale_deposit_value_check
monthly_charges_outright_sale_value_check
],
)
end
end
context "when 2023" do
before do
allow(form).to receive_messages(start_date: Time.zone.local(2023, 2, 8), start_year_2024_or_later?: false)
allow(form).to receive_messages(start_date: Time.zone.local(2024, 2, 8))
end
it "has correct pages" do
@ -60,8 +32,6 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do
outright_sale_mortgage_used_mortgage_value_check
mortgage_amount_outright_sale
outright_sale_mortgage_amount_mortgage_value_check
mortgage_lender_outright_sale
mortgage_lender_other_outright_sale
mortgage_length_outright_sale
extra_borrowing_outright_sale
deposit_outright_sale
@ -74,33 +44,6 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do
end
end
context "when 2024" do
before do
allow(form).to receive_messages(start_date: Time.zone.local(2024, 2, 8), start_year_2024_or_later?: 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
deposit_outright_sale
outright_sale_deposit_joint_purchase_value_check
outright_sale_deposit_value_check
leasehold_charges_outright_sale
monthly_charges_outright_sale_value_check
],
)
end
end
end
it "has the correct id" do
expect(outright_sale.id).to eq("outright_sale")
end

4
spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb

@ -8,7 +8,7 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do
let(:section) { instance_double(Form::Sales::Sections::SaleInformation) }
before do
allow(section).to receive(:form).and_return(instance_double(Form, start_year_2024_or_later?: false, start_year_2025_or_later?: false, start_date: Time.zone.local(2023, 4, 1)))
allow(section).to receive(:form).and_return(instance_double(Form, start_date: Time.zone.local(2024, 4, 1)))
end
it "has correct section" do
@ -46,9 +46,11 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do
mortgage_length_shared_ownership
extra_borrowing_shared_ownership
deposit_shared_ownership
deposit_shared_ownership_optional
deposit_joint_purchase_value_check
deposit_value_check
deposit_discount
deposit_discount_optional
monthly_rent
leasehold_charges_shared_ownership
monthly_charges_shared_ownership_value_check

Loading…
Cancel
Save