Browse Source

CLDC-3499: Fix some final old tests

CLDC-3499-remove-pre-2025-tests
samyou-softwire 1 week ago
parent
commit
358f852164
  1. 34
      spec/models/validations/date_validations_spec.rb
  2. 39
      spec/models/validations/financial_validations_spec.rb
  3. 8
      spec/models/validations/household_validations_spec.rb
  4. 12
      spec/models/validations/sales/sale_information_validations_spec.rb
  5. 20
      spec/models/validations/soft_validations_spec.rb

34
spec/models/validations/date_validations_spec.rb

@ -18,7 +18,7 @@ RSpec.describe Validations::DateValidations do
end end
it "does not raise an error when valid" do it "does not raise an error when valid" do
record.startdate = Time.zone.local(2022, 1, 1) record.startdate = current_collection_start_date + 1.month
date_validator.validate_startdate(record) date_validator.validate_startdate(record)
expect(record.errors["startdate"]).to be_empty expect(record.errors["startdate"]).to be_empty
end end
@ -40,8 +40,8 @@ RSpec.describe Validations::DateValidations do
describe "major repairs date" do describe "major repairs date" do
it "cannot be after the tenancy start date" do it "cannot be after the tenancy start date" do
record.startdate = Time.zone.local(2022, 1, 1) record.startdate = current_collection_start_date + 1.month
record.mrcdate = Time.zone.local(2022, 2, 1) record.mrcdate = current_collection_start_date + 2.months
date_validator.validate_property_major_repairs(record) date_validator.validate_property_major_repairs(record)
expect(record.errors["mrcdate"]) expect(record.errors["mrcdate"])
.to include(match I18n.t("validations.lettings.date.mrcdate.before_tenancy_start")) .to include(match I18n.t("validations.lettings.date.mrcdate.before_tenancy_start"))
@ -50,8 +50,8 @@ RSpec.describe Validations::DateValidations do
end end
it "must be before the tenancy start date" do it "must be before the tenancy start date" do
record.startdate = Time.zone.local(2022, 2, 1) record.startdate = current_collection_start_date + 2.months
record.mrcdate = Time.zone.local(2022, 1, 1) record.mrcdate = current_collection_start_date + 1.month
date_validator.validate_property_major_repairs(record) date_validator.validate_property_major_repairs(record)
expect(record.errors["mrcdate"]).to be_empty expect(record.errors["mrcdate"]).to be_empty
end end
@ -77,7 +77,7 @@ RSpec.describe Validations::DateValidations do
context "when reason for vacancy is first let of property" do context "when reason for vacancy is first let of property" do
it "validates that no major repair date is provided for a new build" do it "validates that no major repair date is provided for a new build" do
record.rsnvac = 15 record.rsnvac = 15
record.mrcdate = Time.zone.local(2022, 1, 1) record.mrcdate = current_collection_start_date + 1.month
date_validator.validate_property_major_repairs(record) date_validator.validate_property_major_repairs(record)
expect(record.errors["mrcdate"]) expect(record.errors["mrcdate"])
.to include(match I18n.t("validations.lettings.date.mrcdate.not_first_let")) .to include(match I18n.t("validations.lettings.date.mrcdate.not_first_let"))
@ -85,7 +85,7 @@ RSpec.describe Validations::DateValidations do
it "validates that no major repair date is provided for a conversion" do it "validates that no major repair date is provided for a conversion" do
record.rsnvac = 16 record.rsnvac = 16
record.mrcdate = Time.zone.local(2022, 1, 1) record.mrcdate = current_collection_start_date + 1.month
date_validator.validate_property_major_repairs(record) date_validator.validate_property_major_repairs(record)
expect(record.errors["mrcdate"]) expect(record.errors["mrcdate"])
.to include(match I18n.t("validations.lettings.date.mrcdate.not_first_let")) .to include(match I18n.t("validations.lettings.date.mrcdate.not_first_let"))
@ -93,7 +93,7 @@ RSpec.describe Validations::DateValidations do
it "validates that no major repair date is provided for a leased property" do it "validates that no major repair date is provided for a leased property" do
record.rsnvac = 17 record.rsnvac = 17
record.mrcdate = Time.zone.local(2022, 1, 1) record.mrcdate = current_collection_start_date + 1.month
date_validator.validate_property_major_repairs(record) date_validator.validate_property_major_repairs(record)
expect(record.errors["mrcdate"]) expect(record.errors["mrcdate"])
.to include(match I18n.t("validations.lettings.date.mrcdate.not_first_let")) .to include(match I18n.t("validations.lettings.date.mrcdate.not_first_let"))
@ -103,7 +103,7 @@ RSpec.describe Validations::DateValidations do
context "when the reason for vacancy is not the first let of property" do context "when the reason for vacancy is not the first let of property" do
it "expects that major repairs can have been done" do it "expects that major repairs can have been done" do
record.rsnvac = "Tenant moved to care home" record.rsnvac = "Tenant moved to care home"
record.mrcdate = Time.zone.local(2022, 1, 1) record.mrcdate = current_collection_start_date + 1.month
date_validator.validate_property_major_repairs(record) date_validator.validate_property_major_repairs(record)
expect(record.errors["mrcdate"]).to be_empty expect(record.errors["mrcdate"]).to be_empty
end end
@ -112,8 +112,8 @@ RSpec.describe Validations::DateValidations do
describe "property void date" do describe "property void date" do
it "cannot be after the tenancy start date" do it "cannot be after the tenancy start date" do
record.startdate = Time.zone.local(2022, 1, 1) record.startdate = current_collection_start_date + 1.month
record.voiddate = Time.zone.local(2022, 2, 1) record.voiddate = current_collection_start_date + 2.months
date_validator.validate_property_void_date(record) date_validator.validate_property_void_date(record)
expect(record.errors["voiddate"]) expect(record.errors["voiddate"])
.to include(match I18n.t("validations.lettings.date.void_date.before_tenancy_start")) .to include(match I18n.t("validations.lettings.date.void_date.before_tenancy_start"))
@ -122,8 +122,8 @@ RSpec.describe Validations::DateValidations do
end end
it "must be before the tenancy start date" do it "must be before the tenancy start date" do
record.startdate = Time.zone.local(2022, 2, 1) record.startdate = current_collection_start_date + 2.months
record.voiddate = Time.zone.local(2022, 1, 1) record.voiddate = current_collection_start_date + 1.month
date_validator.validate_property_void_date(record) date_validator.validate_property_void_date(record)
expect(record.errors["voiddate"]).to be_empty expect(record.errors["voiddate"]).to be_empty
end end
@ -149,8 +149,8 @@ RSpec.describe Validations::DateValidations do
context "when major repairs have been carried out" do context "when major repairs have been carried out" do
it "void_date cannot be after major repairs date" do it "void_date cannot be after major repairs date" do
record.mrcdate = Time.zone.local(2022, 1, 1) record.mrcdate = current_collection_start_date + 1.month
record.voiddate = Time.zone.local(2022, 2, 1) record.voiddate = current_collection_start_date + 2.months
date_validator.validate_property_void_date(record) date_validator.validate_property_void_date(record)
expect(record.errors["voiddate"]) expect(record.errors["voiddate"])
.to include(match I18n.t("validations.lettings.date.void_date.after_mrcdate")) .to include(match I18n.t("validations.lettings.date.void_date.after_mrcdate"))
@ -159,8 +159,8 @@ RSpec.describe Validations::DateValidations do
end end
it "must be before major repairs date" do it "must be before major repairs date" do
record.mrcdate = Time.zone.local(2022, 2, 1) record.mrcdate = current_collection_start_date + 2.months
record.voiddate = Time.zone.local(2022, 1, 1) record.voiddate = current_collection_start_date + 1.month
date_validator.validate_property_void_date(record) date_validator.validate_property_void_date(record)
expect(record.errors["voiddate"]).to be_empty expect(record.errors["voiddate"]).to be_empty
end end

