gds-api-adapters 10.6.0 → 10.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,9 +3,9 @@ require_relative 'finder_schema'
3
3
 
4
4
  module GdsApi
5
5
  class FinderApi < Base
6
- def initialize(url, options, &block)
7
- @schema_factory = options.fetch(:schema_factory) { Schema.method(:new) }
8
- super(url, options, &block)
6
+ def initialize(url, options = {})
7
+ @schema_factory = options.fetch(:schema_factory) { FinderSchema.method(:new) }
8
+ super
9
9
  end
10
10
 
11
11
  def get_documents(finder_slug, options = {})
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '10.6.0'
2
+ VERSION = '10.6.1'
3
3
  end
@@ -2,10 +2,13 @@ require 'test_helper'
2
2
  require 'gds_api/finder_api'
3
3
 
4
4
  describe GdsApi::FinderApi do
5
- before do
6
- @base_api_url = Plek.current.find('finder-api')
7
- @api = GdsApi::FinderApi.new(@base_api_url, schema_factory: schema_factory)
8
- end
5
+ let(:base_api_url) { "http://finder-api" }
6
+ let(:api) {
7
+ GdsApi::FinderApi.new(
8
+ base_api_url,
9
+ schema_factory: schema_factory,
10
+ )
11
+ }
9
12
 
10
13
  let(:schema) { Object.new }
11
14
  let(:schema_factory) {
@@ -29,11 +32,11 @@ describe GdsApi::FinderApi do
29
32
  ]
30
33
  }
31
34
 
32
- req = WebMock.stub_request(:get, "#{@base_api_url}/finders/some-finder-slug/documents.json").
35
+ req = WebMock.stub_request(:get, "#{base_api_url}/finders/some-finder-slug/documents.json").
33
36
  to_return(:body => documents_hash.to_json,
34
37
  :headers => {"Content-type" => "application/json"})
35
38
 
36
- response = @api.get_documents("some-finder-slug")
39
+ response = api.get_documents("some-finder-slug")
37
40
  assert_equal 200, response.code
38
41
  assert_equal documents_hash, response.to_hash
39
42
 
@@ -51,12 +54,12 @@ describe GdsApi::FinderApi do
51
54
  ]
52
55
  }
53
56
 
54
- req = WebMock.stub_request(:get, "#{@base_api_url}/finders/some-finder-slug/documents.json").
57
+ req = WebMock.stub_request(:get, "#{base_api_url}/finders/some-finder-slug/documents.json").
55
58
  with(query: {case_type: 'market-investigations'}).
56
59
  to_return(:body => documents_hash.to_json,
57
60
  :headers => {"Content-type" => "application/json"})
58
61
 
59
- response = @api.get_documents("some-finder-slug", case_type: 'market-investigations')
62
+ response = api.get_documents("some-finder-slug", case_type: 'market-investigations')
60
63
  assert_equal 200, response.code
61
64
  assert_equal documents_hash, response.to_hash
62
65
 
@@ -79,41 +82,42 @@ describe GdsApi::FinderApi do
79
82
  }
80
83
 
81
84
  let(:schema_url) {
82
- "#{@base_api_url}/finders/cma-cases/schema.json"
85
+ "#{base_api_url}/finders/cma-cases/schema.json"
83
86
  }
84
87
 
85
- it "requests the finder's schema" do
86
- req = WebMock.stub_request(:get, schema_url).
88
+
89
+ before do
90
+ @req = WebMock.stub_request(:get, schema_url).
87
91
  to_return(:body => schema_json,
88
92
  :headers => {"Content-type" => "application/json"})
93
+ end
89
94
 
90
- response = @api.get_schema("cma-cases")
95
+ it "requests the finder's schema" do
96
+ api.get_schema("cma-cases")
91
97
 
92
- assert_requested(req)
98
+ assert_requested(@req)
93
99
  end
94
100
 
95
101
  it "constructs and returns a schema object" do
96
- WebMock.stub_request(:get, schema_url)
97
- .to_return(
98
- :body => schema_json,
99
- :headers => {"Content-type" => "application/json"},
100
- )
101
-
102
- returned_schema = @api.get_schema("cma-cases")
102
+ returned_schema = api.get_schema("cma-cases")
103
103
 
104
104
  assert_equal schema, returned_schema
105
105
  schema_factory.verify
106
106
  end
107
107
 
108
108
  it "should forward query parameters" do
109
- req = WebMock.stub_request(:get, "#{@base_api_url}/finders/some-finder-slug/schema.json").
109
+ req = WebMock.stub_request(:get, "#{base_api_url}/finders/some-finder-slug/schema.json").
110
110
  with(query: {locale: 'fr-FR'}).
111
111
  to_return(:body => schema_json,
112
112
  :headers => {"Content-type" => "application/json"})
113
113
 
114
- response = @api.get_schema("some-finder-slug", locale: 'fr-FR')
114
+ response = api.get_schema("some-finder-slug", locale: 'fr-FR')
115
115
 
116
116
  assert_requested(req)
117
117
  end
118
+
119
+ it "defaults the schema factory if not provided" do
120
+ GdsApi::FinderApi.new(base_api_url).get_schema("cma-cases")
121
+ end
118
122
  end
119
123
  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: 10.6.0
4
+ version: 10.6.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -376,7 +376,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
376
376
  version: '0'
377
377
  segments:
378
378
  - 0
379
- hash: 1564566442515579197
379
+ hash: 395287235660569090
380
380
  required_rubygems_version: !ruby/object:Gem::Requirement
381
381
  none: false
382
382
  requirements:
@@ -385,7 +385,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
385
385
  version: '0'
386
386
  segments:
387
387
  - 0
388
- hash: 1564566442515579197
388
+ hash: 395287235660569090
389
389
  requirements: []
390
390
  rubyforge_project:
391
391
  rubygems_version: 1.8.23