Module: GdsApi::TestHelpers::Calendars

Defined in:
lib/gds_api/test_helpers/calendars.rb

Constant Summary collapse

CALENDARS_ENDPOINT =
Plek.current.find('calendars')

Instance Method Summary collapse

Instance Method Details

#calendars_endpoint(in_division: nil) ⇒ Object


6
7
8
9
10
# File 'lib/gds_api/test_helpers/calendars.rb', line 6

def calendars_endpoint(in_division: nil)
  endpoint = "#{CALENDARS_ENDPOINT}/bank-holidays"
  endpoint += "/#{in_division}" unless in_division.nil?
  endpoint + '.json'
end

#calendars_has_a_bank_holiday_on(date, in_division: nil) ⇒ Object


53
54
55
# File 'lib/gds_api/test_helpers/calendars.rb', line 53

def calendars_has_a_bank_holiday_on(date, in_division: nil)
  calendars_has_bank_holidays_on([date], in_division: in_division)
end

#calendars_has_bank_holidays_on(dates, in_division: nil) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/gds_api/test_helpers/calendars.rb', line 16

def calendars_has_bank_holidays_on(dates, in_division: nil)
  events = dates.map.with_index do |date, idx|
    {
      title: "Caturday #{idx}!",
      date: date.to_date.iso8601,
      notes: "Y'know, for cats!",
      bunting: true
    }
  end

  response =
    if in_division.nil?
      {
        'england-and-wales' => {
          division: 'england-and-wales',
          events: events
        },
        'scotland' => {
          division: 'scotland',
          events: events
        },
        'northern-ireland' => {
          division: 'northern-ireland',
          events: events
        }
      }
    else
      {
        division: in_division,
        events: events
      }
    end

  stub_request(:get, calendars_endpoint(in_division: in_division))
    .to_return(body: response.to_json, status: 200)
end

#calendars_has_no_bank_holidays(in_division: nil) ⇒ Object


12
13
14
# File 'lib/gds_api/test_helpers/calendars.rb', line 12

def calendars_has_no_bank_holidays(in_division: nil)
  calendars_has_bank_holidays_on([], in_division: in_division)
end