gds-api-adapters 35.0.0 → 35.0.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: 3de808a31aebeb02fcb1731a56452fac86864c84
4
- data.tar.gz: 89d5c19db3a0a4c9558a2817bc01b77315fcf58f
3
+ metadata.gz: e333779f06ac4e6cd7cdc357ecd49415ff7504ff
4
+ data.tar.gz: 6f5769410683e7342de9505201bf22a1c02732bf
5
5
  SHA512:
6
- metadata.gz: 0aa623216d9876b2c935af07011504a32169b1199eb071bfd68090f43de2aaa1cbde4feeaf3288bae53e9e30485076ecf7b952ae5c73d882cef6be3f589ab546
7
- data.tar.gz: 0048a9e7a5cd71b3d832c3d1cdae804b59557b06e835ae1efe4b12133a2e503d2975fc4fd5cebf28ef1124cd827e1f81f3e7380ea6758047d8a85ca3b6d5bf21
6
+ metadata.gz: 4e75bf5a23893d51a70361a55f1d2b805658678b569f5e4d2f8bd2cdef3b339f5142d3962ee612dac18841cf592685b5969ed7ad2c27b0dade2800fe1fd9c2df
7
+ data.tar.gz: db78f0b50042f099c4fc43a2cd71c0286b69bccea372e7add1727cb55da56aa29a59183e9401c8496d6ba4990f51a46eb315891bb63459dada26260969a20f6f
@@ -169,7 +169,20 @@ module GdsApi
169
169
  #)
170
170
  def publishing_api_has_content(items, params = {})
171
171
  url = PUBLISHING_API_V2_ENDPOINT + "/content"
172
- stub_request(:get, url).with(:query => params).to_return(status: 200, body: { results: items }.to_json, headers: {})
172
+ per_page = params.fetch(:per_page, 50)
173
+ page = params.fetch(:page, 1)
174
+ number_of_pages = items.count < per_page ? 1 : items.count / per_page
175
+
176
+ body = {
177
+ results: items,
178
+ total: items.count,
179
+ pages: number_of_pages,
180
+ current_page: page
181
+ }
182
+
183
+ stub_request(:get, url)
184
+ .with(query: params)
185
+ .to_return(status: 200, body: body.to_json, headers: {})
173
186
  end
174
187
 
175
188
  # This method has been refactored into publishing_api_has_content (above)
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '35.0.0'
2
+ VERSION = '35.0.1'
3
3
  end
@@ -8,7 +8,7 @@ describe GdsApi::PublishingApi do
8
8
 
9
9
  before do
10
10
  @base_api_url = Plek.current.find("publishing-api")
11
- @api_client = GdsApi::PublishingApi.new('http://localhost:3093')
11
+ @api_client = GdsApi::PublishingApi.new(publishing_api_host)
12
12
  end
13
13
 
14
14
  describe "#put_content_item" do
@@ -6,7 +6,7 @@ describe GdsApi::PublishingApiV2 do
6
6
  include PactTest
7
7
 
8
8
  before do
9
- @api_client = GdsApi::PublishingApiV2.new('http://localhost:3093')
9
+ @api_client = GdsApi::PublishingApiV2.new(publishing_api_host)
10
10
  @content_id = "bed722e6-db68-43e5-9079-063f623335a7"
11
11
  end
12
12
 
@@ -6,7 +6,7 @@ describe GdsApi::PublishingApiV2 do
6
6
  include PactTest
7
7
 
8
8
  before do
9
- @api_client = GdsApi::PublishingApiV2.new('http://localhost:3093')
9
+ @api_client = GdsApi::PublishingApiV2.new(publishing_api_host)
10
10
  @content_id = "bed722e6-db68-43e5-9079-063f623335a7"
11
11
  end
12
12
 
@@ -6,7 +6,7 @@ describe GdsApi::PublishingApiV2 do
6
6
  include PactTest
7
7
 
8
8
  before do
9
- @api_client = GdsApi::PublishingApiV2.new('http://localhost:3093')
9
+ @api_client = GdsApi::PublishingApiV2.new(publishing_api_host)
10
10
  end
11
11
 
12
12
  describe "#lookup_content_id" do
@@ -29,7 +29,7 @@ describe GdsApi::PublishingApiV2 do
29
29
  @bearer_token = "example-bearer-token"
30
30
  @base_api_url = Plek.current.find("publishing-api")
31
31
  @api_client = GdsApi::PublishingApiV2.new(
32
- "http://localhost:3093",
32
+ publishing_api_host,
33
33
  bearer_token: @bearer_token,
34
34
  )
35
35
 
@@ -1,7 +1,13 @@
1
+ PUBLISHING_API_PORT=3001
2
+
3
+ def publishing_api_host
4
+ "http://localhost:#{PUBLISHING_API_PORT}"
5
+ end
6
+
1
7
  Pact.service_consumer "GDS API Adapters" do
2
8
  has_pact_with "Publishing API" do
3
9
  mock_service :publishing_api do
4
- port 3093
10
+ port PUBLISHING_API_PORT
5
11
  end
6
12
  end
7
13
  end
@@ -25,6 +25,47 @@ describe GdsApi::TestHelpers::PublishingApiV2 do
25
25
 
26
26
  assert_equal([{ "content_id" => "2878337b-bed9-4e7f-85b6-10ed2cbcd504" }], response)
27
27
  end
28
+
29
+ it 'allows params' do
30
+ publishing_api_has_content(
31
+ [{
32
+ "content_id" => "2878337b-bed9-4e7f-85b6-10ed2cbcd504"
33
+ }],
34
+ document_type: 'document_collection',
35
+ query: 'query',
36
+ )
37
+
38
+ response = publishing_api.get_content_items(
39
+ document_type: 'document_collection',
40
+ query: 'query'
41
+ )['results']
42
+
43
+ assert_equal(
44
+ [{ "content_id" => "2878337b-bed9-4e7f-85b6-10ed2cbcd504" }],
45
+ response
46
+ )
47
+ end
48
+
49
+ it 'returns pagination results' do
50
+ publishing_api_has_content(
51
+ [
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
+ ],
57
+ {
58
+ page: 1,
59
+ per_page: 2
60
+ }
61
+ )
62
+
63
+ response = publishing_api.get_content_items({ page: 1, per_page: 2 })
64
+
65
+ assert_equal(response['total'], 4)
66
+ assert_equal(response['pages'], 2)
67
+ assert_equal(response['current_page'], 1)
68
+ end
28
69
  end
29
70
 
30
71
  describe "#publishing_api_has_expanded_links" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gds-api-adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 35.0.0
4
+ version: 35.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Stewart