gds-api-adapters 38.1.0 → 39.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/test_helper.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
# Ensure that in tests, we get a consistent domain back from Plek < 1.0.0
|
2
|
-
# Without this, content API tests re chunking of requests with long URLs would
|
3
|
-
# pass/fail in dev/CI.
|
4
|
-
ENV['RACK_ENV'] = "test"
|
5
|
-
|
6
|
-
require 'bundler'
|
7
|
-
Bundler.setup :default, :development, :test
|
8
|
-
|
9
|
-
require 'minitest/autorun'
|
10
|
-
require 'rack/utils'
|
11
|
-
require 'rack/test'
|
12
|
-
require 'simplecov'
|
13
|
-
require 'simplecov-rcov'
|
14
|
-
require 'mocha/mini_test'
|
15
|
-
require 'timecop'
|
16
|
-
require 'gds-api-adapters'
|
17
|
-
|
18
|
-
SimpleCov.start do
|
19
|
-
add_filter "/test/"
|
20
|
-
add_group "Test Helpers", "lib/gds_api/test_helpers"
|
21
|
-
formatter SimpleCov::Formatter::RcovFormatter
|
22
|
-
end
|
23
|
-
|
24
|
-
class Minitest::Test
|
25
|
-
def teardown
|
26
|
-
Timecop.return
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
require 'pact/consumer/minitest'
|
31
|
-
module PactTest
|
32
|
-
include Pact::Consumer::Minitest
|
33
|
-
|
34
|
-
def before_suite
|
35
|
-
# Pact does its own stubbing of network connections, so we want to
|
36
|
-
# prevent WebMock interfering when pact is being used.
|
37
|
-
::WebMock.allow_net_connect!
|
38
|
-
super
|
39
|
-
end
|
40
|
-
|
41
|
-
def after_suite
|
42
|
-
super
|
43
|
-
::WebMock.disable_net_connect!
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def load_fixture_file(filename)
|
48
|
-
File.open(File.join(File.dirname(__FILE__), "fixtures", filename), encoding: 'utf-8')
|
49
|
-
end
|
50
|
-
|
51
|
-
require 'webmock/minitest'
|
52
|
-
WebMock.disable_net_connect!
|
53
|
-
|
54
|
-
require 'gds_api/test_helpers/json_client_helper'
|
55
|
-
require 'test_helpers/pact_helper'
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'gds_api/email_alert_api'
|
3
|
-
require 'gds_api/test_helpers/email_alert_api'
|
4
|
-
|
5
|
-
describe GdsApi::TestHelpers::EmailAlertApi do
|
6
|
-
include GdsApi::TestHelpers::EmailAlertApi
|
7
|
-
|
8
|
-
let(:base_api_url) { Plek.current.find("email-alert-api") }
|
9
|
-
let(:email_alert_api) { GdsApi::EmailAlertApi.new(base_api_url) }
|
10
|
-
|
11
|
-
describe "#assert_email_alert_sent" do
|
12
|
-
before { stub_any_email_alert_api_call }
|
13
|
-
|
14
|
-
it "matches a post request with any empty attributes by default" do
|
15
|
-
email_alert_api.send_alert("foo" => "bar")
|
16
|
-
assert_email_alert_sent
|
17
|
-
end
|
18
|
-
|
19
|
-
it "matches a post request subset of attributes" do
|
20
|
-
email_alert_api.send_alert("foo" => "bar", "baz" => "qux")
|
21
|
-
assert_email_alert_sent("foo" => "bar")
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
PUBLISHING_API_PORT = 3001
|
2
|
-
|
3
|
-
def publishing_api_host
|
4
|
-
"http://localhost:#{PUBLISHING_API_PORT}"
|
5
|
-
end
|
6
|
-
|
7
|
-
Pact.service_consumer "GDS API Adapters" do
|
8
|
-
has_pact_with "Publishing API" do
|
9
|
-
mock_service :publishing_api do
|
10
|
-
port PUBLISHING_API_PORT
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'gds_api/panopticon'
|
3
|
-
require 'gds_api/test_helpers/panopticon'
|
4
|
-
|
5
|
-
describe GdsApi::TestHelpers::Panopticon do
|
6
|
-
include GdsApi::TestHelpers::Panopticon
|
7
|
-
|
8
|
-
def assert_stub_exists(*args)
|
9
|
-
expected_signature = WebMock::RequestSignature.new(*args)
|
10
|
-
|
11
|
-
assert(
|
12
|
-
WebMock::StubRegistry.instance.registered_request?(expected_signature),
|
13
|
-
"Stub is not registered:\n\t#{expected_signature}"
|
14
|
-
)
|
15
|
-
end
|
16
|
-
|
17
|
-
let(:base_api_endpoint) { GdsApi::TestHelpers::Panopticon::PANOPTICON_ENDPOINT }
|
18
|
-
|
19
|
-
it 'stubs the tag creation request' do
|
20
|
-
atts = { tag_id: 'foo' }
|
21
|
-
stub_panopticon_tag_creation(atts)
|
22
|
-
|
23
|
-
assert_stub_exists(:post, "#{base_api_endpoint}/tags.json", body: atts.to_json)
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'stubs the tag update request' do
|
27
|
-
atts = { title: 'Foo' }
|
28
|
-
stub_panopticon_tag_update('section', 'foo/bar', atts)
|
29
|
-
|
30
|
-
assert_stub_exists(:put,
|
31
|
-
"#{base_api_endpoint}/tags/section/foo/bar.json",
|
32
|
-
body: atts.to_json
|
33
|
-
)
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'stubs the tag publish request' do
|
37
|
-
stub_panopticon_tag_publish('section', 'foo/bar')
|
38
|
-
|
39
|
-
assert_stub_exists(:post,
|
40
|
-
"#{base_api_endpoint}/tags/section/foo/bar/publish.json",
|
41
|
-
body: {}.to_json
|
42
|
-
)
|
43
|
-
end
|
44
|
-
end
|
@@ -1,129 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'gds_api/publishing_api'
|
3
|
-
require 'gds_api/test_helpers/publishing_api'
|
4
|
-
|
5
|
-
describe GdsApi::TestHelpers::PublishingApi do
|
6
|
-
include GdsApi::TestHelpers::PublishingApi
|
7
|
-
let(:base_api_url) { Plek.current.find("publishing-api") }
|
8
|
-
let(:publishing_api) { GdsApi::PublishingApi.new(base_api_url) }
|
9
|
-
|
10
|
-
describe '#request_json_matching predicate' do
|
11
|
-
describe "nested required attribute" do
|
12
|
-
let(:matcher) { request_json_matching("a" => { "b" => 1 }) }
|
13
|
-
|
14
|
-
it "matches a body with exact same nested hash strucure" do
|
15
|
-
assert matcher.call(stub("request", body: '{"a": {"b": 1}}'))
|
16
|
-
end
|
17
|
-
|
18
|
-
it "matches a body with exact same nested hash strucure and an extra attribute at the top level" do
|
19
|
-
assert matcher.call(stub("request", body: '{"a": {"b": 1}, "c": 3}'))
|
20
|
-
end
|
21
|
-
|
22
|
-
it "does not match a body where the inner hash has the required attribute and an extra one" do
|
23
|
-
refute matcher.call(stub("request", body: '{"a": {"b": 1, "c": 2}}'))
|
24
|
-
end
|
25
|
-
|
26
|
-
it "does not match a body where the inner hash has the required attribute with the wrong value" do
|
27
|
-
refute matcher.call(stub("request", body: '{"a": {"b": 0}}'))
|
28
|
-
end
|
29
|
-
|
30
|
-
it "does not match a body where the inner hash lacks the required attribute" do
|
31
|
-
refute matcher.call(stub("request", body: '{"a": {"c": 1}}'))
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "hash to match uses symbol keys" do
|
36
|
-
let(:matcher) { request_json_matching(a: 1) }
|
37
|
-
|
38
|
-
it "matches a json body" do
|
39
|
-
assert matcher.call(stub("request", body: '{"a": 1}'))
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe '#request_json_including predicate' do
|
45
|
-
describe "no required attributes" do
|
46
|
-
let(:matcher) { request_json_including({}) }
|
47
|
-
|
48
|
-
it "matches an empty body" do
|
49
|
-
assert matcher.call(stub("request", body: "{}"))
|
50
|
-
end
|
51
|
-
|
52
|
-
it "matches a body with some attributes" do
|
53
|
-
assert matcher.call(stub("request", body: '{"a": 1}'))
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe "one required attribute" do
|
58
|
-
let(:matcher) { request_json_including("a" => 1) }
|
59
|
-
|
60
|
-
it "does not match an empty body" do
|
61
|
-
refute matcher.call(stub("request", body: "{}"))
|
62
|
-
end
|
63
|
-
|
64
|
-
it "does not match a body with the required attribute if the value is different" do
|
65
|
-
refute matcher.call(stub("request", body: '{"a": 2}'))
|
66
|
-
end
|
67
|
-
|
68
|
-
it "matches a body with the required attribute and value" do
|
69
|
-
assert matcher.call(stub("request", body: '{"a": 1}'))
|
70
|
-
end
|
71
|
-
|
72
|
-
it "matches a body with the required attribute and value and extra attributes" do
|
73
|
-
assert matcher.call(stub("request", body: '{"a": 1, "b": 2}'))
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe "nested required attribute" do
|
78
|
-
let(:matcher) { request_json_including("a" => { "b" => 1 }) }
|
79
|
-
|
80
|
-
it "matches a body with exact same nested hash strucure" do
|
81
|
-
assert matcher.call(stub("request", body: '{"a": {"b": 1}}'))
|
82
|
-
end
|
83
|
-
|
84
|
-
it "matches a body where the inner hash has the required attribute and an extra one" do
|
85
|
-
assert matcher.call(stub("request", body: '{"a": {"b": 1, "c": 2}}'))
|
86
|
-
end
|
87
|
-
|
88
|
-
it "does not match a body where the inner hash has the required attribute with the wrong value" do
|
89
|
-
refute matcher.call(stub("request", body: '{"a": {"b": 0}}'))
|
90
|
-
end
|
91
|
-
|
92
|
-
it "does not match a body where the inner hash lacks the required attribute" do
|
93
|
-
refute matcher.call(stub("request", body: '{"a": {"c": 1}}'))
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
describe "hash to match uses symbol keys" do
|
98
|
-
let(:matcher) { request_json_including(a: { b: 1 }) }
|
99
|
-
|
100
|
-
it "matches a json body" do
|
101
|
-
assert matcher.call(stub("request", body: '{"a": {"b": 1}}'))
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
describe "nested arrays" do
|
106
|
-
let(:matcher) { request_json_including("a" => [1]) }
|
107
|
-
|
108
|
-
it "matches a body with exact same inner array" do
|
109
|
-
assert matcher.call(stub("request", body: '{"a": [1]}'))
|
110
|
-
end
|
111
|
-
|
112
|
-
it "does not match a body with an array with extra elements" do
|
113
|
-
refute matcher.call(stub("request", body: '{"a": [1, 2]}'))
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe "hashes in nested arrays" do
|
118
|
-
let(:matcher) { request_json_including("a" => [{ "b" => 1 }, 2]) }
|
119
|
-
|
120
|
-
it "matches a body with exact same inner array" do
|
121
|
-
assert matcher.call(stub("request", body: '{"a": [{"b": 1}, 2]}'))
|
122
|
-
end
|
123
|
-
|
124
|
-
it "matches a body with an inner hash with extra elements" do
|
125
|
-
assert matcher.call(stub("request", body: '{"a": [{"b": 1, "c": 3}, 2]}'))
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
@@ -1,170 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'gds_api/publishing_api_v2'
|
3
|
-
require 'gds_api/test_helpers/publishing_api_v2'
|
4
|
-
|
5
|
-
describe GdsApi::TestHelpers::PublishingApiV2 do
|
6
|
-
include GdsApi::TestHelpers::PublishingApiV2
|
7
|
-
let(:publishing_api) { GdsApi::PublishingApiV2.new(Plek.current.find("publishing-api")) }
|
8
|
-
|
9
|
-
describe '#publishing_api_has_linked_items' do
|
10
|
-
it "stubs the get linked items api call" do
|
11
|
-
links = [
|
12
|
-
{ 'content_id' => 'id-1', 'title' => 'title 1', 'link_type' => 'taxons' },
|
13
|
-
{ 'content_id' => 'id-2', 'title' => 'title 2', 'link_type' => 'taxons' },
|
14
|
-
]
|
15
|
-
publishing_api_has_linked_items(
|
16
|
-
links,
|
17
|
-
content_id: 'content-id',
|
18
|
-
link_type: 'taxons',
|
19
|
-
fields: [:title]
|
20
|
-
)
|
21
|
-
|
22
|
-
api_response = publishing_api.get_linked_items(
|
23
|
-
'content-id',
|
24
|
-
link_type: 'taxons',
|
25
|
-
fields: [:title]
|
26
|
-
)
|
27
|
-
|
28
|
-
assert_equal(
|
29
|
-
api_response.to_hash,
|
30
|
-
links
|
31
|
-
)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "#publishing_api_has_lookups" do
|
36
|
-
it "stubs the lookup for content items" do
|
37
|
-
lookup_hash = { "/foo" => "2878337b-bed9-4e7f-85b6-10ed2cbcd504" }
|
38
|
-
|
39
|
-
publishing_api_has_lookups(lookup_hash)
|
40
|
-
|
41
|
-
assert_equal publishing_api.lookup_content_ids(base_paths: ["/foo"]), lookup_hash
|
42
|
-
assert_equal publishing_api.lookup_content_id(base_path: "/foo"), "2878337b-bed9-4e7f-85b6-10ed2cbcd504"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "#publishing_api_has_content" do
|
47
|
-
it "stubs the call to get content items" do
|
48
|
-
publishing_api_has_content([{ "content_id" => "2878337b-bed9-4e7f-85b6-10ed2cbcd504" }])
|
49
|
-
|
50
|
-
response = publishing_api.get_content_items({})['results']
|
51
|
-
|
52
|
-
assert_equal([{ "content_id" => "2878337b-bed9-4e7f-85b6-10ed2cbcd504" }], response)
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'allows params' do
|
56
|
-
publishing_api_has_content(
|
57
|
-
[{
|
58
|
-
"content_id" => "2878337b-bed9-4e7f-85b6-10ed2cbcd504"
|
59
|
-
}],
|
60
|
-
document_type: 'document_collection',
|
61
|
-
query: 'query',
|
62
|
-
)
|
63
|
-
|
64
|
-
response = publishing_api.get_content_items(
|
65
|
-
document_type: 'document_collection',
|
66
|
-
query: 'query'
|
67
|
-
)['results']
|
68
|
-
|
69
|
-
assert_equal(
|
70
|
-
[{ "content_id" => "2878337b-bed9-4e7f-85b6-10ed2cbcd504" }],
|
71
|
-
response
|
72
|
-
)
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'returns paginated results' do
|
76
|
-
content_id_1 = "2878337b-bed9-4e7f-85b6-10ed2cbcd504"
|
77
|
-
content_id_2 = "2878337b-bed9-4e7f-85b6-10ed2cbcd505"
|
78
|
-
content_id_3 = "2878337b-bed9-4e7f-85b6-10ed2cbcd506"
|
79
|
-
|
80
|
-
publishing_api_has_content(
|
81
|
-
[
|
82
|
-
{ "content_id" => content_id_1 },
|
83
|
-
{ "content_id" => content_id_2 },
|
84
|
-
{ "content_id" => content_id_3 },
|
85
|
-
],
|
86
|
-
page: 1,
|
87
|
-
per_page: 2
|
88
|
-
)
|
89
|
-
|
90
|
-
response = publishing_api.get_content_items(page: 1, per_page: 2)
|
91
|
-
records = response['results']
|
92
|
-
|
93
|
-
assert_equal(response['total'], 3)
|
94
|
-
assert_equal(response['pages'], 2)
|
95
|
-
assert_equal(response['current_page'], 1)
|
96
|
-
|
97
|
-
assert_equal(records.length, 2)
|
98
|
-
assert_equal(records.first['content_id'], content_id_1)
|
99
|
-
assert_equal(records.last['content_id'], content_id_2)
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'returns an empty list of results for out-of-bound queries' do
|
103
|
-
content_id_1 = "2878337b-bed9-4e7f-85b6-10ed2cbcd504"
|
104
|
-
content_id_2 = "2878337b-bed9-4e7f-85b6-10ed2cbcd505"
|
105
|
-
|
106
|
-
publishing_api_has_content(
|
107
|
-
[
|
108
|
-
{ "content_id" => content_id_1 },
|
109
|
-
{ "content_id" => content_id_2 },
|
110
|
-
],
|
111
|
-
page: 10,
|
112
|
-
per_page: 2
|
113
|
-
)
|
114
|
-
|
115
|
-
response = publishing_api.get_content_items(page: 10, per_page: 2)
|
116
|
-
records = response['results']
|
117
|
-
|
118
|
-
assert_equal(records, [])
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
describe "#publishing_api_has_expanded_links" do
|
123
|
-
it "stubs the call to get expanded links" do
|
124
|
-
payload = {
|
125
|
-
content_id: "2e20294a-d694-4083-985e-d8bedefc2354",
|
126
|
-
organisations: [
|
127
|
-
{
|
128
|
-
content_id: ["a8a09822-1729-48a7-8a68-d08300de9d1e"]
|
129
|
-
}
|
130
|
-
]
|
131
|
-
}
|
132
|
-
|
133
|
-
publishing_api_has_expanded_links(payload)
|
134
|
-
response = publishing_api.get_expanded_links("2e20294a-d694-4083-985e-d8bedefc2354")
|
135
|
-
|
136
|
-
assert_equal({
|
137
|
-
"content_id" => "2e20294a-d694-4083-985e-d8bedefc2354",
|
138
|
-
"organisations" => [
|
139
|
-
{
|
140
|
-
"content_id" => ["a8a09822-1729-48a7-8a68-d08300de9d1e"]
|
141
|
-
}
|
142
|
-
]
|
143
|
-
}, response.to_h)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
describe "stub_any_publishing_api_publish" do
|
148
|
-
it "stubs any publish request to the publishing api" do
|
149
|
-
stub_any_publishing_api_publish
|
150
|
-
publishing_api.publish("some-content-id", "major")
|
151
|
-
assert_publishing_api_publish("some-content-id")
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
describe "stub_any_publishing_api_unpublish" do
|
156
|
-
it "stubs any unpublish request to the publishing api" do
|
157
|
-
stub_any_publishing_api_unpublish
|
158
|
-
publishing_api.unpublish("some-content-id", type: :gone)
|
159
|
-
assert_publishing_api_unpublish("some-content-id")
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
describe "stub_any_publishing_api_discard_draft" do
|
164
|
-
it "stubs any discard draft request to the publishing api" do
|
165
|
-
stub_any_publishing_api_discard_draft
|
166
|
-
publishing_api.discard_draft("some-content-id")
|
167
|
-
assert_publishing_api_discard_draft("some-content-id")
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
data/test/worldwide_api_test.rb
DELETED
@@ -1,82 +0,0 @@
|
|
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(
|
29
|
-
country_slugs,
|
30
|
-
response.with_subsequent_pages.map { |r| r['details']['slug'] }
|
31
|
-
)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should raise error if endpoint 404s" do
|
35
|
-
stub_request(:get, "#{@base_api_url}/api/world-locations").to_return(status: 404)
|
36
|
-
assert_raises GdsApi::HTTPNotFound do
|
37
|
-
@api.world_locations
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "fetching a world location" do
|
43
|
-
it "should return the details" do
|
44
|
-
worldwide_api_has_location('rohan')
|
45
|
-
|
46
|
-
response = @api.world_location('rohan')
|
47
|
-
assert_equal 'Rohan', response['title']
|
48
|
-
end
|
49
|
-
|
50
|
-
it "raises for a non-existent location" do
|
51
|
-
worldwide_api_does_not_have_location('non-existent')
|
52
|
-
|
53
|
-
assert_raises(GdsApi::HTTPNotFound) do
|
54
|
-
@api.world_location('non-existent')
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "fetching organisations for a location" do
|
60
|
-
it "should return the organisation details" do
|
61
|
-
details = JSON.parse(load_fixture_file("world_organisations_australia.json").read)
|
62
|
-
worldwide_api_has_organisations_for_location('australia', details)
|
63
|
-
|
64
|
-
response = @api.organisations_for_world_location('australia')
|
65
|
-
assert response.is_a?(GdsApi::ListResponse)
|
66
|
-
assert_equal(
|
67
|
-
[
|
68
|
-
"UK Trade & Investment Australia",
|
69
|
-
"British High Commission Canberra"
|
70
|
-
],
|
71
|
-
response.map { |item| item['title'] }
|
72
|
-
)
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should raise error on 404" do
|
76
|
-
stub_request(:get, "#{@base_api_url}/api/world-locations/non-existent/organisations").to_return(status: 404)
|
77
|
-
assert_raises GdsApi::HTTPNotFound do
|
78
|
-
@api.organisations_for_world_location('non-existent')
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|