publishing_platform_api_adapters 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12a639bdc05f05fbcb78557b20924d4d95286b09af685f76f5e2b6989d998bd7
|
4
|
+
data.tar.gz: '0674539db2157aac06598a56fe898cbcb1ce4baa847f2bef637d62dbe4947501'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19667cbc60807f1d7c3fe54eb1ab0a8bd5437fe328f011cd5fc8e1bfa13085218c84bd80a146c645a18cc65af8ddef2dceec9b14a46f689508be7abe737b16c3
|
7
|
+
data.tar.gz: e77e8a1bd9b420c84dfdbf09bcbee8d672eab10f27422a14d6a0568572f0f8286e4a8b11cc25969a70d3e95c67bcde71c46cc55851bdb6c57070c47550e8c6f7
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module PublishingPlatformApi
|
2
|
+
module TestHelpers
|
3
|
+
module ContentItemHelpers
|
4
|
+
def content_item_for_base_path(base_path)
|
5
|
+
{
|
6
|
+
"title" => titleize_base_path(base_path),
|
7
|
+
"description" => "Description for #{base_path}",
|
8
|
+
"schema_name" => "answer",
|
9
|
+
"document_type" => "answer",
|
10
|
+
"public_updated_at" => "2014-05-06T12:01:00+00:00",
|
11
|
+
# base_path is added in as necessary (ie for content-store GET responses)
|
12
|
+
# "base_path" => base_path,
|
13
|
+
"details" => {
|
14
|
+
"body" => "Some content for #{base_path}",
|
15
|
+
},
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def gone_content_item_for_base_path(base_path)
|
20
|
+
{
|
21
|
+
"title" => nil,
|
22
|
+
"description" => nil,
|
23
|
+
"document_type" => "gone",
|
24
|
+
"schema_name" => "gone",
|
25
|
+
"public_updated_at" => nil,
|
26
|
+
"base_path" => base_path,
|
27
|
+
"withdrawn_notice" => {},
|
28
|
+
"details" => {},
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def titleize_base_path(base_path, options = {})
|
33
|
+
if options[:title_case]
|
34
|
+
base_path.tr("-", " ").gsub(/\b./, &:upcase)
|
35
|
+
else
|
36
|
+
base_path.gsub(%r{[-/]}, " ").strip.capitalize
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require "publishing_platform_api/test_helpers/content_item_helpers"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module PublishingPlatformApi
|
5
|
+
module TestHelpers
|
6
|
+
module ContentStore
|
7
|
+
include ContentItemHelpers
|
8
|
+
|
9
|
+
def content_store_endpoint(draft: false)
|
10
|
+
draft ? PublishingPlatformLocation.find("draft-content-store") : PublishingPlatformLocation.find("content-store")
|
11
|
+
end
|
12
|
+
|
13
|
+
# Stubs a content item in the content store.
|
14
|
+
# The following options can be passed in:
|
15
|
+
#
|
16
|
+
# :max_age will set the max-age of the Cache-Control header in the response. Defaults to 900
|
17
|
+
# :private if true, the Cache-Control header will include the "private" directive. By default it
|
18
|
+
# will include "public"
|
19
|
+
# :draft will point to the draft content store if set to true
|
20
|
+
def stub_content_store_has_item(base_path, body = content_item_for_base_path(base_path), options = {})
|
21
|
+
max_age = options.fetch(:max_age, 900)
|
22
|
+
visibility = options[:private] ? "private" : "public"
|
23
|
+
body = body.to_json unless body.is_a?(String)
|
24
|
+
|
25
|
+
endpoint = content_store_endpoint(draft: options[:draft])
|
26
|
+
stub_request(:get, "#{endpoint}/content#{base_path}").to_return(
|
27
|
+
status: 200,
|
28
|
+
body:,
|
29
|
+
headers: {
|
30
|
+
cache_control: "#{visibility}, max-age=#{max_age}",
|
31
|
+
date: Time.now.httpdate,
|
32
|
+
},
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
def stub_content_store_does_not_have_item(base_path, options = {})
|
37
|
+
endpoint = content_store_endpoint(draft: options[:draft])
|
38
|
+
stub_request(:get, "#{endpoint}/content#{base_path}").to_return(status: 404, headers: {})
|
39
|
+
end
|
40
|
+
|
41
|
+
# Content store has gone item
|
42
|
+
#
|
43
|
+
# Stubs a content item in the content store to respond with 410 HTTP Status Code and response body with 'format' set to 'gone'.
|
44
|
+
#
|
45
|
+
# @param base_path [String]
|
46
|
+
# @param body [Hash]
|
47
|
+
# @param options [Hash]
|
48
|
+
# @option options [String] draft Will point to the draft content store if set to true
|
49
|
+
#
|
50
|
+
# @example
|
51
|
+
#
|
52
|
+
# stub_content_store.stub_content_store_has_gone_item('/sample-slug')
|
53
|
+
#
|
54
|
+
# # Will return HTTP Status Code 410 and the following response body:
|
55
|
+
# {
|
56
|
+
# "title" => nil,
|
57
|
+
# "description" => nil,
|
58
|
+
# "format" => "gone",
|
59
|
+
# "schema_name" => "gone",
|
60
|
+
# "public_updated_at" => nil,
|
61
|
+
# "base_path" => "/sample-slug",
|
62
|
+
# "withdrawn_notice" => {},
|
63
|
+
# "details" => {}
|
64
|
+
# }
|
65
|
+
def stub_content_store_has_gone_item(base_path, body = gone_content_item_for_base_path(base_path), options = {})
|
66
|
+
body = body.to_json unless body.is_a?(String)
|
67
|
+
endpoint = content_store_endpoint(draft: options[:draft])
|
68
|
+
stub_request(:get, "#{endpoint}/content#{base_path}").to_return(
|
69
|
+
status: 410,
|
70
|
+
body:,
|
71
|
+
headers: {},
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
def stub_content_store_isnt_available
|
76
|
+
stub_request(:any, /#{content_store_endpoint}\/.*/).to_return(status: 503)
|
77
|
+
end
|
78
|
+
|
79
|
+
def content_item_for_base_path(base_path)
|
80
|
+
super.merge("base_path" => base_path)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: publishing_platform_api_adapters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Publishing Platform
|
@@ -114,6 +114,8 @@ files:
|
|
114
114
|
- lib/publishing_platform_api/railtie.rb
|
115
115
|
- lib/publishing_platform_api/response.rb
|
116
116
|
- lib/publishing_platform_api/router.rb
|
117
|
+
- lib/publishing_platform_api/test_helpers/content_item_helpers.rb
|
118
|
+
- lib/publishing_platform_api/test_helpers/content_store.rb
|
117
119
|
- lib/publishing_platform_api/version.rb
|
118
120
|
- lib/publishing_platform_api_adapters.rb
|
119
121
|
licenses:
|