gds-api-adapters 32.1.0 → 32.2.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24f9c7e9942f51ffbe4ceffdfb89fd546c6ad3e2
|
4
|
+
data.tar.gz: d35330309418eca8f623f00f0f8083fc492bde2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 502332ac6755ce764c1ebf3b742f9e8ac6b5f142e36cd236ffc02beee143f76900670547b84ab1ec95d048faa9205765d8f86c72c205b9f94067e1a0f3057952
|
7
|
+
data.tar.gz: cf6f010f3a4e6d945b75083e8a63fe6cf70b7b808ec90d357551bb9e42e5dd972d3652d7a435f9c7907e0cdd7f56328edb21e50ba3fe0e69a09d9634b0f5d007
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'gds_api/test_helpers/json_client_helper'
|
2
|
+
|
3
|
+
module GdsApi
|
4
|
+
module TestHelpers
|
5
|
+
module LocalLinksManager
|
6
|
+
|
7
|
+
LOCAL_LINKS_MANAGER_ENDPOINT = Plek.current.find('local_links_manager')
|
8
|
+
|
9
|
+
def local_links_manager_has_a_link(authority_slug:, lgsl:, lgil:, url:)
|
10
|
+
response = {
|
11
|
+
"local_authority" => {
|
12
|
+
"name" => authority_slug.capitalize,
|
13
|
+
"snac" => "00AG",
|
14
|
+
"tier" => "unitary",
|
15
|
+
"homepage_url" => "http://#{authority_slug}.example.com",
|
16
|
+
},
|
17
|
+
"local_interaction" => {
|
18
|
+
"lgsl_code" => lgsl,
|
19
|
+
"lgil_code" => lgil,
|
20
|
+
"url" => url,
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
|
25
|
+
.with(query: {authority_slug: authority_slug, lgsl: lgsl, lgil: lgil})
|
26
|
+
.to_return(body: response.to_json, status: 200)
|
27
|
+
end
|
28
|
+
|
29
|
+
def local_links_manager_has_no_link(authority_slug:, lgsl:, lgil:)
|
30
|
+
response = {
|
31
|
+
"local_authority" => {
|
32
|
+
"name" => authority_slug.capitalize,
|
33
|
+
"snac" => "00AG",
|
34
|
+
"tier" => "unitary",
|
35
|
+
"homepage_url" => "http://#{authority_slug}.example.com",
|
36
|
+
},
|
37
|
+
}
|
38
|
+
|
39
|
+
stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
|
40
|
+
.with(query: {authority_slug: authority_slug, lgsl: lgsl, lgil: lgil})
|
41
|
+
.to_return(body: response.to_json, status: 200)
|
42
|
+
end
|
43
|
+
|
44
|
+
def local_links_manager_has_no_link_and_no_homepage_url(authority_slug:, lgsl:, lgil:)
|
45
|
+
response = {
|
46
|
+
"local_authority" => {
|
47
|
+
"name" => authority_slug.capitalize,
|
48
|
+
"snac" => "00AG",
|
49
|
+
"tier" => "unitary",
|
50
|
+
"homepage_url" => nil,
|
51
|
+
},
|
52
|
+
}
|
53
|
+
|
54
|
+
stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
|
55
|
+
.with(query: {authority_slug: authority_slug, lgsl: lgsl, lgil: lgil})
|
56
|
+
.to_return(body: response.to_json, status: 200)
|
57
|
+
end
|
58
|
+
|
59
|
+
def local_links_manager_has_a_fallback_link(authority_slug:, lgsl:, lgil:, url:)
|
60
|
+
response = {
|
61
|
+
"local_authority" => {
|
62
|
+
"name" => authority_slug.capitalize,
|
63
|
+
"snac" => "00AG",
|
64
|
+
"tier" => "unitary",
|
65
|
+
"homepage_url" => "http://#{authority_slug}.example.com",
|
66
|
+
},
|
67
|
+
"local_interaction" => {
|
68
|
+
"lgsl_code" => lgsl,
|
69
|
+
"lgil_code" => lgil,
|
70
|
+
"url" => url,
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
|
75
|
+
.with(query: {authority_slug: authority_slug, lgsl: lgsl})
|
76
|
+
.to_return(body: response.to_json, status: 200)
|
77
|
+
end
|
78
|
+
|
79
|
+
def local_links_manager_has_no_fallback_link(authority_slug:, lgsl:)
|
80
|
+
response = {
|
81
|
+
"local_authority" => {
|
82
|
+
"name" => authority_slug.capitalize,
|
83
|
+
"snac" => "00AG",
|
84
|
+
"tier" => "unitary",
|
85
|
+
"homepage_url" => "http://#{authority_slug}.example.com",
|
86
|
+
},
|
87
|
+
}
|
88
|
+
|
89
|
+
stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
|
90
|
+
.with(query: {authority_slug: authority_slug, lgsl: lgsl})
|
91
|
+
.to_return(body: response.to_json, status: 200)
|
92
|
+
end
|
93
|
+
|
94
|
+
def local_links_manager_request_with_missing_parameters(authority_slug, lgsl)
|
95
|
+
# convert nil to an empty string, otherwise query param is not expressed correctly
|
96
|
+
params = { authority_slug: authority_slug || "", lgsl: lgsl || "" }
|
97
|
+
|
98
|
+
stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
|
99
|
+
.with(query: params)
|
100
|
+
.to_return(body: {}.to_json, status: 400)
|
101
|
+
end
|
102
|
+
|
103
|
+
def local_links_manager_does_not_have_required_objects(authority_slug, lgsl, lgil=nil)
|
104
|
+
params = { authority_slug: authority_slug, lgsl: lgsl }
|
105
|
+
params.merge!(lgil: lgil) if lgil
|
106
|
+
|
107
|
+
stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
|
108
|
+
.with(query: params)
|
109
|
+
.to_return(body: {}.to_json, status: 404)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
data/lib/gds_api/version.rb
CHANGED
@@ -0,0 +1,171 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "gds_api/local_links_manager"
|
3
|
+
require "gds_api/test_helpers/local_links_manager"
|
4
|
+
require 'pry'
|
5
|
+
|
6
|
+
describe GdsApi::LocalLinksManager do
|
7
|
+
include GdsApi::TestHelpers::LocalLinksManager
|
8
|
+
|
9
|
+
before do
|
10
|
+
@base_api_url = Plek.current.find("local_links_manager")
|
11
|
+
@api = GdsApi::LocalLinksManager.new(@base_api_url)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#link" do
|
15
|
+
describe "when making request for specific LGIL" do
|
16
|
+
it "returns the local authority and local interaction details if link present" do
|
17
|
+
local_links_manager_has_a_link(
|
18
|
+
authority_slug: "blackburn",
|
19
|
+
lgsl: 2,
|
20
|
+
lgil: 4,
|
21
|
+
url: "http://blackburn.example.com/abandoned-shopping-trolleys/report"
|
22
|
+
)
|
23
|
+
|
24
|
+
expected_response = {
|
25
|
+
"local_authority" => {
|
26
|
+
"name" => "Blackburn",
|
27
|
+
"snac" => "00AG",
|
28
|
+
"tier" => "unitary",
|
29
|
+
"homepage_url" => "http://blackburn.example.com",
|
30
|
+
},
|
31
|
+
"local_interaction" => {
|
32
|
+
"lgsl_code" => 2,
|
33
|
+
"lgil_code" => 4,
|
34
|
+
"url" => "http://blackburn.example.com/abandoned-shopping-trolleys/report",
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
response = @api.local_link("blackburn", 2, 4)
|
39
|
+
assert_equal expected_response, response.to_hash
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns the local authority details only if no link present" do
|
43
|
+
local_links_manager_has_no_link(
|
44
|
+
authority_slug: "blackburn",
|
45
|
+
lgsl: 2,
|
46
|
+
lgil: 4,
|
47
|
+
)
|
48
|
+
|
49
|
+
expected_response = {
|
50
|
+
"local_authority" => {
|
51
|
+
"name" => "Blackburn",
|
52
|
+
"snac" => "00AG",
|
53
|
+
"tier" => "unitary",
|
54
|
+
"homepage_url" => "http://blackburn.example.com",
|
55
|
+
},
|
56
|
+
}
|
57
|
+
|
58
|
+
response = @api.local_link("blackburn", 2, 4)
|
59
|
+
assert_equal expected_response, response.to_hash
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'returns the local authority without a homepage url if no homepage link present' do
|
63
|
+
local_links_manager_has_no_link_and_no_homepage_url(
|
64
|
+
authority_slug: "blackburn",
|
65
|
+
lgsl: 2,
|
66
|
+
lgil: 4,
|
67
|
+
)
|
68
|
+
|
69
|
+
expected_response = {
|
70
|
+
"local_authority" => {
|
71
|
+
"name" => "Blackburn",
|
72
|
+
"snac" => "00AG",
|
73
|
+
"tier" => "unitary",
|
74
|
+
"homepage_url" => nil,
|
75
|
+
},
|
76
|
+
}
|
77
|
+
|
78
|
+
response = @api.local_link("blackburn", 2, 4)
|
79
|
+
assert_equal expected_response, response.to_hash
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "when making request without LGIL" do
|
84
|
+
it "returns the local authority and local interaction details if link present" do
|
85
|
+
local_links_manager_has_a_fallback_link(
|
86
|
+
authority_slug: "blackburn",
|
87
|
+
lgsl: 2,
|
88
|
+
lgil: 3,
|
89
|
+
url: "http://blackburn.example.com/abandoned-shopping-trolleys/report"
|
90
|
+
)
|
91
|
+
|
92
|
+
expected_response = {
|
93
|
+
"local_authority" => {
|
94
|
+
"name" => "Blackburn",
|
95
|
+
"snac" => "00AG",
|
96
|
+
"tier" => "unitary",
|
97
|
+
"homepage_url" => "http://blackburn.example.com",
|
98
|
+
},
|
99
|
+
"local_interaction" => {
|
100
|
+
"lgsl_code" => 2,
|
101
|
+
"lgil_code" => 3,
|
102
|
+
"url" => "http://blackburn.example.com/abandoned-shopping-trolleys/report",
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
response = @api.local_link("blackburn", 2)
|
107
|
+
assert_equal expected_response, response.to_hash
|
108
|
+
end
|
109
|
+
|
110
|
+
it "returns the local authority and local interaction details if no link present" do
|
111
|
+
local_links_manager_has_no_fallback_link(
|
112
|
+
authority_slug: "blackburn",
|
113
|
+
lgsl: 2
|
114
|
+
)
|
115
|
+
|
116
|
+
expected_response = {
|
117
|
+
"local_authority" => {
|
118
|
+
"name" => "Blackburn",
|
119
|
+
"snac" => "00AG",
|
120
|
+
"tier" => "unitary",
|
121
|
+
"homepage_url" => "http://blackburn.example.com",
|
122
|
+
},
|
123
|
+
}
|
124
|
+
|
125
|
+
response = @api.local_link("blackburn", 2)
|
126
|
+
assert_equal expected_response, response.to_hash
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "when making request with missing required parameters" do
|
131
|
+
it "raises HTTPClientError when authority_slug is missing" do
|
132
|
+
local_links_manager_request_with_missing_parameters(nil, 2)
|
133
|
+
|
134
|
+
assert_raises GdsApi::HTTPClientError do
|
135
|
+
@api.local_link(nil, 2)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
it "raises HTTPClientError when LGSL is missing" do
|
140
|
+
local_links_manager_request_with_missing_parameters('blackburn', nil)
|
141
|
+
|
142
|
+
assert_raises GdsApi::HTTPClientError do
|
143
|
+
@api.local_link('blackburn', nil)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe "when making request with invalid required parameters" do
|
149
|
+
it "returns nil when authority_slug is invalid" do
|
150
|
+
local_links_manager_does_not_have_required_objects("hogwarts", 2)
|
151
|
+
|
152
|
+
response = @api.local_link("hogwarts", 2)
|
153
|
+
assert_equal nil, response
|
154
|
+
end
|
155
|
+
|
156
|
+
it "returns nil when LGSL is invalid" do
|
157
|
+
local_links_manager_does_not_have_required_objects("blackburn", 999)
|
158
|
+
|
159
|
+
response = @api.local_link("blackburn", 999)
|
160
|
+
assert_equal nil, response
|
161
|
+
end
|
162
|
+
|
163
|
+
it "returns nil when the LGSL and LGIL combination is invalid" do
|
164
|
+
local_links_manager_does_not_have_required_objects("blackburn", 2, 9)
|
165
|
+
|
166
|
+
response = @api.local_link("blackburn", 2, 9)
|
167
|
+
assert_equal nil, response
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gds-api-adapters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 32.
|
4
|
+
version: 32.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Stewart
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: plek
|
@@ -344,6 +344,7 @@ files:
|
|
344
344
|
- lib/gds_api/json_client.rb
|
345
345
|
- lib/gds_api/licence_application.rb
|
346
346
|
- lib/gds_api/list_response.rb
|
347
|
+
- lib/gds_api/local_links_manager.rb
|
347
348
|
- lib/gds_api/mapit.rb
|
348
349
|
- lib/gds_api/maslow.rb
|
349
350
|
- lib/gds_api/middleware/govuk_header_sniffer.rb
|
@@ -379,6 +380,7 @@ files:
|
|
379
380
|
- lib/gds_api/test_helpers/intent_helpers.rb
|
380
381
|
- lib/gds_api/test_helpers/json_client_helper.rb
|
381
382
|
- lib/gds_api/test_helpers/licence_application.rb
|
383
|
+
- lib/gds_api/test_helpers/local_links_manager.rb
|
382
384
|
- lib/gds_api/test_helpers/mapit.rb
|
383
385
|
- lib/gds_api/test_helpers/need_api.rb
|
384
386
|
- lib/gds_api/test_helpers/organisations.rb
|
@@ -418,6 +420,7 @@ files:
|
|
418
420
|
- test/json_client_test.rb
|
419
421
|
- test/licence_application_api_test.rb
|
420
422
|
- test/list_response_test.rb
|
423
|
+
- test/local_links_manager_api_test.rb
|
421
424
|
- test/mapit_test.rb
|
422
425
|
- test/maslow_test.rb
|
423
426
|
- test/middleware/govuk_header_sniffer_test.rb
|
@@ -479,6 +482,7 @@ test_files:
|
|
479
482
|
- test/publishing_api_v2/get_expanded_links_test.rb
|
480
483
|
- test/whitehall_admin_api_test.rb
|
481
484
|
- test/pp_data_in_test.rb
|
485
|
+
- test/local_links_manager_api_test.rb
|
482
486
|
- test/publishing_api/special_route_publisher_test.rb
|
483
487
|
- test/need_api_test.rb
|
484
488
|
- test/publisher_api_test.rb
|