Module: GdsApi::TestHelpers::Panopticon

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

Constant Summary collapse

PANOPTICON_ENDPOINT =

Generally true. If you are initializing the client differently, you could redefine/override the constant or stub directly.

Plek.current.find('panopticon')

Instance Method Summary collapse

Instance Method Details

#panopticon_has_metadata(metadata) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gds_api/test_helpers/panopticon.rb', line 17

def ()
   = stringify_hash_keys()

  json = JSON.dump()

  urls = []
  urls << "#{PANOPTICON_ENDPOINT}/artefacts/#{['id']}.json" if ['id']
  urls << "#{PANOPTICON_ENDPOINT}/artefacts/#{['slug']}.json" if ['slug']

  urls.each { |url| stub_request(:get, url).to_return(:status => 200, :body => json, :headers => {}) }

  return urls.first
end

#panopticon_has_no_metadata_for(slug) ⇒ Object



31
32
33
34
# File 'lib/gds_api/test_helpers/panopticon.rb', line 31

def (slug)
  url = "#{PANOPTICON_ENDPOINT}/artefacts/#{slug}.json"
  stub_request(:get, url).to_return(:status => 404, :body => "", :headers => {})
end

#stringify_hash_keys(input_hash) ⇒ Object



10
11
12
13
14
15
# File 'lib/gds_api/test_helpers/panopticon.rb', line 10

def stringify_hash_keys(input_hash)
  input_hash.inject({}) do |options, (key, value)|
    options[key.to_s] = value
    options
  end
end

#stub_panopticon_default_artefactObject



36
37
38
39
40
41
# File 'lib/gds_api/test_helpers/panopticon.rb', line 36

def stub_panopticon_default_artefact
  stub_request(:get, %r{\A#{PANOPTICON_ENDPOINT}/artefacts}).to_return { |request|
    # return a response with only a slug, and set that slug to match the requested artefact slug
    {:body => JSON.dump("slug" => request.uri.path.split('/').last.chomp('.json'))}
  }
end