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_artefact_registration(slug, request_details = nil, custom_matcher = false) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/gds_api/test_helpers/panopticon.rb', line 43

def stub_artefact_registration(slug, request_details = nil, custom_matcher = false)
  stub = stub_http_request(:put, "#{PANOPTICON_ENDPOINT}/artefacts/#{slug}.json")

  if request_details
    request_details = request_details.to_json unless custom_matcher
    stub.with(:body => request_details) 
  end

  stub.to_return(:status => 201)
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

#stub_panopticon_tag_creation(attributes) ⇒ Object



54
55
56
57
58
59
# File 'lib/gds_api/test_helpers/panopticon.rb', line 54

def stub_panopticon_tag_creation(attributes)
  url = "#{PANOPTICON_ENDPOINT}/tags.json"
  stub_request(:post, url)
          .with(body: attributes.to_json)
          .to_return(status: 201, body: attributes.to_json)
end

#stub_panopticon_tag_publish(tag_type, tag_id) ⇒ Object



68
69
70
71
72
73
# File 'lib/gds_api/test_helpers/panopticon.rb', line 68

def stub_panopticon_tag_publish(tag_type, tag_id)
  url = "#{PANOPTICON_ENDPOINT}/tags/#{tag_type}/#{tag_id}/publish.json"
  stub_request(:post, url)
          .with(body: {}.to_json)
          .to_return(status: 200)
end

#stub_panopticon_tag_update(tag_type, tag_id, attributes) ⇒ Object



61
62
63
64
65
66
# File 'lib/gds_api/test_helpers/panopticon.rb', line 61

def stub_panopticon_tag_update(tag_type, tag_id, attributes)
  url = "#{PANOPTICON_ENDPOINT}/tags/#{tag_type}/#{tag_id}.json"
  stub_request(:put, url)
          .with(body: attributes.to_json)
          .to_return(status: 200)
end