Module: PublishingPlatformApi::TestHelpers::ContentStore
- Includes:
- ContentItemHelpers
- Defined in:
- lib/publishing_platform_api/test_helpers/content_store.rb
Instance Method Summary collapse
- #content_item_for_base_path(base_path) ⇒ Object
- #content_store_endpoint(draft: false) ⇒ Object
- #stub_content_store_does_not_have_item(base_path, options = {}) ⇒ Object
-
#stub_content_store_has_gone_item(base_path, body = gone_content_item_for_base_path(base_path), options = {}) ⇒ Object
Content store has gone item.
-
#stub_content_store_has_item(base_path, body = content_item_for_base_path(base_path), options = {}) ⇒ Object
Stubs a content item in the content store.
- #stub_content_store_isnt_available ⇒ Object
Methods included from ContentItemHelpers
#gone_content_item_for_base_path, #titleize_base_path
Instance Method Details
#content_item_for_base_path(base_path) ⇒ Object
79 80 81 |
# File 'lib/publishing_platform_api/test_helpers/content_store.rb', line 79 def content_item_for_base_path(base_path) super.merge("base_path" => base_path) end |
#content_store_endpoint(draft: false) ⇒ Object
9 10 11 |
# File 'lib/publishing_platform_api/test_helpers/content_store.rb', line 9 def content_store_endpoint(draft: false) draft ? PublishingPlatformLocation.find("draft-content-store") : PublishingPlatformLocation.find("content-store") end |
#stub_content_store_does_not_have_item(base_path, options = {}) ⇒ Object
36 37 38 39 |
# File 'lib/publishing_platform_api/test_helpers/content_store.rb', line 36 def stub_content_store_does_not_have_item(base_path, = {}) endpoint = content_store_endpoint(draft: [:draft]) stub_request(:get, "#{endpoint}/content#{base_path}").to_return(status: 404, headers: {}) end |
#stub_content_store_has_gone_item(base_path, body = gone_content_item_for_base_path(base_path), options = {}) ⇒ Object
Content store has gone item
Stubs a content item in the content store to respond with 410 HTTP Status Code and response body with ‘format’ set to ‘gone’.
65 66 67 68 69 70 71 72 73 |
# File 'lib/publishing_platform_api/test_helpers/content_store.rb', line 65 def stub_content_store_has_gone_item(base_path, body = gone_content_item_for_base_path(base_path), = {}) body = body.to_json unless body.is_a?(String) endpoint = content_store_endpoint(draft: [:draft]) stub_request(:get, "#{endpoint}/content#{base_path}").to_return( status: 410, body:, headers: {}, ) end |
#stub_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"
:draft will point to the draft content store if set to true
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/publishing_platform_api/test_helpers/content_store.rb', line 20 def stub_content_store_has_item(base_path, body = content_item_for_base_path(base_path), = {}) max_age = .fetch(:max_age, 900) visibility = [:private] ? "private" : "public" body = body.to_json unless body.is_a?(String) endpoint = content_store_endpoint(draft: [:draft]) stub_request(:get, "#{endpoint}/content#{base_path}").to_return( status: 200, body:, headers: { cache_control: "#{visibility}, max-age=#{max_age}", date: Time.now.httpdate, }, ) end |
#stub_content_store_isnt_available ⇒ Object
75 76 77 |
# File 'lib/publishing_platform_api/test_helpers/content_store.rb', line 75 def stub_content_store_isnt_available stub_request(:any, /#{content_store_endpoint}\/.*/).to_return(status: 503) end |