gds-api-adapters 38.0.0 → 38.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +5 -5
  3. data/lib/gds_api/asset_manager.rb +7 -7
  4. data/lib/gds_api/base.rb +13 -11
  5. data/lib/gds_api/business_support_api.rb +3 -4
  6. data/lib/gds_api/content_api.rb +31 -44
  7. data/lib/gds_api/content_store.rb +2 -3
  8. data/lib/gds_api/email_alert_api.rb +6 -7
  9. data/lib/gds_api/exceptions.rb +4 -1
  10. data/lib/gds_api/gov_uk_delivery.rb +9 -8
  11. data/lib/gds_api/govuk_headers.rb +1 -1
  12. data/lib/gds_api/imminence.rb +9 -10
  13. data/lib/gds_api/json_client.rb +21 -34
  14. data/lib/gds_api/licence_application.rb +2 -2
  15. data/lib/gds_api/list_response.rb +7 -10
  16. data/lib/gds_api/local_links_manager.rb +1 -1
  17. data/lib/gds_api/mapit.rb +5 -6
  18. data/lib/gds_api/middleware/govuk_header_sniffer.rb +1 -1
  19. data/lib/gds_api/need_api.rb +7 -8
  20. data/lib/gds_api/null_cache.rb +2 -2
  21. data/lib/gds_api/organisations.rb +2 -2
  22. data/lib/gds_api/panopticon.rb +11 -11
  23. data/lib/gds_api/performance_platform/data_in.rb +4 -4
  24. data/lib/gds_api/performance_platform/data_out.rb +1 -1
  25. data/lib/gds_api/publishing_api.rb +4 -5
  26. data/lib/gds_api/publishing_api/special_route_publisher.rb +5 -3
  27. data/lib/gds_api/publishing_api_v2.rb +8 -16
  28. data/lib/gds_api/response.rb +2 -5
  29. data/lib/gds_api/router.rb +18 -9
  30. data/lib/gds_api/rummager.rb +6 -7
  31. data/lib/gds_api/support.rb +7 -6
  32. data/lib/gds_api/support_api.rb +14 -14
  33. data/lib/gds_api/test_helpers/asset_manager.rb +3 -6
  34. data/lib/gds_api/test_helpers/business_support_api.rb +4 -4
  35. data/lib/gds_api/test_helpers/business_support_helper.rb +9 -8
  36. data/lib/gds_api/test_helpers/common_responses.rb +10 -12
  37. data/lib/gds_api/test_helpers/content_api.rb +23 -23
  38. data/lib/gds_api/test_helpers/content_api/artefact_stub.rb +13 -12
  39. data/lib/gds_api/test_helpers/content_item_helpers.rb +4 -4
  40. data/lib/gds_api/test_helpers/content_store.rb +3 -3
  41. data/lib/gds_api/test_helpers/email_alert_api.rb +8 -10
  42. data/lib/gds_api/test_helpers/gov_uk_delivery.rb +0 -1
  43. data/lib/gds_api/test_helpers/imminence.rb +4 -4
  44. data/lib/gds_api/test_helpers/intent_helpers.rb +0 -2
  45. data/lib/gds_api/test_helpers/local_links_manager.rb +12 -13
  46. data/lib/gds_api/test_helpers/mapit.rb +14 -15
  47. data/lib/gds_api/test_helpers/need_api.rb +4 -4
  48. data/lib/gds_api/test_helpers/organisations.rb +13 -15
  49. data/lib/gds_api/test_helpers/panopticon.rb +6 -6
  50. data/lib/gds_api/test_helpers/performance_platform/data_in.rb +8 -8
  51. data/lib/gds_api/test_helpers/publishing_api.rb +19 -20
  52. data/lib/gds_api/test_helpers/publishing_api_v2.rb +13 -13
  53. data/lib/gds_api/test_helpers/router.rb +5 -5
  54. data/lib/gds_api/test_helpers/rummager.rb +5 -4
  55. data/lib/gds_api/test_helpers/support.rb +11 -11
  56. data/lib/gds_api/test_helpers/support_api.rb +14 -14
  57. data/lib/gds_api/test_helpers/whitehall_admin_api.rb +1 -1
  58. data/lib/gds_api/test_helpers/worldwide.rb +16 -19
  59. data/lib/gds_api/version.rb +1 -1
  60. data/lib/gds_api/worldwide.rb +4 -4
  61. data/test/asset_manager_test.rb +6 -6
  62. data/test/business_support_api_test.rb +9 -10
  63. data/test/content_api_test.rb +81 -83
  64. data/test/email_alert_api_test.rb +3 -5
  65. data/test/gds_api_base_test.rb +9 -10
  66. data/test/gov_uk_delivery_test.rb +4 -6
  67. data/test/imminence_api_test.rb +7 -9
  68. data/test/json_client_test.rb +71 -64
  69. data/test/licence_application_api_test.rb +5 -7
  70. data/test/list_response_test.rb +27 -32
  71. data/test/mapit_test.rb +7 -9
  72. data/test/middleware/govuk_header_sniffer_test.rb +1 -1
  73. data/test/need_api_test.rb +8 -8
  74. data/test/organisations_api_test.rb +2 -2
  75. data/test/panopticon_registerer_test.rb +10 -10
  76. data/test/panopticon_test.rb +5 -5
  77. data/test/pp_data_in_test.rb +3 -3
  78. data/test/publishing_api_test.rb +2 -6
  79. data/test/publishing_api_v2_test.rb +40 -50
  80. data/test/response_test.rb +21 -22
  81. data/test/router_test.rb +78 -80
  82. data/test/rummager_test.rb +14 -14
  83. data/test/support_api_test.rb +13 -13
  84. data/test/support_test.rb +15 -16
  85. data/test/test_helper.rb +1 -1
  86. data/test/test_helpers/email_alert_api_test.rb +3 -3
  87. data/test/test_helpers/pact_helper.rb +1 -1
  88. data/test/test_helpers/panopticon_test.rb +1 -1
  89. data/test/test_helpers/publishing_api_test.rb +7 -7
  90. data/test/test_helpers/publishing_api_v2_test.rb +5 -9
  91. data/test/worldwide_api_test.rb +3 -3
  92. metadata +2 -3
  93. data/lib/gds_api/core-ext/openstruct.rb +0 -5
