Module: GdsApi::TestHelpers::PublishingApi

Includes:
ContentItemHelpers, IntentHelpers
Defined in:
lib/gds_api/test_helpers/publishing_api.rb

Constant Summary collapse

PUBLISHING_API_ENDPOINT =
Plek.current.find('publishing-api')

Instance Method Summary collapse

Methods included from IntentHelpers

#intent_for_base_path

Methods included from ContentItemHelpers

#content_item_for_base_path, #titleize_base_path

Instance Method Details

#assert_publishing_api_put(url, attributes = {}, times = 1) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/gds_api/test_helpers/publishing_api.rb', line 54

def assert_publishing_api_put(url, attributes = {}, times = 1)
  if attributes.empty?
    assert_requested(:put, url, times: times)
  else
    assert_requested(:put, url, times: times) do |req|
      data = JSON.parse(req.body)
      attributes.to_a.all? do |key, value|
        data[key.to_s] == value
      end
    end
  end
end

#assert_publishing_api_put_intent(base_path, attributes = {}, times = 1) ⇒ Object



49
50
51
52
# File 'lib/gds_api/test_helpers/publishing_api.rb', line 49

def assert_publishing_api_put_intent(base_path, attributes = {}, times = 1)
  url = PUBLISHING_API_ENDPOINT + "/publish-intent" + base_path
  assert_publishing_api_put(url, attributes, times)
end

#assert_publishing_api_put_item(base_path, attributes = {}, times = 1) ⇒ Object



44
45
46
47
# File 'lib/gds_api/test_helpers/publishing_api.rb', line 44

def assert_publishing_api_put_item(base_path, attributes = {}, times = 1)
  url = PUBLISHING_API_ENDPOINT + "/content" + base_path
  assert_publishing_api_put(url, attributes, times)
end

#publishing_api_isnt_availableObject



67
68
69
# File 'lib/gds_api/test_helpers/publishing_api.rb', line 67

def publishing_api_isnt_available
  stub_request(:any, /#{PUBLISHING_API_ENDPOINT}\/.*/).to_return(:status => 503)
end

#stub_default_publishing_api_putObject



36
37
38
# File 'lib/gds_api/test_helpers/publishing_api.rb', line 36

def stub_default_publishing_api_put()
  stub_request(:put, %r{\A#{PUBLISHING_API_ENDPOINT}/content})
end

#stub_default_publishing_api_put_intentObject



40
41
42
# File 'lib/gds_api/test_helpers/publishing_api.rb', line 40

def stub_default_publishing_api_put_intent()
  stub_request(:put, %r{\A#{PUBLISHING_API_ENDPOINT}/publish-intent})
end

#stub_publishing_api_destroy_intent(base_path) ⇒ Object



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

def stub_publishing_api_destroy_intent(base_path)
  url = PUBLISHING_API_ENDPOINT + "/publish-intent" + base_path
  response_body = {base_path: base_path}.to_json
  stub_request(:delete, url).to_return(status: 201, body: response_body)
end

#stub_publishing_api_put_draft_item(base_path, body = content_item_for_base_path(base_path)) ⇒ Object



14
15
16
# File 'lib/gds_api/test_helpers/publishing_api.rb', line 14

def stub_publishing_api_put_draft_item(base_path, body = content_item_for_base_path(base_path))
  stub_publishing_api_put_item(base_path, body, '/draft-content')
end

#stub_publishing_api_put_intent(base_path, body = intent_for_base_path(base_path)) ⇒ Object



24
25
26
27
28
# File 'lib/gds_api/test_helpers/publishing_api.rb', line 24

def stub_publishing_api_put_intent(base_path, body = intent_for_base_path(base_path))
  url = PUBLISHING_API_ENDPOINT + "/publish-intent" + base_path
  body = body.to_json unless body.is_a?(String)
  stub_request(:put, url).with(body: body).to_return(status: 201, body: body, headers: {})
end

#stub_publishing_api_put_item(base_path, body = content_item_for_base_path(base_path), resource_path = '/content') ⇒ Object



18
19
20
21
22
# File 'lib/gds_api/test_helpers/publishing_api.rb', line 18

def stub_publishing_api_put_item(base_path, body = content_item_for_base_path(base_path), resource_path = '/content')
  url = PUBLISHING_API_ENDPOINT + resource_path + base_path
  body = body.to_json unless body.is_a?(String)
  stub_request(:put, url).with(body: body).to_return(status: 201, body: body, headers: {})
end