gds-api-adapters 38.1.0 → 39.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gds_api/test_helpers/need_api.rb +0 -15
- data/lib/gds_api/test_helpers/organisations.rb +5 -0
- data/lib/gds_api/version.rb +1 -1
- metadata +3 -103
- data/test/asset_manager_test.rb +0 -94
- data/test/business_support_api_test.rb +0 -45
- data/test/content_api_test.rb +0 -712
- data/test/content_store_test.rb +0 -55
- data/test/email_alert_api_test.rb +0 -189
- data/test/fixtures/finder_api/cma-case-schema.json +0 -103
- data/test/fixtures/hello.txt +0 -1
- data/test/fixtures/new_policies_for_dwp.json +0 -298
- data/test/fixtures/no_services_and_info_data_found_fixture.json +0 -14
- data/test/fixtures/old_policies_for_dwp.json +0 -413
- data/test/fixtures/services_and_info_fixture.json +0 -73
- data/test/fixtures/sub_sector_organisations.json +0 -57
- data/test/fixtures/world_organisations_australia.json +0 -490
- data/test/gds_api_base_test.rb +0 -110
- data/test/gov_uk_delivery_test.rb +0 -67
- data/test/govuk_headers_test.rb +0 -30
- data/test/helpers_test.rb +0 -23
- data/test/imminence_api_test.rb +0 -196
- data/test/json_client_test.rb +0 -879
- data/test/licence_application_api_test.rb +0 -196
- data/test/list_response_test.rb +0 -189
- data/test/local_links_manager_api_test.rb +0 -236
- data/test/mapit_test.rb +0 -117
- data/test/maslow_test.rb +0 -12
- data/test/middleware/govuk_header_sniffer_test.rb +0 -18
- data/test/need_api_test.rb +0 -345
- data/test/organisations_api_test.rb +0 -58
- data/test/panopticon_registerer_test.rb +0 -118
- data/test/panopticon_test.rb +0 -190
- data/test/pp_data_in_test.rb +0 -52
- data/test/pp_data_out_test.rb +0 -24
- data/test/publishing_api/special_route_publisher_test.rb +0 -104
- data/test/publishing_api_test.rb +0 -186
- data/test/publishing_api_v2/get_expanded_links_test.rb +0 -85
- data/test/publishing_api_v2/get_links_test.rb +0 -89
- data/test/publishing_api_v2/lookup_test.rb +0 -70
- data/test/publishing_api_v2_test.rb +0 -1649
- data/test/response_test.rb +0 -245
- data/test/router_test.rb +0 -456
- data/test/rummager_helpers_test.rb +0 -20
- data/test/rummager_test.rb +0 -150
- data/test/support_api_test.rb +0 -189
- data/test/support_test.rb +0 -95
- data/test/test_helper.rb +0 -55
- data/test/test_helpers/email_alert_api_test.rb +0 -24
- data/test/test_helpers/pact_helper.rb +0 -13
- data/test/test_helpers/panopticon_test.rb +0 -44
- data/test/test_helpers/publishing_api_test.rb +0 -129
- data/test/test_helpers/publishing_api_v2_test.rb +0 -170
- data/test/worldwide_api_test.rb +0 -82
data/test/response_test.rb
DELETED
@@ -1,245 +0,0 @@
|
|
1
|
-
require_relative 'test_helper'
|
2
|
-
require 'gds_api/response'
|
3
|
-
|
4
|
-
describe GdsApi::Response do
|
5
|
-
describe "accessing HTTP response details" do
|
6
|
-
before :each do
|
7
|
-
@mock_http_response = stub(body: "A Response body", code: 200, headers: { cache_control: 'public' })
|
8
|
-
@response = GdsApi::Response.new(@mock_http_response)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should return the raw response body" do
|
12
|
-
assert_equal "A Response body", @response.raw_response_body
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should return the status code" do
|
16
|
-
assert_equal 200, @response.code
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should pass-on the response headers" do
|
20
|
-
assert_equal({ cache_control: 'public' }, @response.headers)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe ".expires_at" do
|
25
|
-
it "should be calculated from cache-control max-age" do
|
26
|
-
Timecop.freeze(Time.parse("15:00")) do
|
27
|
-
cache_control_headers = { cache_control: 'public, max-age=900' }
|
28
|
-
headers = cache_control_headers.merge(date: Time.now.httpdate)
|
29
|
-
|
30
|
-
mock_http_response = stub(body: "A Response body", code: 200, headers: headers)
|
31
|
-
response = GdsApi::Response.new(mock_http_response)
|
32
|
-
|
33
|
-
assert_equal Time.parse("15:15"), response.expires_at
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should be same as the value of Expires header in absence of max-age" do
|
38
|
-
Timecop.freeze(Time.parse("15:00")) do
|
39
|
-
cache_headers = { cache_control: 'public', expires: (Time.now + 900).httpdate }
|
40
|
-
headers = cache_headers.merge(date: Time.now.httpdate)
|
41
|
-
|
42
|
-
mock_http_response = stub(body: "A Response body", code: 200, headers: headers)
|
43
|
-
response = GdsApi::Response.new(mock_http_response)
|
44
|
-
|
45
|
-
assert_equal Time.parse("15:15"), response.expires_at
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should be nil in absence of Expires header and max-age" do
|
50
|
-
mock_http_response = stub(body: "A Response body", code: 200, headers: { date: Time.now.httpdate })
|
51
|
-
response = GdsApi::Response.new(mock_http_response)
|
52
|
-
|
53
|
-
assert_nil response.expires_at
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should be nil in absence of Date header and max-age" do
|
57
|
-
mock_http_response = stub(body: "A Response body", code: 200, headers: {})
|
58
|
-
response = GdsApi::Response.new(mock_http_response)
|
59
|
-
|
60
|
-
assert_nil response.expires_at
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe ".expires_in" do
|
65
|
-
it "should be seconds remaining from expiration time inferred from max-age" do
|
66
|
-
cache_control_headers = { cache_control: 'public, max-age=900' }
|
67
|
-
headers = cache_control_headers.merge(date: Time.now.httpdate)
|
68
|
-
mock_http_response = stub(body: "A Response body", code: 200, headers: headers)
|
69
|
-
|
70
|
-
Timecop.travel(12 * 60) do
|
71
|
-
response = GdsApi::Response.new(mock_http_response)
|
72
|
-
assert_equal 180, response.expires_in
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should be seconds remaining from expiration time inferred from Expires header" do
|
77
|
-
cache_headers = { cache_control: 'public', expires: (Time.now + 900).httpdate }
|
78
|
-
headers = cache_headers.merge(date: Time.now.httpdate)
|
79
|
-
mock_http_response = stub(body: "A Response body", code: 200, headers: headers)
|
80
|
-
|
81
|
-
Timecop.travel(12 * 60) do
|
82
|
-
response = GdsApi::Response.new(mock_http_response)
|
83
|
-
assert_equal 180, response.expires_in
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
it "should be nil in absence of Expires header and max-age" do
|
88
|
-
mock_http_response = stub(body: "A Response body", code: 200, headers: { date: Time.now.httpdate })
|
89
|
-
response = GdsApi::Response.new(mock_http_response)
|
90
|
-
|
91
|
-
assert_nil response.expires_in
|
92
|
-
end
|
93
|
-
|
94
|
-
it "should be nil in absence of Date header" do
|
95
|
-
cache_control_headers = { cache_control: 'public, max-age=900' }
|
96
|
-
mock_http_response = stub(body: "A Response body", code: 200, headers: cache_control_headers)
|
97
|
-
response = GdsApi::Response.new(mock_http_response)
|
98
|
-
|
99
|
-
assert_nil response.expires_in
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
describe "processing web_urls" do
|
104
|
-
def build_response(body_string, relative_to = "https://www.gov.uk")
|
105
|
-
GdsApi::Response.new(stub(body: body_string), web_urls_relative_to: relative_to)
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should map web URLs" do
|
109
|
-
body = {
|
110
|
-
"web_url" => "https://www.gov.uk/test"
|
111
|
-
}.to_json
|
112
|
-
assert_equal "/test", build_response(body)['web_url']
|
113
|
-
end
|
114
|
-
|
115
|
-
it "should leave other properties alone" do
|
116
|
-
body = {
|
117
|
-
"title" => "Title",
|
118
|
-
"description" => "Description"
|
119
|
-
}.to_json
|
120
|
-
response = build_response(body)
|
121
|
-
assert_equal "Title", response['title']
|
122
|
-
assert_equal "Description", response['description']
|
123
|
-
end
|
124
|
-
|
125
|
-
it "should traverse into hashes" do
|
126
|
-
body = {
|
127
|
-
"details" => {
|
128
|
-
"chirality" => "widdershins",
|
129
|
-
"web_url" => "https://www.gov.uk/left",
|
130
|
-
}
|
131
|
-
}.to_json
|
132
|
-
|
133
|
-
response = build_response(body)
|
134
|
-
assert_equal "/left", response['details']['web_url']
|
135
|
-
end
|
136
|
-
|
137
|
-
it "should traverse into arrays" do
|
138
|
-
body = {
|
139
|
-
"other_urls" => [
|
140
|
-
{ "title" => "Pies", "web_url" => "https://www.gov.uk/pies" },
|
141
|
-
{ "title" => "Cheese", "web_url" => "https://www.gov.uk/cheese" },
|
142
|
-
]
|
143
|
-
}.to_json
|
144
|
-
|
145
|
-
response = build_response(body)
|
146
|
-
assert_equal "/pies", response['other_urls'][0]['web_url']
|
147
|
-
assert_equal "/cheese", response['other_urls'][1]['web_url']
|
148
|
-
end
|
149
|
-
|
150
|
-
it "should handle nil values" do
|
151
|
-
body = { "web_url" => nil }.to_json
|
152
|
-
|
153
|
-
response = build_response(body)
|
154
|
-
assert_nil response['web_url']
|
155
|
-
end
|
156
|
-
|
157
|
-
it "should handle query parameters" do
|
158
|
-
body = {
|
159
|
-
"web_url" => "https://www.gov.uk/thing?does=stuff"
|
160
|
-
}.to_json
|
161
|
-
|
162
|
-
response = build_response(body)
|
163
|
-
assert_equal "/thing?does=stuff", response['web_url']
|
164
|
-
end
|
165
|
-
|
166
|
-
it "should handle fragments" do
|
167
|
-
body = {
|
168
|
-
"web_url" => "https://www.gov.uk/thing#part-2"
|
169
|
-
}.to_json
|
170
|
-
|
171
|
-
response = build_response(body)
|
172
|
-
assert_equal "/thing#part-2", response['web_url']
|
173
|
-
end
|
174
|
-
|
175
|
-
it "should keep URLs from other domains absolute" do
|
176
|
-
body = {
|
177
|
-
"web_url" => "https://www.example.com/example"
|
178
|
-
}.to_json
|
179
|
-
|
180
|
-
response = build_response(body)
|
181
|
-
assert_equal "https://www.example.com/example", response['web_url']
|
182
|
-
end
|
183
|
-
|
184
|
-
it "should keep URLs with other schemes absolute" do
|
185
|
-
body = {
|
186
|
-
"web_url" => "http://www.example.com/example"
|
187
|
-
}.to_json
|
188
|
-
|
189
|
-
response = build_response(body)
|
190
|
-
assert_equal "http://www.example.com/example", response['web_url']
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
describe "hash and openstruct access" do
|
195
|
-
before :each do
|
196
|
-
@response_data = {
|
197
|
-
"_response_info" => {
|
198
|
-
"status" => "ok"
|
199
|
-
},
|
200
|
-
"id" => "https://www.gov.uk/api/vat-rates.json",
|
201
|
-
"web_url" => "https://www.gov.uk/vat-rates",
|
202
|
-
"title" => "VAT rates",
|
203
|
-
"format" => "answer",
|
204
|
-
"updated_at" => "2013-04-04T15:51:54+01:00",
|
205
|
-
"details" => {
|
206
|
-
"need_id" => "1870",
|
207
|
-
"business_proposition" => false,
|
208
|
-
"description" => "Current VAT rates - standard 20% and rates for reduced rate and zero-rated items",
|
209
|
-
"language" => "en",
|
210
|
-
},
|
211
|
-
"tags" => [
|
212
|
-
{ "slug" => "foo" },
|
213
|
-
{ "slug" => "bar" },
|
214
|
-
{ "slug" => "baz" },
|
215
|
-
],
|
216
|
-
}
|
217
|
-
@response = GdsApi::Response.new(stub(body: @response_data.to_json))
|
218
|
-
end
|
219
|
-
|
220
|
-
describe "behaving like a read-only hash" do
|
221
|
-
it "should allow accessing members by key" do
|
222
|
-
assert_equal "VAT rates", @response["title"]
|
223
|
-
end
|
224
|
-
|
225
|
-
it "should allow accessing nested keys" do
|
226
|
-
assert_equal "1870", @response["details"]["need_id"]
|
227
|
-
end
|
228
|
-
|
229
|
-
it "should return nil for a non-existent key" do
|
230
|
-
assert_equal nil, @response["foo"]
|
231
|
-
end
|
232
|
-
|
233
|
-
it "should memoize the parsed hash" do
|
234
|
-
@response["id"]
|
235
|
-
JSON.expects(:parse).never
|
236
|
-
assert_equal "VAT rates", @response["title"]
|
237
|
-
end
|
238
|
-
|
239
|
-
it "should allow using dig to access nested keys" do
|
240
|
-
skip unless RUBY_VERSION > "2.3"
|
241
|
-
assert_equal "1870", @response.dig("details", "need_id")
|
242
|
-
end
|
243
|
-
end
|
244
|
-
end
|
245
|
-
end
|
data/test/router_test.rb
DELETED
@@ -1,456 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'gds_api/router'
|
3
|
-
|
4
|
-
describe GdsApi::Router do
|
5
|
-
before do
|
6
|
-
@base_api_url = "http://router-api.example.com"
|
7
|
-
@api = GdsApi::Router.new(@base_api_url)
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "managing backends" do
|
11
|
-
describe "fetching details about a backend" do
|
12
|
-
it "should return backend details" do
|
13
|
-
req = WebMock.stub_request(:get, "#{@base_api_url}/backends/foo").
|
14
|
-
to_return(body: { "backend_id" => "foo", "backend_url" => "http://foo.example.com/" }.to_json,
|
15
|
-
headers: { "Content-type" => "application/json" })
|
16
|
-
|
17
|
-
response = @api.get_backend("foo")
|
18
|
-
assert_equal 200, response.code
|
19
|
-
assert_equal "http://foo.example.com/", response['backend_url']
|
20
|
-
|
21
|
-
assert_requested(req)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "raises for a non-existend backend" do
|
25
|
-
req = WebMock.stub_request(:get, "#{@base_api_url}/backends/foo").
|
26
|
-
to_return(status: 404)
|
27
|
-
|
28
|
-
assert_raises(GdsApi::HTTPNotFound) do
|
29
|
-
@api.get_backend("foo")
|
30
|
-
end
|
31
|
-
|
32
|
-
assert_requested(req)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should URI escape the given ID" do
|
36
|
-
req = WebMock.stub_request(:get, "#{@base_api_url}/backends/foo+bar").
|
37
|
-
to_return(status: 404)
|
38
|
-
|
39
|
-
assert_raises(GdsApi::HTTPNotFound) do
|
40
|
-
@api.get_backend("foo bar")
|
41
|
-
end
|
42
|
-
|
43
|
-
assert_requested(req)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "creating/updating a backend" do
|
48
|
-
it "should allow creating/updating a backend" do
|
49
|
-
req = WebMock.stub_request(:put, "#{@base_api_url}/backends/foo").
|
50
|
-
with(body: { "backend" => { "backend_url" => "http://foo.example.com/" } }.to_json).
|
51
|
-
to_return(status: 201, body: { "backend_id" => "foo", "backend_url" => "http://foo.example.com/" }.to_json,
|
52
|
-
headers: { "Content-type" => "application/json" })
|
53
|
-
|
54
|
-
response = @api.add_backend("foo", "http://foo.example.com/")
|
55
|
-
assert_equal 201, response.code
|
56
|
-
assert_equal "http://foo.example.com/", response['backend_url']
|
57
|
-
|
58
|
-
assert_requested(req)
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should raise an error if creating/updating a backend fails" do
|
62
|
-
response_data = { "backend_id" => "foo", "backend_url" => "ftp://foo.example.com/", "errors" => { "backend_url" => "is not an HTTP URL" } }
|
63
|
-
req = WebMock.stub_request(:put, "#{@base_api_url}/backends/foo").
|
64
|
-
with(body: { "backend" => { "backend_url" => "http://foo.example.com/" } }.to_json).
|
65
|
-
to_return(status: 400, body: response_data.to_json, headers: { "Content-type" => "application/json" })
|
66
|
-
|
67
|
-
e = nil
|
68
|
-
begin
|
69
|
-
@api.add_backend("foo", "http://foo.example.com/")
|
70
|
-
rescue GdsApi::HTTPErrorResponse => ex
|
71
|
-
e = ex
|
72
|
-
end
|
73
|
-
|
74
|
-
refute_nil e
|
75
|
-
assert_equal 400, e.code
|
76
|
-
assert_equal response_data, e.error_details
|
77
|
-
|
78
|
-
assert_requested(req)
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should URI escape the passed id" do
|
82
|
-
req = WebMock.stub_request(:put, "#{@base_api_url}/backends/foo+bar").
|
83
|
-
with(body: { "backend" => { "backend_url" => "http://foo.example.com/" } }.to_json).
|
84
|
-
to_return(status: 404, body: "Not found")
|
85
|
-
|
86
|
-
# We expect a GdsApi::HTTPErrorResponse, but we want to ensure nothing else is raised
|
87
|
-
begin
|
88
|
-
@api.add_backend("foo bar", "http://foo.example.com/")
|
89
|
-
rescue GdsApi::HTTPErrorResponse
|
90
|
-
nil
|
91
|
-
end
|
92
|
-
|
93
|
-
assert_requested(req)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
describe "deleting a backend" do
|
98
|
-
it "allow deleting a backend" do
|
99
|
-
req = WebMock.stub_request(:delete, "#{@base_api_url}/backends/foo").
|
100
|
-
to_return(status: 200, body: { "backend_id" => "foo", "backend_url" => "http://foo.example.com/" }.to_json,
|
101
|
-
headers: { "Content-type" => "application/json" })
|
102
|
-
|
103
|
-
response = @api.delete_backend("foo")
|
104
|
-
assert_equal 200, response.code
|
105
|
-
assert_equal "http://foo.example.com/", response['backend_url']
|
106
|
-
|
107
|
-
assert_requested(req)
|
108
|
-
end
|
109
|
-
|
110
|
-
it "should raise an error if deleting the backend fails" do
|
111
|
-
response_data = { "backend_id" => "foo", "backend_url" => "ftp://foo.example.com/", "errors" => { "base" => "Backend has routes - can't delete" } }
|
112
|
-
req = WebMock.stub_request(:delete, "#{@base_api_url}/backends/foo").
|
113
|
-
to_return(status: 400, body: response_data.to_json, headers: { "Content-type" => "application/json" })
|
114
|
-
|
115
|
-
e = nil
|
116
|
-
begin
|
117
|
-
@api.delete_backend("foo")
|
118
|
-
rescue GdsApi::HTTPErrorResponse => ex
|
119
|
-
e = ex
|
120
|
-
end
|
121
|
-
|
122
|
-
refute_nil e
|
123
|
-
assert_equal 400, e.code
|
124
|
-
assert_equal response_data, e.error_details
|
125
|
-
|
126
|
-
assert_requested(req)
|
127
|
-
end
|
128
|
-
|
129
|
-
it "should URI escape the passed id" do
|
130
|
-
req = WebMock.stub_request(:delete, "#{@base_api_url}/backends/foo+bar").
|
131
|
-
to_return(status: 404, body: "Not found")
|
132
|
-
|
133
|
-
# We expect a GdsApi::HTTPErrorResponse, but we want to ensure nothing else is raised
|
134
|
-
assert_raises GdsApi::HTTPErrorResponse do
|
135
|
-
@api.delete_backend("foo bar")
|
136
|
-
end
|
137
|
-
|
138
|
-
assert_requested(req)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
describe "managing routes" do
|
144
|
-
before :each do
|
145
|
-
@commit_req = WebMock.stub_request(:post, "#{@base_api_url}/routes/commit").
|
146
|
-
to_return(status: 200, body: "Routers updated")
|
147
|
-
end
|
148
|
-
|
149
|
-
describe "fetching a route" do
|
150
|
-
it "should return the route details" do
|
151
|
-
route_data = { "incoming_path" => "/foo", "route_type" => "exact", "handler" => "backend", "backend_id" => "foo" }
|
152
|
-
req = WebMock.stub_request(:get, "#{@base_api_url}/routes").
|
153
|
-
with(query: { "incoming_path" => "/foo" }).
|
154
|
-
to_return(status: 200, body: route_data.to_json, headers: { "Content-type" => "application/json" })
|
155
|
-
|
156
|
-
response = @api.get_route("/foo")
|
157
|
-
assert_equal 200, response.code
|
158
|
-
assert_equal "foo", response['backend_id']
|
159
|
-
|
160
|
-
assert_requested(req)
|
161
|
-
assert_not_requested(@commit_req)
|
162
|
-
end
|
163
|
-
|
164
|
-
it "should raise if nothing found" do
|
165
|
-
req = WebMock.stub_request(:get, "#{@base_api_url}/routes").
|
166
|
-
with(query: { "incoming_path" => "/foo" }).
|
167
|
-
to_return(status: 404)
|
168
|
-
|
169
|
-
assert_raises(GdsApi::HTTPNotFound) do
|
170
|
-
@api.get_route("/foo")
|
171
|
-
end
|
172
|
-
|
173
|
-
assert_requested(req)
|
174
|
-
assert_not_requested(@commit_req)
|
175
|
-
end
|
176
|
-
|
177
|
-
it "should escape the params" do
|
178
|
-
# The WebMock query matcher matches unescaped params. The call blows up if they're not escaped
|
179
|
-
|
180
|
-
req = WebMock.stub_request(:get, "#{@base_api_url}/routes").
|
181
|
-
with(query: { "incoming_path" => "/foo bar" }).
|
182
|
-
to_return(status: 404)
|
183
|
-
|
184
|
-
assert_raises(GdsApi::HTTPNotFound) do
|
185
|
-
@api.get_route("/foo bar")
|
186
|
-
end
|
187
|
-
|
188
|
-
assert_requested(req)
|
189
|
-
assert_not_requested(@commit_req)
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
describe "creating/updating a route" do
|
194
|
-
it "should allow creating/updating a route" do
|
195
|
-
route_data = { "incoming_path" => "/foo", "route_type" => "exact", "handler" => "backend", "backend_id" => "foo" }
|
196
|
-
req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
|
197
|
-
with(body: { "route" => route_data }.to_json).
|
198
|
-
to_return(status: 201, body: route_data.to_json, headers: { "Content-type" => "application/json" })
|
199
|
-
|
200
|
-
response = @api.add_route("/foo", "exact", "foo")
|
201
|
-
assert_equal 201, response.code
|
202
|
-
assert_equal "foo", response['backend_id']
|
203
|
-
|
204
|
-
assert_requested(req)
|
205
|
-
assert_not_requested(@commit_req)
|
206
|
-
end
|
207
|
-
|
208
|
-
it "should commit the routes when asked to" do
|
209
|
-
req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
|
210
|
-
to_return(status: 201, body: {}.to_json, headers: { "Content-type" => "application/json" })
|
211
|
-
|
212
|
-
@api.add_route("/foo", "exact", "foo", commit: true)
|
213
|
-
|
214
|
-
assert_requested(req)
|
215
|
-
assert_requested(@commit_req)
|
216
|
-
end
|
217
|
-
|
218
|
-
it "should raise an error if creating/updating the route fails" do
|
219
|
-
route_data = { "incoming_path" => "/foo", "route_type" => "exact", "handler" => "backend", "backend_id" => "foo" }
|
220
|
-
response_data = route_data.merge("errors" => { "backend_id" => "does not exist" })
|
221
|
-
|
222
|
-
req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
|
223
|
-
with(body: { "route" => route_data }.to_json).
|
224
|
-
to_return(status: 400, body: response_data.to_json, headers: { "Content-type" => "application/json" })
|
225
|
-
|
226
|
-
e = nil
|
227
|
-
begin
|
228
|
-
@api.add_route("/foo", "exact", "foo")
|
229
|
-
rescue GdsApi::HTTPErrorResponse => ex
|
230
|
-
e = ex
|
231
|
-
end
|
232
|
-
|
233
|
-
refute_nil e
|
234
|
-
assert_equal 400, e.code
|
235
|
-
assert_equal response_data, e.error_details
|
236
|
-
|
237
|
-
assert_requested(req)
|
238
|
-
assert_not_requested(@commit_req)
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
describe "creating/updating a redirect route" do
|
243
|
-
it "should allow creating/updating a redirect route" do
|
244
|
-
route_data = { "incoming_path" => "/foo", "route_type" => "exact", "handler" => "redirect",
|
245
|
-
"redirect_to" => "/bar", "redirect_type" => "permanent", "segments_mode" => nil }
|
246
|
-
req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
|
247
|
-
with(body: { "route" => route_data }.to_json).
|
248
|
-
to_return(status: 201, body: route_data.to_json, headers: { "Content-type" => "application/json" })
|
249
|
-
|
250
|
-
response = @api.add_redirect_route("/foo", "exact", "/bar")
|
251
|
-
assert_equal 201, response.code
|
252
|
-
assert_equal "/bar", response['redirect_to']
|
253
|
-
|
254
|
-
assert_requested(req)
|
255
|
-
assert_not_requested(@commit_req)
|
256
|
-
end
|
257
|
-
|
258
|
-
it "should allow creating/updating a temporary redirect route" do
|
259
|
-
route_data = { "incoming_path" => "/foo", "route_type" => "exact", "handler" => "redirect",
|
260
|
-
"redirect_to" => "/bar", "redirect_type" => "temporary", "segments_mode" => nil }
|
261
|
-
req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
|
262
|
-
with(body: { "route" => route_data }.to_json).
|
263
|
-
to_return(status: 201, body: route_data.to_json, headers: { "Content-type" => "application/json" })
|
264
|
-
|
265
|
-
response = @api.add_redirect_route("/foo", "exact", "/bar", "temporary")
|
266
|
-
assert_equal 201, response.code
|
267
|
-
assert_equal "/bar", response['redirect_to']
|
268
|
-
|
269
|
-
assert_requested(req)
|
270
|
-
assert_not_requested(@commit_req)
|
271
|
-
end
|
272
|
-
|
273
|
-
it "should allow creating/updating a redirect route which preserves segments" do
|
274
|
-
route_data = { "incoming_path" => "/foo", "route_type" => "exact", "handler" => "redirect",
|
275
|
-
"redirect_to" => "/bar", "redirect_type" => "temporary", "segments_mode" => "preserve" }
|
276
|
-
req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
|
277
|
-
with(body: { "route" => route_data }.to_json).
|
278
|
-
to_return(status: 201, body: route_data.to_json, headers: { "Content-type" => "application/json" })
|
279
|
-
|
280
|
-
response = @api.add_redirect_route("/foo", "exact", "/bar", "temporary", segments_mode: "preserve")
|
281
|
-
assert_equal 201, response.code
|
282
|
-
assert_equal "/bar", response['redirect_to']
|
283
|
-
|
284
|
-
assert_requested(req)
|
285
|
-
assert_not_requested(@commit_req)
|
286
|
-
end
|
287
|
-
|
288
|
-
it "should commit the routes when asked to" do
|
289
|
-
req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
|
290
|
-
to_return(status: 201, body: {}.to_json, headers: { "Content-type" => "application/json" })
|
291
|
-
|
292
|
-
@api.add_redirect_route("/foo", "exact", "/bar", "temporary", commit: true)
|
293
|
-
|
294
|
-
assert_requested(req)
|
295
|
-
assert_requested(@commit_req)
|
296
|
-
end
|
297
|
-
|
298
|
-
it "should raise an error if creating/updating the redirect route fails" do
|
299
|
-
route_data = { "incoming_path" => "/foo", "route_type" => "exact", "handler" => "redirect",
|
300
|
-
"redirect_to" => "bar", "redirect_type" => "permanent", "segments_mode" => nil }
|
301
|
-
response_data = route_data.merge("errors" => { "redirect_to" => "is not a valid URL path" })
|
302
|
-
|
303
|
-
req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
|
304
|
-
with(body: { "route" => route_data }.to_json).
|
305
|
-
to_return(status: 400, body: response_data.to_json, headers: { "Content-type" => "application/json" })
|
306
|
-
|
307
|
-
e = nil
|
308
|
-
begin
|
309
|
-
@api.add_redirect_route("/foo", "exact", "bar")
|
310
|
-
rescue GdsApi::HTTPErrorResponse => ex
|
311
|
-
e = ex
|
312
|
-
end
|
313
|
-
|
314
|
-
refute_nil e
|
315
|
-
assert_equal 400, e.code
|
316
|
-
assert_equal response_data, e.error_details
|
317
|
-
|
318
|
-
assert_requested(req)
|
319
|
-
assert_not_requested(@commit_req)
|
320
|
-
end
|
321
|
-
end
|
322
|
-
|
323
|
-
describe "#add_gone_route" do
|
324
|
-
it "should allow creating/updating a gone route" do
|
325
|
-
route_data = { "incoming_path" => "/foo", "route_type" => "exact", "handler" => "gone" }
|
326
|
-
req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
|
327
|
-
with(body: { "route" => route_data }.to_json).
|
328
|
-
to_return(status: 201, body: route_data.to_json, headers: { "Content-type" => "application/json" })
|
329
|
-
|
330
|
-
response = @api.add_gone_route("/foo", "exact")
|
331
|
-
assert_equal 201, response.code
|
332
|
-
assert_equal "/foo", response['incoming_path']
|
333
|
-
|
334
|
-
assert_requested(req)
|
335
|
-
assert_not_requested(@commit_req)
|
336
|
-
end
|
337
|
-
|
338
|
-
it "should commit the routes when asked to" do
|
339
|
-
req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
|
340
|
-
to_return(status: 201, body: {}.to_json, headers: { "Content-type" => "application/json" })
|
341
|
-
|
342
|
-
@api.add_gone_route("/foo", "exact", commit: true)
|
343
|
-
|
344
|
-
assert_requested(req)
|
345
|
-
assert_requested(@commit_req)
|
346
|
-
end
|
347
|
-
|
348
|
-
it "should raise an error if creating/updating the gone route fails" do
|
349
|
-
route_data = { "incoming_path" => "foo", "route_type" => "exact", "handler" => "gone" }
|
350
|
-
response_data = route_data.merge("errors" => { "incoming_path" => "is not a valid URL path" })
|
351
|
-
|
352
|
-
req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
|
353
|
-
with(body: { "route" => route_data }.to_json).
|
354
|
-
to_return(status: 400, body: response_data.to_json, headers: { "Content-type" => "application/json" })
|
355
|
-
|
356
|
-
e = nil
|
357
|
-
begin
|
358
|
-
@api.add_gone_route("foo", "exact")
|
359
|
-
rescue GdsApi::HTTPErrorResponse => ex
|
360
|
-
e = ex
|
361
|
-
end
|
362
|
-
|
363
|
-
refute_nil e
|
364
|
-
assert_equal 400, e.code
|
365
|
-
assert_equal response_data, e.error_details
|
366
|
-
|
367
|
-
assert_requested(req)
|
368
|
-
assert_not_requested(@commit_req)
|
369
|
-
end
|
370
|
-
end
|
371
|
-
|
372
|
-
describe "deleting a route" do
|
373
|
-
it "should allow deleting a route" do
|
374
|
-
route_data = { "incoming_path" => "/foo", "route_type" => "exact", "handler" => "backend", "backend_id" => "foo" }
|
375
|
-
req = WebMock.stub_request(:delete, "#{@base_api_url}/routes").
|
376
|
-
with(query: { "incoming_path" => "/foo" }).
|
377
|
-
to_return(status: 200, body: route_data.to_json, headers: { "Content-type" => "application/json" })
|
378
|
-
|
379
|
-
response = @api.delete_route("/foo")
|
380
|
-
assert_equal 200, response.code
|
381
|
-
assert_equal "foo", response['backend_id']
|
382
|
-
|
383
|
-
assert_requested(req)
|
384
|
-
assert_not_requested(@commit_req)
|
385
|
-
end
|
386
|
-
|
387
|
-
it "should commit the routes when asked to" do
|
388
|
-
req = WebMock.stub_request(:delete, "#{@base_api_url}/routes").
|
389
|
-
with(query: { "incoming_path" => "/foo" }).
|
390
|
-
to_return(status: 200, body: {}.to_json, headers: { "Content-type" => "application/json" })
|
391
|
-
|
392
|
-
@api.delete_route("/foo", commit: true)
|
393
|
-
|
394
|
-
assert_requested(req)
|
395
|
-
assert_requested(@commit_req)
|
396
|
-
end
|
397
|
-
|
398
|
-
it "should raise HTTPNotFound if nothing found" do
|
399
|
-
req = WebMock.stub_request(:delete, "#{@base_api_url}/routes").
|
400
|
-
with(query: { "incoming_path" => "/foo" }).
|
401
|
-
to_return(status: 404)
|
402
|
-
|
403
|
-
e = nil
|
404
|
-
begin
|
405
|
-
@api.delete_route("/foo")
|
406
|
-
rescue GdsApi::HTTPNotFound => ex
|
407
|
-
e = ex
|
408
|
-
end
|
409
|
-
|
410
|
-
refute_nil e
|
411
|
-
assert_equal 404, e.code
|
412
|
-
|
413
|
-
assert_requested(req)
|
414
|
-
assert_not_requested(@commit_req)
|
415
|
-
end
|
416
|
-
|
417
|
-
it "should escape the params" do
|
418
|
-
# The WebMock query matcher matches unescaped params. The call blows up if they're not escaped
|
419
|
-
|
420
|
-
req = WebMock.stub_request(:delete, "#{@base_api_url}/routes").
|
421
|
-
with(query: { "incoming_path" => "/foo bar" }).
|
422
|
-
to_return(status: 404)
|
423
|
-
|
424
|
-
assert_raises GdsApi::HTTPNotFound do
|
425
|
-
@api.delete_route("/foo bar")
|
426
|
-
end
|
427
|
-
|
428
|
-
assert_requested(req)
|
429
|
-
end
|
430
|
-
end
|
431
|
-
|
432
|
-
describe "committing the routes" do
|
433
|
-
it "should allow committing the routes" do
|
434
|
-
@api.commit_routes
|
435
|
-
|
436
|
-
assert_requested(@commit_req)
|
437
|
-
end
|
438
|
-
|
439
|
-
it "should raise an error if committing the routes fails" do
|
440
|
-
WebMock.stub_request(:post, "#{@base_api_url}/routes/commit").
|
441
|
-
to_return(status: 500, body: "Failed to update all routers")
|
442
|
-
|
443
|
-
e = nil
|
444
|
-
begin
|
445
|
-
@api.commit_routes
|
446
|
-
rescue GdsApi::HTTPErrorResponse => ex
|
447
|
-
e = ex
|
448
|
-
end
|
449
|
-
|
450
|
-
refute_nil e
|
451
|
-
assert_equal 500, e.code
|
452
|
-
assert_equal "URL: #{@base_api_url}/routes/commit\nResponse body:\nFailed to update all routers\n\nRequest body:\n{}", e.message
|
453
|
-
end
|
454
|
-
end
|
455
|
-
end
|
456
|
-
end
|