diff --git a/app/models/validations/soft_validations.rb b/app/models/validations/soft_validations.rb index 686c69174..ed90cbcd9 100644 --- a/app/models/validations/soft_validations.rb +++ b/app/models/validations/soft_validations.rb @@ -62,6 +62,14 @@ module Validations::SoftValidations end end + def major_repairs_date_in_soft_range? + mrcdate.present? && startdate.present? && mrcdate.between?(startdate.to_date - 3650, startdate.to_date - 730) + end + + def voiddate_date_in_soft_range? + voiddate.present? && startdate.present? && voiddate.between?(startdate.to_date - 3650, startdate.to_date - 730) + end + private def details_known_or_lead_tenant?(tenant_number) diff --git a/spec/models/validations/soft_validations_spec.rb b/spec/models/validations/soft_validations_spec.rb index b28a53b9e..b38a34888 100644 --- a/spec/models/validations/soft_validations_spec.rb +++ b/spec/models/validations/soft_validations_spec.rb @@ -205,4 +205,36 @@ RSpec.describe Validations::SoftValidations do end end end + + describe "major repairs date soft validations" do + context "when the major repairs date is within 10 years of the tenancy start date" do + it "shows the interruption screen" do + record.update!(startdate: Time.zone.local(2022, 2, 1), mrcdate: Time.zone.local(2013, 2, 1)) + expect(record.major_repairs_date_in_soft_range?).to be true + end + end + + 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 + record.update!(startdate: Time.zone.local(2022, 2, 1), mrcdate: Time.zone.local(2021, 2, 1)) + expect(record.major_repairs_date_in_soft_range?).to be false + end + end + end + + describe "void date soft validations" do + context "when the void date is within 10 years of the tenancy start date" do + it "shows the interruption screen" do + record.update!(startdate: Time.zone.local(2022, 2, 1), voiddate: Time.zone.local(2013, 2, 1)) + expect(record.voiddate_date_in_soft_range?).to be true + end + end + + context "when the void date is less than 2 years before the tenancy start date" do + it "does not show the interruption screen" do + record.update!(startdate: Time.zone.local(2022, 2, 1), voiddate: Time.zone.local(2021, 2, 1)) + expect(record.voiddate_date_in_soft_range?).to be false + end + end + end end