gds-api-adapters 36.4.0 → 36.4.1

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: 8adaaae453e95827a4b45119e1fa4af4e677c30f
4
- data.tar.gz: 8398a28ba9d312dee84402c0f4b5c25f0629aba6
3
+ metadata.gz: 06df600e92d5e29ebcc9d2d1011169f25ed806d3
4
+ data.tar.gz: 61a8846b1ce2833f1c72124435c154f5246439e5
5
5
  SHA512:
6
- metadata.gz: 2391b55015a41eb094d96409442fa7d1203737e250f5eda7cb040d8fc7692dbfe199afed1e4c4ca280452f3cc9ecd0efa99bbaa0eef8373c40d1be7ef8bb663c
7
- data.tar.gz: abefc29609acf31b9d565d6526a0eba7e9a9264d38e2be28900509ba36194bda0e126fb5397e8968569465355930e200871658d679c19625dc763207a1bfe490
6
+ metadata.gz: 66e7c5af97fc0c0f6766be3b134757b96b3e448b231f4898d284d7b53b49bed2521903c7a9621e27bfde9c657bee2febc3b3ab38ad469901cde1f469d5fee6b9
7
+ data.tar.gz: 972920cf66478a2134769bcb57958dd70ea58278162d40671940c0c0604552cddc620b33f7293ed295a51cd11fae9896c4a1bb7cb15ff52bca945dac51a0f9fe
@@ -169,6 +169,7 @@ module GdsApi
169
169
  #)
170
170
  def publishing_api_has_content(items, params = {})
171
171
  url = PUBLISHING_API_V2_ENDPOINT + "/content"
172
+
172
173
  if params.respond_to? :fetch
173
174
  per_page = params.fetch(:per_page, 50)
174
175
  page = params.fetch(:page, 1)
@@ -176,10 +177,19 @@ module GdsApi
176
177
  per_page = 50
177
178
  page = 1
178
179
  end
179
- number_of_pages = items.count < per_page ? 1 : items.count / per_page
180
+
181
+ start_position = (page-1) * per_page
182
+ page_items = items.slice(start_position, per_page) || []
183
+
184
+ number_of_pages =
185
+ if items.count < per_page
186
+ 1
187
+ else
188
+ (items.count / per_page.to_f).ceil
189
+ end
180
190
 
181
191
  body = {
182
- results: items,
192
+ results: page_items,
183
193
  total: items.count,
184
194
  pages: number_of_pages,
185
195
  current_page: page
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '36.4.0'
2
+ VERSION = '36.4.1'
3
3
  end
@@ -339,6 +339,49 @@ describe GdsApi::PublishingApiV2 do
339
339
  end
340
340
  end
341
341
 
342
+ describe "when a content item cannot be published because of a path conflict" do
343
+ before do
344
+ @content_item = content_item_for_content_id(@content_id)
345
+
346
+ publishing_api
347
+ .given("a draft content item exists with content_id #{@content_id} with a blocking live item at the same path")
348
+ .upon_receiving("a request to return the draft content item")
349
+ .with(
350
+ method: :get,
351
+ path: "/v2/content/#{@content_id}",
352
+ headers: GdsApi::JsonClient.default_request_headers.merge(
353
+ "Authorization" => "Bearer #{@bearer_token}"
354
+ ),
355
+ )
356
+ .will_respond_with(
357
+ status: 200,
358
+ body: {
359
+ "warnings" => Pact.like({"content_item_blocking_publish" => "message"}),
360
+ "content_id" => @content_id,
361
+ "document_type" => Pact.like("special_route"),
362
+ "schema_name" => Pact.like("special_route"),
363
+ "publishing_app" => Pact.like("publisher"),
364
+ "rendering_app" => Pact.like("frontend"),
365
+ "locale" => Pact.like("en"),
366
+ "routes" => Pact.like([{}]),
367
+ "public_updated_at" => Pact.like("2015-07-30T13:58:11.000Z"),
368
+ "details" => Pact.like({}),
369
+ "publication_state" => "draft"
370
+ },
371
+ headers: {
372
+ "Content-Type" => "application/json; charset=utf-8",
373
+ },
374
+ )
375
+ end
376
+
377
+ it "responds with 200 and the draft content item containing a warning" do
378
+ response = @api_client.get_content(@content_id, version: 2)
379
+ assert_equal 200, response.code
380
+ assert_equal hash_including("content_item_blocking_publish"), response["warnings"]
381
+ end
382
+
383
+ end
384
+
342
385
  describe "when requesting the published version" do
343
386
  before do
344
387
  @content_item = content_item_for_content_id(@content_id)
@@ -46,13 +46,16 @@ describe GdsApi::TestHelpers::PublishingApiV2 do
46
46
  )
47
47
  end
48
48
 
49
- it 'returns pagination results' do
49
+ it 'returns paginated results' do
50
+ content_id_1 = "2878337b-bed9-4e7f-85b6-10ed2cbcd504"
51
+ content_id_2 = "2878337b-bed9-4e7f-85b6-10ed2cbcd505"
52
+ content_id_3 = "2878337b-bed9-4e7f-85b6-10ed2cbcd506"
53
+
50
54
  publishing_api_has_content(
51
55
  [
52
- { "content_id" => "2878337b-bed9-4e7f-85b6-10ed2cbcd504" },
53
- { "content_id" => "2878337b-bed9-4e7f-85b6-10ed2cbcd505" },
54
- { "content_id" => "2878337b-bed9-4e7f-85b6-10ed2cbcd506" },
55
- { "content_id" => "2878337b-bed9-4e7f-85b6-10ed2cbcd507" },
56
+ { "content_id" => content_id_1 },
57
+ { "content_id" => content_id_2 },
58
+ { "content_id" => content_id_3 },
56
59
  ],
57
60
  {
58
61
  page: 1,
@@ -61,10 +64,36 @@ describe GdsApi::TestHelpers::PublishingApiV2 do
61
64
  )
62
65
 
63
66
  response = publishing_api.get_content_items({ page: 1, per_page: 2 })
67
+ records = response['results']
64
68
 
65
- assert_equal(response['total'], 4)
69
+ assert_equal(response['total'], 3)
66
70
  assert_equal(response['pages'], 2)
67
71
  assert_equal(response['current_page'], 1)
72
+
73
+ assert_equal(records.length, 2)
74
+ assert_equal(records.first['content_id'], content_id_1)
75
+ assert_equal(records.last['content_id'], content_id_2)
76
+ end
77
+
78
+ it 'returns an empty list of results for out-of-bound queries' do
79
+ content_id_1 = "2878337b-bed9-4e7f-85b6-10ed2cbcd504"
80
+ content_id_2 = "2878337b-bed9-4e7f-85b6-10ed2cbcd505"
81
+
82
+ publishing_api_has_content(
83
+ [
84
+ { "content_id" => content_id_1 },
85
+ { "content_id" => content_id_2 },
86
+ ],
87
+ {
88
+ page: 10,
89
+ per_page: 2
90
+ }
91
+ )
92
+
93
+ response = publishing_api.get_content_items({ page: 10, per_page: 2 })
94
+ records = response['results']
95
+
96
+ assert_equal(records, [])
68
97
  end
69
98
  end
70
99
 
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: 36.4.0
4
+ version: 36.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Stewart
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-29 00:00:00.000000000 Z
11
+ date: 2016-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: plek