gds-api-adapters 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,23 +1,22 @@
1
1
  require_relative "base"
2
2
 
3
3
  class GdsApi::LicenceApplication < GdsApi::Base
4
+ def all_licences
5
+ get_json!("#{@endpoint}/api/licences")
6
+ end
7
+
4
8
  def details_for_licence(id, snac_code = nil)
5
9
  return nil if id.nil?
6
-
7
- if response = get_json(build_url(id, snac_code))
8
- response.to_hash
9
- else
10
- nil
11
- end
10
+ get_json(build_licence_url(id, snac_code))
12
11
  end
13
12
 
14
13
  private
15
14
 
16
- def build_url(id, snac_code)
15
+ def build_licence_url(id, snac_code)
17
16
  if snac_code
18
- "#{@endpoint}/api/#{id}/#{snac_code}"
17
+ "#{@endpoint}/api/licence/#{id}/#{snac_code}"
19
18
  else
20
- "#{@endpoint}/api/#{id}"
19
+ "#{@endpoint}/api/licence/#{id}"
21
20
  end
22
21
  end
23
22
  end
@@ -0,0 +1,24 @@
1
+ require 'gds_api/test_helpers/json_client_helper'
2
+
3
+ module GdsApi
4
+ module TestHelpers
5
+ module LicenceApplication
6
+ LICENCE_APPLICATION_ENDPOINT = "https://licenceapplication.test.alphagov.co.uk"
7
+
8
+ def licence_exists(identifier, licence)
9
+ licence = licence.to_json unless licence.is_a?(String)
10
+ stub_request(:get, "#{LICENCE_APPLICATION_ENDPOINT}/api/licence/#{identifier}").
11
+ with(headers: GdsApi::JsonClient::DEFAULT_REQUEST_HEADERS).
12
+ to_return(status: 200,
13
+ body: licence)
14
+ end
15
+
16
+ def licence_does_not_exist(identifier)
17
+ stub_request(:get, "#{LICENCE_APPLICATION_ENDPOINT}/api/licence/#{identifier}").
18
+ with(headers: GdsApi::JsonClient::DEFAULT_REQUEST_HEADERS).
19
+ to_return(status: 404,
20
+ body: "{\"error\": [\"Unrecognised Licence Id: #{identifier}\"]}")
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '2.1.0'
2
+ VERSION = '2.2.0'
3
3
  end
@@ -11,9 +11,14 @@ class GdsApiBaseTest < MiniTest::Unit::TestCase
11
11
  end
12
12
 
13
13
  def setup
14
+ @orig_cache = GdsApi::JsonClient.cache
14
15
  @api = ConcreteApi.new('test')
15
16
  end
16
17
 
18
+ def teardown
19
+ GdsApi::JsonClient.cache = @orig_cache
20
+ end
21
+
17
22
  def test_should_construct_escaped_query_string
18
23
  api = ConcreteApi.new('test')
19
24
  url = api.url_for_slug("slug", "a" => " ", "b" => "/")
@@ -1,7 +1,13 @@
1
1
  require "test_helper"
2
2
  require "gds_api/licence_application"
3
+ require "gds_api/test_helpers/licence_application"
3
4
 
4
5
  class LicenceApplicationApiTest < MiniTest::Unit::TestCase
6
+ include GdsApi::TestHelpers::LicenceApplication
7
+
8
+ def setup
9
+ @core_url = LICENCE_APPLICATION_ENDPOINT
10
+ end
5
11
 
6
12
  def api
7
13
  GdsApi::LicenceApplication.new "test"
@@ -11,67 +17,158 @@ class LicenceApplicationApiTest < MiniTest::Unit::TestCase
11
17
  assert_equal false, api.nil?
12
18
  end
13
19
 
14
- def test_should_return_nil_if_id_nil
15
- assert_equal nil, api.details_for_licence(nil)
20
+ def test_should_return_list_of_licences
21
+ stub_request(:get, "#{@core_url}/api/licences").
22
+ with(headers: GdsApi::JsonClient::DEFAULT_REQUEST_HEADERS).
23
+ to_return(:status => 200,
24
+ :body => <<-EOS
25
+ [
26
+ {
27
+ "code":"1324-5-1",
28
+ "name":"Land drainage consents",
29
+ "legislation":[
30
+ "Land Drainage Act 1991"
31
+ ]
32
+ },
33
+ {
34
+ "code":"695-5-1",
35
+ "name":"Skip operator licence",
36
+ "legislation":[
37
+ "Highways Act 1980, Section 139"
38
+ ]
39
+ },
40
+ {
41
+ "code":"1251-4-1",
42
+ "name":"Residential care homes",
43
+ "legislation":[
44
+ "Health and Personal Social Services (Quality, Improvement and Regulation) (Northern Ireland) Order 2003"
45
+ ]
46
+ }
47
+ ]
48
+ EOS
49
+ )
50
+
51
+ land_drainage = {
52
+ "code" => "1324-5-1",
53
+ "name" => "Land drainage consents",
54
+ "legislation" => ["Land Drainage Act 1991"],
55
+ }
56
+
57
+ assert_includes api.all_licences, land_drainage
16
58
  end