@@ -1,7 +1,6 @@
1
1
  module GdsApi
2
2
  module TestHelpers
3
3
  module IntentHelpers
4
-
5
4
  def intent_for_base_path(base_path)
6
5
  {
7
6
  "base_path" => base_path,
@@ -11,4 +10,3 @@ module GdsApi
11
10
  end
12
11
  end
13
12
  end
14
-
@@ -3,7 +3,6 @@ require 'gds_api/test_helpers/json_client_helper'
3
3
  module GdsApi
4
4
  module TestHelpers
5
5
  module LocalLinksManager
6
-
7
6
  LOCAL_LINKS_MANAGER_ENDPOINT = Plek.current.find('local-links-manager')
8
7
 
9
8
  def local_links_manager_has_a_link(authority_slug:, lgsl:, lgil:, url:)
@@ -22,7 +21,7 @@ module GdsApi
22
21
  }
23
22
 
24
23
  stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
25
- .with(query: {authority_slug: authority_slug, lgsl: lgsl, lgil: lgil})
24
+ .with(query: { authority_slug: authority_slug, lgsl: lgsl, lgil: lgil })
26
25
  .to_return(body: response.to_json, status: 200)
27
26
  end
28
27
 
@@ -37,7 +36,7 @@ module GdsApi
37
36
  }
38
37
 
39
38
  stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
40
- .with(query: {authority_slug: authority_slug, lgsl: lgsl, lgil: lgil})
39
+ .with(query: { authority_slug: authority_slug, lgsl: lgsl, lgil: lgil })
41
40
  .to_return(body: response.to_json, status: 200)
42
41
  end
43
42
 
@@ -52,7 +51,7 @@ module GdsApi
52
51
  }
