Browse Source

create method to test whether we are currently in the crossover period and associated tests

pull/1396/head
Arthur Campbell 3 years ago
parent
commit
5e8bb3e27a
  1. 12
      app/helpers/collection_time_helper.rb
  2. 60
      spec/helpers/collection_time_helper_spec.rb

12
app/helpers/collection_time_helper.rb

@ -44,4 +44,16 @@ module CollectionTimeHelper
def previous_collection_start_date
current_collection_start_date - 1.year
end
def currently_crossover_period?
# generally the crossover period ends on the first Friday in June, but there may be arbitrary exceptions such as in 2023
today = Time.zone.today
if today.year == 2023
today.between?(Time.zone.local(2023, 4, 1).to_date, Time.zone.local(2023, 6, 9).to_date)
else
crossover_end_date = Time.zone.local(today.year, 6, 1).to_date
crossover_end_date += 1 until crossover_end_date.friday?
today.between?(Time.zone.local(today.year, 4, 1).to_date, crossover_end_date)
end
end
end

60
spec/helpers/collection_time_helper_spec.rb

@ -109,4 +109,64 @@ RSpec.describe CollectionTimeHelper do
end
end
end
describe "#currently_crossover_period?", focus: true do
subject(:result) { currently_crossover_period? }
around do |example|
Timecop.freeze(now) do
example.run
end
end
context "when it is January" do
let(:now) { Time.utc(2022, 1, 3) }
it "returns false" do
expect(result).to be false
end
end
context "when it is December" do
let(:now) { Time.utc(2020, 12, 3) }
it "returns false" do
expect(result).to be false
end
end
context "when it is April" do
let(:now) { Time.utc(2023, 4, 3) }
it "returns true" do
expect(result).to be true
end
end
context "when it is June" do
context "and it is the first Friday" do
let(:now) { Time.utc(2024, 6, 7) }
it "returns true" do
expect(result).to be true
end
end
context "and it is after the first Friday" do
let(:now) { Time.utc(2024, 6, 8) }
it "returns false" do
expect(result).to be false
end
end
context "and it is 2023, after the first Friday, but before the arbitrary crossover period end" do
let(:now) { Time.utc(2023, 6, 7) }
it "returns true" do
expect(result).to be true
end
end
end
end
end

Loading…
Cancel
Save