17
59
 
18
- def test_should_return_an_error_message_if_licence_is_unrecognised
19
- stub_request(:get, "https://licenceapplication.test.alphagov.co.uk/api/bloop").
60
+ def test_should_return_error_message_if_licences_collection_not_found
61
+ stub_request(:get, "#{@core_url}/api/licences").
20
62
  with(headers: GdsApi::JsonClient::DEFAULT_REQUEST_HEADERS).
21
- to_return(status: 404, body: "{\"error\": [\"Unrecognised Licence Id: bloop\"]}")
63
+ to_return(status: 404,
64
+ body: "{\"error\": \"Error\"}")
22
65
 
23
- assert_equal nil, api.details_for_licence("bloop")
66
+ assert_raises GdsApi::HTTPNotFound do
67
+ api.all_licences
68
+ end
69
+ end
70
+
71
+ def test_should_return_nil_if_id_nil
72
+ assert_nil api.details_for_licence(nil)
73
+ end
74
+
75
+ def test_should_return_nil_if_licence_is_unrecognised
76
+ licence_does_not_exist('bloop')
77
+
78
+ assert_nil api.details_for_licence("bloop")
24
79
  end
25
80
 
26
81
  def test_should_provide_full_licence_details_for_canonical_id
27
- stub_request(:get, "https://licenceapplication.test.alphagov.co.uk/api/590001").
28
- with(headers: GdsApi::JsonClient::DEFAULT_REQUEST_HEADERS).
29
- to_return(status: 200, body: "{\"issuingAuthorityType\":\"non-geographical\",\"geographicalAvailability\":\"England\",\"issuingAuthorities\":[{\"authorityName\":\"Authority Name\",\"interactions\":{\"apply\":{\"url\":\"www.gov.uk\",\"usesLicensify\":true,\"description\":\"Custom description\",\"payment\":\"none\",\"paymentAmount\":0}}}]}")
82
+ licence_exists('590001', {"isLocationSpecific" => true, "geographicalAvailability" => ["England","Wales"], "issuingAuthorities" => []})
30
83
 
31
84
  expected = {
32
- "issuingAuthorityType" => "non-geographical",
33
- "geographicalAvailability" => "England",
34
- "issuingAuthorities" => [{"authorityName" => "Authority Name",
35
- "interactions" => {
36
- "apply" => {
37
- "url" => "www.gov.uk",
38
- "usesLicensify" => true,
39
- "description" => "Custom description",
40
- "payment" => "none",
41
- "paymentAmount" => 0}
42
- }
43
- }]
85
+ "isLocationSpecific" => true,
86
+ "geographicalAvailability" => ["England", "Wales"],
87
+ "issuingAuthorities" => []
44
88
  }
45
89
 
46
- assert_equal expected, api.details_for_licence("590001")
90
+ assert_equal expected, api.details_for_licence("590001").to_hash
47
91
  end
48
92
 
49
- def test_should_return_an_error_message_for_bad_snac_code_entry
50
- stub_request(:get, "https://licenceapplication.test.alphagov.co.uk/api/590001/bleep").
51
- with(headers: GdsApi::JsonClient::DEFAULT_REQUEST_HEADERS).
52
- to_return(status: 404, body: "{\"error\": [\"Unrecognised SNAC: bleep\"]}")
93
+ def test_should_return_nil_for_bad_snac_code_entry
94
+ licence_does_not_exist('590001/bleep')
53
95
 
54
- assert_equal nil, api.details_for_licence("590001", "bleep")
96
+ assert_nil api.details_for_licence("590001", "bleep")
55
97
  end
56
98
 
57
- def test_should_return_error_messages_for_bad_licence_id_and_snac_code
58
- stub_request(:get, "https://licenceapplication.test.alphagov.co.uk/api/bloop/bleep").
59
- with(headers: GdsApi::JsonClient::DEFAULT_REQUEST_HEADERS).
60
- to_return(status: 404, body: "{\"error\": [\"Unrecognised Licence Id: bloop\", \"Unrecognised SNAC: bleep\"]}")
99
+ def test_should_return_nil_for_bad_licence_id_and_snac_code
100
+ licence_does_not_exist('bloop/bleep')
61
101
 
