gds-api-adapters 0.0.49 → 0.0.50

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.
@@ -27,7 +27,11 @@ class GdsApi::Publisher < GdsApi::Base
27
27
 
28
28
  def licences_for_ids(ids)
29
29
  response = get_json("#{@endpoint}/licences.json?ids=#{ids.map(&:to_s).sort.join(',')}")
30
- response.to_ostruct
30
+ if response
31
+ response.to_ostruct
32
+ else
33
+ nil
34
+ end
31
35
  end
32
36
 
33
37
  private
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '0.0.49'
2
+ VERSION = '0.0.50'
3
3
  end
@@ -3,7 +3,7 @@ require 'gds_api/publisher'
3
3
  require 'gds_api/json_client'
4
4
  require 'gds_api/test_helpers/publisher'
5
5
 
6
- class GdsApi::PublisherTest < MiniTest::Unit::TestCase
6
+ describe GdsApi::Publisher do
7
7
  include GdsApi::TestHelpers::Publisher
8
8
 
9
9
  def basic_answer
@@ -54,14 +54,14 @@ class GdsApi::PublisherTest < MiniTest::Unit::TestCase
54
54
  GdsApi::Publisher.new("test")
55
55
  end
56
56
 
57
- def test_given_a_slug_should_go_get_resource_from_publisher_app
57
+ it "should go get resource from publisher app given a slug" do
58
58
  publication_exists(basic_answer)
59
59
  pub = api.publication_for_slug(basic_answer['slug'])
60
60
 
61
61
  assert_equal "Something", pub.body
62
62
  end
63
63
 
64
- def test_should_optionally_accept_an_edition_id
64
+ it "should optionally accept an edition id" do
65
65
  slug = "a-publication"
