gds-api-adapters 26.4.0 → 26.5.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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6e6086fcd077f82492196d0fba5f3c57ec3c739a
|
|
4
|
+
data.tar.gz: 9f4140565169ee3dbf5ff33a638bbb483c1124d3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f4ae8d18936478c15316167e6c815eb34ed715b7e99d9a19aea47779ab6b1e23f872e92a8ff2de15171399901f3c9854c156e339ad3bf212b7491af13ae2494f
|
|
7
|
+
data.tar.gz: 32850c738b23681f5b2610351ea018a48f1aa41a4ad59462a25f788afdec48e2c360e7aa9e0f6cce7066d5af1b024cd6880354928a044cdf04e1b02244797c80
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require "gds_api/
|
|
1
|
+
require "gds_api/publishing_api_v2"
|
|
2
2
|
require "time"
|
|
3
3
|
|
|
4
4
|
module GdsApi
|
|
@@ -6,14 +6,14 @@ module GdsApi
|
|
|
6
6
|
class SpecialRoutePublisher
|
|
7
7
|
def initialize(options = {})
|
|
8
8
|
@logger = options[:logger] || GdsApi::Base.logger
|
|
9
|
-
@publishing_api = options[:publishing_api] || GdsApi::
|
|
9
|
+
@publishing_api = options[:publishing_api] || GdsApi::PublishingApiV2.new(Plek.find("publishing-api"))
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def publish(options)
|
|
13
13
|
logger.info("Publishing #{options.fetch(:type)} route #{options.fetch(:base_path)}, routing to #{options.fetch(:rendering_app)}")
|
|
14
14
|
|
|
15
|
-
publishing_api.
|
|
16
|
-
|
|
15
|
+
put_content_response = publishing_api.put_content(options.fetch(:content_id), {
|
|
16
|
+
base_path: options.fetch(:base_path),
|
|
17
17
|
format: "special_route",
|
|
18
18
|
title: options.fetch(:title),
|
|
19
19
|
description: options[:description] || "",
|
|
@@ -25,9 +25,10 @@ module GdsApi
|
|
|
25
25
|
],
|
|
26
26
|
publishing_app: options.fetch(:publishing_app),
|
|
27
27
|
rendering_app: options.fetch(:rendering_app),
|
|
28
|
-
update_type: "major",
|
|
29
28
|
public_updated_at: time.now.iso8601,
|
|
30
29
|
})
|
|
30
|
+
publishing_api.publish(options.fetch(:content_id), 'major')
|
|
31
|
+
put_content_response
|
|
31
32
|
end
|
|
32
33
|
|
|
33
34
|
private
|
|
@@ -10,8 +10,20 @@ module GdsApi
|
|
|
10
10
|
|
|
11
11
|
PUBLISHING_API_V2_ENDPOINT = Plek.current.find('publishing-api') + '/v2'
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
# stubs a PUT /v2/content/:content_id request with the given content id and request body.
|
|
14
|
+
# if no response_hash is given, a default response as follows is created:
|
|
15
|
+
# {status: 200, body: '{}', headers: {"Content-Type" => "application/json; charset=utf-8"}}
|
|
16
|
+
#
|
|
17
|
+
# if a response is given, then it will be merged with the default response.
|
|
18
|
+
# if the given parameter for the response body is a Hash, it will be converted to JSON.
|
|
19
|
+
#
|
|
20
|
+
# e.g. The following two examples are equivalent:
|
|
21
|
+
#
|
|
22
|
+
# * stub_publishing_api_put_content(my_content_id, my_request_body, { status: 201, body: {version: 33}.to_json })
|
|
23
|
+
# * stub_publishing_api_put_content(my_content_id, my_request_body, { status: 201, body: {version: 33} })
|
|
24
|
+
#
|
|
25
|
+
def stub_publishing_api_put_content(content_id, body, response_hash = {})
|
|
26
|
+
stub_publishing_api_put(content_id, body, '/content', response_hash)
|
|
15
27
|
end
|
|
16
28
|
|
|
17
29
|
def stub_publishing_api_put_links(content_id, body)
|
|
@@ -58,6 +70,10 @@ module GdsApi
|
|
|
58
70
|
.to_return(status: 404, headers: {"Content-Type" => "application/json; charset=utf-8"})
|
|
59
71
|
end
|
|
60
72
|
|
|
73
|
+
def publishing_api_isnt_available
|
|
74
|
+
stub_request(:any, /#{PUBLISHING_API_V2_ENDPOINT}\/.*/).to_return(status: 503)
|
|
75
|
+
end
|
|
76
|
+
|
|
61
77
|
def assert_publishing_api_put_content(content_id, attributes_or_matcher = {}, times = 1)
|
|
62
78
|
url = PUBLISHING_API_V2_ENDPOINT + "/content/" + content_id
|
|
63
79
|
assert_publishing_api(:put, url, attributes_or_matcher, times)
|
|
@@ -68,6 +84,11 @@ module GdsApi
|
|
|
68
84
|
assert_publishing_api(:post, url, attributes_or_matcher, times)
|
|
69
85
|
end
|
|
70
86
|
|
|
87
|
+
def assert_publishing_api_put_links(content_id, attributes_or_matcher = {}, times = 1)
|
|
88
|
+
url = PUBLISHING_API_V2_ENDPOINT + "/links/" + content_id
|
|
89
|
+
assert_publishing_api(:put, url, attributes_or_matcher, times)
|
|
90
|
+
end
|
|
91
|
+
|
|
71
92
|
def assert_publishing_api_discard_draft(content_id, attributes_or_matcher = {}, times = 1)
|
|
72
93
|
url = PUBLISHING_API_V2_ENDPOINT + "/content/#{content_id}/discard-draft"
|
|
73
94
|
assert_publishing_api(:post, url, attributes_or_matcher, times)
|
|
@@ -122,9 +143,12 @@ module GdsApi
|
|
|
122
143
|
end
|
|
123
144
|
|
|
124
145
|
private
|
|
125
|
-
def stub_publishing_api_put(content_id, body, resource_path)
|
|
146
|
+
def stub_publishing_api_put(content_id, body, resource_path, override_response_hash = {})
|
|
147
|
+
response_hash = {status: 200, body: '{}', headers: {"Content-Type" => "application/json; charset=utf-8"}}
|
|
148
|
+
response_hash.merge!(override_response_hash)
|
|
149
|
+
response_hash[:body] = response_hash[:body].to_json if response_hash[:body].is_a?(Hash)
|
|
126
150
|
url = PUBLISHING_API_V2_ENDPOINT + resource_path + "/" + content_id
|
|
127
|
-
stub_request(:put, url).with(body: body).to_return(
|
|
151
|
+
stub_request(:put, url).with(body: body).to_return(response_hash)
|
|
128
152
|
end
|
|
129
153
|
end
|
|
130
154
|
end
|
data/lib/gds_api/version.rb
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
require "gds_api/publishing_api/special_route_publisher"
|
|
3
|
+
require File.dirname(__FILE__) + '/../../lib/gds_api/test_helpers/publishing_api_v2'
|
|
3
4
|
|
|
4
5
|
describe GdsApi::PublishingApi::SpecialRoutePublisher do
|
|
5
|
-
|
|
6
|
-
stub(:publishing_api, put_content_item: nil)
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
let(:publisher) {
|
|
10
|
-
GdsApi::PublishingApi::SpecialRoutePublisher.new(publishing_api: publishing_api)
|
|
11
|
-
}
|
|
6
|
+
include ::GdsApi::TestHelpers::PublishingApiV2
|
|
12
7
|
|
|
8
|
+
let(:content_id) { 'a-content-id-of-sorts' }
|
|
13
9
|
let(:special_route) {
|
|
14
10
|
{
|
|
15
|
-
content_id:
|
|
11
|
+
content_id: content_id,
|
|
16
12
|
title: "A title",
|
|
17
13
|
description: "A description",
|
|
18
14
|
base_path: "/favicon.ico",
|
|
@@ -24,55 +20,71 @@ describe GdsApi::PublishingApi::SpecialRoutePublisher do
|
|
|
24
20
|
|
|
25
21
|
describe ".publish" do
|
|
26
22
|
it "publishes the special routes" do
|
|
23
|
+
|
|
27
24
|
Timecop.freeze(Time.now) do
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
)
|
|
25
|
+
publisher = GdsApi::PublishingApi::SpecialRoutePublisher.new
|
|
26
|
+
endpoint = Plek.current.find('publishing-api')
|
|
27
|
+
payload = {
|
|
28
|
+
base_path: special_route[:base_path],
|
|
29
|
+
format: "special_route",
|
|
30
|
+
title: special_route[:title],
|
|
31
|
+
description: special_route[:description],
|
|
32
|
+
routes: [
|
|
33
|
+
{
|
|
34
|
+
path: special_route[:base_path],
|
|
35
|
+
type: special_route[:type],
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
publishing_app: special_route[:publishing_app],
|
|
39
|
+
rendering_app: special_route[:rendering_app],
|
|
40
|
+
public_updated_at: Time.now.iso8601,
|
|
41
|
+
}
|
|
47
42
|
|
|
43
|
+
stub_any_publishing_api_call
|
|
44
|
+
|
|
48
45
|
publisher.publish(special_route)
|
|
46
|
+
|
|
47
|
+
base_path = "#{endpoint}/v2/content/#{content_id}"
|
|
48
|
+
assert_requested(:put, base_path, body: payload)
|
|
49
|
+
assert_requested(:post, "#{base_path}/publish", body: { update_type: 'major' })
|
|
50
|
+
|
|
49
51
|
end
|
|
50
52
|
end
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
describe 'Timezone handling' do
|
|
55
|
+
let(:publishing_api) {
|
|
56
|
+
stub(:publishing_api, put_content_item: nil)
|
|
57
|
+
}
|
|
58
|
+
let(:publisher) {
|
|
59
|
+
GdsApi::PublishingApi::SpecialRoutePublisher.new(publishing_api: publishing_api)
|
|
60
|
+
}
|
|
55
61
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
it "is robust to Time.zone returning nil" do
|
|
63
|
+
Timecop.freeze(Time.now) do
|
|
64
|
+
Time.stubs(:zone).returns(nil)
|
|
65
|
+
publishing_api.expects(:put_content).with(
|
|
66
|
+
anything,
|
|
67
|
+
has_entries(public_updated_at: Time.now.iso8601)
|
|
68
|
+
)
|
|
69
|
+
publishing_api.expects(:publish)
|
|
60
70
|
|
|
61
|
-
|
|
71
|
+
publisher.publish(special_route)
|
|
72
|
+
end
|
|
62
73
|
end
|
|
63
|
-
end
|
|
64
74
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
75
|
+
it "uses Time.zone if available" do
|
|
76
|
+
Timecop.freeze(Time.now) do
|
|
77
|
+
time_in_zone = stub("Time in zone", now: Time.parse("2010-01-01 10:10:10 +04:00"))
|
|
78
|
+
Time.stubs(:zone).returns(time_in_zone)
|
|
69
79
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
80
|
+
publishing_api.expects(:put_content).with(
|
|
81
|
+
anything,
|
|
82
|
+
has_entries(public_updated_at: time_in_zone.now.iso8601)
|
|
83
|
+
)
|
|
84
|
+
publishing_api.expects(:publish)
|
|
74
85
|
|
|
75
|
-
|
|
86
|
+
publisher.publish(special_route)
|
|
87
|
+
end
|
|
76
88
|
end
|
|
77
89
|
end
|
|
78
90
|
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: 26.
|
|
4
|
+
version: 26.5.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-12-
|
|
11
|
+
date: 2015-12-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: plek
|