53
52
 
54
53
  stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
55
- .with(query: {authority_slug: authority_slug, lgsl: lgsl, lgil: lgil})
54
+ .with(query: { authority_slug: authority_slug, lgsl: lgsl, lgil: lgil })
56
55
  .to_return(body: response.to_json, status: 200)
57
56
  end
58
57
 
@@ -72,7 +71,7 @@ module GdsApi
72
71
  }
73
72
 
74
73
  stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
75
- .with(query: {authority_slug: authority_slug, lgsl: lgsl})
74
+ .with(query: { authority_slug: authority_slug, lgsl: lgsl })
76
75
  .to_return(body: response.to_json, status: 200)
77
76
  end
78
77
 
@@ -87,7 +86,7 @@ module GdsApi
87
86
  }
88
87
 
89
88
  stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
90
- .with(query: {authority_slug: authority_slug, lgsl: lgsl})
89
+ .with(query: { authority_slug: authority_slug, lgsl: lgsl })
91
90
  .to_return(body: response.to_json, status: 200)
92
91
  end
93
92
 
@@ -100,9 +99,9 @@ module GdsApi
100
99
  .to_return(body: {}.to_json, status: 400)
101
100
  end
102
101
 
103
- def local_links_manager_does_not_have_required_objects(authority_slug, lgsl, lgil=nil)
102
+ def local_links_manager_does_not_have_required_objects(authority_slug, lgsl, lgil = nil)
104
103
  params = { authority_slug: authority_slug, lgsl: lgsl }
105
- params.merge!(lgil: lgil) if lgil
104
+ params[:lgil] = lgil if lgil
106
105
 
107
106
  stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
108
107
  .with(query: params)
@@ -121,7 +120,7 @@ module GdsApi
121
120
  }
122
121
 
123
122
  stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority")
124
- .with(query: {authority_slug: authority_slug})
123
+ .with(query: { authority_slug: authority_slug })
125
124
  .to_return(body: response.to_json, status: 200)
126
125
  end
127
126
 
@@ -142,19 +141,19 @@ module GdsApi
142
141
  }
143
142
 
144
143
  stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority")
145
- .with(query: {authority_slug: district_slug})
144
+ .with(query: { authority_slug: district_slug })
146
145
  .to_return(body: response.to_json, status: 200)
147
146
  end
148
147
 
149
148
  def local_links_manager_request_without_local_authority_slug
150
149
  stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority")
151
- .with(query: {authority_slug: ''})
150
+ .with(query: { authority_slug: '' })
152
151
  .to_return(body: {}.to_json, status: 400)
153
152
  end
154
153
 
155
154
  def local_links_manager_does_not_have_an_authority(authority_slug)
156
155
  stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority")
157
- .with(query: {authority_slug: authority_slug})
156
+ .with(query: { authority_slug: authority_slug })
158
157
  .to_return(body: {}.to_json, status: 404)
159
158
  end
160
159
 
@@ -170,7 +169,7 @@ module GdsApi
170
169
  }
171
170
 
172
171
  stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority")
173
- .with(query: {authority_slug: authority_slug})
172
+ .with(query: { authority_slug: authority_slug })
174
173
  .to_return(body: response.to_json, status: 200)
175
174
  end
176
175
  end
@@ -1,7 +1,6 @@
1
1
  module GdsApi
2
2
  module TestHelpers
3
3
  module Mapit
4
-
5
4
  MAPIT_ENDPOINT = Plek.current.find('mapit')
6
5
 
7
6
  def mapit_has_a_postcode(postcode, coords)
@@ -11,10 +10,10 @@ module GdsApi
11
10
  "postcode" => postcode
12
11
  }
13
12
 
14
- stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.gsub(' ','+') + ".json")
15
- .to_return(:body => response.to_json, :status => 200)
13
+ stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.tr(' ', '+') + ".json")
14
+ .to_return(body: response.to_json, status: 200)
16
15
  stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/partial/" + postcode.split(' ').first + ".json")
