gds-api-adapters 25.2.0 → 25.3.0

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
  SHA1:
3
- metadata.gz: ada01a209e69e96a0d9429e656111fc308e548f5
4
- data.tar.gz: d1f6eadba826f1c3e96e8db670776dfc2a33b317
3
+ metadata.gz: d2555915b5d69ad8c15524c8f877683304c6c4c8
4
+ data.tar.gz: 1e5f35033578543f092550da455351b4cd3b11b6
5
5
  SHA512:
6
- metadata.gz: e5843c224cb8fb8cf1bb448df38dc96d9dcf5c1c3242975e5ed4ada6630468af381b7d57640ac9de80461765aaac52e80f3fb6c54b84d62260f787b473dae31f
7
- data.tar.gz: 855bb0ad98d8cefe9c616c56a1d542e7af3726db10df33f1efacff897a958b43061e3f66e45c3f826081a9ddc69cb66f098d8ae145db132ed2823ecf03208431
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
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '25.2.0'
2
+ VERSION = '25.3.0'
3
3
  end
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.2.0
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-17 00:00:00.000000000 Z
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