gds-api-adapters 27.0.0 → 27.1.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: d5601500bc73e6401843858f7f7bdd8e70f82963
4
- data.tar.gz: 479957e64e4c38b8a16946d8903843bdb2a93972
3
+ metadata.gz: 2cc5c429a92aa4d47b59848ce81b9e9504c9fab8
4
+ data.tar.gz: 7fc82ec64a0798bdcc0757f0f2623f2670f42160
5
5
  SHA512:
6
- metadata.gz: 3cd53fd771715e3f0670a359287a96b1a90efc27bb76fc7f0bcf0cb799beae8b3cf6119023ca96df220ae9f457024a4207929d7798650ae0bbfd58a57ad6fd26
7
- data.tar.gz: b51ff2b5bfeadff897d9e889e984206b052ce9bffdd2428729509f1291b945fba0cd0397d4ae85eb3b61426f765bb5fb281720bc85249d2e9265971255f16872
6
+ metadata.gz: 0836a94e3cb61226df632dfff455226282b89e3df98cfbe83ecf5ee854602c1786a6c1c3544b39495e07a99e6cb1666266512acefe76684a1447aefb0f352415
7
+ data.tar.gz: 838dc7fcc6d4b5c2cde66ad9f6a069840f597b0464c194784ee901af5579acbb7b3fc4d5f12c531f3cd2c3035810271041da20b329f129aaa7e45ac7210f871e
@@ -14,10 +14,11 @@ module GdsApi
14
14
  class HTTPErrorResponse < BaseError
15
15
  attr_accessor :code, :error_details
16
16
 
17
- def initialize(code, message = nil, error_details = nil)
17
+ def initialize(code, message = nil, error_details = nil, request_body = nil)
18
18
  super(message)
19
19
  @code = code
20
20
  @error_details = error_details
21
+ @request_body = request_body
21
22
  end
22
23
  end
23
24
 
@@ -52,8 +53,8 @@ module GdsApi
52
53
  ignoring([HTTPNotFound, HTTPGone], &block)
53
54
  end
54
55
 
55
- def build_specific_http_error(error, url, details = nil)
56
- message = "url: #{url}\n#{error.http_body}"
56
+ def build_specific_http_error(error, url, details = nil, request_body = nil)
57
+ message = "URL: #{url}\nResponse body:\n#{error.http_body}\n\nRequest body:\n#{request_body}"
57
58
  code = error.http_code
58
59
 
59
60
  case code
@@ -121,7 +121,7 @@ module GdsApi
121
121
  def do_raw_request(method, url, params = nil)
122
122
  response = do_request(method, url, params)
123
123
  rescue RestClient::Exception => e
124
- raise build_specific_http_error(e, url)
124
+ raise build_specific_http_error(e, url, nil, params)
125
125
  end
126
126
 
127
127
  # method: the symbolic name of the method to use, e.g. :get, :post
@@ -141,7 +141,7 @@ module GdsApi
141
141
  rescue JSON::ParserError
142
142
  nil
143
143
  end
144
- raise build_specific_http_error(e, url, error_details)
144
+ raise build_specific_http_error(e, url, error_details, params)
145
145
  end
146
146
 
147
147
  # If no custom response is given, just instantiate Response
@@ -4,13 +4,15 @@ require 'json'
4
4
  module GdsApi
5
5
  module TestHelpers
6
6
  module EmailAlertApi
7
+ EMAIL_ALERT_API_ENDPOINT = Plek.find("email-alert-api")
8
+
7
9
  def email_alert_api_has_subscriber_list(attributes)
8
10
  title = attributes.fetch("title")
9
11
  tags = attributes.fetch("tags")
10
12
 
11
13
  query = Rack::Utils.build_nested_query(tags: tags)
12
14
 
