Skip to content

Commit

Permalink
Can cancel dates for open bureau in config file
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuelfaure committed Nov 12, 2024
1 parent 717e14b commit 8682cf8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/services/open_bureau_date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ class OpenBureauDate
include DateAndTime::Calculations

def next_date
date = next_theoretical_date

date = date.next_occurring(:tuesday).next_occurring(:tuesday) while cancelled_dates.include?(date)

date
end

private

def next_theoretical_date
return Time.zone.today if open_bureau_today?

next_tuesday = Time.zone.today.next_occurring(:tuesday)
Expand All @@ -11,7 +21,9 @@ def next_date
next_tuesday.next_occurring(:tuesday)
end

private
def cancelled_dates
YAML.load_file(Rails.root.join('config/cancelled_open_bureau_dates.yml')).map(&:to_date)
end

def open_bureau_today?
today = Time.zone.today
Expand Down
2 changes: 2 additions & 0 deletions config/cancelled_open_bureau_dates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- '2024-11-19'
- '2024-12-3'
11 changes: 11 additions & 0 deletions spec/services/open_bureau_date_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,16 @@
it { is_expected.to eq(next_date.to_s) }
end
end

describe 'when it is a cancelled date' do
before do
Timecop.freeze(Date.new(2024, 11, 12))
allow(YAML).to receive(:load_file).and_return(['2024-11-19'])
end

let(:next_date) { Date.new(2024, 12, 3) }

it { is_expected.to eq(next_date.to_s) }
end
end
end

0 comments on commit 8682cf8

Please sign in to comment.