39
spec/models/validations/financial_validations_spec.rb

@ -1,15 +1,12 @@
require "rails_helper" require "rails_helper"
RSpec.describe Validations::FinancialValidations do RSpec.describe Validations::FinancialValidations do
include CollectionTimeHelper
subject(:financial_validator) { validator_class.new } subject(:financial_validator) { validator_class.new }
let(:validator_class) { Class.new { include Validations::FinancialValidations } } let(:validator_class) { Class.new { include Validations::FinancialValidations } }
let(:record) { FactoryBot.create(:lettings_log) } let(:record) { FactoryBot.create(:lettings_log) }
let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") }
before do
allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form)
end
describe "earnings and income frequency" do describe "earnings and income frequency" do
it "when earnings are provided it validates that income frequency must be provided" do it "when earnings are provided it validates that income frequency must be provided" do
@ -203,7 +200,7 @@ RSpec.describe Validations::FinancialValidations do
end end
describe "housing benefit rent shortfall validations" do describe "housing benefit rent shortfall validations" do
before { record.startdate = Time.zone.local(2022, 5, 1) } before { record.startdate = current_collection_start_date }
context "when shortfall is yes" do context "when shortfall is yes" do
it "validates that housing benefit is not none" do it "validates that housing benefit is not none" do
@ -233,7 +230,7 @@ RSpec.describe Validations::FinancialValidations do
describe "net income validations" do describe "net income validations" do
it "validates that the net income is within the expected range for the household’s employment status" do it "validates that the net income is within the expected range for the household’s employment status" do
record.startdate = Time.zone.local(2023, 5, 1) record.startdate = current_collection_start_date
record.earnings = 200 record.earnings = 200
record.incfreq = 1 record.incfreq = 1
record.hhmemb = 1 record.hhmemb = 1
@ -244,7 +241,7 @@ RSpec.describe Validations::FinancialValidations do
context "when the net income is higher than the hard max for their employment status" do context "when the net income is higher than the hard max for their employment status" do
it "adds an error" do it "adds an error" do
record.startdate = Time.zone.local(2023, 5, 1) record.startdate = current_collection_start_date
record.earnings = 5000 record.earnings = 5000
record.incfreq = 1 record.incfreq = 1
record.hhmemb = 1 record.hhmemb = 1
@ -261,7 +258,7 @@ RSpec.describe Validations::FinancialValidations do
context "when the net income is lower than the hard min for their employment status" do context "when the net income is lower than the hard min for their employment status" do
it "adds an error" do it "adds an error" do
record.startdate = Time.zone.local(2023, 5, 1) record.startdate = current_collection_start_date
record.earnings = 50 record.earnings = 50
record.incfreq = 1 record.incfreq = 1
record.hhmemb = 1 record.hhmemb = 1
@ -278,7 +275,7 @@ RSpec.describe Validations::FinancialValidations do
context "when there is more than one household member" do context "when there is more than one household member" do
it "allows income levels based on all working situations combined" do it "allows income levels based on all working situations combined" do
record.startdate = Time.zone.local(2023, 5, 1) record.startdate = current_collection_start_date
record.earnings = 5000 record.earnings = 5000
record.incfreq = 1 record.incfreq = 1
record.hhmemb = 4 record.hhmemb = 4
@ -291,7 +288,7 @@ RSpec.describe Validations::FinancialValidations do
end end
it "uses the combined value in error messages" do it "uses the combined value in error messages" do
record.startdate = Time.zone.local(2023, 5, 1) record.startdate = current_collection_start_date
record.earnings = 100 record.earnings = 100
record.incfreq = 1 record.incfreq = 1
record.hhmemb = 3 record.hhmemb = 3
@ -304,7 +301,7 @@ RSpec.describe Validations::FinancialValidations do
end end
it "adds errors to relevant fields for each tenant when income is too high" do it "adds errors to relevant fields for each tenant when income is too high" do
record.startdate = Time.zone.local(2023, 5, 1) record.startdate = current_collection_start_date
record.earnings = 5000 record.earnings = 5000
record.incfreq = 1 record.incfreq = 1
record.hhmemb = 3 record.hhmemb = 3
@ -328,7 +325,7 @@ RSpec.describe Validations::FinancialValidations do
end end
it "adds errors to relevant fields for each tenant when income is too low" do it "adds errors to relevant fields for each tenant when income is too low" do
record.startdate = Time.zone.local(2023, 5, 1) record.startdate = current_collection_start_date
record.earnings = 50 record.earnings = 50
record.incfreq = 1 record.incfreq = 1
record.hhmemb = 3 record.hhmemb = 3
@ -996,7 +993,7 @@ RSpec.describe Validations::FinancialValidations do
soft_max: 89.54, soft_max: 89.54,
hard_min: 9.87, hard_min: 9.87,
hard_max: 100.99, hard_max: 100.99,
start_year: 2021, start_year: current_collection_start_year,
) )
LaRentRange.create!( LaRentRange.create!(
ranges_rent_id: "2", ranges_rent_id: "2",
@ -1007,7 +1004,7 @@ RSpec.describe Validations::FinancialValidations do
soft_max: 89.54, soft_max: 89.54,
hard_min: 9.87, hard_min: 9.87,
hard_max: 100.99, hard_max: 100.99,
start_year: 2021, start_year: current_collection_start_year,
) )
end end
@ -1017,7 +1014,7 @@ RSpec.describe Validations::FinancialValidations do
record.period = 1 record.period = 1
record.la = "E07000223" record.la = "E07000223"
record.beds = 4 record.beds = 4
record.startdate = Time.zone.local(2021, 9, 17) record.startdate = current_collection_start_date
record.brent = 9.17 record.brent = 9.17
financial_validator.validate_rent_amount(record) financial_validator.validate_rent_amount(record)
@ -1030,7 +1027,7 @@ RSpec.describe Validations::FinancialValidations do
record.lettype = 2 record.lettype = 2
record.period = 1 record.period = 1
record.location = location record.location = location
record.startdate = Time.zone.local(2021, 9, 17) record.startdate = current_collection_start_date
record.brent = 9.17 record.brent = 9.17
financial_validator.validate_rent_amount(record) financial_validator.validate_rent_amount(record)
@ -1049,7 +1046,7 @@ RSpec.describe Validations::FinancialValidations do
record.period = 1 record.period = 1
record.la = "E07000223" record.la = "E07000223"
record.beds = 4 record.beds = 4
record.startdate = Time.zone.local(2021, 9, 17) record.startdate = current_collection_start_date
record.brent = 200 record.brent = 200
financial_validator.validate_rent_amount(record) financial_validator.validate_rent_amount(record)
@ -1067,7 +1064,7 @@ RSpec.describe Validations::FinancialValidations do
record.lettype = 2 record.lettype = 2
record.period = 1 record.period = 1
record.location = location record.location = location
record.startdate = Time.zone.local(2021, 9, 17) record.startdate = current_collection_start_date
record.brent = 200 record.brent = 200
financial_validator.validate_rent_amount(record) financial_validator.validate_rent_amount(record)
@ -1084,7 +1081,7 @@ RSpec.describe Validations::FinancialValidations do
record.lettype = 1 record.lettype = 1
record.period = 1 record.period = 1
record.la = "E07000223" record.la = "E07000223"
record.startdate = Time.zone.local(2022, 2, 5) record.startdate = current_collection_start_date
record.beds = 4 record.beds = 4
record.brent = 200 record.brent = 200
@ -1100,7 +1097,7 @@ RSpec.describe Validations::FinancialValidations do
it "does not error if some of the fields are missing" do it "does not error if some of the fields are missing" do
record.managing_organisation.provider_type = 2 record.managing_organisation.provider_type = 2
record.startdate = Time.zone.local(2021, 9, 17) record.startdate = current_collection_start_date
record.brent = 200 record.brent = 200
financial_validator.validate_rent_amount(record) financial_validator.validate_rent_amount(record)

