gds-api-adapters 25.2.0 → 25.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gds_api/test_helpers/publishing_api_v2.rb +100 -0
- data/lib/gds_api/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2555915b5d69ad8c15524c8f877683304c6c4c8
|
4
|
+
data.tar.gz: 1e5f35033578543f092550da455351b4cd3b11b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 236561122353b68ccf5be91f61c19330def6b148337960dd5459d5ac9ca01df7c83855301d7d51d06de85ce899b6f98d2ce5a986b123ceebe2f75681cbe3dc99
|
7
|
+
data.tar.gz: 420733946206a10016daf9a4c501f9d98b53a62ac5f59b3571727f09d936848ff4cf671cd8409adcc27b6a7d3f3196f8a2eafcc57fdd78f36a87a2003aeaf778
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'gds_api/test_helpers/json_client_helper'
|
2
|
+
require 'gds_api/test_helpers/content_item_helpers'
|
3
|
+
require 'gds_api/test_helpers/intent_helpers'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module GdsApi
|
7
|
+
module TestHelpers
|
8
|
+
module PublishingApiV2
|
9
|
+
include ContentItemHelpers
|
10
|
+
|
11
|
+
PUBLISHING_API_V2_ENDPOINT = Plek.current.find('publishing-api') + '/v2'
|
12
|
+
|
13
|
+
def stub_publishing_api_put_content(content_id, body)
|
14
|
+
stub_publishing_api_put(content_id, body, '/content')
|
15
|
+
end
|
16
|
+
|
17
|
+
def stub_publishing_api_put_links(content_id, body)
|
18
|
+
stub_publishing_api_put(content_id, body, '/links')
|
19
|
+
end
|
20
|
+
|
21
|
+
def stub_publishing_api_publish(content_id, body)
|
22
|
+
url = PUBLISHING_API_V2_ENDPOINT + "/content/#{content_id}/publish"
|
23
|
+
stub_request(:post, url).with(body: body).to_return(status: 200, body: '{}', headers: {"Content-Type" => "application/json; charset=utf-8"})
|
24
|
+
end
|
25
|
+
|
26
|
+
def stub_publishing_api_put_content_links_and_publish(body, content_id = nil, publish_options = nil)
|
27
|
+
content_id ||= body[:content_id]
|
28
|
+
publish_options ||= { update_type: { update_type: body[:update_type], locale: body[:locale] } }
|
29
|
+
stubs = []
|
30
|
+
stubs << stub_publishing_api_put_content(content_id, body.except(:links))
|
31
|
+
stubs << stub_publishing_api_put_links(content_id, body.slice(:links)) unless body.slice(:links).empty?
|
32
|
+
stubs << stub_publishing_api_publish(content_id, publish_options)
|
33
|
+
stubs
|
34
|
+
end
|
35
|
+
|
36
|
+
def stub_default_publishing_api_put
|
37
|
+
stub_request(:put, %r{\A#{PUBLISHING_API_V2_ENDPOINT}/content})
|
38
|
+
end
|
39
|
+
|
40
|
+
def assert_publishing_api_put_item(content_id, attributes_or_matcher = {}, times = 1)
|
41
|
+
url = PUBLISHING_API_V2_ENDPOINT + "/content/" + content_id
|
42
|
+
assert_publishing_api_put(url, attributes_or_matcher, times)
|
43
|
+
end
|
44
|
+
|
45
|
+
def assert_publishing_api_put(url, attributes_or_matcher = {}, times = 1)
|
46
|
+
if attributes_or_matcher.is_a?(Hash)
|
47
|
+
matcher = attributes_or_matcher.empty? ? nil : request_json_matching(attributes_or_matcher)
|
48
|
+
else
|
49
|
+
matcher = attributes_or_matcher
|
50
|
+
end
|
51
|
+
|
52
|
+
if matcher
|
53
|
+
assert_requested(:put, url, times: times, &matcher)
|
54
|
+
else
|
55
|
+
assert_requested(:put, url, times: times)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def request_json_matching(required_attributes)
|
60
|
+
->(request) do
|
61
|
+
data = JSON.parse(request.body)
|
62
|
+
required_attributes.to_a.all? { |key, value| data[key.to_s] == value }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def request_json_including(required_attributes)
|
67
|
+
->(request) do
|
68
|
+
data = JSON.parse(request.body)
|
69
|
+
required_attributes == data
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def publishing_api_has_fields_for_format(format, items, fields)
|
74
|
+
body = items.map { |item|
|
75
|
+
item.with_indifferent_access.slice(*fields)
|
76
|
+
}
|
77
|
+
|
78
|
+
query_params = fields.map { |f|
|
79
|
+
"&fields%5B%5D=#{f}"
|
80
|
+
}
|
81
|
+
|
82
|
+
url = PUBLISHING_API_V2_ENDPOINT + "/content?content_format=#{format}#{query_params.join('')}"
|
83
|
+
|
84
|
+
stub_request(:get, url).to_return(:status => 200, :body => body.to_json, :headers => {})
|
85
|
+
end
|
86
|
+
|
87
|
+
def publishing_api_has_item(item)
|
88
|
+
item = item.with_indifferent_access
|
89
|
+
url = PUBLISHING_API_V2_ENDPOINT + "/content/" + item[:content_id]
|
90
|
+
stub_request(:get, url).to_return(status: 200, body: item.to_json, headers: {})
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
def stub_publishing_api_put(content_id, body, resource_path)
|
95
|
+
url = PUBLISHING_API_V2_ENDPOINT + resource_path + "/" + content_id
|
96
|
+
stub_request(:put, url).with(body: body).to_return(status: 200, body: '{}', headers: {"Content-Type" => "application/json; charset=utf-8"})
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/lib/gds_api/version.rb
CHANGED
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: 25.
|
4
|
+
version: 25.3.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: 2015-11-
|
11
|
+
date: 2015-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: plek
|
@@ -390,6 +390,7 @@ files:
|
|
390
390
|
- lib/gds_api/test_helpers/performance_platform/data_in.rb
|
391
391
|
- lib/gds_api/test_helpers/publisher.rb
|
392
392
|
- lib/gds_api/test_helpers/publishing_api.rb
|
393
|
+
- lib/gds_api/test_helpers/publishing_api_v2.rb
|
393
394
|
- lib/gds_api/test_helpers/router.rb
|
394
395
|
- lib/gds_api/test_helpers/rummager.rb
|
395
396
|
- lib/gds_api/test_helpers/support.rb
|