Sha256: 20b186d5dab2c8776cb7c3c9bc27db569838af89152da7f7ce49331a51c0f1c5

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

# Read fixtures from disk
module ApiFixturesHelper
  private

  def all_cinemas_plist
    read_fixture('api/all_cinemas')
  end

  def app_init_plist
    read_fixture('api/app_init')
  end

  def film_times_plist(cinema_id, film_id)
    read_fixture("api/film_times/#{cinema_id}-#{film_id}")
  end

  def film_times_plist_random
    read_fixture("api/film_times/#{film_times_plist_names(71).sample}")
  end

  def film_times_plist_names(cinema_id)
    Dir.entries(File.expand_path('../../fixtures/api/film_times', __FILE__))
       .reject { |filename| !filename.match(/\A#{cinema_id}-/) }
       .map { |filename| filename.gsub('.plist', '') }
  end

  def parse(content)
    plist = CFPropertyList::List.new(data: content).value
    CFPropertyList.native_types(plist).fetch('data', {})
  end

  def read_fixture(filepath)
    File.read(File.expand_path("../../fixtures/#{filepath}.plist", __FILE__))
  end

  def stub_post(site_path, request_body, response_body)
    url      = "https://api.odeon.co.uk/2.1/api/#{site_path}"
    response = { status: 200, body: response_body, headers: {} }
    stub_request(:post, url).with(body: request_body).to_return(response)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
odeon_uk-4.0.1 test/support/api_fixtures_helper.rb
odeon_uk-4.0.0 test/support/api_fixtures_helper.rb