Module: GdsApi::TestHelpers::Panopticon
- Defined in:
- lib/gds_api/test_helpers/panopticon.rb
Constant Summary collapse
- PANOPTICON_ENDPOINT =
'https://panopticon.test.alphagov.co.uk'
Instance Method Summary collapse
- #panopticon_has_metadata(metadata) ⇒ Object
- #panopticon_has_no_metadata_for(slug) ⇒ Object
- #stringify_hash_keys(input_hash) ⇒ Object
- #stub_panopticon_default_artefact ⇒ Object
Instance Method Details
#panopticon_has_metadata(metadata) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/gds_api/test_helpers/panopticon.rb', line 15 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
29 30 31 32 |
# File 'lib/gds_api/test_helpers/panopticon.rb', line 29 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
8 9 10 11 12 13 |
# File 'lib/gds_api/test_helpers/panopticon.rb', line 8 def stringify_hash_keys(input_hash) input_hash.inject({}) do |, (key, value)| [key.to_s] = value end end |
#stub_panopticon_default_artefact ⇒ Object
34 35 36 37 38 39 |
# File 'lib/gds_api/test_helpers/panopticon.rb', line 34 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 |