From 7b0ea9f4ed19d2581a57b2981c542df302e506ac Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Mon, 4 Mar 2024 12:36:06 +0000 Subject: [PATCH] Update tests --- .../validations/date_validations_spec.rb | 13 ----------- .../validations/setup_validations_spec.rb | 22 +++++++++++++++++++ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/spec/models/validations/date_validations_spec.rb b/spec/models/validations/date_validations_spec.rb index 0fc706707..5b9d1a436 100644 --- a/spec/models/validations/date_validations_spec.rb +++ b/spec/models/validations/date_validations_spec.rb @@ -59,19 +59,6 @@ RSpec.describe Validations::DateValidations do date_validator.validate_startdate(record) expect(record.errors["startdate"]).to be_empty end - - it "validates that the tenancy start date is not later than 14 days from the current date" do - record.startdate = Time.zone.today + 15.days - date_validator.validate_startdate(record) - expect(record.errors["startdate"]) - .to include(match I18n.t("validations.setup.startdate.later_than_14_days_after")) - end - - it "produces no error when tenancy start date is not later than 14 days from the current date" do - record.startdate = Time.zone.today + 7.days - date_validator.validate_startdate(record) - expect(record.errors["startdate"]).to be_empty - end end describe "major repairs date" do diff --git a/spec/models/validations/setup_validations_spec.rb b/spec/models/validations/setup_validations_spec.rb index 763bf89b9..ae893d880 100644 --- a/spec/models/validations/setup_validations_spec.rb +++ b/spec/models/validations/setup_validations_spec.rb @@ -141,6 +141,28 @@ RSpec.describe Validations::SetupValidations do end end + context "when attempted startdate is more than 14 days from the current date" do + before do + Timecop.freeze(2024, 3, 1) + end + + it "adds an error to startdate" do + record.startdate = Time.zone.local(2024, 3, 31) + setup_validator.validate_startdate_setup(record) + expect(record.errors["startdate"]).to include(match I18n.t("validations.setup.startdate.later_than_14_days_after")) + end + + context "and the attempted startdate is in a future collection year" do + it "adds both errors to startdate, with the collection year error first" do + record.startdate = Time.zone.local(2024, 4, 1) + setup_validator.validate_startdate_setup(record) + expect(record.errors["startdate"].length).to be >= 2 + expect(record.errors["startdate"][0]).to eq("Enter a date within the 23/24 collection year, which is between 1st April 2023 and 31st March 2024") + expect(record.errors["startdate"][1]).to eq(I18n.t("validations.setup.startdate.later_than_14_days_after")) + end + end + end + context "when organisations were merged" do around do |example| Timecop.freeze(Time.zone.local(2023, 5, 1))