8
spec/models/validations/household_validations_spec.rb

@ -53,7 +53,7 @@ RSpec.describe Validations::HouseholdValidations do
end end
context "when form year is >= 2024" do context "when form year is >= 2024" do
let(:startdate) { Time.zone.local(2024, 4, 1) } let(:startdate) { current_collection_start_date }
context "when checking the content of reasonother" do context "when checking the content of reasonother" do
it "validates that the reason doesn't match phrase indicating homelessness" do it "validates that the reason doesn't match phrase indicating homelessness" do
@ -271,7 +271,7 @@ RSpec.describe Validations::HouseholdValidations do
describe "#validate_person_age_matches_relationship" do describe "#validate_person_age_matches_relationship" do
context "with 2024 logs" do context "with 2024 logs" do
let(:startdate) { Time.zone.local(2024, 4, 1) } let(:startdate) { current_collection_start_date }
it "does not add an error is person under 16 is a partner" do it "does not add an error is person under 16 is a partner" do
record.age2 = 14 record.age2 = 14
@ -293,7 +293,7 @@ RSpec.describe Validations::HouseholdValidations do
describe "#validate_person_age_matches_economic_status" do describe "#validate_person_age_matches_economic_status" do
context "with 2024 logs" do context "with 2024 logs" do
let(:startdate) { Time.zone.local(2024, 4, 1) } let(:startdate) { current_collection_start_date }
it "does not run the validation" do it "does not run the validation" do
record.age2 = 14 record.age2 = 14
@ -309,7 +309,7 @@ RSpec.describe Validations::HouseholdValidations do
describe "#validate_person_age_and_relationship_matches_economic_status" do describe "#validate_person_age_and_relationship_matches_economic_status" do
context "with 2024 logs" do context "with 2024 logs" do
let(:startdate) { Time.zone.local(2024, 4, 1) } let(:startdate) { current_collection_start_date }
context "when the household contains a tenant’s child between the ages of 16 and 19" do context "when the household contains a tenant’s child between the ages of 16 and 19" do
it "does not add an error" do it "does not add an error" do

