gds-api-adapters 26.7.0 → 27.0.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5601500bc73e6401843858f7f7bdd8e70f82963
|
4
|
+
data.tar.gz: 479957e64e4c38b8a16946d8903843bdb2a93972
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cd53fd771715e3f0670a359287a96b1a90efc27bb76fc7f0bcf0cb799beae8b3cf6119023ca96df220ae9f457024a4207929d7798650ae0bbfd58a57ad6fd26
|
7
|
+
data.tar.gz: b51ff2b5bfeadff897d9e889e984206b052ce9bffdd2428729509f1291b945fba0cd0397d4ae85eb3b61426f765bb5fb281720bc85249d2e9265971255f16872
|
@@ -27,6 +27,7 @@ module GdsApi
|
|
27
27
|
rendering_app: options.fetch(:rendering_app),
|
28
28
|
public_updated_at: time.now.iso8601,
|
29
29
|
})
|
30
|
+
publishing_api.put_links(options.fetch(:content_id), links: options[:links]) if options[:links]
|
30
31
|
publishing_api.publish(options.fetch(:content_id), 'major')
|
31
32
|
put_content_response
|
32
33
|
end
|
@@ -17,7 +17,7 @@ module GdsApi
|
|
17
17
|
# if a response is given, then it will be merged with the default response.
|
18
18
|
# if the given parameter for the response body is a Hash, it will be converted to JSON.
|
19
19
|
#
|
20
|
-
# e.g. The following two examples are equivalent:
|
20
|
+
# e.g. The following two examples are equivalent:
|
21
21
|
#
|
22
22
|
# * stub_publishing_api_put_content(my_content_id, my_request_body, { status: 201, body: {version: 33}.to_json })
|
23
23
|
# * stub_publishing_api_put_content(my_content_id, my_request_body, { status: 201, body: {version: 33} })
|
@@ -74,6 +74,17 @@ module GdsApi
|
|
74
74
|
stub_request(:any, /#{PUBLISHING_API_V2_ENDPOINT}\/.*/).to_return(status: 503)
|
75
75
|
end
|
76
76
|
|
77
|
+
def assert_publishing_api_put_content_links_and_publish(body, content_id = nil, publish_body = nil)
|
78
|
+
content_id ||= body[:content_id]
|
79
|
+
if publish_body.nil?
|
80
|
+
publish_body = { update_type: body.fetch(:update_type) }
|
81
|
+
publish_body[:locale] = body[:locale] if body[:locale]
|
82
|
+
end
|
83
|
+
assert_publishing_api_put_content(content_id, body.except(:links))
|
84
|
+
assert_publishing_api_put_links(content_id, body.slice(:links)) unless body.slice(:links).empty?
|
85
|
+
assert_publishing_api_publish(content_id, publish_body)
|
86
|
+
end
|
87
|
+
|
77
88
|
def assert_publishing_api_put_content(content_id, attributes_or_matcher = {}, times = 1)
|
78
89
|
url = PUBLISHING_API_V2_ENDPOINT + "/content/" + content_id
|
79
90
|
assert_publishing_api(:put, url, attributes_or_matcher, times)
|
@@ -94,9 +105,9 @@ module GdsApi
|
|
94
105
|
assert_publishing_api(:post, url, attributes_or_matcher, times)
|
95
106
|
end
|
96
107
|
|
97
|
-
def assert_publishing_api(verb, url, attributes_or_matcher =
|
108
|
+
def assert_publishing_api(verb, url, attributes_or_matcher = nil, times = 1)
|
98
109
|
if attributes_or_matcher.is_a?(Hash)
|
99
|
-
matcher =
|
110
|
+
matcher = request_json_matches(attributes_or_matcher)
|
100
111
|
else
|
101
112
|
matcher = attributes_or_matcher
|
102
113
|
end
|
@@ -108,17 +119,18 @@ module GdsApi
|
|
108
119
|
end
|
109
120
|
end
|
110
121
|
|
111
|
-
def
|
122
|
+
def request_json_includes(required_attributes)
|
112
123
|
->(request) do
|
113
124
|
data = JSON.parse(request.body)
|
114
|
-
required_attributes.
|
125
|
+
deep_stringify_keys(required_attributes).
|
126
|
+
to_a.all? { |key, value| data[key] == value }
|
115
127
|
end
|
116
128
|
end
|
117
129
|
|
118
|
-
def
|
130
|
+
def request_json_matches(required_attributes)
|
119
131
|
->(request) do
|
120
132
|
data = JSON.parse(request.body)
|
121
|
-
required_attributes == data
|
133
|
+
deep_stringify_keys(required_attributes) == data
|
122
134
|
end
|
123
135
|
end
|
124
136
|
|
@@ -150,6 +162,23 @@ module GdsApi
|
|
150
162
|
url = PUBLISHING_API_V2_ENDPOINT + resource_path + "/" + content_id
|
151
163
|
stub_request(:put, url).with(body: body).to_return(response_hash)
|
152
164
|
end
|
165
|
+
|
166
|
+
def deep_stringify_keys(hash)
|
167
|
+
deep_transform_keys(hash) { |key| key.to_s }
|
168
|
+
end
|
169
|
+
|
170
|
+
def deep_transform_keys(object, &block)
|
171
|
+
case object
|
172
|
+
when Hash
|
173
|
+
object.each_with_object({}) do |(key, value), result|
|
174
|
+
result[yield(key)] = deep_transform_keys(value, &block)
|
175
|
+
end
|
176
|
+
when Array
|
177
|
+
object.map{ |item| deep_transform_keys(item, &block) }
|
178
|
+
else
|
179
|
+
object
|
180
|
+
end
|
181
|
+
end
|
153
182
|
end
|
154
183
|
end
|
155
184
|
end
|
data/lib/gds_api/version.rb
CHANGED
@@ -5,7 +5,7 @@ require File.dirname(__FILE__) + '/../../lib/gds_api/test_helpers/publishing_api
|
|
5
5
|
describe GdsApi::PublishingApi::SpecialRoutePublisher do
|
6
6
|
include ::GdsApi::TestHelpers::PublishingApiV2
|
7
7
|
|
8
|
-
let(:content_id) { 'a-content-id-of-sorts' }
|
8
|
+
let(:content_id) { 'a-content-id-of-sorts' }
|
9
9
|
let(:special_route) {
|
10
10
|
{
|
11
11
|
content_id: content_id,
|
@@ -18,13 +18,19 @@ describe GdsApi::PublishingApi::SpecialRoutePublisher do
|
|
18
18
|
}
|
19
19
|
}
|
20
20
|
|
21
|
+
let(:publisher) { GdsApi::PublishingApi::SpecialRoutePublisher.new }
|
22
|
+
let(:endpoint) { Plek.current.find('publishing-api') }
|
23
|
+
|
21
24
|
describe ".publish" do
|
25
|
+
before do
|
26
|
+
stub_any_publishing_api_call
|
27
|
+
end
|
28
|
+
|
22
29
|
it "publishes the special routes" do
|
23
|
-
|
24
30
|
Timecop.freeze(Time.now) do
|
25
|
-
publisher
|
26
|
-
|
27
|
-
|
31
|
+
publisher.publish(special_route)
|
32
|
+
|
33
|
+
expected_payload = {
|
28
34
|
base_path: special_route[:base_path],
|
29
35
|
format: "special_route",
|
30
36
|
title: special_route[:title],
|
@@ -40,15 +46,21 @@ describe GdsApi::PublishingApi::SpecialRoutePublisher do
|
|
40
46
|
public_updated_at: Time.now.iso8601,
|
41
47
|
}
|
42
48
|
|
43
|
-
|
44
|
-
|
45
|
-
|
49
|
+
assert_requested(:put, "#{endpoint}/v2/content/#{content_id}", body: expected_payload)
|
50
|
+
assert_publishing_api_publish(content_id, update_type: 'major')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "publishes links" do
|
55
|
+
links = {
|
56
|
+
links: {
|
57
|
+
organisations: ['org-content-id']
|
58
|
+
}
|
59
|
+
}
|
46
60
|
|
47
|
-
|
48
|
-
assert_requested(:put, base_path, body: payload)
|
49
|
-
assert_requested(:post, "#{base_path}/publish", body: { update_type: 'major' })
|
61
|
+
publisher.publish(special_route.merge(links))
|
50
62
|
|
51
|
-
|
63
|
+
assert_requested(:put, "#{endpoint}/v2/links/#{content_id}", body: links)
|
52
64
|
end
|
53
65
|
|
54
66
|
describe 'Timezone handling' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gds-api-adapters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 27.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Stewart
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: plek
|