publishing_platform_api_adapters 0.8.0 → 0.8.2
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: f71db8ee0d906b1e92fd7592d4c7938d338da0f901adc11c44e96db86f0ea955
|
4
|
+
data.tar.gz: 0e1f95953370551c78a5496ad7abbd7fab542c5dcf10ebf4c608901218381c16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f369bad7e927df6175e3b444fae7a35a78dd65edd5a0c3f045ea001dcce007af12ce7745bc2b24249b1f5cf8b8b56bf764a39f3b8f443f8de4f1f659c5a3e54
|
7
|
+
data.tar.gz: '04836b8766c6d12c8ec2280827cc2eb5c4da0be1302353d9d89f4e029a633f6263601219f62c06a62668a4dfcbad9434a1207b67bebd68b2e732f1e247c79358'
|
@@ -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
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require "publishing_platform_api/test_helpers/json_client_helper"
|
2
|
+
|
3
|
+
module PublishingPlatformApi
|
4
|
+
module TestHelpers
|
5
|
+
module Router
|
6
|
+
ROUTER_API_ENDPOINT = PublishingPlatformLocation.find("router-api")
|
7
|
+
|
8
|
+
def stub_router_has_route(path, route, bearer_token = ENV["ROUTER_API_BEARER_TOKEN"])
|
9
|
+
stub_get_route(path, bearer_token).to_return(
|
10
|
+
status: 200,
|
11
|
+
body: route.to_json,
|
12
|
+
headers: { "Content-Type" => "application/json" },
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
def stub_router_doesnt_have_route(path, bearer_token = ENV["ROUTER_API_BEARER_TOKEN"])
|
17
|
+
stub_get_route(path, bearer_token).to_return(status: 404)
|
18
|
+
end
|
19
|
+
|
20
|
+
def stub_router_has_backend_route(path, backend_id:, route_type: "exact", disabled: false)
|
21
|
+
stub_router_has_route(path, handler: "backend", backend_id:, disabled:, route_type:)
|
22
|
+
end
|
23
|
+
|
24
|
+
def stub_router_has_redirect_route(path, redirect_to:, route_type: "exact", disabled: false)
|
25
|
+
stub_router_has_route(path, handler: "redirect", redirect_to:, disabled:, route_type:)
|
26
|
+
end
|
27
|
+
|
28
|
+
def stub_router_has_gone_route(path, route_type: "exact", disabled: false)
|
29
|
+
stub_router_has_route(path, handler: "gone", route_type:, disabled:)
|
30
|
+
end
|
31
|
+
|
32
|
+
def stub_all_router_registration
|
33
|
+
stub_request(:put, "#{ROUTER_API_ENDPOINT}/routes")
|
34
|
+
end
|
35
|
+
|
36
|
+
def stub_route_registration(path, type, backend_id)
|
37
|
+
stub_route_put({
|
38
|
+
route: {
|
39
|
+
incoming_path: path,
|
40
|
+
route_type: type,
|
41
|
+
handler: "backend",
|
42
|
+
backend_id:,
|
43
|
+
},
|
44
|
+
})
|
45
|
+
end
|
46
|
+
|
47
|
+
def stub_redirect_registration(path, type, destination, segments_mode = nil)
|
48
|
+
stub_route_put({
|
49
|
+
route: {
|
50
|
+
incoming_path: path,
|
51
|
+
route_type: type,
|
52
|
+
handler: "redirect",
|
53
|
+
redirect_to: destination,
|
54
|
+
segments_mode:,
|
55
|
+
},
|
56
|
+
})
|
57
|
+
end
|
58
|
+
|
59
|
+
def stub_gone_route_registration(path, type)
|
60
|
+
stub_route_put({
|
61
|
+
route: {
|
62
|
+
incoming_path: path,
|
63
|
+
route_type: type,
|
64
|
+
handler: "gone",
|
65
|
+
},
|
66
|
+
})
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def stub_get_route(path, bearer_token)
|
72
|
+
stub_http_request(:get, "#{ROUTER_API_ENDPOINT}/routes")
|
73
|
+
.with(
|
74
|
+
query: { "incoming_path" => path },
|
75
|
+
headers: { "Authorization" => "Bearer #{bearer_token}" },
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
def stub_route_put(route)
|
80
|
+
stub_http_request(:put, "#{ROUTER_API_ENDPOINT}/routes")
|
81
|
+
.with(body: route.to_json)
|
82
|
+
.to_return(status: 201)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Publishing Platform
|
@@ -114,6 +114,9 @@ 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
|
119
|
+
- lib/publishing_platform_api/test_helpers/router.rb
|
117
120
|
- lib/publishing_platform_api/version.rb
|
118
121
|
- lib/publishing_platform_api_adapters.rb
|
119
122
|
licenses:
|
@@ -133,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
136
|
- !ruby/object:Gem::Version
|
134
137
|
version: '0'
|
135
138
|
requirements: []
|
136
|
-
rubygems_version: 3.6.
|
139
|
+
rubygems_version: 3.6.8
|
137
140
|
specification_version: 4
|
138
141
|
summary: Adapters to work with Publishing Platform APIs
|
139
142
|
test_files: []
|