66
66
  publication = %@{"audiences":[""],
67
67
  "slug":"#{slug}",
@@ -76,58 +76,67 @@ class GdsApi::PublisherTest < MiniTest::Unit::TestCase
76
76
  pub = api.publication_for_slug(slug,{:edition => 678})
77
77
  end
78
78
 
79
- def test_should_construct_correct_url_for_a_slug
79
+ it "should construct correct url for a slug" do
80
80
  assert_equal "#{PUBLISHER_ENDPOINT}/publications/slug.json", api.url_for_slug("slug")
81
81
  end
82
82
 
83
- def test_parts_should_be_deserialised_into_whole_objects
83
+ it "should deserialise parts into whole objects" do
84
84
  publication_exists(publication_with_parts)
85
85
  pub = api.publication_for_slug(publication_with_parts['slug'])
86
86
  assert_equal 3, pub.parts.size
87
87
  assert_equal "introduction", pub.parts.first.slug
88
88
  end
89
89
 
90
- def test_a_publication_with_parts_should_have_part_specific_methods
90
+ it "should have part specific methods for a publication with parts" do
91
91
  publication_exists(publication_with_parts)
92
92
  pub = api.publication_for_slug(publication_with_parts['slug'])
93
93
  assert_equal pub.part_index("introduction"),0
94
94
  end
95
95
 
96
- def test_updated_at_should_be_a_time_on_deserialisation
96
+ it "should deserialise updated at as a time" do
97
97
  publication_exists(publication_with_parts)
98
98
  pub = api.publication_for_slug(publication_with_parts['slug'])
99
99
  assert_equal Time, pub.updated_at.class
100
100
  end
101
101
 
102
- def test_should_be_able_to_retrieve_local_transaction_details
102
+ it "should be able to retrieve local transaction details" do
103
103
  stub_request(:post, "#{PUBLISHER_ENDPOINT}/local_transactions/fake-transaction/verify_snac.json").
104
104
  with(:body => "{\"snac_codes\":[12345]}", :headers => GdsApi::JsonClient::REQUEST_HEADERS).
105
105
  to_return(:status => 200, :body => '{"snac": "12345"}', :headers => {})
106
106
  assert_equal '12345', api.council_for_slug('fake-transaction', [12345])
107
107
  end
108
108
 
109
- def test_should_get_licence_details_from_publisher
110
- setup_publisher_licences_stubs
111
-
112
- publisher_has_licence :licence_identifier => "1234", :title => 'Test Licence 1', :slug => 'test-licence-1',
113
- :licence_short_description => 'A short description'
114
- publisher_has_licence :licence_identifier => "1235", :title => 'Test Licence 2', :slug => 'test-licence-2',
115
- :licence_short_description => 'A short description'
116
- publisher_has_licence :licence_identifier => "AB1234", :title => 'Test Licence 3', :slug => 'test-licence-3',
117
- :licence_short_description => 'A short description'
118
-
119
- results = api.licences_for_ids([1234, 'AB1234', 'something'])
120
- assert_equal 2, results.size
121
- assert_equal ['1234', 'AB1234'], results.map(&:licence_identifier)
122
- assert_equal ['Test Licence 1', 'Test Licence 3'], results.map(&:title).sort
123
- assert_equal ['test-licence-1', 'test-licence-3'], results.map(&:slug).sort
124
- assert_equal 'A short description', results[0].licence_short_description
125
- assert_equal 'A short description', results[1].licence_short_description
126
- end
127
-
128
- def test_should_return_empty_array_with_no_licences
129
- setup_publisher_licences_stubs
130
-
131
- assert_equal [], api.licences_for_ids([123,124])
109
+ describe "getting licence details from publisher" do
110
+ it "should get licence details from publisher" do
111
+ setup_publisher_licences_stubs
112
+
113
+ publisher_has_licence :licence_identifier => "1234", :title => 'Test Licence 1', :slug => 'test-licence-1',
114
+ :licence_short_description => 'A short description'
115
+ publisher_has_licence :licence_identifier => "1235", :title => 'Test Licence 2', :slug => 'test-licence-2',
116
+ :licence_short_description => 'A short description'
117
+ publisher_has_licence :licence_identifier => "AB1234", :title => 'Test Licence 3', :slug => 'test-licence-3',
118
+ :licence_short_description => 'A short description'
119
+
120
+ results = api.licences_for_ids([1234, 'AB1234', 'something'])
121
+ assert_equal 2, results.size
122
+ assert_equal ['1234', 'AB1234'], results.map(&:licence_identifier)
123
+ assert_equal ['Test Licence 1', 'Test Licence 3'], results.map(&:title).sort
124
+ assert_equal ['test-licence-1', 'test-licence-3'], results.map(&:slug).sort
125
+ assert_equal 'A short description', results[0].licence_short_description
126
+ assert_equal 'A short description', results[1].licence_short_description
127
+ end
128
+
129
+ it "should return empty array with no licences" do
130
+ setup_publisher_licences_stubs
131
+
132
+ assert_equal [], api.licences_for_ids([123,124])
133
+ end
134
+
135
+ it "should return nil if publisher returns an error" do
136
+ stub_request(:get, %r[\A#{PUBLISHER_ENDPOINT}/licences]).
137
+ to_return(:status => [503, "Service temporarily unabailable"])
138
+
139
+ assert_equal nil, api.licences_for_ids([123,124])
140
+ end
132
141
  end
133
142
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: gds-api-adapters
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.49
5
+ version: 0.0.50
6
6
  platform: ruby
7
7
  authors:
8
8
  - James Stewart
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-06-07 00:00:00 Z
13
+ date: 2012-06-22 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: plek
@@ -185,7 +185,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
185
  requirements:
186
186
  - - ">="
187
187
  - !ruby/object:Gem::Version
188
- hash: 3231493740475825517
188
+ hash: 2100847049130283593
189
189
  segments:
190
190
  - 0
191
191
  version: "0"
@@ -194,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
194
  requirements:
195
195
  - - ">="
196
196
  - !ruby/object:Gem::Version
197
- hash: 3231493740475825517
197
+ hash: 2100847049130283593
198
198
  segments:
199
199
  - 0
200
200
  version: "0"