gds-api-adapters 37.5.1 → 38.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/helpers_test.rb CHANGED
@@ -13,7 +13,6 @@ describe GdsApi::Helpers do
13
13
  refute_nil test_with_helpers.business_support_api
14
14
  refute_nil test_with_helpers.content_api
15
15
  refute_nil test_with_helpers.content_store
16
- refute_nil test_with_helpers.publisher_api
17
16
  refute_nil test_with_helpers.imminence_api
18
17
  refute_nil test_with_helpers.licence_application_api
19
18
  refute_nil test_with_helpers.need_api
@@ -28,21 +28,6 @@ class JsonClientTest < MiniTest::Spec
28
28
  {}
29
29
  end
30
30
 
31
- # TODO: When we remove `GdsApi.config.hash_response_for_requests`, this helper
32
- # method no longer makes sense and it should be deleted.
33
- def with_hash_response_for_requests_disabled
34
- @old_hash_response_for_requests = GdsApi.config.hash_response_for_requests
35
- GdsApi.configure do |config|
36
- config.hash_response_for_requests = false
37
- end
38
-
39
- yield
40
-
41
- GdsApi.configure do |config|
42
- config.hash_response_for_requests = @old_hash_response_for_requests
43
- end
44
- end
45
-
46
31
  def test_long_get_requests_timeout
47
32
  url = "http://www.example.com/timeout.json"
48
33
  stub_request(:get, url).to_timeout
@@ -399,39 +384,6 @@ class JsonClientTest < MiniTest::Spec
399
384
  end
400
385
  end
401
386
 
402
- # TODO: always_raise_for_not_found will be gone by December 1st, 2016. We will
403
- # need to remove it from this test.
404
- def test_get_should_be_nil_if_404_returned_from_endpoint_and_always_raise_for_not_found_is_disabled
405
- @old_always_raise = GdsApi.config.always_raise_for_not_found
406
- GdsApi.configure do |config|
407
- config.always_raise_for_not_found = false
408
- end
409
- url = "http://some.endpoint/some.json"
410
- stub_request(:get, url).to_return(body: "{}", status: 404)
411
-
412
- assert_nil @client.get_json(url)
413
- ensure
414
- GdsApi.configure do |config|
415
- config.always_raise_for_not_found = @old_always_raise
416
- end
417
- end
418
-
419
- # TODO: always_raise_for_not_found will be gone by December 1st, 2016. We will
420
- # need to remove it from this test.
421
- def test_get_should_be_nil_if_410_returned_from_endpoint_and_always_raise_for_not_found_is_disabled
422
- @old_always_raise = GdsApi.config.always_raise_for_not_found
423
- GdsApi.configure do |config|
424
- config.always_raise_for_not_found = false
425
- end
426
- url = "http://some.endpoint/some.json"
427
- stub_request(:get, url).to_return(body: "{}", status: 410)
428
- assert_nil @client.get_json(url)
429
- ensure
430
- GdsApi.configure do |config|
431
- config.always_raise_for_not_found = @old_always_raise
432
- end
433
- end
434
-
435
387
  def test_get_should_raise_if_404_returned_from_endpoint
436
388
  url = "http://some.endpoint/some.json"
437
389
  stub_request(:get, url).to_return(body: "{}", status: 404)
@@ -448,38 +400,6 @@ class JsonClientTest < MiniTest::Spec
448
400
  end
449
401
  end
450
402
 
