gds-api-adapters 5.5.0 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gds_api/base.rb +9 -1
- data/lib/gds_api/content_api.rb +5 -6
- data/lib/gds_api/helpers.rb +5 -0
- data/lib/gds_api/json_client.rb +48 -17
- data/lib/gds_api/{content_api/list_response.rb → list_response.rb} +5 -5
- data/lib/gds_api/null_cache.rb +13 -0
- data/lib/gds_api/response.rb +54 -13
- data/lib/gds_api/rummager.rb +12 -33
- data/lib/gds_api/test_helpers/common_responses.rb +36 -0
- data/lib/gds_api/test_helpers/content_api.rb +6 -33
- data/lib/gds_api/test_helpers/json_client_helper.rb +2 -14
- data/lib/gds_api/test_helpers/worldwide.rb +116 -0
- data/lib/gds_api/version.rb +1 -1
- data/lib/gds_api/worldwide.rb +21 -0
- data/test/fixtures/world_organisations_australia.json +490 -0
- data/test/gds_api_base_test.rb +5 -0
- data/test/json_client_test.rb +66 -30
- data/test/list_response_test.rb +179 -0
- data/test/response_test.rb +192 -0
- data/test/rummager_test.rb +8 -32
- data/test/test_helper.rb +2 -0
- data/test/worldwide_api_test.rb +71 -0
- metadata +17 -8
- data/lib/gds_api/content_api/response.rb +0 -56
- data/test/content_api_response_test.rb +0 -97
@@ -0,0 +1,179 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
require 'gds_api/list_response'
|
3
|
+
|
4
|
+
describe GdsApi::ListResponse do
|
5
|
+
|
6
|
+
describe "accessing results" do
|
7
|
+
before :each do
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should allow Enumerable access to the results array" do
|
11
|
+
data = {
|
12
|
+
"results" => [
|
13
|
+
"foo",
|
14
|
+
"bar",
|
15
|
+
"baz",
|
16
|
+
],
|
17
|
+
"total" => 3,
|
18
|
+
"_response_info" => {
|
19
|
+
"status" => "ok",
|
20
|
+
}
|
21
|
+
}
|
22
|
+
response = GdsApi::ListResponse.new(stub(:body => data.to_json), nil)
|
23
|
+
|
24
|
+
assert_equal "foo", response.first
|
25
|
+
assert_equal %w(foo bar baz), response.to_a
|
26
|
+
assert response.any?
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should handle an empty result set" do
|
30
|
+
data = {
|
31
|
+
"results" => [],
|
32
|
+
"total" => 0,
|
33
|
+
"_response_info" => {
|
34
|
+
"status" => "ok",
|
35
|
+
}
|
36
|
+
}
|
37
|
+
response = GdsApi::ListResponse.new(stub(:body => data.to_json), nil)
|
38
|
+
|
39
|
+
assert_equal [], response.to_a
|
40
|
+
assert ! response.any?
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "handling pagination" do
|
45
|
+
before :each do
|
46
|
+
page_1 = {
|
47
|
+
"results" => ["foo1", "bar1"],
|
48
|
+
"total" => 6,
|
49
|
+
"current_page" => 1, "pages" => 3, "page_size" => 2,
|
50
|
+
"_response_info" => {
|
51
|
+
"status" => "ok",
|
52
|
+
"links" => [
|
53
|
+
{"href" => "http://www.example.com/2", "rel" => "next"},
|
54
|
+
{"href" => "http://www.example.com/1", "rel" => "self"},
|
55
|
+
]
|
56
|
+
}
|
57
|
+
}
|
58
|
+
page_2 = {
|
59
|
+
"results" => ["foo2", "bar2"],
|
60
|
+
"total" => 6,
|
61
|
+
"current_page" => 2, "pages" => 3, "page_size" => 2,
|
62
|
+
"_response_info" => {
|
63
|
+
"status" => "ok",
|
64
|
+
"links" => [
|
65
|
+
{"href" => "http://www.example.com/1", "rel" => "previous"},
|
66
|
+
{"href" => "http://www.example.com/3", "rel" => "next"},
|
67
|
+
{"href" => "http://www.example.com/2", "rel" => "self"},
|
68
|
+
]
|
69
|
+
}
|
70
|
+
}
|
71
|
+
page_3 = {
|
72
|
+
"results" => ["foo3", "bar3"],
|
73
|
+
"total" => 6,
|
74
|
+
"current_page" => 3, "pages" => 3, "page_size" => 2,
|
75
|
+
"_response_info" => {
|
76
|
+
"status" => "ok",
|
77
|
+
"links" => [
|
78
|
+
{"href" => "http://www.example.com/2", "rel" => "previous"},
|
79
|
+
{"href" => "http://www.example.com/3", "rel" => "self"},
|
80
|
+
]
|
81
|
+
}
|
82
|
+
}
|
83
|
+
@p1_response = stub(:body => page_1.to_json, :status => 200,
|
84
|
+
:headers => {:link => '<http://www.example.com/1>; rel="self", <http://www.example.com/2>; rel="next"'})
|
85
|
+
@p2_response = stub(:body => page_2.to_json, :status => 200,
|
86
|
+
:headers => {:link => '<http://www.example.com/2>; rel="self", <http://www.example.com/3>; rel="next", <http://www.example.com/1>; rel="previous"'})
|
87
|
+
@p3_response = stub(:body => page_3.to_json, :status => 200,
|
88
|
+
:headers => {:link => '<http://www.example.com/3>; rel="self", <http://www.example.com/1>; rel="previous"'})
|
89
|
+
|
90
|
+
@client = stub()
|
91
|
+
@client.stubs(:get_list!).with("http://www.example.com/1").returns(GdsApi::ListResponse.new(@p1_response, @client))
|
92
|
+
@client.stubs(:get_list!).with("http://www.example.com/2").returns(GdsApi::ListResponse.new(@p2_response, @client))
|
93
|
+
@client.stubs(:get_list!).with("http://www.example.com/3").returns(GdsApi::ListResponse.new(@p3_response, @client))
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "accessing next page" do
|
97
|
+
it "should allow accessing the next page" do
|
98
|
+
resp = GdsApi::ListResponse.new(@p1_response, @client)
|
99
|
+
assert resp.has_next_page?
|
100
|
+
assert_equal %w(foo2 bar2), resp.next_page.results
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should return nil with no next page" do
|
104
|
+
resp = GdsApi::ListResponse.new(@p3_response, @client)
|
105
|
+
assert ! resp.has_next_page?
|
106
|
+
assert_equal nil, resp.next_page
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should memoize the next_page" do
|
110
|
+
resp = GdsApi::ListResponse.new(@p1_response, @client)
|
111
|
+
first_call = resp.next_page
|
112
|
+
|
113
|
+
@client.unstub(:get_list!) # Necessary because of https://github.com/freerange/mocha/issues/44
|
114
|
+
@client.expects(:get_list!).never
|
115
|
+
second_call = resp.next_page
|
116
|
+
assert_equal first_call, second_call
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "accessing previous page" do
|
121
|
+
it "should allow accessing the previous page" do
|
122
|
+
resp = GdsApi::ListResponse.new(@p2_response, @client)
|
123
|
+
assert resp.has_previous_page?
|
124
|
+
assert_equal %w(foo1 bar1), resp.previous_page.results
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should return nil with no previous page" do
|
128
|
+
resp = GdsApi::ListResponse.new(@p1_response, @client)
|
129
|
+
assert ! resp.has_previous_page?
|
130
|
+
assert_equal nil, resp.previous_page
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should memoize the previous_page" do
|
134
|
+
resp = GdsApi::ListResponse.new(@p3_response, @client)
|
135
|
+
first_call = resp.previous_page
|
136
|
+
|
137
|
+
@client.unstub(:get_list!) # Necessary because of https://github.com/freerange/mocha/issues/44
|
138
|
+
@client.expects(:get_list!).never
|
139
|
+
second_call = resp.previous_page
|
140
|
+
assert_equal first_call, second_call
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "accessing content across all pages" do
|
145
|
+
before :each do
|
146
|
+
@response = GdsApi::ListResponse.new(@p1_response, @client)
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should allow iteration across multiple pages" do
|
150
|
+
assert_equal 6, @response.with_subsequent_pages.count
|
151
|
+
assert_equal %w(foo1 bar1 foo2 bar2 foo3 bar3), @response.with_subsequent_pages.to_a
|
152
|
+
assert_equal %w(foo1 foo2 foo3), @response.with_subsequent_pages.select {|s| s =~ /foo/}
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should not load a page multiple times" do
|
156
|
+
@client.unstub(:get_list!) # Necessary because of https://github.com/freerange/mocha/issues/44
|
157
|
+
@client.expects(:get_list!).with("http://www.example.com/2").once.returns(GdsApi::ListResponse.new(@p2_response, @client))
|
158
|
+
@client.expects(:get_list!).with("http://www.example.com/3").once.returns(GdsApi::ListResponse.new(@p3_response, @client))
|
159
|
+
|
160
|
+
3.times do
|
161
|
+
@response.with_subsequent_pages.to_a
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should work with a non-paginated response" do
|
166
|
+
data = {
|
167
|
+
"results" => ["foo1", "bar1"],
|
168
|
+
"total" => 2,
|
169
|
+
"_response_info" => {
|
170
|
+
"status" => "ok",
|
171
|
+
}
|
172
|
+
}
|
173
|
+
response = GdsApi::ListResponse.new(stub(:body => data.to_json, :status => 200, :headers => {}), nil)
|
174
|
+
|
175
|
+
assert_equal %w(foo1 bar1), response.with_subsequent_pages.to_a
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
require 'gds_api/response'
|
3
|
+
|
4
|
+
describe GdsApi::Response do
|
5
|
+
|
6
|
+
describe "accessing HTTP response details" do
|
7
|
+
before :each do
|
8
|
+
@mock_http_response = stub(:body => "A Response body", :code => 200)
|
9
|
+
@response = GdsApi::Response.new(@mock_http_response)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return the raw response body" do
|
13
|
+
assert_equal "A Response body", @response.raw_response_body
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return the status code" do
|
17
|
+
assert_equal 200, @response.code
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "processing web_urls" do
|
22
|
+
def build_response(body_string, relative_to = "https://www.gov.uk")
|
23
|
+
GdsApi::Response.new(stub(:body => body_string), :web_urls_relative_to => relative_to)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should map web URLs" do
|
27
|
+
body = {
|
28
|
+
"web_url" => "https://www.gov.uk/test"
|
29
|
+
}.to_json
|
30
|
+
assert_equal "/test", build_response(body).web_url
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should leave other properties alone" do
|
34
|
+
body = {
|
35
|
+
"title" => "Title",
|
36
|
+
"description" => "Description"
|
37
|
+
}.to_json
|
38
|
+
response = build_response(body)
|
39
|
+
assert_equal "Title", response.title
|
40
|
+
assert_equal "Description", response.description
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should traverse into hashes" do
|
44
|
+
body = {
|
45
|
+
"details" => {
|
46
|
+
"chirality" => "widdershins",
|
47
|
+
"web_url" => "https://www.gov.uk/left",
|
48
|
+
}
|
49
|
+
}.to_json
|
50
|
+
|
51
|
+
response = build_response(body)
|
52
|
+
assert_equal "/left", response.details.web_url
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should traverse into arrays" do
|
56
|
+
body = {
|
57
|
+
"other_urls" => [
|
58
|
+
{ "title" => "Pies", "web_url" => "https://www.gov.uk/pies" },
|
59
|
+
{ "title" => "Cheese", "web_url" => "https://www.gov.uk/cheese" },
|
60
|
+
]
|
61
|
+
}.to_json
|
62
|
+
|
63
|
+
response = build_response(body)
|
64
|
+
assert_equal "/pies", response.other_urls[0].web_url
|
65
|
+
assert_equal "/cheese", response.other_urls[1].web_url
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should handle nil values" do
|
69
|
+
body = {"web_url" => nil}.to_json
|
70
|
+
|
71
|
+
response = build_response(body)
|
72
|
+
assert_nil response.web_url
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should handle query parameters" do
|
76
|
+
body = {
|
77
|
+
"web_url" => "https://www.gov.uk/thing?does=stuff"
|
78
|
+
}.to_json
|
79
|
+
|
80
|
+
response = build_response(body)
|
81
|
+
assert_equal "/thing?does=stuff", response.web_url
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should handle fragments" do
|
85
|
+
body = {
|
86
|
+
"web_url" => "https://www.gov.uk/thing#part-2"
|
87
|
+
}.to_json
|
88
|
+
|
89
|
+
response = build_response(body)
|
90
|
+
assert_equal "/thing#part-2", response.web_url
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should keep URLs from other domains absolute" do
|
94
|
+
body = {
|
95
|
+
"web_url" => "https://www.example.com/example"
|
96
|
+
}.to_json
|
97
|
+
|
98
|
+
response = build_response(body)
|
99
|
+
assert_equal "https://www.example.com/example", response.web_url
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should keep URLs with other schemes absolute" do
|
103
|
+
body = {
|
104
|
+
"web_url" => "http://www.example.com/example"
|
105
|
+
}.to_json
|
106
|
+
|
107
|
+
response = build_response(body)
|
108
|
+
assert_equal "http://www.example.com/example", response.web_url
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "hash and openstruct access" do
|
113
|
+
before :each do
|
114
|
+
@response_data = {
|
115
|
+
"_response_info" => {
|
116
|
+
"status" => "ok"
|
117
|
+
},
|
118
|
+
"id" => "https://www.gov.uk/api/vat-rates.json",
|
119
|
+
"web_url" => "https://www.gov.uk/vat-rates",
|
120
|
+
"title" => "VAT rates",
|
121
|
+
"format" => "answer",
|
122
|
+
"updated_at" => "2013-04-04T15:51:54+01:00",
|
123
|
+
"details" => {
|
124
|
+
"need_id" => "1870",
|
125
|
+
"business_proposition" => false,
|
126
|
+
"description" => "Current VAT rates - standard 20% and rates for reduced rate and zero-rated items",
|
127
|
+
"language" => "en",
|
128
|
+
},
|
129
|
+
"tags" => [
|
130
|
+
{"slug" => "foo"},
|
131
|
+
{"slug" => "bar"},
|
132
|
+
{"slug" => "baz"},
|
133
|
+
],
|
134
|
+
}
|
135
|
+
@response = GdsApi::Response.new(stub(:body => @response_data.to_json))
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "behaving like a read-only hash" do
|
139
|
+
it "should allow accessing members by key" do
|
140
|
+
assert_equal "VAT rates", @response["title"]
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should allow accessing nested keys" do
|
144
|
+
assert_equal "1870", @response["details"]["need_id"]
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should return nil for a non-existent key" do
|
148
|
+
assert_equal nil, @response["foo"]
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should memoize the parsed hash" do
|
152
|
+
@response["id"]
|
153
|
+
JSON.expects(:parse).never
|
154
|
+
assert_equal "VAT rates", @response["title"]
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "behaving like a read-only openstruct" do
|
159
|
+
it "should allow accessing members using methods" do
|
160
|
+
assert_equal "VAT rates", @response.title
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should allow accessing nested values" do
|
164
|
+
assert_equal "1870", @response.details.need_id
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should allow accessing values nested within arrays" do
|
168
|
+
assert_equal "bar", @response.tags[1].slug
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should return nil for a non-existent key" do
|
172
|
+
assert_equal nil, @response.foo
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should memoize the generated openstruct" do
|
176
|
+
@response.id
|
177
|
+
GdsApi::Response.expects(:build_ostruct_recursively).never
|
178
|
+
assert_equal "VAT rates", @response.title
|
179
|
+
end
|
180
|
+
|
181
|
+
describe "handling respond_to?" do
|
182
|
+
it "should respond_to methods for keys that exist" do
|
183
|
+
assert @response.respond_to?(:title)
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should not respond_to keys that don't exist" do
|
187
|
+
assert ! @response.respond_to?(:foo)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
data/test/rummager_test.rb
CHANGED
@@ -8,27 +8,23 @@ describe GdsApi::Rummager do
|
|
8
8
|
stub_request(:get, /example.com\/advanced_search/).to_return(body: "[]")
|
9
9
|
end
|
10
10
|
|
11
|
-
it "should raise an exception if the search service uri is not set" do
|
12
|
-
assert_raises(GdsApi::Rummager::SearchUriNotSpecified) { GdsApi::Rummager.new(nil) }
|
13
|
-
end
|
14
|
-
|
15
11
|
it "should raise an exception if the service at the search URI returns a 500" do
|
16
12
|
stub_request(:get, /example.com\/search/).to_return(status: [500, "Internal Server Error"])
|
17
|
-
assert_raises(GdsApi::
|
13
|
+
assert_raises(GdsApi::HTTPErrorResponse) do
|
18
14
|
GdsApi::Rummager.new("http://example.com").search("query")
|
19
15
|
end
|
20
16
|
end
|
21
17
|
|
22
18
|
it "should raise an exception if the service at the search URI returns a 404" do
|
23
19
|
stub_request(:get, /example.com\/search/).to_return(status: [404, "Not Found"])
|
24
|
-
assert_raises(GdsApi::
|
20
|
+
assert_raises(GdsApi::HTTPNotFound) do
|
25
21
|
GdsApi::Rummager.new("http://example.com").search("query")
|
26
22
|
end
|
27
23
|
end
|
28
24
|
|
29
25
|
it "should raise an exception if the service at the search URI times out" do
|
30
26
|
stub_request(:get, /example.com\/search/).to_timeout
|
31
|
-
assert_raises(GdsApi::
|
27
|
+
assert_raises(GdsApi::TimedOutException) do
|
32
28
|
GdsApi::Rummager.new("http://example.com").search("query")
|
33
29
|
end
|
34
30
|
end
|
@@ -38,7 +34,7 @@ describe GdsApi::Rummager do
|
|
38
34
|
stub_request(:get, /example.com\/search/).to_return(body: search_results.to_json)
|
39
35
|
results = GdsApi::Rummager.new("http://example.com").search("query")
|
40
36
|
|
41
|
-
assert_equal search_results, results
|
37
|
+
assert_equal search_results, results.to_hash
|
42
38
|
end
|
43
39
|
|
44
40
|
it "should return an empty set of results without making request if query is empty" do
|
@@ -73,26 +69,6 @@ describe GdsApi::Rummager do
|
|
73
69
|
assert_requested :get, /format_filter=specialist_guidance/
|
74
70
|
end
|
75
71
|
|
76
|
-
it "should not tell the http client to use ssl if we're connecting to an http host" do
|
77
|
-
response = stub('response', code: '200', body: '[]')
|
78
|
-
http = stub('http', get: response)
|
79
|
-
Net::HTTP.stubs(:new).returns(http)
|
80
|
-
|
81
|
-
http.expects(:use_ssl=).never
|
82
|
-
|
83
|
-
client = GdsApi::Rummager.new("http://example.com").search "search-term"
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should tell the http client to use ssl if we're connecting to an https host" do
|
87
|
-
response = stub('response', code: '200', body: '[]')
|
88
|
-
http = stub('http', get: response)
|
89
|
-
Net::HTTP.stubs(:new).returns(http)
|
90
|
-
|
91
|
-
http.expects(:use_ssl=).with(true)
|
92
|
-
|
93
|
-
client = GdsApi::Rummager.new("https://example.com").search "search-term"
|
94
|
-
end
|
95
|
-
|
96
72
|
it "should add a format filter parameter to autocomplete if provided" do
|
97
73
|
GdsApi::Rummager.new("http://example.com").autocomplete "search-term", "specialist_guidance"
|
98
74
|
|
@@ -118,21 +94,21 @@ describe GdsApi::Rummager do
|
|
118
94
|
|
119
95
|
it "#advanced_search should raise an exception if the service at the search URI returns a 500" do
|
120
96
|
stub_request(:get, /example.com\/advanced_search/).to_return(status: [500, "Internal Server Error"])
|
121
|
-
assert_raises(GdsApi::
|
97
|
+
assert_raises(GdsApi::HTTPErrorResponse) do
|
122
98
|
GdsApi::Rummager.new("http://example.com").advanced_search({keywords: "query"})
|
123
99
|
end
|
124
100
|
end
|
125
101
|
|
126
102
|
it "#advanced_search should raise an exception if the service at the search URI returns a 404" do
|
127
103
|
stub_request(:get, /example.com\/advanced_search/).to_return(status: [404, "Not Found"])
|
128
|
-
assert_raises(GdsApi::
|
104
|
+
assert_raises(GdsApi::HTTPNotFound) do
|
129
105
|
GdsApi::Rummager.new("http://example.com").advanced_search({keywords: "query"})
|
130
106
|
end
|
131
107
|
end
|
132
108
|
|
133
109
|
it "#advanced_search should raise an exception if the service at the search URI times out" do
|
134
110
|
stub_request(:get, /example.com\/advanced_search/).to_timeout
|
135
|
-
assert_raises(GdsApi::
|
111
|
+
assert_raises(GdsApi::TimedOutException) do
|
136
112
|
GdsApi::Rummager.new("http://example.com").advanced_search({keywords: "query"})
|
137
113
|
end
|
138
114
|
end
|
@@ -142,7 +118,7 @@ describe GdsApi::Rummager do
|
|
142
118
|
stub_request(:get, /example.com\/advanced_search/).to_return(body: search_results.to_json)
|
143
119
|
results = GdsApi::Rummager.new("http://example.com").advanced_search({keywords: "query"})
|
144
120
|
|
145
|
-
assert_equal search_results, results
|
121
|
+
assert_equal search_results, results.to_hash
|
146
122
|
end
|
147
123
|
|
148
124
|
it "#advanced_search should return an empty set of results without making request if arguments are empty" do
|
data/test/test_helper.rb
CHANGED
@@ -0,0 +1,71 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
require 'gds_api/worldwide'
|
3
|
+
require 'gds_api/test_helpers/worldwide'
|
4
|
+
|
5
|
+
describe GdsApi::Worldwide do
|
6
|
+
include GdsApi::TestHelpers::Worldwide
|
7
|
+
|
8
|
+
before do
|
9
|
+
@base_api_url = GdsApi::TestHelpers::Worldwide::WORLDWIDE_API_ENDPOINT
|
10
|
+
@api = GdsApi::Worldwide.new(@base_api_url)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "fetching list of world locations" do
|
14
|
+
it "should get the world locations" do
|
15
|
+
country_slugs = %w(the-shire rivendel rohan lorien gondor arnor mordor)
|
16
|
+
worldwide_api_has_locations(country_slugs)
|
17
|
+
|
18
|
+
response = @api.world_locations
|
19
|
+
assert_equal country_slugs, response.map {|r| r.details.slug }
|
20
|
+
assert_equal "Rohan", response.results[2].title
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should handle the pagination" do
|
24
|
+
country_slugs = (1..50).map {|n| "country-#{n}" }
|
25
|
+
worldwide_api_has_locations(country_slugs)
|
26
|
+
|
27
|
+
response = @api.world_locations
|
28
|
+
assert_equal country_slugs, response.with_subsequent_pages.map {|r| r.details.slug }
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should raise error if endpoint 404s" do
|
32
|
+
stub_request(:get, "#{@base_api_url}/api/world-locations").to_return(:status => 404)
|
33
|
+
assert_raises GdsApi::HTTPNotFound do
|
34
|
+
@api.world_locations
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "fetching a world location" do
|
40
|
+
it "should return the details" do
|
41
|
+
worldwide_api_has_location('rohan')
|
42
|
+
|
43
|
+
response = @api.world_location('rohan')
|
44
|
+
assert_equal 'Rohan', response.title
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should return nil for a non-existent location" do
|
48
|
+
worldwide_api_does_not_have_location('non-existent')
|
49
|
+
|
50
|
+
assert_nil @api.world_location('non-existent')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "fetching organisations for a location" do
|
55
|
+
it "should return the organisation details" do
|
56
|
+
details = JSON.parse(load_fixture_file("world_organisations_australia.json").read)
|
57
|
+
worldwide_api_has_organisations_for_location('australia', details)
|
58
|
+
|
59
|
+
response = @api.organisations_for_world_location('australia')
|
60
|
+
assert response.is_a?(GdsApi::ListResponse)
|
61
|
+
assert_equal ["UK Trade & Investment Australia", "British High Commission Canberra"], response.map(&:title)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should raise error on 404" do
|
65
|
+
stub_request(:get, "#{@base_api_url}/api/world-locations/non-existent/organisations").to_return(:status => 404)
|
66
|
+
assert_raises GdsApi::HTTPNotFound do
|
67
|
+
@api.organisations_for_world_location('non-existent')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: gds-api-adapters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version:
|
5
|
+
version: 6.0.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James Stewart
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2013-04-
|
13
|
+
date: 2013-04-25 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: plek
|
@@ -191,6 +191,7 @@ files:
|
|
191
191
|
- lib/gds_api/base.rb
|
192
192
|
- lib/gds_api/gov_uk_delivery.rb
|
193
193
|
- lib/gds_api/licence_application.rb
|
194
|
+
- lib/gds_api/null_cache.rb
|
194
195
|
- lib/gds_api/panopticon/registerer.rb
|
195
196
|
- lib/gds_api/needotron.rb
|
196
197
|
- lib/gds_api/imminence.rb
|
@@ -198,14 +199,14 @@ files:
|
|
198
199
|
- lib/gds_api/content_api.rb
|
199
200
|
- lib/gds_api/mapit.rb
|
200
201
|
- lib/gds_api/exceptions.rb
|
202
|
+
- lib/gds_api/list_response.rb
|
201
203
|
- lib/gds_api/json_client.rb
|
202
204
|
- lib/gds_api/core-ext/openstruct.rb
|
203
205
|
- lib/gds_api/response.rb
|
204
|
-
- lib/gds_api/content_api/list_response.rb
|
205
|
-
- lib/gds_api/content_api/response.rb
|
206
206
|
- lib/gds_api/publisher.rb
|
207
207
|
- lib/gds_api/test_helpers/gov_uk_delivery.rb
|
208
208
|
- lib/gds_api/test_helpers/licence_application.rb
|
209
|
+
- lib/gds_api/test_helpers/common_responses.rb
|
209
210
|
- lib/gds_api/test_helpers/imminence.rb
|
210
211
|
- lib/gds_api/test_helpers/content_api.rb
|
211
212
|
- lib/gds_api/test_helpers/mapit.rb
|
@@ -214,15 +215,16 @@ files:
|
|
214
215
|
- lib/gds_api/test_helpers/asset_manager.rb
|
215
216
|
- lib/gds_api/test_helpers/panopticon.rb
|
216
217
|
- lib/gds_api/test_helpers/json_client_helper.rb
|
218
|
+
- lib/gds_api/test_helpers/worldwide.rb
|
217
219
|
- lib/gds_api/part_methods.rb
|
218
220
|
- lib/gds_api/asset_manager.rb
|
219
221
|
- lib/gds_api/panopticon.rb
|
222
|
+
- lib/gds_api/worldwide.rb
|
220
223
|
- lib/gds_api/helpers.rb
|
221
224
|
- README.md
|
222
225
|
- Rakefile
|
223
226
|
- test/rummager_test.rb
|
224
227
|
- test/publisher_api_test.rb
|
225
|
-
- test/content_api_response_test.rb
|
226
228
|
- test/licence_application_api_test.rb
|
227
229
|
- test/mapit_test.rb
|
228
230
|
- test/gov_uk_delivery_test.rb
|
@@ -230,7 +232,11 @@ files:
|
|
230
232
|
- test/imminence_api_test.rb
|
231
233
|
- test/json_client_test.rb
|
232
234
|
- test/test_helper.rb
|
235
|
+
- test/list_response_test.rb
|
236
|
+
- test/worldwide_api_test.rb
|
237
|
+
- test/fixtures/world_organisations_australia.json
|
233
238
|
- test/fixtures/hello.txt
|
239
|
+
- test/response_test.rb
|
234
240
|
- test/asset_manager_test.rb
|
235
241
|
- test/gds_api_base_test.rb
|
236
242
|
- test/content_api_test.rb
|
@@ -248,7 +254,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
248
254
|
requirements:
|
249
255
|
- - ">="
|
250
256
|
- !ruby/object:Gem::Version
|
251
|
-
hash:
|
257
|
+
hash: -4292266406700187648
|
252
258
|
segments:
|
253
259
|
- 0
|
254
260
|
version: "0"
|
@@ -257,7 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
257
263
|
requirements:
|
258
264
|
- - ">="
|
259
265
|
- !ruby/object:Gem::Version
|
260
|
-
hash:
|
266
|
+
hash: -4292266406700187648
|
261
267
|
segments:
|
262
268
|
- 0
|
263
269
|
version: "0"
|
@@ -271,7 +277,6 @@ summary: Adapters to work with GDS APIs
|
|
271
277
|
test_files:
|
272
278
|
- test/rummager_test.rb
|
273
279
|
- test/publisher_api_test.rb
|
274
|
-
- test/content_api_response_test.rb
|
275
280
|
- test/licence_application_api_test.rb
|
276
281
|
- test/mapit_test.rb
|
277
282
|
- test/gov_uk_delivery_test.rb
|
@@ -279,7 +284,11 @@ test_files:
|
|
279
284
|
- test/imminence_api_test.rb
|
280
285
|
- test/json_client_test.rb
|
281
286
|
- test/test_helper.rb
|
287
|
+
- test/list_response_test.rb
|
288
|
+
- test/worldwide_api_test.rb
|
289
|
+
- test/fixtures/world_organisations_australia.json
|
282
290
|
- test/fixtures/hello.txt
|
291
|
+
- test/response_test.rb
|
283
292
|
- test/asset_manager_test.rb
|
284
293
|
- test/gds_api_base_test.rb
|
285
294
|
- test/content_api_test.rb
|