17
- .to_return(:body => response.to_json, :status => 200)
16
+ .to_return(body: response.to_json, status: 200)
18
17
  end
19
18
 
20
19
  def mapit_has_a_postcode_and_areas(postcode, coords, areas)
@@ -36,40 +35,40 @@ module GdsApi
36
35
  }]
37
36
  }]
38
37
 
39
- stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.gsub(' ','+') + ".json")
40
- .to_return(:body => response.merge({'areas' => area_response}).to_json, :status => 200)
38
+ stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.tr(' ', '+') + ".json")
39
+ .to_return(body: response.merge('areas' => area_response).to_json, status: 200)
41
40
  stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/partial/" + postcode.split(' ').first + ".json")
42
- .to_return(:body => response.to_json, :status => 200)
41
+ .to_return(body: response.to_json, status: 200)
43
42
  end
44
43
 
45
44
  def mapit_does_not_have_a_postcode(postcode)
46
- stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.gsub(' ','+') + ".json")
47
- .to_return(:body => { "code" => 404, "error" => "No Postcode matches the given query." }.to_json, :status => 404)
45
+ stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.tr(' ', '+') + ".json")
46
+ .to_return(body: { "code" => 404, "error" => "No Postcode matches the given query." }.to_json, status: 404)
48
47
  end
49
48
 
50
49
  def mapit_does_not_have_a_bad_postcode(postcode)
51
- stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.gsub(' ','+') + ".json")
52
- .to_return(:body => { "code" => 400, "error" => "Postcode '#{postcode}' is not valid." }.to_json, :status => 400)
50
+ stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.tr(' ', '+') + ".json")
51
+ .to_return(body: { "code" => 400, "error" => "Postcode '#{postcode}' is not valid." }.to_json, status: 400)
53
52
  end
54
53
 
55
54
  def mapit_has_areas(area_type, areas)
56
55
  stub_request(:get, "#{MAPIT_ENDPOINT}/areas/" + area_type + ".json")
57
- .to_return(:body => areas.to_json, :status => 200)
56
+ .to_return(body: areas.to_json, status: 200)
58
57
  end
59
58
 
60
59
  def mapit_does_not_have_areas(area_type)
61
60
  stub_request(:get, "#{MAPIT_ENDPOINT}/areas/" + area_type + ".json")
62
- .to_return(:body => [].to_json, :status => 200)
61
+ .to_return(body: [].to_json, status: 200)
63
62
  end
64
63
 
65
64
  def mapit_has_area_for_code(code_type, code, area)
66
65
  stub_request(:get, "#{MAPIT_ENDPOINT}/code/#{code_type}/#{code}.json")
67
- .to_return(:body => area.to_json, :status => 200)
66
+ .to_return(body: area.to_json, status: 200)
68
67
  end
69
68
 
70
69
  def mapit_does_not_have_area_for_code(code_type, code)
71
70
  stub_request(:get, "#{MAPIT_ENDPOINT}/code/#{code_type}/#{code}.json")
72
- .to_return(:body => { "code" => 404, "error" => "No areas were found that matched code #{code_type} = #{code}." }.to_json, :status => 404)
71
+ .to_return(body: { "code" => 404, "error" => "No areas were found that matched code #{code_type} = #{code}." }.to_json, status: 404)
73
72
  end
74
73
  end
75
74
  end
@@ -51,7 +51,7 @@ module GdsApi
51
51
  end
52
52
 
53
53
  def need_api_has_need_ids(needs)
54
- ids = needs.map {|need| (need["id"] || need[:id]).to_i }.sort.join(',')
54
+ ids = needs.map { |need| (need["id"] || need[:id]).to_i }.sort.join(',')
55
55
  url = NEED_API_ENDPOINT + "/needs?ids=#{ids}"
56
56
 
