gds-api-adapters 24.6.0 → 24.7.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: 212e116b422961283b637ba076848769be4c2eaa
4
- data.tar.gz: c79059c7b2f7040590283f54ff51950db3b401cb
3
+ metadata.gz: 4ef68ae8d9f4be614277bc8a7acb8027f1c07545
4
+ data.tar.gz: 932afdaf75d50446a826c4f3792457977eebe3c8
5
5
  SHA512:
6
- metadata.gz: 982d5e547eec900056a748469da51fe2be0f62c831eb90074f56dfb748d8aa8a624e7af3b30b0c7996c61d52cfbb1c9db68ce9e350c8e3bbc1f8696f988c3897
7
- data.tar.gz: 88442f8971daf8150de2328246199d0f1ee89e020a97f4443cb180a0da95d2f94af65783468420f7f005c5921d10faaaa51a2945780fc254d4adaa9cbefd5fd9
6
+ metadata.gz: c09577ea35742649e8614f0c0a274e5604fd416c031f47b1d22853a21724cc8d2826aeafd571f125f690be6b7ba794e9eb8451228c9ec3356f8160b1efe71e31
7
+ data.tar.gz: 06d0fa4e1ec14347dbb178d57aa011a5b75c188255f2e1cee60ec718aaa614820011c0a2da8a2c1836f1c91e62fb11792c98646e37c9b2dfa7a8fe60cdd17c04
data/Rakefile CHANGED
@@ -1,6 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- require "bundler/gem_tasks"
4
3
  require "rdoc/task"
5
4
  require 'rake/testtask'
6
5
 
@@ -15,11 +14,35 @@ Rake::TestTask.new("test") do |t|
15
14
  t.test_files = FileList["test/**/*_test.rb"]
16
15
  t.verbose = true
17
16
  end
17
+ task :default => :test
18
+
19
+ require 'pact_broker/client/tasks'
20
+
21
+ def configure_pact_broker_location(task)
22
+ task.pact_broker_base_url = ENV.fetch("PACT_BROKER_BASE_URL")
23
+ if ENV['PACT_BROKER_USERNAME']
24
+ task.pact_broker_basic_auth = { username: ENV['PACT_BROKER_USERNAME'], password: ENV['PACT_BROKER_PASSWORD']}
25
+ end
26
+ end
27
+
28
+ PactBroker::Client::PublicationTask.new("branch") do | task |
29
+ task.consumer_version = ENV.fetch("PACT_TARGET_BRANCH")
30
+ configure_pact_broker_location(task)
31
+ end
32
+
33
+ PactBroker::Client::PublicationTask.new("released_version") do | task |
34
+ require 'gds_api/version'
35
+ task.consumer_version = GdsApi::VERSION
36
+ configure_pact_broker_location(task)
37
+ end
18
38
 
19
39
  require "gem_publisher"
40
+ desc "Publish gem to rubygems.org if necessary"
20
41
  task :publish_gem do |t|
21
42
  gem = GemPublisher.publish_if_updated("gds-api-adapters.gemspec", :rubygems)
22
- puts "Published #{gem}" if gem
23
- end
43
+ if gem
44
+ puts "Published #{gem}"
24
45
 
25
- task :default => :test
46
+ Rake::Task["pact:publish:released_version"].invoke
47
+ end
48
+ end
@@ -21,6 +21,10 @@ class GdsApi::PublishingApi < GdsApi::Base
21
21
  e
22
22
  end
23
23
 
24
+ def put_path(base_path, payload)
25
+ put_json!(paths_url(base_path), payload)
26
+ end
27
+
24
28
 
25
29
  private
26
30
 
@@ -35,4 +39,8 @@ class GdsApi::PublishingApi < GdsApi::Base
35
39
  def intent_url(base_path)
36
40
  "#{endpoint}/publish-intent#{base_path}"
37
41
  end
42
+
43
+ def paths_url(base_path)
44
+ "#{endpoint}/paths#{base_path}"
45
+ end
38
46
  end
@@ -6,14 +6,18 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
6
6
  put_json!(content_url(content_id), payload)
7
7
  end
8
8
 
9
- def get_content(content_id)
10
- get_json(content_url(content_id))
9
+ def get_content(content_id, options = {})
10
+ params = {}
11
+ params = params.merge(locale: options[:locale]) if options[:locale]
12
+
13
+ get_json(content_url(content_id, params))
11
14
  end
12
15
 
