gds-api-adapters 7.22.3 → 7.23.3

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.
@@ -0,0 +1,21 @@
1
+ require_relative 'base'
2
+ require_relative 'exceptions'
3
+ require_relative 'list_response'
4
+
5
+ class GdsApi::BusinessSupportApi < GdsApi::Base
6
+ include GdsApi::ExceptionHandling
7
+
8
+ def schemes(options = {})
9
+ get_list!(url_for_slug('business-support-schemes', options))
10
+ end
11
+
12
+ def scheme(slug)
13
+ get_json!(url_for_slug("business-support-schemes/#{slug}"))
14
+ end
15
+
16
+ private
17
+
18
+ def base_url
19
+ endpoint
20
+ end
21
+ end
@@ -0,0 +1,49 @@
1
+ require 'gds_api/test_helpers/json_client_helper'
2
+ require 'cgi'
3
+ require 'gds_api/test_helpers/common_responses'
4
+
5
+ module GdsApi
6
+ module TestHelpers
7
+ module BusinessSupportApi
8
+ include GdsApi::TestHelpers::CommonResponses
9
+ # Generally true. If you are initializing the client differently,
10
+ # you could redefine/override the constant or stub directly.
11
+ BUSINESS_SUPPORT_API_ENDPOINT = Plek.current.find('business-support-api')
12
+
13
+ def setup_business_support_api_schemes_stubs
14
+ @stubbed_content_api_business_support_schemes = {}
15
+ stub_request(:get, %r{\A#{BUSINESS_SUPPORT_API_ENDPOINT}/business-support-schemes\.json}).to_return do |request|
16
+ if request.uri.query_values
17
+ key = request.uri.query_values.values.sort.hash
18
+ results = @stubbed_content_api_business_support_schemes[key] || []
19
+ else
20
+ results = @stubbed_content_api_business_support_schemes.values.flatten
21
+ end
22
+ {:body => plural_response_base.merge("results" => results, "total" => results.size).to_json}
23
+ end
24
+
25
+ end
26
+
27
+ def business_support_api_has_scheme(scheme, facets={})
28
+ key = facets.values.sort.hash
29
+ unless @stubbed_content_api_business_support_schemes[key]
30
+ @stubbed_content_api_business_support_schemes[key] = []
31
+ end
32
+ @stubbed_content_api_business_support_schemes[key] << scheme
33
+ end
34
+
35
+ def business_support_api_has_schemes(schemes, facets={})
36
+ schemes.each do |scheme|
37
+ business_support_api_has_scheme(scheme, facets)
38
+ end
39
+ end
40
+
41
+ def business_support_api_has_a_scheme(slug, scheme)
42
+ title = scheme.delete(:title)
43
+ stub_request(:get, %r{\A#{BUSINESS_SUPPORT_API_ENDPOINT}/business-support-schemes/#{slug}\.json}).to_return do |request|
44
+ {:body => response_base.merge(:format => 'business_support', :title => title, :details => scheme).to_json}
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '7.22.3'
2
+ VERSION = '7.23.3'
3
3
  end
@@ -0,0 +1,45 @@
1
+ require 'test_helper'
2
+ require 'gds_api/business_support_api'
3
+ require 'gds_api/test_helpers/business_support_api'
4
+
5
+ describe GdsApi::BusinessSupportApi do
6
+ include GdsApi::TestHelpers::BusinessSupportApi
7
+
8
+ before do
9
+ @base_api_url = Plek.current.find("business-support-api")
10
+ @api = GdsApi::BusinessSupportApi.new(@base_api_url)
11
+ setup_business_support_api_schemes_stubs
12
+ end
13
+
14
+ describe "searching for schemes" do
15
+ it "should return all schemes when called with no facets" do
16
+ business_support_api_has_schemes([:scheme1, :scheme2, :scheme3])
17
+ response = @api.schemes
18
+ assert_equal ["scheme1", "scheme2", "scheme3"], response['results']
19
+ end
20
+ it "should return schemes for applicable facets" do
21
+ business_support_api_has_scheme(:scottish_manufacturing, {locations: 'scotland', sectors: 'manufacturing', support_types: 'grant,loan'})
22
+ response = @api.schemes({locations: 'scotland', sectors: 'manufacturing', support_types: 'grant,loan'})
23
+ assert_equal ["scottish_manufacturing"], response["results"]
24
+ end
25
+ it "should return an empty result when facets are not applicable" do
26
+ business_support_api_has_scheme(:super_secret, {locations: 'the moon', sectors: 'espionage'})
27
+ response = @api.schemes({locations: 'earth', sectors: 'espionage'})
28
+ assert_empty response["results"]
29
+ end
30
+ end
31
+
32
+ describe "finding a scheme by slug" do
33
+ it "should give the scheme details" do
34
+ business_support_api_has_a_scheme('superbiz-wunderfundz', {
35
+ :title => 'Superbiz wunderfundz',
36
+ :short_description => 'Wunderfundz for your superbiz',
37
+ :body => 'Do you run or work for a Superbiz? Well we have the Wunderfundz.'})
38
+ response = @api.scheme('superbiz-wunderfundz')
39
+ assert_equal 'business_support', response['format']
40
+ assert_equal 'Superbiz wunderfundz', response['title']
41
+ assert_equal 'Wunderfundz for your superbiz', response['details']['short_description']
42
+ assert_equal 'Do you run or work for a Superbiz? Well we have the Wunderfundz.', response['details']['body']
43
+ end
44
+ end
45
+ end
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: 7.22.3
4
+ version: 7.23.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-04 00:00:00.000000000 Z
12
+ date: 2013-12-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: plek
@@ -284,6 +284,7 @@ files:
284
284
  - lib/gds_api/test_helpers/fact_cave.rb
285
285
  - lib/gds_api/test_helpers/publisher.rb
286
286
  - lib/gds_api/test_helpers/common_responses.rb
287
+ - lib/gds_api/test_helpers/business_support_api.rb
287
288
  - lib/gds_api/test_helpers/content_api.rb
288
289
  - lib/gds_api/organisations.rb
289
290
  - lib/gds_api/needotron.rb
@@ -300,6 +301,7 @@ files:
300
301
  - lib/gds_api/response.rb
301
302
  - lib/gds_api/publisher.rb
302
303
  - lib/gds_api/router.rb
304
+ - lib/gds_api/business_support_api.rb
303
305
  - lib/gds_api/content_api.rb
304
306
  - README.md
305
307
  - Rakefile
@@ -326,6 +328,7 @@ files:
326
328
  - test/gds_api_base_test.rb
327
329
  - test/worldwide_api_test.rb
328
330
  - test/test_helper.rb
331
+ - test/business_support_api_test.rb
329
332
  homepage: http://github.com/alphagov/gds-api-adapters
330
333
  licenses: []
331
334
  post_install_message:
@@ -340,7 +343,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
340
343
  version: '0'
341
344
  segments:
342
345
  - 0
343
- hash: 2261435228405301514
346
+ hash: 1175191499223805366
344
347
  required_rubygems_version: !ruby/object:Gem::Requirement
345
348
  none: false
346
349
  requirements:
@@ -349,7 +352,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
349
352
  version: '0'
350
353
  segments:
351
354
  - 0
352
- hash: 2261435228405301514
355
+ hash: 1175191499223805366
353
356
  requirements: []
354
357
  rubyforge_project:
355
358
  rubygems_version: 1.8.23
@@ -380,3 +383,4 @@ test_files:
380
383
  - test/gds_api_base_test.rb
381
384
  - test/worldwide_api_test.rb
382
385
  - test/test_helper.rb
386
+ - test/business_support_api_test.rb