Module: GdsApi::TestHelpers::Publisher

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

Constant Summary collapse

PUBLISHER_ENDPOINT =

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

Plek.current.find("publisher")

Instance Method Summary collapse

Instance Method Details

#council_exists_for_slug(input_details, output_details) ⇒ Object



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

def council_exists_for_slug(input_details, output_details)
  json = JSON.dump(output_details)
  slug = input_details.delete('slug')
  uri = "#{PUBLISHER_ENDPOINT}/local_transactions/#{slug}/verify_snac.json"
  stub_request(:post, uri).with(:body => JSON.dump(input_details),
    :headers => GdsApi::JsonClient::DEFAULT_REQUEST_HEADERS).
    to_return(:body => json, :status => 200)
end

#no_council_for_slug(slug) ⇒ Object



43
44
45
46
# File 'lib/gds_api/test_helpers/publisher.rb', line 43

def no_council_for_slug(slug)
  uri = "#{PUBLISHER_ENDPOINT}/local_transactions/#{slug}.json"
  stub_request(:post, uri).to_return(:body => "", :status => 404)
end

#publication_does_not_exist(details) ⇒ Object



28
29
30
31
32
# File 'lib/gds_api/test_helpers/publisher.rb', line 28

def publication_does_not_exist(details)
  uri = "#{PUBLISHER_ENDPOINT}/publications/#{details['slug']}.json"
  stub_request(:get, uri).to_return(:body => 'Not Found', :status => 404)
  return uri
end

#publication_exists(details, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/gds_api/test_helpers/publisher.rb', line 10

def publication_exists(details, options = {})
  json = JSON.dump(details)
  uri = "#{PUBLISHER_ENDPOINT}/publications/#{details['slug']}.json"
  if options[:edition]
    uri += "?edition=#{options[:edition]}"
  end
  stub_request(:get, uri).to_return(:body => json, :status => 200)
  return uri
end

#publication_exists_for_snac(snac, details) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/gds_api/test_helpers/publisher.rb', line 20

def publication_exists_for_snac(snac, details)
  json = JSON.dump(details)
  uri = "#{PUBLISHER_ENDPOINT}/publications/#{details['slug']}.json"
  stub_request(:get, uri).to_return(:body => json, :status => 200)
  stub_request(:get, uri).with(:query => {:snac => snac.to_s}).to_return(:body => json, :status => 200)
  return uri
end