13
- def publish(content_id, update_type)
14
- post_json!(content_url(content_id) + "/publish", {
15
- update_type: update_type,
16
- })
16
+ def publish(content_id, update_type, options = {})
17
+ params = { update_type: update_type }
18
+ params = params.merge(locale: options[:locale]) if options[:locale]
19
+
20
+ post_json!(publish_url(content_id), params)
17
21
  end
18
22
 
19
23
  def get_links(content_id)
@@ -27,11 +31,16 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
27
31
 
28
32
  private
29
33
 
30
- def content_url(content_id)
31
- "#{endpoint}/v2/content/#{content_id}"
34
+ def content_url(content_id, params = {})
35
+ query = query_string(params)
36
+ "#{endpoint}/v2/content/#{content_id}#{query}"
32
37
  end
33
38
 
34
39
  def links_url(content_id)
35
40
  "#{endpoint}/v2/links/#{content_id}"
36
41
  end
42
+
43
+ def publish_url(content_id)
44
+ "#{endpoint}/v2/content/#{content_id}/publish"
45
+ end
37
46
  end
@@ -11,16 +11,16 @@ module GdsApi
11
11
 
12
12
  PUBLISHING_API_ENDPOINT = Plek.current.find('publishing-api')
13
13
 
14
- def stub_publishing_api_put_draft_item(base_path, body = content_item_for_base_path(base_path))
14
+ def stub_publishing_api_put_draft_item(base_path, body = content_item_for_publishing_api(base_path))
15
15
  stub_publishing_api_put_item(base_path, body, '/draft-content')
16
16
  end
17
17
 
18
- def stub_publishing_api_put_item(base_path, body = content_item_for_base_path(base_path), resource_path = '/content')
18
+ def stub_publishing_api_put_item(base_path, body = content_item_for_publishing_api(base_path), resource_path = '/content')
19
19
  url = PUBLISHING_API_ENDPOINT + resource_path + base_path
20
20
  stub_request(:put, url).with(body: body).to_return(status: 200, body: '{}', headers: {"Content-Type" => "application/json; charset=utf-8"})
21
21
  end
22
22
 
23
- def stub_publishing_api_put_intent(base_path, body = intent_for_base_path(base_path))
23
+ def stub_publishing_api_put_intent(base_path, body = intent_for_publishing_api(base_path))
24
24
  url = PUBLISHING_API_ENDPOINT + "/publish-intent" + base_path
25
25
  body = body.to_json unless body.is_a?(String)
26
26
  stub_request(:put, url).with(body: body).to_return(status: 200, body: '{}', headers: {"Content-Type" => "application/json; charset=utf-8"})
@@ -109,6 +109,14 @@ module GdsApi
109
109
  expected_value == actual_value
110
110
  end
111
111
  end
112
+
113
+ def content_item_for_publishing_api(base_path, publishing_app="publisher")
114
+ content_item_for_base_path(base_path).merge("publishing_app" => publishing_app)
115
+ end
116
+
117
+ def intent_for_publishing_api(base_path, publishing_app="publisher")
118
+ intent_for_base_path(base_path).merge("publishing_app" => publishing_app)
119
+ end
112
120
  end
113
121
  end
114
122
  end
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '24.6.0'
2
+ VERSION = '24.7.0'
3
3
  end
@@ -52,7 +52,7 @@ describe GdsApi::AssetManager do
52
52
  let(:asset_id) { "test-id" }
53
53
 
54
54
  it "updates an asset with a file" do
55
- req = stub_request(:put, "http://asset-manager.dev.gov.uk/assets/test-id").
55
+ req = stub_request(:put, "#{base_api_url}/assets/test-id").
56
56
  to_return(:body => JSON.dump(asset_manager_response), :status => 200)
57
57
 
58
58
  response = api.update_asset(asset_id, :file => file_fixture)
@@ -14,7 +14,7 @@ describe GdsApi::PublishingApi do
14
14
  describe "#put_content_item" do
15
15
  it "responds with 200 OK if the entry is valid" do
16
16
  base_path = "/test-content-item"
17
- content_item = content_item_for_base_path(base_path).merge("update_type" => "major")
17
+ content_item = content_item_for_publishing_api(base_path).merge("update_type" => "major")
18
18
 
19
19
  publishing_api
20
20
  .given("both content stores and the url-arbiter are empty")
@@ -43,7 +43,7 @@ describe GdsApi::PublishingApi do
43
43
  describe "#put_draft_content_item" do
44
44
  it "responds with 200 OK if the entry is valid" do
45
45
  base_path = "/test-draft-content-item"
