diff --git a/app/helpers/collection_time_helper.rb b/app/helpers/collection_time_helper.rb index acd9cf7a5..a58bb8516 100644 --- a/app/helpers/collection_time_helper.rb +++ b/app/helpers/collection_time_helper.rb @@ -30,7 +30,7 @@ module CollectionTimeHelper end def current_collection_after_crossover_start_date - Form::DEADLINES[current_collection_start_year][:edit_end_date] + 1.day + Form::DEADLINES[previous_collection_start_year][:edit_end_date] + 1.day end def collection_end_date(date) diff --git a/spec/models/location_spec.rb b/spec/models/location_spec.rb index 9f1b57671..319f62d33 100644 --- a/spec/models/location_spec.rb +++ b/spec/models/location_spec.rb @@ -1,6 +1,8 @@ require "rails_helper" RSpec.describe Location, type: :model do + include CollectionTimeHelper + before do LocalAuthorityLink.create(local_authority_id: LocalAuthority.find_by(code: "E07000030").id, linked_local_authority_id: LocalAuthority.find_by(code: "E06000063").id) end @@ -1184,35 +1186,19 @@ RSpec.describe Location, type: :model do end context "when there is no start date" do - context "and the location was created at the start of the 2022/23 collection window" do - let(:location) { FactoryBot.build(:location, created_at: Time.zone.local(2022, 4, 6), startdate: nil) } - - it "returns the beginning of 21/22 collection window" do - expect(location.available_from).to eq(Time.zone.local(2021, 4, 1)) - end - end - - context "and the location was created at the end of the 2022/23 collection window" do - let(:location) { FactoryBot.build(:location, created_at: Time.zone.local(2023, 2, 6), startdate: nil) } - - it "returns the beginning of 22/23 collection window" do - expect(location.available_from).to eq(Time.zone.local(2022, 4, 1)) - end - end - - context "and the location was created at the start of the 2021/22 collection window" do - let(:location) { FactoryBot.build(:location, created_at: Time.zone.local(2021, 4, 6), startdate: nil) } + context "and the location was created at the start of the collection window" do + let(:location) { FactoryBot.build(:location, created_at: current_collection_start_date, startdate: nil) } - it "returns the beginning of 20/21 collection window" do - expect(location.available_from).to eq(Time.zone.local(2020, 4, 1)) + it "returns the beginning of previous collection window" do + expect(location.available_from).to eq(previous_collection_start_date) end end - context "and the location was created at the end of the 2021/22 collection window" do - let(:location) { FactoryBot.build(:location, created_at: Time.zone.local(2022, 2, 6), startdate: nil) } + context "and the location was created after the crossover date" do + let(:location) { FactoryBot.build(:location, created_at: current_collection_after_crossover_start_date, startdate: nil) } - it "returns the beginning of 20/21 collection window" do - expect(location.available_from).to eq(Time.zone.local(2020, 4, 1)) + it "returns the beginning of current collection window" do + expect(location.available_from).to eq(current_collection_start_date) end end end