451
- # TODO: always_raise_for_not_found will be gone by December 1st, 2016. We will
452
- # need to remove it from this test.
453
- def test_get_raw_should_be_nil_if_404_returned_from_endpoint_and_always_raise_for_not_found_is_disabled
454
- @old_always_raise = GdsApi.config.always_raise_for_not_found
455
- GdsApi.configure do |config|
456
- config.always_raise_for_not_found = false
457
- end
458
- url = "http://some.endpoint/some.json"
459
- stub_request(:get, url).to_return(body: "{}", status: 404)
460
- assert_nil @client.get_raw(url)
461
- ensure
462
- GdsApi.configure do |config|
463
- config.always_raise_for_not_found = @old_always_raise
464
- end
465
- end
466
-
467
- # TODO: always_raise_for_not_found will be gone by December 1st, 2016. We will
468
- # need to remove it from this test.
469
- def test_get_raw_should_be_nil_if_410_returned_from_endpoint_and_always_raise_for_not_found_is_disabled
470
- @old_always_raise = GdsApi.config.always_raise_for_not_found
471
- GdsApi.configure do |config|
472
- config.always_raise_for_not_found = false
473
- end
474
- url = "http://some.endpoint/some.json"
475
- stub_request(:get, url).to_return(body: "{}", status: 410)
476
- assert_nil @client.get_raw(url)
477
- ensure
478
- GdsApi.configure do |config|
479
- config.always_raise_for_not_found = @old_always_raise
480
- end
481
- end
482
-
483
403
  def test_get_raw_should_raise_if_404_returned_from_endpoint
484
404
  url = "http://some.endpoint/some.json"
485
405
  stub_request(:get, url).to_return(body: "{}", status: 404)
@@ -700,18 +620,6 @@ class JsonClientTest < MiniTest::Spec
700
620
  assert_equal "Hello there!", response
701
621
  end
702
622
 
703
- # TODO: When we remove `GdsApi.config.hash_response_for_requests`, this test
704
- # no longer makes sense and it should be deleted.
705
- def test_can_convert_response_to_ostruct
706
- with_hash_response_for_requests_disabled do
707
- url = "http://some.endpoint/some.json"
708
- payload = { a: 1 }
709
- stub_request(:put, url).with(body: payload.to_json).to_return(body: '{"a":1}', status: 200)
710
- response = @client.put_json(url, payload)
711
- assert_equal(OpenStruct.new(a: 1), response.to_ostruct)
712
- end
713
- end
714
-
715
623
  def test_can_access_attributes_of_response_directly
716
624
  url = "http://some.endpoint/some.json"
717
625
  payload = { a: 1 }
@@ -720,49 +628,6 @@ class JsonClientTest < MiniTest::Spec
720
628
  assert_equal 2, response['a']['b']
721
629
  end
722
630
 
723
- def test_cant_access_attributes_of_response_directly_if_hash_only
724
- url = "http://some.endpoint/some.json"
725
- payload = { a: 1 }
726
- stub_request(:put, url).with(body: payload.to_json).to_return(body: '{"a":{"b":2}}', status: 200)
727
- response = @client.put_json(url, payload)
728
-
729
- @old_hash_response_for_requests = GdsApi.config.hash_response_for_requests
730
- GdsApi.configure do |config|
731
- config.hash_response_for_requests = true
732
- end
733
-
734
- assert_raises NoMethodError do
735
- response.a.b
736
- end
737
-
738
- GdsApi.configure do |config|
739
- config.hash_response_for_requests = @old_hash_response_for_requests
740
- end
741
- end
742
-
743
- # TODO: When we remove `GdsApi.config.hash_response_for_requests`, this test
744
- # no longer makes sense and it should be deleted.
745
- def test_accessing_non_existent_attribute_of_response_returns_nil
746
- with_hash_response_for_requests_disabled do
747
- url = "http://some.endpoint/some.json"
748
- stub_request(:put, url).to_return(body: '{"a":1}', status: 200)
749
- response = @client.put_json(url, {})
750
- assert_equal nil, response.does_not_exist
751
- end
752
- end
753
-
754
- # TODO: When we remove `GdsApi.config.hash_response_for_requests`, this test
755
- # no longer makes sense and it should be deleted.
756
- def test_response_does_not_claim_to_respond_to_methods_corresponding_to_non_existent_attributes
757
- with_hash_response_for_requests_disabled do
758
- # This mimics the behaviour of OpenStruct
759
- url = "http://some.endpoint/some.json"
760
- stub_request(:put, url).to_return(body: '{"a":1}', status: 200)
761
- response = @client.put_json(url, {})
762
- assert ! response.respond_to?(:does_not_exist)
763
- end
764
- end
765
-
766
631
  def test_a_response_is_always_considered_present_and_not_blank