46
- content_item = content_item_for_base_path(base_path).merge("update_type" => "major")
46
+ content_item = content_item_for_publishing_api(base_path).merge("update_type" => "major")
47
47
 
48
48
  publishing_api
49
49
  .given("both content stores and the url-arbiter are empty")
@@ -72,7 +72,7 @@ describe GdsApi::PublishingApi do
72
72
  describe "#put_intent" do
73
73
  it "responds with 200 OK if publish intent is valid" do
74
74
  base_path = "/test-intent"
75
- publish_intent = intent_for_base_path(base_path)
75
+ publish_intent = intent_for_publishing_api(base_path)
76
76
 
77
77
  publishing_api
78
78
  .given("both content stores and the url-arbiter are empty")
@@ -102,7 +102,7 @@ describe GdsApi::PublishingApi do
102
102
  it "returns 200 OK if intent existed and was deleted" do
103
103
  base_path = "/test-intent"
104
104
 
105
- publish_intent = intent_for_base_path(base_path)
105
+ publish_intent = intent_for_publishing_api(base_path)
106
106
 
107
107
  publishing_api
108
108
  .given("a publish intent exists at /test-intent in the live content store")
@@ -126,7 +126,7 @@ describe GdsApi::PublishingApi do
126
126
  it "returns 404 Not found if the intent does not exist" do
127
127
  base_path = "/test-intent"
128
128
 
129
- publish_intent = intent_for_base_path(base_path)
129
+ publish_intent = intent_for_publishing_api(base_path)
130
130
 
131
131
  publishing_api
132
132
  .given("both content stores and the url-arbiter are empty")
@@ -147,4 +147,72 @@ describe GdsApi::PublishingApi do
147
147
  assert_equal 404, response.code
148
148
  end
149
149
  end
150
+
151
+ describe "#put_path" do
152
+ it "returns 200 if the path was successfully reserved" do
153
+ base_path = "/test-intent"
154
+ payload = {
155
+ publishing_app: "publisher"
156
+ }
157
+
158
+ publishing_api
159
+ .given("both content stores and the url-arbiter are empty")
160
+ .upon_receiving("a request to put a path")
161
+ .with(
162
+ method: :put,
163
+ path: "/paths#{base_path}",
164
+ body: payload,
165
+ headers: {
166
+ "Content-Type" => "application/json"
167
+ },
168
+ )
169
+ .will_respond_with(
170
+ status: 200,
171
+ body: {},
172
+ headers: {
173
+ "Content-Type" => "application/json; charset=utf-8"
174
+ }
175
+ )
176
+
177
+ response = @api_client.put_path(base_path, payload)
178
+ assert_equal 200, response.code
179
+ end
180
+
181
+ it "returns 422 if the request is invalid" do
182
+ base_path = "/test-item"
183
+ payload = {
184
+ publishing_app: "whitehall"
185
+ }
186
+
187
+ publishing_api
188
+ .given("/test-item has been reserved in url-arbiter by the Publisher application")
189
+ .upon_receiving("a request to change publishing app")
190
+ .with(
191
+ method: :put,
192
+ path: "/paths#{base_path}",
193
+ body: payload,
194
+ headers: {
195
+ "Content-Type" => "application/json"
196
+ },
197
+
198
+ )
199
+ .will_respond_with(
200
+ status: 422,
201
+ body: {
202
+ "error" => {
203
+ "code" => 422,
204
+ "message" => Pact.term(generate: "Unprocessable", matcher:/\S+/),
205
+ "fields" => {
206
+ "base_path" => Pact.each_like("has been reserved", :min => 1),
207
+ },
208
+ },
209
+ },
210
+ )
211
+
212
+ error = assert_raises GdsApi::HTTPClientError do
213
+ @api_client.put_path(base_path, payload)
214
+ end
215
+ assert_equal "Unprocessable", error.error_details["error"]["message"]
216
+ end
217
+ end
150
218
  end
@@ -75,10 +75,10 @@ describe GdsApi::PublishingApiV2 do
75
75
  }
76
76
  )