12
spec/models/validations/sales/sale_information_validations_spec.rb

@ -815,18 +815,6 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end end
end end
context "with a 2024 log that is not an outright sale" do
let(:record) { FactoryBot.build(:sales_log, value: 300_000, ownershipsch: 2, saledate: Time.zone.local(2024, 5, 1)) }
it "does not add errors" do
record.mortgageused = 1
record.mortgage = 100_000
record.deposit = 100_000
sale_information_validator.validate_outright_sale_value_matches_mortgage_plus_deposit(record)
expect(record.errors).to be_empty
end
end
describe "#validate_basic_monthly_rent" do describe "#validate_basic_monthly_rent" do
context "when within permitted bounds" do context "when within permitted bounds" do
let(:record) { build(:sales_log, mrent: 9998, ownershipsch: 1, type: 2) } let(:record) { build(:sales_log, mrent: 9998, ownershipsch: 1, type: 2) }

20
spec/models/validations/soft_validations_spec.rb

@ -18,7 +18,7 @@ RSpec.describe Validations::SoftValidations do
soft_max: 89.54, soft_max: 89.54,
hard_min: 9.87, hard_min: 9.87,
hard_max: 100.99, hard_max: 100.99,
start_year: 2021, start_year: current_collection_start_year,
) )
record.la = "E07000223" record.la = "E07000223"
@ -26,7 +26,7 @@ RSpec.describe Validations::SoftValidations do
record.rent_type = 0 record.rent_type = 0
record.beds = 1 record.beds = 1
record.period = 1 record.period = 1
record.startdate = Time.zone.local(2021, 10, 10) record.startdate = current_collection_start_date
end end
context "when validating soft min" do context "when validating soft min" do
@ -504,16 +504,16 @@ RSpec.describe Validations::SoftValidations do
describe "major repairs date soft validations" do describe "major repairs date soft validations" do
context "when the major repairs date is within 10 years of the tenancy start date" do context "when the major repairs date is within 10 years of the tenancy start date" do
it "shows the interruption screen" do it "shows the interruption screen" do
record.startdate = Time.zone.local(2022, 2, 1) record.startdate = current_collection_start_date
record.mrcdate = Time.zone.local(2013, 2, 1) record.mrcdate = current_collection_start_date- 9.years
expect(record.major_repairs_date_in_soft_range?).to be true expect(record.major_repairs_date_in_soft_range?).to be true
end end
end end
context "when the major repairs date is less than 2 years before the tenancy start date" do context "when the major repairs date is less than 2 years before the tenancy start date" do
it "does not show the interruption screen" do it "does not show the interruption screen" do
record.startdate = Time.zone.local(2022, 2, 1) record.startdate = current_collection_start_date
record.mrcdate = Time.zone.local(2021, 2, 1) record.mrcdate = current_collection_start_date- 1.year
expect(record.major_repairs_date_in_soft_range?).to be false expect(record.major_repairs_date_in_soft_range?).to be false
end end
end end
@ -540,16 +540,16 @@ RSpec.describe Validations::SoftValidations do
describe "void date soft validations" do describe "void date soft validations" do
context "when the void date is within 10 years of the tenancy start date" do context "when the void date is within 10 years of the tenancy start date" do
it "shows the interruption screen" do it "shows the interruption screen" do
record.startdate = Time.zone.local(2022, 2, 1) record.startdate = current_collection_start_date
record.voiddate = Time.zone.local(2013, 2, 1) record.voiddate = current_collection_start_date - 9.years
expect(record.voiddate_in_soft_range?).to be true expect(record.voiddate_in_soft_range?).to be true
end end
end end
context "when the void date is less than 2 years before the tenancy start date" do context "when the void date is less than 2 years before the tenancy start date" do
it "does not show the interruption screen" do it "does not show the interruption screen" do
record.startdate = Time.zone.local(2022, 2, 1) record.startdate = current_collection_start_date
record.voiddate = Time.zone.local(2021, 2, 1) record.voiddate = current_collection_start_date - 1.year
expect(record.voiddate_in_soft_range?).to be false expect(record.voiddate_in_soft_range?).to be false
end end
end end

Loading…
Cancel
Save