767
632
  url = "http://some.endpoint/some.json"
768
633
  stub_request(:put, url).to_return(body: '{"a":1}', status: 200)
@@ -219,6 +219,22 @@ describe GdsApi::NeedApi do
219
219
  end
220
220
  end
221
221
 
222
+ describe "viewing content_ids for needs" do
223
+ it "should return the content_id for a need_id" do
224
+ need = {
225
+ id: 100700,
226
+ content_id: "abcdef-12345",
227
+ role: "need",
228
+ goal: "needy",
229
+ benefit: "needless"
230
+ }
231
+ need_api_has_content_id_for_need(need)
232
+
233
+ need_response = @api.content_id(100700)
234
+ assert_equal 'abcdef-12345', need_response.body
235
+ end
236
+ end
237
+
222
238
  describe "updating needs" do
223
239
  it "should send a PUT request" do
224
240
  updated_fields = {
@@ -11,64 +11,6 @@ describe GdsApi::PublishingApi do
11
11
  @api_client = GdsApi::PublishingApi.new(publishing_api_host)
12
12
  end
13
13
 
14
- describe "#put_content_item" do
15
- it "responds with 200 OK if the entry is valid" do
16
- base_path = "/test-content-item"
17
- content_item = content_item_for_publishing_api(base_path).merge("update_type" => "major")
18
-
19
- publishing_api
20
- .given("no content exists")
21
- .upon_receiving("a request to create a content item")
22
- .with(
23
- method: :put,
24
- path: "/content#{base_path}",
25
- body: content_item,
26
- headers: {
27
- "Content-Type" => "application/json"
28
- },
29
- )
30
- .will_respond_with(
31
- status: 200,
32
- body: content_item,
33
- headers: {
34
- "Content-Type" => "application/json; charset=utf-8"
35
- },
36
- )
37
-
38
- response = @api_client.put_content_item(base_path, content_item)
39
- assert_equal 200, response.code
40
- end
41
- end
42
-
43
- describe "#put_draft_content_item" do
44
- it "responds with 200 OK if the entry is valid" do
45
- base_path = "/test-draft-content-item"
46
- content_item = content_item_for_publishing_api(base_path).merge("update_type" => "major")
47
-
48
- publishing_api
49
- .given("no content exists")
50
- .upon_receiving("a request to create a draft content item")
51
- .with(
52
- method: :put,
53
- path: "/draft-content#{base_path}",
54
- body: content_item,
55
- headers: {
56
- "Content-Type" => "application/json"
57
- },
58
- )
59
- .will_respond_with(
60
- status: 200,
61
- body: content_item,
62
- headers: {
63
- "Content-Type" => "application/json; charset=utf-8"
64
- },
65
- )
66
-
67
- response = @api_client.put_draft_content_item(base_path, content_item)
68
- assert_equal 200, response.code
69
- end
70
- end
71
-
72
14
  describe "#put_intent" do
73
15
  it "responds with 200 OK if publish intent is valid" do
74
16
  base_path = "/test-intent"
@@ -242,68 +242,5 @@ describe GdsApi::Response do
242
242
  assert_equal "1870", @response.dig("details", "need_id")
243
243
  end
244
244
  end
245
-
246
- # TODO: When we remove `GdsApi.config.hash_response_for_requests`, this
247
- # describe block no longer makes sense and it should be removed.
248
- describe "behaving like a read-only openstruct" do
249
- def with_hash_response_for_requests_disabled
250
- @old_hash_response_for_requests = GdsApi.config.hash_response_for_requests
251
- GdsApi.configure do |config|
252
- config.hash_response_for_requests = false
253
- end
254
-
255
- yield
256
-
257
- GdsApi.configure do |config|
258
- config.hash_response_for_requests = @old_hash_response_for_requests
259
- end
260
- end
261
-
262
- it "should allow accessing members using methods" do
263
- with_hash_response_for_requests_disabled do
264
- assert_equal "VAT rates", @response.title
265
- end
266
- end
267
-
268
- it "should allow accessing nested values" do
269
- with_hash_response_for_requests_disabled do
270
- assert_equal "1870", @response.details.need_id
271
- end
272
- end
273
-
274
- it "should allow accessing values nested within arrays" do
275
- with_hash_response_for_requests_disabled do
276
- assert_equal "bar", @response.tags[1].slug
277
- end
278
- end
279
-
280
- it "should return nil for a non-existent key" do
281
- with_hash_response_for_requests_disabled do
282
- assert_equal nil, @response.foo
283
- end
284
- end
285
-
286
- it "should memoize the generated openstruct" do
287
- with_hash_response_for_requests_disabled do
288
- @response.id
289
- GdsApi::Response.expects(:build_ostruct_recursively).never
290
- assert_equal "VAT rates", @response.title
291
- end
292
- end
293
-
294
- describe "handling respond_to?" do
295
- it "should respond_to methods for keys that exist" do
296
- with_hash_response_for_requests_disabled do
297
- assert @response.respond_to?(:title)
298
- end
299
- end
300
-
301
- it "should not respond_to keys that don't exist" do
302
- with_hash_response_for_requests_disabled do
303
- assert ! @response.respond_to?(:foo)
304
- end
305
- end
306
- end
307
- end
308
245
  end
309
246
  end
@@ -135,7 +135,7 @@ describe GdsApi::Rummager do
135
135
  it "#delete_content removes a document" do
136
136
  request = stub_request(:delete, "http://example.com/content?link=/foo/bar")
137
137
 
138
- GdsApi::Rummager.new("http://example.com").delete_content!("/foo/bar")
138
+ GdsApi::Rummager.new("http://example.com").delete_content("/foo/bar")
139
139
 
140
140
  assert_requested(request)
141
141
  end
@@ -143,7 +143,7 @@ describe GdsApi::Rummager do
143
143
  it "#get_content Retrieves a document" do
144
144
  request = stub_request(:get, "http://example.com/content?link=/foo/bar")
145
145
 
146
- GdsApi::Rummager.new("http://example.com").get_content!("/foo/bar")
146
+ GdsApi::Rummager.new("http://example.com").get_content("/foo/bar")
147
147
 
148
148
  assert_requested(request)
149
149
  end
@@ -7,35 +7,6 @@ describe GdsApi::TestHelpers::PublishingApi do
7
7
  let(:base_api_url) { Plek.current.find("publishing-api") }
8
8
  let(:publishing_api) { GdsApi::PublishingApi.new(base_api_url) }
9
9
 
10
- describe "#assert_publishing_api_put_item" do
11
- before { stub_default_publishing_api_put }
12
- let(:base_path) { "/example" }
13
-
14
- it "matches a put request with any empty attributes by default" do
15
- publishing_api.put_content_item(base_path, {})
16
- assert_publishing_api_put_item(base_path)
17
- end
18
-
19
- it "matches a put request with any arbitrary attributes by default" do
20
- random_attributes = Hash[10.times.map {|n| [Random.rand * 1_000_000_000_000, Random.rand * 1_000_000_000_000]}]
21
- publishing_api.put_content_item(base_path, random_attributes)
22
- assert_publishing_api_put_item(base_path)
23
- end
24
-
25
- it "if attributes are specified, matches a request with at least those attributes" do
26
- publishing_api.put_content_item(base_path, {"required_attribute" => 1, "extra_attrbibute" => 1})
27
- assert_publishing_api_put_item(base_path, {"required_attribute" => 1})
28
- end
29
-
30
- it "matches using a custom request matcher" do
31
- publishing_api.put_content_item(base_path, {})
32
- matcher_was_called = false
33
- matcher = ->(request) { matcher_was_called = true; true }
34
- assert_publishing_api_put_item(base_path, matcher)
35
- assert matcher_was_called, "matcher should have been called"
36
- end
37
- end
38
-
39
10
  describe '#request_json_matching predicate' do
40
11
  describe "nested required attribute" do
41
12
  let(:matcher) { request_json_matching({"a" => {"b" => 1}}) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gds-api-adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 37.5.1
4
+ version: 38.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Stewart
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-28 00:00:00.000000000 Z
11
+ date: 2016-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: plek
@@ -345,13 +345,11 @@ files:
345
345
  - lib/gds_api/asset_manager.rb
346
346
  - lib/gds_api/base.rb
347
347
  - lib/gds_api/business_support_api.rb
348
- - lib/gds_api/config.rb
349
348
  - lib/gds_api/content_api.rb
350
349
  - lib/gds_api/content_store.rb
351
350
  - lib/gds_api/core-ext/openstruct.rb
352
351
  - lib/gds_api/email_alert_api.rb
353
352
  - lib/gds_api/exceptions.rb
354
- - lib/gds_api/external_link_tracker.rb
355
353
  - lib/gds_api/gov_uk_delivery.rb
356
354
  - lib/gds_api/govuk_headers.rb
357
355
  - lib/gds_api/helpers.rb
@@ -364,15 +362,12 @@ files:
364
362
  - lib/gds_api/maslow.rb
365
363
  - lib/gds_api/middleware/govuk_header_sniffer.rb
366
364
  - lib/gds_api/need_api.rb
367
- - lib/gds_api/needotron.rb
368
365
  - lib/gds_api/null_cache.rb
369
366
  - lib/gds_api/organisations.rb
370
367
  - lib/gds_api/panopticon.rb
371
368
  - lib/gds_api/panopticon/registerer.rb
372
- - lib/gds_api/part_methods.rb
373
369
  - lib/gds_api/performance_platform/data_in.rb
374
370
  - lib/gds_api/performance_platform/data_out.rb
375
- - lib/gds_api/publisher.rb
376
371
  - lib/gds_api/publishing_api.rb
377
372
  - lib/gds_api/publishing_api/special_route_publisher.rb
378
373
  - lib/gds_api/publishing_api_v2.rb
@@ -403,7 +398,6 @@ files:
403
398
  - lib/gds_api/test_helpers/panopticon.rb
404
399
  - lib/gds_api/test_helpers/performance_platform/data_in.rb
405
400
  - lib/gds_api/test_helpers/performance_platform/data_out.rb
406
- - lib/gds_api/test_helpers/publisher.rb
407
401
  - lib/gds_api/test_helpers/publishing_api.rb
408
402
  - lib/gds_api/test_helpers/publishing_api_v2.rb
409
403
  - lib/gds_api/test_helpers/router.rb
@@ -419,7 +413,6 @@ files:
419
413
  - test/content_api_test.rb
420
414
  - test/content_store_test.rb
421
415
  - test/email_alert_api_test.rb
422
- - test/external_link_tracker_test.rb
423
416
  - test/fixtures/finder_api/cma-case-schema.json
424
417
  - test/fixtures/hello.txt
425
418
  - test/fixtures/new_policies_for_dwp.json
@@ -446,7 +439,6 @@ files:
446
439
  - test/panopticon_test.rb
447
440
  - test/pp_data_in_test.rb
448
441
  - test/pp_data_out_test.rb
449
- - test/publisher_api_test.rb
450
442
  - test/publishing_api/special_route_publisher_test.rb
451
443
  - test/publishing_api_test.rb
452
444
  - test/publishing_api_v2/get_expanded_links_test.rb
@@ -507,7 +499,6 @@ test_files:
507
499
  - test/licence_application_api_test.rb
508
500
  - test/test_helper.rb
509
501
  - test/govuk_headers_test.rb
510
- - test/publisher_api_test.rb
511
502
  - test/mapit_test.rb
512
503
  - test/rummager_helpers_test.rb
513
504
  - test/publishing_api_v2_test.rb
@@ -519,7 +510,6 @@ test_files:
519
510
  - test/gds_api_base_test.rb
520
511
  - test/router_test.rb
521
512
  - test/publishing_api/special_route_publisher_test.rb
522
- - test/external_link_tracker_test.rb
523
513
  - test/need_api_test.rb
524
514
  - test/panopticon_test.rb
525
515
  - test/pp_data_in_test.rb