Module: GdsApi::TestHelpers::ContentStore

Includes:
ContentItemHelpers
Defined in:
lib/gds_api/test_helpers/content_store.rb

Constant Summary collapse

CONTENT_STORE_ENDPOINT =
Plek.current.find('content-store')

Instance Method Summary collapse

Methods included from ContentItemHelpers

#titleize_base_path

Instance Method Details

#content_item_for_base_path(base_path) ⇒ Object



46
47
48
# File 'lib/gds_api/test_helpers/content_store.rb', line 46

def content_item_for_base_path(base_path)
  super.merge({ "base_path" => base_path })
end

#content_store_does_not_have_item(base_path) ⇒ Object



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

def content_store_does_not_have_item(base_path)
  url = CONTENT_STORE_ENDPOINT + "/content" + base_path
  stub_request(:get, url).to_return(status: 404, headers: {})

  url = CONTENT_STORE_ENDPOINT + "/incoming-links" + base_path
  stub_request(:get, url).to_return(status: 404, headers: {})
end


50
51
52
53
54
55
# File 'lib/gds_api/test_helpers/content_store.rb', line 50

def content_store_has_incoming_links(base_path, links)
  url = CONTENT_STORE_ENDPOINT + "/incoming-links" + base_path
  body = links.to_json

  stub_request(:get, url).to_return(body: body)
end

#content_store_has_item(base_path, body = content_item_for_base_path(base_path), options = {}) ⇒ Object

Stubs a content item in the content store. The following options can be passed in:

:max_age  will set the max-age of the Cache-Control header in the response. Defaults to 900
:private  if true, the Cache-Control header will include the "private" directive. By default it
          will include "public"


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gds_api/test_helpers/content_store.rb', line 18

def content_store_has_item(base_path, body = content_item_for_base_path(base_path), options = {})
  max_age = options.fetch(:max_age, 900)
  visibility = options[:private] ? "private" : "public"
  url = CONTENT_STORE_ENDPOINT + "/content" + base_path
  body = body.to_json unless body.is_a?(String)

  stub_request(:get, url).to_return(
    status: 200,
    body: body,
    headers: {
      cache_control: "#{visibility}, max-age=#{max_age}",
      date: Time.now.httpdate
    }
  )
end

#content_store_isnt_availableObject



42
43
44
# File 'lib/gds_api/test_helpers/content_store.rb', line 42

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