77
77
  .will_respond_with(
78
- status: 409,
78
+ status: 422,
79
79
  body: {
80
80
  "error" => {
81
- "code" => 409,
81
+ "code" => 422,
82
82
  "message" => Pact.term(generate: "Conflict", matcher:/\S+/),
83
83
  "fields" => {
84
84
  "base_path" => Pact.each_like("is already in use by the 'publisher' app", :min => 1),
@@ -91,8 +91,8 @@ describe GdsApi::PublishingApiV2 do
91
91
  )
92
92
  end
93
93
 
94
- it "responds with 409 Conflict" do
95
- error = assert_raises GdsApi::HTTPConflict do
94
+ it "responds with 422 Unprocessable Entity" do
95
+ error = assert_raises GdsApi::HTTPClientError do
96
96
  @api_client.put_content(@content_id, @content_item)
97
97
  end
98
98
  assert_equal "Conflict", error.error_details["error"]["message"]
@@ -178,6 +178,43 @@ describe GdsApi::PublishingApiV2 do
178
178
  end
179
179
  end
180
180
 
181
+ describe "when a content item exists in multiple locales" do
182
+ before do
183
+ @content_item = content_item_for_content_id(@content_id)
184
+
185
+ publishing_api
186
+ .given("a content item exists in multiple locales with content_id: #{@content_id}")
187
+ .upon_receiving("a request to return the content item")
188
+ .with(
189
+ method: :get,
190
+ path: "/v2/content/#{@content_id}",
191
+ query: "locale=fr",
192
+ )
193
+ .will_respond_with(
194
+ status: 200,
195
+ body: {
196
+ "content_id" => @content_id,
197
+ "format" => Pact.like("special_route"),
198
+ "publishing_app" => Pact.like("publisher"),
199
+ "rendering_app" => Pact.like("frontend"),
200
+ "locale" => "fr",
201
+ "routes" => Pact.like([{}]),
202
+ "public_updated_at" => Pact.like("2015-07-30T13:58:11.000Z"),
203
+ "details" => Pact.like({})
204
+ },
205
+ headers: {
206
+ "Content-Type" => "application/json; charset=utf-8",
207
+ },
208
+ )
209
+ end
210
+
211
+ it "responds with 200 and the content item" do
212
+ response = @api_client.get_content(@content_id, locale: "fr")
213
+ assert_equal 200, response.code
214
+ assert_equal response["locale"], "fr"
215
+ end
216
+ end
217
+
181
218
  describe "a non-existent item" do
182
219
  before do
183
220
  publishing_api
@@ -237,7 +274,7 @@ describe GdsApi::PublishingApiV2 do
237
274
  describe "if the content item does not exist" do
238
275
  before do
239
276
  publishing_api
240
- .given("both content stores and url-arbiter empty")
277
+ .given("both content stores and the url-arbiter are empty")
241
278
  .upon_receiving("a publish request")
242
279
  .with(
243
280
  method: :post,
@@ -374,6 +411,33 @@ describe GdsApi::PublishingApiV2 do
374
411
  assert_equal "Cannot publish an already published content item", error.error_details["error"]["message"]
375
412
  end
376
413
  end
414
+
415
+ describe "if the update information contains a locale" do
416
+ before do
417
+ publishing_api
418
+ .given("a draft content item exists with content_id: #{@content_id} and locale: fr")
419
+ .upon_receiving("a publish request")
420
+ .with(
421
+ method: :post,
422
+ path: "/v2/content/#{@content_id}/publish",
423
+ body: {
424
+ update_type: "major",
425
+ locale: "fr",
426
+ },
427
+ headers: {
428
+ "Content-Type" => "application/json",
429
+ },
430
+ )
431
+ .will_respond_with(
432
+ status: 200,
433
+ )
434
+ end
435
+
436
+ it "responds with 200 if the publish command succeeds" do
437
+ response = @api_client.publish(@content_id, "major", locale: "fr")
438
+ assert_equal 200, response.code
439
+ end
440
+ end
377
441
  end
378
442
 
379
443
  describe "#get_links" 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: 24.6.0
4
+ version: 24.7.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-10-21 00:00:00.000000000 Z
11
+ date: 2015-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: plek
@@ -290,6 +290,20 @@ dependencies:
290
290
  - - "~>"
291
291
  - !ruby/object:Gem::Version
292
292
  version: '1.19'
293
+ - !ruby/object:Gem::Dependency
294
+ name: pact_broker-client
295
+ requirement: !ruby/object:Gem::Requirement
296
+ requirements:
297
+ - - "~>"
298
+ - !ruby/object:Gem::Version
299
+ version: 1.0.0
300
+ type: :development
301
+ prerelease: false
302
+ version_requirements: !ruby/object:Gem::Requirement
303
+ requirements:
304
+ - - "~>"
305
+ - !ruby/object:Gem::Version
306
+ version: 1.0.0
293
307
  description: A set of adapters providing easy access to the GDS GOV.UK APIs
294
308
  email:
295
309
  - jystewart@gmail.com