From 642b9cdaf23086c264c7ef45d58199e64ecf424d Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Mon, 4 Mar 2024 14:28:27 +0000 Subject: [PATCH] CLDC-3264: Setup to allow using future form on staging for testing (#2279) * CLDC-3264: Setup to allow using future form on staging for testing * Update bulk upload year_spec tests * Fix indentation * Disable future form use on review apps for testing * Move lettings startdate 14 day validation to enforce order * Update tests * Restore future form use on review apps --- .../bulk_upload_lettings_logs_controller.rb | 6 +- .../bulk_upload_sales_logs_controller.rb | 8 +- app/models/form_handler.rb | 12 ++ .../bulk_upload_lettings/prepare_your_file.rb | 6 +- app/models/forms/bulk_upload_lettings/year.rb | 5 +- .../bulk_upload_sales/prepare_your_file.rb | 6 +- app/models/forms/bulk_upload_sales/year.rb | 6 +- app/models/validations/date_validations.rb | 4 - .../validations/sales/setup_validations.rb | 4 +- app/models/validations/setup_validations.rb | 6 +- app/services/feature_toggle.rb | 21 +-- .../bulk_upload_lettings_logs_spec.rb | 122 ++++++++++-------- spec/features/bulk_upload_sales_logs_spec.rb | 90 +++++++------ .../forms/bulk_upload_lettings/year_spec.rb | 47 ++++++- .../forms/bulk_upload_sales/year_spec.rb | 51 ++++++-- .../validations/date_validations_spec.rb | 13 -- .../validations/setup_validations_spec.rb | 22 ++++ 17 files changed, 268 insertions(+), 161 deletions(-) diff --git a/app/controllers/bulk_upload_lettings_logs_controller.rb b/app/controllers/bulk_upload_lettings_logs_controller.rb index c9cdb0eaa..4ab636e7a 100644 --- a/app/controllers/bulk_upload_lettings_logs_controller.rb +++ b/app/controllers/bulk_upload_lettings_logs_controller.rb @@ -3,7 +3,7 @@ class BulkUploadLettingsLogsController < ApplicationController before_action :validate_data_protection_agrement_signed! def start - if in_crossover_period? + if have_choice_of_year? redirect_to bulk_upload_lettings_log_path(id: "year") else redirect_to bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year: current_year }) @@ -34,8 +34,8 @@ private FormHandler.instance.current_collection_start_year end - def in_crossover_period? - return true if FeatureToggle.force_crossover? + def have_choice_of_year? + return true if FeatureToggle.allow_future_form_use? FormHandler.instance.lettings_in_crossover_period? end diff --git a/app/controllers/bulk_upload_sales_logs_controller.rb b/app/controllers/bulk_upload_sales_logs_controller.rb index c1004ced4..18f1e89c8 100644 --- a/app/controllers/bulk_upload_sales_logs_controller.rb +++ b/app/controllers/bulk_upload_sales_logs_controller.rb @@ -3,7 +3,7 @@ class BulkUploadSalesLogsController < ApplicationController before_action :validate_data_protection_agrement_signed! def start - if in_crossover_period? + if have_choice_of_year? redirect_to bulk_upload_sales_log_path(id: "year") else redirect_to bulk_upload_sales_log_path(id: "prepare-your-file", form: { year: current_year }) @@ -31,11 +31,11 @@ private end def current_year - FormHandler.instance.forms["current_sales"].start_date.year + FormHandler.instance.current_collection_start_year end - def in_crossover_period? - return true if FeatureToggle.force_crossover? + def have_choice_of_year? + return true if FeatureToggle.allow_future_form_use? FormHandler.instance.sales_in_crossover_period? end diff --git a/app/models/form_handler.rb b/app/models/form_handler.rb index 32968fa53..3625dc04b 100644 --- a/app/models/form_handler.rb +++ b/app/models/form_handler.rb @@ -32,10 +32,22 @@ class FormHandler forms["previous_lettings"] end + def next_lettings_form + forms["next_lettings"] + end + def current_sales_form forms["current_sales"] end + def previous_sales_form + forms["previous_sales"] + end + + def next_sales_form + forms["next_sales"] + end + def sales_forms @sales_forms ||= { "current_sales" => Form.new(nil, current_collection_start_year, SALES_SECTIONS, "sales"), diff --git a/app/models/forms/bulk_upload_lettings/prepare_your_file.rb b/app/models/forms/bulk_upload_lettings/prepare_your_file.rb index a2dfcd8e4..b5069d908 100644 --- a/app/models/forms/bulk_upload_lettings/prepare_your_file.rb +++ b/app/models/forms/bulk_upload_lettings/prepare_your_file.rb @@ -18,7 +18,7 @@ module Forms end def back_path - if in_crossover_period? + if have_choice_of_year? Rails.application.routes.url_helpers.bulk_upload_lettings_log_path(id: "year", form: { year: }) else Rails.application.routes.url_helpers.lettings_logs_path @@ -65,8 +65,8 @@ module Forms private - def in_crossover_period? - return true if FeatureToggle.force_crossover? + def have_choice_of_year? + return true if FeatureToggle.allow_future_form_use? FormHandler.instance.lettings_in_crossover_period? end diff --git a/app/models/forms/bulk_upload_lettings/year.rb b/app/models/forms/bulk_upload_lettings/year.rb index bbd424dfe..e199559fa 100644 --- a/app/models/forms/bulk_upload_lettings/year.rb +++ b/app/models/forms/bulk_upload_lettings/year.rb @@ -36,8 +36,9 @@ module Forms def possible_years [ FormHandler.instance.lettings_forms["current_lettings"].start_date.year, - FormHandler.instance.lettings_forms["previous_lettings"].start_date.year, - ] + (FormHandler.instance.previous_lettings_form.start_date.year if FormHandler.instance.lettings_in_crossover_period?), + (FormHandler.instance.next_lettings_form.start_date.year if FeatureToggle.allow_future_form_use?), + ].compact end end end diff --git a/app/models/forms/bulk_upload_sales/prepare_your_file.rb b/app/models/forms/bulk_upload_sales/prepare_your_file.rb index f72e41d55..387f6239f 100644 --- a/app/models/forms/bulk_upload_sales/prepare_your_file.rb +++ b/app/models/forms/bulk_upload_sales/prepare_your_file.rb @@ -17,7 +17,7 @@ module Forms end def back_path - if in_crossover_period? + if have_choice_of_year? Rails.application.routes.url_helpers.bulk_upload_sales_log_path(id: "year", form: { year: }) else Rails.application.routes.url_helpers.sales_logs_path @@ -63,8 +63,8 @@ module Forms private - def in_crossover_period? - return true if FeatureToggle.force_crossover? + def have_choice_of_year? + return true if FeatureToggle.allow_future_form_use? FormHandler.instance.sales_in_crossover_period? end diff --git a/app/models/forms/bulk_upload_sales/year.rb b/app/models/forms/bulk_upload_sales/year.rb index 86b8967b7..85959c4e5 100644 --- a/app/models/forms/bulk_upload_sales/year.rb +++ b/app/models/forms/bulk_upload_sales/year.rb @@ -34,7 +34,11 @@ module Forms private def possible_years - [FormHandler.instance.sales_forms["current_sales"].start_date.year, FormHandler.instance.sales_forms["previous_sales"].start_date.year] + [ + FormHandler.instance.current_sales_form.start_date.year, + (FormHandler.instance.previous_sales_form.start_date.year if FormHandler.instance.sales_in_crossover_period?), + (FormHandler.instance.next_sales_form.start_date.year if FeatureToggle.allow_future_form_use?), + ].compact end end end diff --git a/app/models/validations/date_validations.rb b/app/models/validations/date_validations.rb index 47c5d9638..dce5c1ef0 100644 --- a/app/models/validations/date_validations.rb +++ b/app/models/validations/date_validations.rb @@ -34,10 +34,6 @@ module Validations::DateValidations def validate_startdate(record) return unless record.startdate && date_valid?("startdate", record) - if FeatureToggle.startdate_two_week_validation_enabled? && record.startdate > Time.zone.today + 14.days - record.errors.add :startdate, I18n.t("validations.setup.startdate.later_than_14_days_after") - end - if record["voiddate"].present? && record.startdate < record["voiddate"] record.errors.add :startdate, I18n.t("validations.setup.startdate.after_void_date") end diff --git a/app/models/validations/sales/setup_validations.rb b/app/models/validations/sales/setup_validations.rb index d52af8f9b..e32fa70a1 100644 --- a/app/models/validations/sales/setup_validations.rb +++ b/app/models/validations/sales/setup_validations.rb @@ -3,7 +3,7 @@ module Validations::Sales::SetupValidations include CollectionTimeHelper def validate_saledate_collection_year(record) - return unless record.saledate && date_valid?("saledate", record) && FeatureToggle.saledate_collection_window_validation_enabled? + return unless record.saledate && date_valid?("saledate", record) && !FeatureToggle.allow_future_form_use? first_collection_start_date = if record.saledate_was.present? editable_collection_start_date @@ -17,7 +17,7 @@ module Validations::Sales::SetupValidations end def validate_saledate_two_weeks(record) - return unless record.saledate && date_valid?("saledate", record) && FeatureToggle.saledate_two_week_validation_enabled? + return unless record.saledate && date_valid?("saledate", record) && !FeatureToggle.allow_future_form_use? if record.saledate > Time.zone.today + 14.days record.errors.add :saledate, I18n.t("validations.setup.saledate.later_than_14_days_after") diff --git a/app/models/validations/setup_validations.rb b/app/models/validations/setup_validations.rb index 79a5d5c7a..1967ee80f 100644 --- a/app/models/validations/setup_validations.rb +++ b/app/models/validations/setup_validations.rb @@ -3,7 +3,7 @@ module Validations::SetupValidations include CollectionTimeHelper def validate_startdate_setup(record) - return unless record.startdate && date_valid?("startdate", record) && FeatureToggle.startdate_collection_window_validation_enabled? + return unless record.startdate && date_valid?("startdate", record) && !FeatureToggle.allow_future_form_use? first_collection_start_date = if record.startdate_was.present? editable_collection_start_date @@ -14,6 +14,10 @@ module Validations::SetupValidations unless record.startdate.between?(first_collection_start_date, current_collection_end_date) record.errors.add :startdate, startdate_validation_error_message end + + if record.startdate > Time.zone.today + 14.days + record.errors.add :startdate, I18n.t("validations.setup.startdate.later_than_14_days_after") + end end def validate_organisation(record) diff --git a/app/services/feature_toggle.rb b/app/services/feature_toggle.rb index e00e89b90..22d43f513 100644 --- a/app/services/feature_toggle.rb +++ b/app/services/feature_toggle.rb @@ -1,19 +1,6 @@ class FeatureToggle - # Disable check on preview apps to allow for testing of future forms - def self.saledate_collection_window_validation_enabled? - Rails.env.production? || Rails.env.test? || Rails.env.staging? - end - - def self.startdate_collection_window_validation_enabled? - Rails.env.production? || Rails.env.test? || Rails.env.staging? - end - - def self.startdate_two_week_validation_enabled? - Rails.env.production? || Rails.env.test? || Rails.env.staging? - end - - def self.saledate_two_week_validation_enabled? - Rails.env.production? || Rails.env.test? || Rails.env.staging? + def self.allow_future_form_use? + Rails.env.development? || Rails.env.review? || Rails.env.staging? end def self.bulk_upload_duplicate_log_check_enabled? @@ -24,10 +11,6 @@ class FeatureToggle !Rails.env.development? end - def self.force_crossover? - false - end - def self.deduplication_flow_enabled? true end diff --git a/spec/features/bulk_upload_lettings_logs_spec.rb b/spec/features/bulk_upload_lettings_logs_spec.rb index ac05d7dec..222edaa05 100644 --- a/spec/features/bulk_upload_lettings_logs_spec.rb +++ b/spec/features/bulk_upload_lettings_logs_spec.rb @@ -22,94 +22,108 @@ RSpec.describe "Bulk upload lettings log" do # rubocop:disable RSpec/AnyInstance context "when during crossover period" do before do - allow(FeatureToggle).to receive(:force_crossover?).and_return(true) + Timecop.freeze(2023, 6, 1) + end + + after do + Timecop.return end it "shows journey with year option" do - Timecop.freeze(2023, 6, 1) do - visit("/lettings-logs") - expect(page).to have_link("Upload lettings logs in bulk") - click_link("Upload lettings logs in bulk") + visit("/lettings-logs") + expect(page).to have_link("Upload lettings logs in bulk") + click_link("Upload lettings logs in bulk") - expect(page).to have_content("Which year") - click_button("Continue") + expect(page).to have_content("Which year") + click_button("Continue") - expect(page).to have_content("You must select a collection period to upload for") - choose("2023/2024") - click_button("Continue") + expect(page).to have_content("You must select a collection period to upload for") + choose("2023/2024") + click_button("Continue") - click_link("Back") + click_link("Back") - expect(page.find_field("form-year-2023-field")).to be_checked - click_button("Continue") + expect(page.find_field("form-year-2023-field")).to be_checked + click_button("Continue") - expect(page).to have_content("Upload lettings logs in bulk (2023/24)") - click_button("Continue") + expect(page).to have_content("Upload lettings logs in bulk (2023/24)") + click_button("Continue") - expect(page).not_to have_content("What is the needs type?") + expect(page).not_to have_content("What is the needs type?") - expect(page).to have_content("Upload lettings logs in bulk (2023/24)") - expect(page).to have_content("Upload your file") - click_button("Upload") + expect(page).to have_content("Upload lettings logs in bulk (2023/24)") + expect(page).to have_content("Upload your file") + click_button("Upload") - allow_any_instance_of(Forms::BulkUploadLettings::UploadYourFile).to receive(:`).and_return("not a csv") + allow_any_instance_of(Forms::BulkUploadLettings::UploadYourFile).to receive(:`).and_return("not a csv") - expect(page).to have_content("Select which file to upload") - attach_file "file", file_fixture("2023_24_lettings_bulk_upload.xlsx") - click_button("Upload") + expect(page).to have_content("Select which file to upload") + attach_file "file", file_fixture("2023_24_lettings_bulk_upload.xlsx") + click_button("Upload") - allow_any_instance_of(Forms::BulkUploadLettings::UploadYourFile).to receive(:`).and_return("text/csv") + allow_any_instance_of(Forms::BulkUploadLettings::UploadYourFile).to receive(:`).and_return("text/csv") - expect(page).to have_content("Your file must be in CSV format") - attach_file "file", file_fixture("blank_bulk_upload_sales.csv") - expect { - click_button("Upload") - }.to change(BulkUpload, :count).by(1) + expect(page).to have_content("Your file must be in CSV format") + attach_file "file", file_fixture("blank_bulk_upload_sales.csv") + expect { + click_button("Upload") + }.to change(BulkUpload, :count).by(1) - expect(page).to have_content("Once this is done") - click_link("Back") + expect(page).to have_content("Once this is done") + click_link("Back") - expect(page).to have_content("Upload lettings logs in bulk") - end + expect(page).to have_content("Upload lettings logs in bulk") end end # rubocop:enable RSpec/AnyInstance context "when not it crossover period" do + before do + Timecop.freeze(2024, 1, 1) + end + + after do + Timecop.return + end + it "shows journey with year option" do - Timecop.freeze(2024, 1, 1) do - visit("/lettings-logs") - expect(page).to have_link("Upload lettings logs in bulk") - click_link("Upload lettings logs in bulk") + visit("/lettings-logs") + expect(page).to have_link("Upload lettings logs in bulk") + click_link("Upload lettings logs in bulk") - expect(page).to have_content("Upload lettings logs in bulk (2023/24)") - click_button("Continue") + expect(page).to have_content("Upload lettings logs in bulk (2023/24)") + click_button("Continue") - expect(page).to have_content("Upload your file") - end + expect(page).to have_content("Upload your file") end end context "when the collection year isn't 22/23" do + before do + Timecop.freeze(2024, 1, 1) + end + + after do + Timecop.return + end + it "shows journey without the needstype" do - Timecop.freeze(2024, 1, 1) do - visit("/lettings-logs") - expect(page).to have_link("Upload lettings logs in bulk") - click_link("Upload lettings logs in bulk") + visit("/lettings-logs") + expect(page).to have_link("Upload lettings logs in bulk") + click_link("Upload lettings logs in bulk") - expect(page).to have_content("Prepare your file") - click_button("Continue") + expect(page).to have_content("Prepare your file") + click_button("Continue") - click_link("Back") + click_link("Back") - expect(page).to have_content("Prepare your file") - click_button("Continue") + expect(page).to have_content("Prepare your file") + click_button("Continue") - expect(page).to have_content("Upload lettings logs in bulk (2023/24)") + expect(page).to have_content("Upload lettings logs in bulk (2023/24)") - expect(page).to have_content("Upload your file") - click_button("Upload") - end + expect(page).to have_content("Upload your file") + click_button("Upload") end end end diff --git a/spec/features/bulk_upload_sales_logs_spec.rb b/spec/features/bulk_upload_sales_logs_spec.rb index 57d99a9e8..e47273cdc 100644 --- a/spec/features/bulk_upload_sales_logs_spec.rb +++ b/spec/features/bulk_upload_sales_logs_spec.rb @@ -22,68 +22,76 @@ RSpec.describe "Bulk upload sales log" do # rubocop:disable RSpec/AnyInstance context "when during crossover period" do before do - allow(FeatureToggle).to receive(:force_crossover?).and_return(true) + Timecop.freeze(2023, 5, 1) + end + + after do + Timecop.return end it "shows journey with year option" do - Timecop.freeze(2023, 5, 1) do - visit("/sales-logs") - expect(page).to have_link("Upload sales logs in bulk") - click_link("Upload sales logs in bulk") + visit("/sales-logs") + expect(page).to have_link("Upload sales logs in bulk") + click_link("Upload sales logs in bulk") - expect(page).to have_content("Which year") - click_button("Continue") + expect(page).to have_content("Which year") + click_button("Continue") - expect(page).to have_content("You must select a collection period to upload for") - choose("2023/2024") - click_button("Continue") + expect(page).to have_content("You must select a collection period to upload for") + choose("2023/2024") + click_button("Continue") - click_link("Back") + click_link("Back") - expect(page.find_field("form-year-2023-field")).to be_checked - click_button("Continue") + expect(page.find_field("form-year-2023-field")).to be_checked + click_button("Continue") - expect(page).to have_content("Upload sales logs in bulk (2023/24)") - click_button("Continue") + expect(page).to have_content("Upload sales logs in bulk (2023/24)") + click_button("Continue") - expect(page).to have_content("Upload your file") - click_button("Upload") + expect(page).to have_content("Upload your file") + click_button("Upload") - allow_any_instance_of(Forms::BulkUploadSales::UploadYourFile).to receive(:`).and_return("not a csv") + allow_any_instance_of(Forms::BulkUploadSales::UploadYourFile).to receive(:`).and_return("not a csv") - expect(page).to have_content("Select which file to upload") - attach_file "file", file_fixture("2023_24_lettings_bulk_upload.xlsx") - click_button("Upload") + expect(page).to have_content("Select which file to upload") + attach_file "file", file_fixture("2023_24_lettings_bulk_upload.xlsx") + click_button("Upload") - allow_any_instance_of(Forms::BulkUploadSales::UploadYourFile).to receive(:`).and_return("text/csv") + allow_any_instance_of(Forms::BulkUploadSales::UploadYourFile).to receive(:`).and_return("text/csv") - expect(page).to have_content("Your file must be in CSV format") - attach_file "file", file_fixture("blank_bulk_upload_sales.csv") - expect { - click_button("Upload") - }.to change(BulkUpload, :count).by(1) + expect(page).to have_content("Your file must be in CSV format") + attach_file "file", file_fixture("blank_bulk_upload_sales.csv") + expect { + click_button("Upload") + }.to change(BulkUpload, :count).by(1) - expect(page).to have_content("Once this is done") - click_link("Back") + expect(page).to have_content("Once this is done") + click_link("Back") - expect(page).to have_content("Upload sales logs in bulk") - end + expect(page).to have_content("Upload sales logs in bulk") end end # rubocop:enable RSpec/AnyInstance - context "when not it crossover period" do - xit "shows journey with year option" do - Timecop.freeze(2023, 10, 1) do - visit("/sales-logs") - expect(page).to have_link("Upload sales logs in bulk") - click_link("Upload sales logs in bulk") + context "when not in crossover period" do + before do + Timecop.freeze(2024, 2, 1) + end + + after do + Timecop.return + end + + it "shows journey without year option" do + visit("/sales-logs") + expect(page).to have_link("Upload sales logs in bulk") + click_link("Upload sales logs in bulk") - expect(page).to have_content("Upload sales logs in bulk (2023/24)") - click_button("Continue") + expect(page).to have_content("Upload sales logs in bulk (2023/24)") + click_button("Continue") - expect(page).to have_content("Upload your file") - end + expect(page).to have_content("Upload your file") end end end diff --git a/spec/models/forms/bulk_upload_lettings/year_spec.rb b/spec/models/forms/bulk_upload_lettings/year_spec.rb index ebb65e517..241a0a918 100644 --- a/spec/models/forms/bulk_upload_lettings/year_spec.rb +++ b/spec/models/forms/bulk_upload_lettings/year_spec.rb @@ -4,9 +4,50 @@ RSpec.describe Forms::BulkUploadLettings::Year do subject(:form) { described_class.new } describe "#options" do - it "returns correct years" do - expect(form.options.map(&:id)).to eql([2023, 2022]) - expect(form.options.map(&:name)).to eql(%w[2023/2024 2022/2023]) + context "when in a crossover period" do + before do + Timecop.freeze(2024, 4, 1) + end + + after do + Timecop.return + end + + it "returns current and previous years" do + expect(form.options.map(&:id)).to eql([2024, 2023]) + expect(form.options.map(&:name)).to eql(%w[2024/2025 2023/2024]) + end + end + + context "when not in a crossover period" do + before do + Timecop.freeze(2024, 3, 1) + end + + after do + Timecop.return + end + + it "returns the current year" do + expect(form.options.map(&:id)).to eql([2023]) + expect(form.options.map(&:name)).to eql(%w[2023/2024]) + end + end + + context "when allow_future_form_use is toggled on" do + before do + Timecop.freeze(2024, 3, 1) + allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true) + end + + after do + Timecop.return + end + + it "returns current and next years" do + expect(form.options.map(&:id)).to eql([2023, 2024]) + expect(form.options.map(&:name)).to eql(%w[2023/2024 2024/2025]) + end end end end diff --git a/spec/models/forms/bulk_upload_sales/year_spec.rb b/spec/models/forms/bulk_upload_sales/year_spec.rb index e8f2a04e5..654a5760e 100644 --- a/spec/models/forms/bulk_upload_sales/year_spec.rb +++ b/spec/models/forms/bulk_upload_sales/year_spec.rb @@ -3,16 +3,51 @@ require "rails_helper" RSpec.describe Forms::BulkUploadSales::Year do subject(:form) { described_class.new } - around do |example| - Timecop.freeze(Time.zone.now) do - example.run + describe "#options" do + context "when in a crossover period" do + before do + Timecop.freeze(2024, 4, 1) + end + + after do + Timecop.return + end + + it "returns current and previous years" do + expect(form.options.map(&:id)).to eql([2024, 2023]) + expect(form.options.map(&:name)).to eql(%w[2024/2025 2023/2024]) + end end - end - describe "#options" do - it "returns correct years" do - expect(form.options.map(&:id)).to eql([2023, 2022]) - expect(form.options.map(&:name)).to eql(%w[2023/2024 2022/2023]) + context "when not in a crossover period" do + before do + Timecop.freeze(2024, 3, 1) + end + + after do + Timecop.return + end + + it "returns the current year" do + expect(form.options.map(&:id)).to eql([2023]) + expect(form.options.map(&:name)).to eql(%w[2023/2024]) + end + end + + context "when allow_future_form_use is toggled on" do + before do + Timecop.freeze(2024, 3, 1) + allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true) + end + + after do + Timecop.return + end + + it "returns current and next years" do + expect(form.options.map(&:id)).to eql([2023, 2024]) + expect(form.options.map(&:name)).to eql(%w[2023/2024 2024/2025]) + end end end end 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))