62
- assert_equal nil, api.details_for_licence("bloop", "bleep")
102
+ assert_nil api.details_for_licence("bloop", "bleep")
63
103
  end
64
104
 
65
105
  def test_should_return_error_message_to_pick_a_relevant_snac_code_for_the_provided_licence_id
66
- stub_request(:get, "https://licenceapplication.test.alphagov.co.uk/api/590001/sw10").
106
+ stub_request(:get, "#{@core_url}/api/licence/590001/sw10").
67
107
  with(headers: GdsApi::JsonClient::DEFAULT_REQUEST_HEADERS).
68
- to_return(status: 200, body: "{\"error\": [\"Licence not available in the provided snac area\"], \"geographicalAvailability\": [\"Scotland\", \"NI\"]}")
108
+ to_return(status: 404,
109
+ body: "{\"error\": \"No authorities found for the licence 590001 and for the snacCode sw10\"}")
69
110
 
70
- expected = {
71
- "error" => ["Licence not available in the provided snac area"],
72
- "geographicalAvailability" => ["Scotland", "NI"]
73
- }
111
+ assert_nil api.details_for_licence("590001", "sw10")
112
+ end
74
113
 
75
- assert_equal expected, api.details_for_licence("590001", "sw10")
114
+ def test_should_return_full_licence_details_with_location_specific_information
115
+ licence_exists('866-5-1/00AA', <<-EOS
116
+ {
117
+ "isLocationSpecific":true,
118
+ "geographicalAvailability":[
119
+ "England",
120
+ "Wales"
121
+ ],
122
+ "issuingAuthorities":[
123
+ {
124
+ "authorityName":"City of London",
125
+ "authorityInteractions":{
126
+ "apply":[
127
+ {
128
+ "url":"https://www.gov.uk/motor-salvage-operator-registration/city-of-london/apply-1",
129
+ "usesLicensify":true,
130
+ "description":"Application to register as a motor salvage operator",
131
+ "payment":"none"
132
+ }
133
+ ],
134
+ "renew":[
135
+ {
136
+ "url":"https://www.gov.uk/motor-salvage-operator-registration/city-of-london/renew-1",
137
+ "usesLicensify":true,
138
+ "description":"Application to renew a registration as motor salvage operator",
139
+ "payment":"none"
140
+ }
141
+ ],
142
+ "change":[
143
+ {
144
+ "url":"https://www.gov.uk/motor-salvage-operator-registration/city-of-london/change-1",
145
+ "usesLicensify":true,
146
+ "description":"Application to change a registration as motor salvage operator",
147
+ "payment":"none"
148
+ },
149
+ {
150
+ "url":"https://www.gov.uk/motor-salvage-operator-registration/city-of-london/change-2",
151
+ "usesLicensify":true,
152
+ "description":"Application to surrender a registration as motor salvage operator",
153
+ "payment":"none"
154
+ }
155
+ ]
156
+ }
157
+ }
158
+ ]
159
+ }
160
+ EOS
161
+ )
162
+
163
+ response = api.details_for_licence("866-5-1", "00AA")
164
+
165
+ assert_equal true, response["isLocationSpecific"]
166
+
167
+ assert_includes response["issuingAuthorities"][0]["authorityInteractions"]["apply"], {
168
+ "url" => "https://www.gov.uk/motor-salvage-operator-registration/city-of-london/apply-1",
169
+ "usesLicensify" => true,
170
+ "description" => "Application to register as a motor salvage operator",
171
+ "payment" => "none"
172
+ }
76
173
  end
77
174
  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: 2.1.0
5
+ version: 2.2.0
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-09-17 00:00:00 Z
13
+ date: 2012-09-19 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: plek
@@ -157,6 +157,7 @@ files:
157
157
  - lib/gds_api/content_api.rb
158
158
  - lib/gds_api/licence_application.rb
159
159
  - lib/gds_api/test_helpers/content_api.rb
160
+ - lib/gds_api/test_helpers/licence_application.rb
160
161
  - lib/gds_api/test_helpers/contactotron.rb
161
162
  - lib/gds_api/test_helpers/json_client_helper.rb
162
163
  - lib/gds_api/test_helpers/publisher.rb
@@ -202,7 +203,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
202
203
  requirements:
203
204
  - - ">="
204
205
  - !ruby/object:Gem::Version
205
- hash: -2247885112967886087
206
+ hash: -4439184631815807956
206
207
  segments:
207
208
  - 0
208
209
  version: "0"
@@ -211,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
211
212
  requirements:
212
213
  - - ">="
213
214
  - !ruby/object:Gem::Version
214
- hash: -2247885112967886087
215
+ hash: -4439184631815807956
215
216
  segments:
216
217
  - 0
217
218
  version: "0"