13
- stub_request(:get, "http://some-domain/subscriber-lists?#{query}")
15
+ stub_request(:get, subscriber_lists_url(query))
14
16
  .to_return(
15
17
  :status => 200,
16
18
  :body => get_subscriber_list_response(attributes).to_json,
@@ -20,12 +22,12 @@ module GdsApi
20
22
  def email_alert_api_does_not_have_subscriber_list(attributes)
21
23
  query = Rack::Utils.build_nested_query(tags: attributes.fetch("tags"))
22
24
 
23
- stub_request(:get, "http://some-domain/subscriber-lists?#{query}")
25
+ stub_request(:get, subscriber_lists_url(query))
24
26
  .to_return(status: 404)
25
27
  end
26
28
 
27
29
  def email_alert_api_creates_subscriber_list(attributes)
28
- stub_request(:post, "http://some-domain/subscriber-lists")
30
+ stub_request(:post, subscriber_lists_url)
29
31
  .to_return(
30
32
  :status => 201,
31
33
  :body => get_subscriber_list_response(attributes).to_json,
@@ -33,7 +35,7 @@ module GdsApi
33
35
  end
34
36
 
35
37
  def email_alert_api_refuses_to_create_subscriber_list
36
- stub_request(:post, "http://some-domain/subscriber-lists")
38
+ stub_request(:post, subscriber_lists_url)
37
39
  .to_return(
38
40
  :status => 422,
39
41
  )
@@ -54,7 +56,7 @@ module GdsApi
54
56
  end
55
57
 
56
58
  def email_alert_api_accepts_alert
57
- stub_request(:post, "http://some-domain/notifications")
59
+ stub_request(:post, notifications_url)
58
60
  .to_return(
59
61
  :status => 202,
60
62
  :body => {}.to_json,
@@ -64,6 +66,17 @@ module GdsApi
64
66
  def post_alert_response
65
67
  {}
66
68
  end
69
+
70
+ private
71
+
72
+ def subscriber_lists_url(query = nil)
73
+ url = EMAIL_ALERT_API_ENDPOINT + "/subscriber-lists"
74
+ query ? "#{url}?#{query}" : url
75
+ end
76
+
77
+ def notifications_url
78
+ EMAIL_ALERT_API_ENDPOINT + "/notifications"
79
+ end
67
80
  end
68
81
  end
69
82
  end
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '27.0.0'
2
+ VERSION = '27.1.0'
3
3
  end
@@ -45,7 +45,7 @@ describe GdsApi::ContentStore do
45
45
  end
46
46
 
47
47
  assert_equal 404, e.code
48
- assert_equal "url: #{@base_api_url}/content/non-existent", e.message.strip
48
+ assert_equal "URL: #{@base_api_url}/content/non-existent\nResponse body:\n\n\nRequest body:", e.message.strip
49
49
  end
50
50
  end
51
51
 
@@ -5,7 +5,7 @@ require 'gds_api/test_helpers/email_alert_api'
5
5
  describe GdsApi::EmailAlertApi do
6
6
  include GdsApi::TestHelpers::EmailAlertApi
7
7
 
8
- let(:base_url) { "http://some-domain" }
8
+ let(:base_url) { Plek.find("email-alert-api") }
9
9
  let(:api_client) { GdsApi::EmailAlertApi.new(base_url) }
10
10
 
11
11
  let(:title) { "Some Title" }
@@ -925,6 +925,102 @@ describe GdsApi::PublishingApiV2 do
925
925
  { 'title' => 'Content Item B', 'base_path' => '/another-base-path' },
926
926
  ], response.to_a
927
927
  end
928
+
929
+ it "returns the content items in english locale by default" do
930
+ publishing_api
931
+ .given("a content item exists in multiple locales with content_id: #{@content_id}")
932
+ .upon_receiving("a get entries request")
933
+ .with(
934
+ method: :get,
935
+ path: "/v2/content",
936
+ query: "content_format=topic&fields%5B%5D=content_id&fields%5B%5D=locale",
937
+ headers: {
938
+ "Content-Type" => "application/json",
939
+ },
940
+ )
941
+ .will_respond_with(
942
+ status: 200,
943
+ body: [
944
+ { content_id: @content_id, locale: "en" },
945
+ ]
946
+ )
947
+
948
+ response = @api_client.get_content_items(
949
+ content_format: 'topic',
950
+ fields: [:content_id, :locale],
951
+ )
952
+
953
+ assert_equal 200, response.code
954
+ assert_equal [
955
+ { 'content_id' => @content_id, 'locale' => 'en' },
956
+ ], response.to_a
957
+ end
958
+
959
+ it "returns the content items in a specific locale" do
960
+ publishing_api
961
+ .given("a content item exists in multiple locales with content_id: #{@content_id}")
962
+ .upon_receiving("a get entries request with a specific locale")
963
+ .with(
964
+ method: :get,
965
+ path: "/v2/content",
966
+ query: "content_format=topic&fields%5B%5D=content_id&fields%5B%5D=locale&locale=fr",
967
+ headers: {
968
+ "Content-Type" => "application/json",
969
+ },
970
+ )
971
+ .will_respond_with(
972
+ status: 200,
973
+ body: [
974
+ { content_id: @content_id, locale: "fr" },
975
+ ]
976
+ )
977
+
978
+ response = @api_client.get_content_items(
979
+ content_format: 'topic',
980
+ fields: [:content_id, :locale],
981
+ locale: 'fr',
982
+ )
983
+
984
+ assert_equal 200, response.code
985
+ assert_equal [
986
+ { 'content_id' => @content_id, 'locale' => 'fr' },
987
+ ], response.to_a
988
+ end
989
+
990
+ it "returns the content items in all the available locales" do
991
+ publishing_api
992
+ .given("a content item exists in multiple locales with content_id: #{@content_id}")
993
+ .upon_receiving("a get entries request with an 'all' locale")
994
+ .with(
995
+ method: :get,
996
+ path: "/v2/content",
997
+ query: "content_format=topic&fields%5B%5D=content_id&fields%5B%5D=locale&locale=all",
998
+ headers: {
999
+ "Content-Type" => "application/json",
1000
+ },
1001
+ )
1002
+ .will_respond_with(
1003
+ status: 200,
1004
+ body: [
1005
+ { content_id: @content_id, locale: "en" },
1006
+ { content_id: @content_id, locale: "fr" },
1007
+ { content_id: @content_id, locale: "ar" },
1008
+ ]
1009
+ )
1010
+
1011
+ response = @api_client.get_content_items(
1012
+ content_format: 'topic',
1013
+ fields: [:content_id, :locale],
1014
+ locale: 'all',
1015
+ )
1016
+
1017
+ assert_equal 200, response.code
1018
+ assert_equal [
1019
+ { 'content_id' => @content_id, 'locale' => 'en' },
1020
+ { 'content_id' => @content_id, 'locale' => 'fr' },
1021
+ { 'content_id' => @content_id, 'locale' => 'ar' },
1022
+ ], response.to_a
1023
+ end
928
1024
  end
929
1025
 
930
1026
  describe "#discard_draft(content_id, options = {})" do
@@ -447,7 +447,7 @@ describe GdsApi::Router do
447
447
 
448
448
  refute_nil e
449
449
  assert_equal 500, e.code
450
- assert_equal "url: #{@base_api_url}/routes/commit\nFailed to update all routers", e.message
450
+ assert_equal "URL: #{@base_api_url}/routes/commit\nResponse body:\nFailed to update all routers\n\nRequest body:\n{}", e.message
451
451
  end
452
452
  end
453
453
  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: 27.0.0
4
+ version: 27.1.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: 2016-01-18 00:00:00.000000000 Z
11
+ date: 2016-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: plek