gds-api-adapters 7.15.0 → 7.16.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,10 +8,19 @@ class GdsApi::NeedApi < GdsApi::Base
8
8
  get_list!("#{endpoint}/needs#{query}")
9
9
  end
10
10
 
11
+ def need(need_id)
12
+ get_json("#{endpoint}/needs/#{CGI.escape(need_id.to_s)}")
13
+ end
14
+
11
15
  def create_need(need)
12
16
  post_json!("#{endpoint}/needs", need)
13
17
  end
14
18
 
19
+ def update_need(need_id, need_update)
20
+ # `need_update` can be a hash of updated fields or a complete need
21
+ put_json!("#{endpoint}/needs/#{CGI.escape(need_id.to_s)}", need_update)
22
+ end
23
+
15
24
  def organisations
16
25
  get_json!("#{endpoint}/organisations")["organisations"]
17
26
  end
@@ -39,6 +39,27 @@ module GdsApi
39
39
  )
40
40
  stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
41
41
  end
42
+
43
+ def need_api_has_need(need)
44
+ need_id = need["need_id"] || need[:need_id]
45
+ raise ArgumentError, "Test need is missing an ID" unless need_id
46
+
47
+ url = NEED_API_ENDPOINT + "/needs/#{need_id}"
48
+ stub_request(:get, url).to_return(status: 200, body: need.to_json, headers: {})
49
+ end
50
+
51
+ def need_api_has_no_need(need_id)
52
+ url = NEED_API_ENDPOINT + "/needs/#{need_id}"
53
+ not_found_body = {
54
+ "_response_info" => {"status" => "not_found"},
55
+ "error" => "No need exists with this ID"
56
+ }
57
+ stub_request(:get, url).to_return(
58
+ status: 404,
59
+ body: not_found_body.to_json,
60
+ headers: {}
61
+ )
62
+ end
42
63
  end
43
64
  end
44
65
  end
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '7.15.0'
2
+ VERSION = '7.16.0'
3
3
  end
@@ -129,6 +129,52 @@ describe GdsApi::NeedApi do
129
129
  end
130
130
  end
131
131
 
132
+ describe "viewing needs" do
133
+ it "should return a need response" do
134
+ need = {
135
+ need_id: 100500,
136
+ role: "parent",
137
+ goal: "do things",
138
+ benefit: "good things"
139
+ }
140
+ need_api_has_need(need)
141
+
142
+ need_response = @api.need(100500)
143
+ assert_equal "good things", need_response.benefit
144
+ end
145
+
146
+ it "should return nil for a missing need" do
147
+ need_api_has_no_need(100600)
148
+ assert_nil @api.need(100600)
149
+ end
150
+ end
151
+
152
+ describe "updating needs" do
153
+ it "should send a PUT request" do
154
+ updated_fields = {
155
+ role: "parent",
156
+ goal: "do things",
157
+ benefit: "good things"
158
+ }
159
+
160
+ update_stub = stub_request(:put, @base_api_url + "/needs/100005")
161
+ .with(body: updated_fields.to_json)
162
+ .to_return(status: 204)
163
+ @api.update_need(100005, updated_fields)
164
+ assert_requested update_stub
165
+ end
166
+
167
+ it "should accept partial updates" do
168
+ updated_fields = { role: "parent" }
169
+
170
+ update_stub = stub_request(:put, @base_api_url + "/needs/100005")
171
+ .with(body: updated_fields.to_json)
172
+ .to_return(status: 204)
173
+ @api.update_need(100005, updated_fields)
174
+ assert_requested update_stub
175
+ end
176
+ end
177
+
132
178
  describe "viewing organisations" do
133
179
  it "should return a list of organisations" do
134
180
  request_stub = need_api_has_organisations(
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.15.0
4
+ version: 7.16.0
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-10-25 00:00:00.000000000 Z
12
+ date: 2013-10-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: plek
@@ -340,7 +340,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
340
340
  version: '0'
341
341
  segments:
342
342
  - 0
343
- hash: 988402629754510037
343
+ hash: 4084552957732553558
344
344
  required_rubygems_version: !ruby/object:Gem::Requirement
345
345
  none: false
346
346
  requirements:
@@ -349,7 +349,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
349
349
  version: '0'
350
350
  segments:
351
351
  - 0
352
- hash: 988402629754510037
352
+ hash: 4084552957732553558
353
353
  requirements: []
354
354
  rubyforge_project:
355
355
  rubygems_version: 1.8.23