Browse Source

CLDC-3501: Reinstate skipped setup test

add some new time helpers to do with crossover periods
pull/3127/head
Samuel Young 3 weeks ago
parent
commit
afa56063b4
  1. 8
      app/helpers/collection_time_helper.rb
  2. 20
      spec/models/validations/setup_validations_spec.rb

8
app/helpers/collection_time_helper.rb

@ -58,6 +58,14 @@ module CollectionTimeHelper
current_collection_start_year - 2 current_collection_start_year - 2
end end
def previous_collection_new_logs_end_date
FormHandler.instance.lettings_form_for_start_year(previous_collection_start_year).new_logs_end_date
end
def previous_collection_edit_end_date
FormHandler.instance.lettings_form_for_start_year(previous_collection_start_year).edit_end_date
end
def generate_different_date_within_collection_year(date, start_date_override: nil, end_date_override: nil) def generate_different_date_within_collection_year(date, start_date_override: nil, end_date_override: nil)
start_date = [start_date_override&.to_date, collection_start_date(date).to_date].compact.max.to_date start_date = [start_date_override&.to_date, collection_start_date(date).to_date].compact.max.to_date
end_date = [end_date_override&.to_date, collection_end_date(date).to_date].compact.min.to_date end_date = [end_date_override&.to_date, collection_end_date(date).to_date].compact.min.to_date

20
spec/models/validations/setup_validations_spec.rb

@ -1,6 +1,8 @@
require "rails_helper" require "rails_helper"
RSpec.describe Validations::SetupValidations do RSpec.describe Validations::SetupValidations do
include CollectionTimeHelper
subject(:setup_validator) { setup_validator_class.new } subject(:setup_validator) { setup_validator_class.new }
let(:setup_validator_class) { Class.new { include Validations::SetupValidations } } let(:setup_validator_class) { Class.new { include Validations::SetupValidations } }
@ -96,24 +98,28 @@ RSpec.describe Validations::SetupValidations do
context "when after the new logs end date but before edit end date for the previous period" do context "when after the new logs end date but before edit end date for the previous period" do
before do before do
allow(Time).to receive(:now).and_return(Time.zone.local(2024, 1, 8)) Timecop.freeze(previous_collection_edit_end_date)
end
after do
Timecop.return
end end
it "cannot create new logs for the previous collection year" do it "cannot create new logs for the previous collection year" do
record.update!(startdate: nil) record.update!(startdate: nil)
record.startdate = Time.zone.local(2023, 1, 1) record.startdate = previous_collection_start_date
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record) setup_validator.validate_merged_organisations_start_date(record)
expect(record.errors["startdate"]).to include(match "Enter a date within the 2023 to 2024 collection year, which is between 1st April 2023 and 31st March 2024") expect(record.errors["startdate"]).to include(match "Enter a date within the #{current_collection_start_year} to #{next_collection_start_year} collection year, which is between 1st April #{current_collection_start_year} and 31st March #{next_collection_start_year}")
end end
xit "can edit already created logs for the previous collection year" do it "can edit already created logs for the previous collection year" do
record.startdate = Time.zone.local(2023, 1, 2) record.startdate = previous_collection_start_date + 1.day
record.save!(validate: false) record.save!(validate: false)
record.startdate = Time.zone.local(2023, 1, 1) record.startdate = previous_collection_start_date
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record) setup_validator.validate_merged_organisations_start_date(record)
expect(record.errors["startdate"]).not_to include(match "Enter a date within the 2023 to 2024 collection year, which is between 1st April 2023 and 31st March 2024") expect(record.errors["startdate"]).not_to include(match "Enter a date within the #{current_collection_start_year} to #{next_collection_start_year} collection year, which is between 1st April #{current_collection_start_year} and 31st March #{next_collection_start_year}")
end end
end end

Loading…
Cancel
Save