57
57
  body = response_base.merge(
@@ -85,7 +85,7 @@ module GdsApi
85
85
  def need_api_has_no_need(need_id)
86
86
  url = NEED_API_ENDPOINT + "/needs/#{need_id}"
87
87
  not_found_body = {
88
- "_response_info" => {"status" => "not_found"},
88
+ "_response_info" => { "status" => "not_found" },
89
89
  "error" => "No need exists with this ID"
90
90
  }
91
91
  stub_request(:get, url).to_return(
@@ -97,8 +97,8 @@ module GdsApi
97
97
 
98
98
  def stub_create_note(note_details = nil)
99
99
  post_stub = stub_request(:post, NEED_API_ENDPOINT + "/notes")
100
- post_stub.with(:body => note_details.to_json) unless note_details.nil?
101
- post_stub.to_return(:status => 201)
100
+ post_stub.with(body: note_details.to_json) unless note_details.nil?
101
+ post_stub.to_return(status: 201)
102
102
  end
103
103
  end
104
104
  end
@@ -34,43 +34,41 @@ module GdsApi
34
34
  end
35
35
 
36
36
  pages.each_with_index do |page, i|
37
- page_details = plural_response_base.merge({
38
- "results" => page,
37
+ page_details = plural_response_base.merge("results" => page,
39
38
  "total" => organisation_bodies.size,
40
39
  "pages" => pages.size,
41
40
  "current_page" => i + 1,
42
41
  "page_size" => 20,
43
- "start_index" => i * 20 + 1,
44
- })
42
+ "start_index" => i * 20 + 1)
45
43
 
46
- links = {:self => "#{ORGANISATIONS_API_ENDPOINT}/api/organisations?page=#{i + 1}" }
47
- links[:next] = "#{ORGANISATIONS_API_ENDPOINT}/api/organisations?page=#{i + 2}" if pages[i+1]
44
+ links = { self: "#{ORGANISATIONS_API_ENDPOINT}/api/organisations?page=#{i + 1}" }
45
+ links[:next] = "#{ORGANISATIONS_API_ENDPOINT}/api/organisations?page=#{i + 2}" if pages[i + 1]
48
46
  links[:previous] = "#{ORGANISATIONS_API_ENDPOINT}/api/organisations?page=#{i}" unless i == 0
49
47
  page_details["_response_info"]["links"] = []
50
48
  link_headers = []
51
49
  links.each do |rel, href|
52
- page_details["_response_info"]["links"] << {"rel" => rel, "href" => href}
50
+ page_details["_response_info"]["links"] << { "rel" => rel, "href" => href }
53
51
  link_headers << "<#{href}>; rel=\"#{rel}\""
54
52
  end
55
53
 
56
54
  stub_request(:get, links[:self]).
57
- to_return(:status => 200, :body => page_details.to_json, :headers => {"Link" => link_headers.join(", ")})
55
+ to_return(status: 200, body: page_details.to_json, headers: { "Link" => link_headers.join(", ") })
58
56
  if i == 0
59
57
  # First page exists at URL with and without page param
60
58
  stub_request(:get, links[:self].sub(/\?page=1/, '')).
61
- to_return(:status => 200, :body => page_details.to_json, :headers => {"Link" => link_headers.join(", ")})
59
+ to_return(status: 200, body: page_details.to_json, headers: { "Link" => link_headers.join(", ") })
62
60
  end
63
61
  end
64
62
  end
65
63
 
66
- def organisations_api_has_organisation(organisation_slug, details=nil)
64
+ def organisations_api_has_organisation(organisation_slug, details = nil)
67
65
  details ||= organisation_for_slug(organisation_slug)
68
66
  stub_request(:get, "#{ORGANISATIONS_API_ENDPOINT}/api/organisations/#{organisation_slug}").
69
- to_return(:status => 200, :body => details.to_json)
67
+ to_return(status: 200, body: details.to_json)
70
68
  end
71
69
 
72
70
  def organisations_api_does_not_have_organisation(organisation_slug)
73
- stub_request(:get, "#{ORGANISATIONS_API_ENDPOINT}/api/organisations/#{organisation_slug}").to_return(:status => 404)
71
+ stub_request(:get, "#{ORGANISATIONS_API_ENDPOINT}/api/organisations/#{organisation_slug}").to_return(status: 404)
74
72
  end
75
73
 
76
74
  def organisation_for_slug(slug)
@@ -81,17 +79,17 @@ module GdsApi
81
79
  #
82
80
  # if the slug contains 'ministry' the format will be set to 'Ministerial department'
83
81
  # otherwise it will be set to 'Executive agency'
84
- def organisation_details_for_slug(slug, content_id=SecureRandom.uuid)
82
+ def organisation_details_for_slug(slug, content_id = SecureRandom.uuid)
85
83
  {
86
84
  "id" => "#{ORGANISATIONS_API_ENDPOINT}/api/organisations/#{slug}",
87
- "title" => titleize_slug(slug, :title_case => true),
85
+ "title" => titleize_slug(slug, title_case: true),
88
86
  "format" => (slug =~ /ministry/ ? "Ministerial department" : "Executive agency"),
89
87
  "updated_at" => "2013-03-25T13:06:42+00:00",
90
88
  "web_url" => "#{PUBLIC_HOST}/government/organisations/#{slug}",
91
89
  "details" => {
92
90
  "slug" => slug,
93
91
  "abbreviation" => acronymize_slug(slug),
94
- "logo_formatted_name" => titleize_slug(slug, :title_case => true),
92
+ "logo_formatted_name" => titleize_slug(slug, title_case: true),
95
93
  "organisation_brand_colour_class_name" => slug,
96
94
  "organisation_logo_type_class_name" => (slug =~ /ministry/ ? "single-identity" : "eo"),
97
95
  "closed_at" => nil,
@@ -23,20 +23,20 @@ module GdsApi
23
23
  urls << "#{PANOPTICON_ENDPOINT}/artefacts/#{metadata['id']}.json" if metadata['id']
24
24
  urls << "#{PANOPTICON_ENDPOINT}/artefacts/#{metadata['slug']}.json" if metadata['slug']
25
25
 
26
- urls.each { |url| stub_request(:get, url).to_return(:status => 200, :body => json, :headers => {}) }
26
+ urls.each { |url| stub_request(:get, url).to_return(status: 200, body: json, headers: {}) }
27
27
 
28
- return urls.first
28
+ urls.first
29
29
  end
30
30
 
31
31
  def panopticon_has_no_metadata_for(slug)
32
32
  url = "#{PANOPTICON_ENDPOINT}/artefacts/#{slug}.json"
33
- stub_request(:get, url).to_return(:status => 404, :body => "", :headers => {})
33
+ stub_request(:get, url).to_return(status: 404, body: "", headers: {})
34
34
  end
35
35
 
36
36
  def stub_panopticon_default_artefact
37
37
  stub_request(:get, %r{\A#{PANOPTICON_ENDPOINT}/artefacts}).to_return { |request|
38
38
  # return a response with only a slug, and set that slug to match the requested artefact slug
39
- {:body => JSON.dump("slug" => request.uri.path.split('/').last.chomp('.json'))}
39
+ { body: JSON.dump("slug" => request.uri.path.split('/').last.chomp('.json')) }
40
40
  }
41
41
  end
42
42
 
@@ -45,10 +45,10 @@ module GdsApi
45
45
 
46
46
  if request_details
47
47
  request_details = request_details.to_json unless custom_matcher
48
- stub.with(:body => request_details)
48
+ stub.with(body: request_details)
49
49
  end
50
50
 
51
- stub.to_return(:status => 201)
51
+ stub.to_return(status: 201)
52
52
  end
53
53
 
54
54
  def stub_panopticon_tag_creation(attributes)
@@ -2,42 +2,42 @@ module GdsApi
2
2
  module TestHelpers
3
3
  module PerformancePlatform
4
4
  module DataIn
5
- PP_DATA_IN_ENDPOINT = "http://www.performance.dev.gov.uk"
5
+ PP_DATA_IN_ENDPOINT = "http://www.performance.dev.gov.uk".freeze
6
6
 
7
7
  def stub_service_feedback_day_aggregate_submission(slug, request_body = nil)
8
8
  post_stub = stub_http_request(:post, "#{PP_DATA_IN_ENDPOINT}/data/#{slug}/customer-satisfaction")
9
9
  post_stub.with(body: request_body) unless request_body.nil?
10
- post_stub.to_return(:status => 200)
10
+ post_stub.to_return(status: 200)
11
11
  end
12
12
 
13
13
  def stub_corporate_content_problem_report_count_submission(submissions = nil)
14
14
  post_stub = stub_http_request(:post, "#{PP_DATA_IN_ENDPOINT}/data/gov-uk-content/feedback-count")
15
15
  post_stub.with(body: submissions.to_json) unless submissions.nil?
16
- post_stub.to_return(:status => 200)
16
+ post_stub.to_return(status: 200)
17
17
  end
18
18
 
19
19
  def stub_corporate_content_urls_with_the_most_problem_reports_submission(submissions = nil)
20
20
  post_stub = stub_http_request(:post, "#{PP_DATA_IN_ENDPOINT}/data/gov-uk-content/top-urls")
21
21
  post_stub.with(body: submissions.to_json) unless submissions.nil?
22
- post_stub.to_return(:status => 200)
22
+ post_stub.to_return(status: 200)
23
23
  end
24
24
 
25
25
  def stub_problem_report_daily_totals_submission(submissions = nil)
26
26
  post_stub = stub_http_request(:post, "#{PP_DATA_IN_ENDPOINT}/data/govuk-info/page-contacts")
27
27
  post_stub.with(body: submissions.to_json) unless submissions.nil?
28
- post_stub.to_return(:status => 200)
28
+ post_stub.to_return(status: 200)
29
29
  end
30
30
 
31
31
  def stub_service_feedback_bucket_unavailable_for(slug)
32
- stub_request(:post, "#{PP_DATA_IN_ENDPOINT}/data/#{slug}/customer-satisfaction").to_return(:status => 404)
32
+ stub_request(:post, "#{PP_DATA_IN_ENDPOINT}/data/#{slug}/customer-satisfaction").to_return(status: 404)
33
33
  end
34
34
 
35
35
  def stub_pp_isnt_available
36
- stub_request(:post, /#{PP_DATA_IN_ENDPOINT}\/.*/).to_return(:status => 503)
36
+ stub_request(:post, /#{PP_DATA_IN_ENDPOINT}\/.*/).to_return(status: 503)
37
37
  end
38
38
 
39
39
  def stub_pp_dataset_unavailable
40
- stub_request(:any, /#{PP_DATA_IN_ENDPOINT}/).to_return(:status => 404)
40
+ stub_request(:any, /#{PP_DATA_IN_ENDPOINT}/).to_return(status: 404)
41
41
  end
42
42
  end
43
43
  end
@@ -14,15 +14,15 @@ module GdsApi
14
14
  def stub_publishing_api_put_intent(base_path, body = intent_for_publishing_api(base_path))
15
15
  url = PUBLISHING_API_ENDPOINT + "/publish-intent" + base_path
16
16
  body = body.to_json unless body.is_a?(String)
17
- stub_request(:put, url).with(body: body).to_return(status: 200, body: '{}', headers: {"Content-Type" => "application/json; charset=utf-8"})
17
+ stub_request(:put, url).with(body: body).to_return(status: 200, body: '{}', headers: { "Content-Type" => "application/json; charset=utf-8" })
18
18
  end
19
19
 
20
20
  def stub_publishing_api_destroy_intent(base_path)
21
21
  url = PUBLISHING_API_ENDPOINT + "/publish-intent" + base_path
22
- stub_request(:delete, url).to_return(status: 200, body: '{}', headers: {"Content-Type" => "application/json; charset=utf-8"})
22
+ stub_request(:delete, url).to_return(status: 200, body: '{}', headers: { "Content-Type" => "application/json; charset=utf-8" })
23
23
  end
24
24
 
25
- def stub_default_publishing_api_put_intent()
25
+ def stub_default_publishing_api_put_intent
26
26
  stub_request(:put, %r{\A#{PUBLISHING_API_ENDPOINT}/publish-intent})
27
27
  end
28
28
 
@@ -60,43 +60,42 @@ module GdsApi
60
60
  end
61
61
 
62
62
  def publishing_api_isnt_available
63
- stub_request(:any, /#{PUBLISHING_API_ENDPOINT}\/.*/).to_return(:status => 503)
63
+ stub_request(:any, /#{PUBLISHING_API_ENDPOINT}\/.*/).to_return(status: 503)
64
64
  end
65
65
 
66
66
  def stub_default_publishing_api_path_reservation
67
67
  stub_request(:put, %r[\A#{PUBLISHING_API_ENDPOINT}/paths/]).to_return { |request|
68
- base_path = request.uri.path.sub(%r{\A/paths/}, "")
69
- { :status => 200, :headers => {:content_type => "application/json"},
70
- :body => publishing_api_path_data_for(base_path).to_json }
68
+ base_path = request.uri.path.sub(%r{\A/paths/}, "")
69
+ { status: 200, headers: { content_type: "application/json" },
70
+ body: publishing_api_path_data_for(base_path).to_json }
71
71
  }
72
72
  end
73
73
 
74
74
  def publishing_api_has_path_reservation_for(path, publishing_app)
75
75
  data = publishing_api_path_data_for(path, "publishing_app" => publishing_app)
76
- error_data = data.merge({
77
- "errors" => {"path" => ["is already reserved by the #{publishing_app} application"]},
78
- })
76
+ error_data = data.merge("errors" => { "path" => ["is already reserved by the #{publishing_app} application"] })
79
77
 
80
78
  stub_request(:put, "#{PUBLISHING_API_ENDPOINT}/paths#{path}").
81
- to_return(:status => 422, :body => error_data.to_json,
82
- :headers => {:content_type => "application/json"})
79
+ to_return(status: 422, body: error_data.to_json,
80
+ headers: { content_type: "application/json" })
83
81
 
84
82
  stub_request(:put, "#{PUBLISHING_API_ENDPOINT}/paths#{path}").
85
- with(:body => {"publishing_app" => publishing_app}).
86
- to_return(:status => 200,
87
- :headers => {:content_type => "application/json"},
88
- :body => data.to_json)
83
+ with(body: { "publishing_app" => publishing_app }).
84
+ to_return(status: 200,
85
+ headers: { content_type: "application/json" },
86
+ body: data.to_json)
89
87
  end
90
88
 
91
89
  def publishing_api_returns_path_reservation_validation_error_for(path, error_details = nil)
92
- error_details ||= {"base" => ["computer says no"]}
90
+ error_details ||= { "base" => ["computer says no"] }
93
91
  error_data = publishing_api_path_data_for(path).merge("errors" => error_details)
94
92
 
95
93
  stub_request(:put, "#{PUBLISHING_API_ENDPOINT}/paths#{path}").
96
- to_return(:status => 422, :body => error_data.to_json, :headers => {:content_type => "application/json"})
94
+ to_return(status: 422, body: error_data.to_json, headers: { content_type: "application/json" })
97
95
  end
98
96
 
99
97
  private
98
+
100
99
  def values_match_recursively(expected_value, actual_value)
101
100
  case expected_value
102
101
  when Hash
@@ -116,11 +115,11 @@ module GdsApi
116
115
  end
117
116
  end
118
117
 
119
- def content_item_for_publishing_api(base_path, publishing_app="publisher")
118
+ def content_item_for_publishing_api(base_path, publishing_app = "publisher")
120
119
  content_item_for_base_path(base_path).merge("publishing_app" => publishing_app)
121
120
  end
122
121
 
123
- def intent_for_publishing_api(base_path, publishing_app="publisher")
122
+ def intent_for_publishing_api(base_path, publishing_app = "publisher")
124
123
  intent_for_base_path(base_path).merge("publishing_app" => publishing_app)
125
124
  end
126
125