gds-api-adapters 10.6.2 → 10.6.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,6 +8,13 @@ class GdsApi::NeedApi < GdsApi::Base
8
8
  get_list!("#{endpoint}/needs#{query}")
9
9
  end
10
10
 
11
+ def needs_by_id(*ids)
12
+ ids_string = ids.flatten.map(&:to_i).sort.join(',')
13
+ query = query_string(ids: ids_string)
14
+
15
+ get_list!("#{endpoint}/needs#{query}")
16
+ end
17
+
11
18
  def need(need_id)
12
19
  get_json("#{endpoint}/needs/#{CGI.escape(need_id.to_s)}")
13
20
  end
@@ -50,6 +50,16 @@ module GdsApi
50
50
  stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
51
51
  end
52
52
 
53
+ def need_api_has_need_ids(needs)
54
+ ids = needs.map {|need| (need["id"] || need[:id]).to_i }.sort.join(',')
55
+ url = NEED_API_ENDPOINT + "/needs?ids=#{ids}"
56
+
57
+ body = response_base.merge(
58
+ "results" => needs
59
+ )
60
+ stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
61
+ end
62
+
53
63
  def need_api_has_need(need)
54
64
  need_id = need["id"] || need[:id]
55
65
  raise ArgumentError, "Test need is missing an ID" unless need_id
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '10.6.2'
2
+ VERSION = '10.6.3'
3
3
  end
@@ -10,6 +10,55 @@ describe GdsApi::NeedApi do
10
10
  @api = GdsApi::NeedApi.new(@base_api_url)
11
11
  end
12
12
 
13
+ describe "requesting needs by ID" do
14
+ before do
15
+ need_api_has_need_ids([
16
+ {
17
+ "id" => "1",
18
+ "role" => "parent",
19
+ "goal" => "apply for a primary school place",
20
+ "benefit" => "my child can start school",
21
+ },
22
+ {
23
+ "id" => "2",
24
+ "role" => "user",
25
+ "goal" => "find out about becoming a British citizen",
26
+ "benefit" => "i can take the correct steps to apply for citizenship",
27
+ },
28
+ {
29
+ "id" => "3",
30
+ "role" => "user",
31
+ "goal" => "find out about unemployment benefits",
32
+ "benefit" => "i have financial support whilst unemployed",
33
+ }
34
+ ])
35
+ end
36
+
37
+ it "returns a list of needs matching the IDs" do
38
+ needs = @api.needs_by_id(1,2,3)
39
+
40
+ assert_equal 3, needs.count
41
+ assert_equal %w(1 2 3), needs.map(&:id)
42
+ assert_equal "apply for a primary school place", needs.results[0].goal
43
+ assert_equal "find out about becoming a British citizen", needs.results[1].goal
44
+ assert_equal "find out about unemployment benefits", needs.results[2].goal
45
+ end
46
+
47
+ it "makes the same request regardless of the order of the IDs" do
48
+ needs = @api.needs_by_id(2,1,3)
49
+
50
+ assert_equal 3, needs.count
51
+ assert_equal %w(1 2 3), needs.map(&:id)
52
+ end
53
+
54
+ it "correctly sorts IDs requested as strings" do
55
+ needs = @api.needs_by_id(%w(02 3 1))
56
+
57
+ assert_equal 3, needs.count
58
+ assert_equal %w(1 2 3), needs.map(&:id)
59
+ end
60
+ end
61
+
13
62
  describe "requesting needs" do
14
63
  it "should return a list of all needs" do
15
64
  req = need_api_has_needs([
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.2
4
+ version: 10.6.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: 2014-04-08 00:00:00.000000000 Z
12
+ date: 2014-04-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: plek
@@ -376,7 +376,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
376
376
  version: '0'
377
377
  segments:
378
378
  - 0
379
- hash: 2318323185419183875
379
+ hash: -3682421441784526579
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: 2318323185419183875
388
+ hash: -3682421441784526579
389
389
  requirements: []
390
390
  rubyforge_project:
391
391
  rubygems_version: 1.8.23