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
@@ -1,58 +0,0 @@
|
|
1
|
-
require_relative 'test_helper'
|
2
|
-
require 'gds_api/organisations'
|
3
|
-
require 'gds_api/test_helpers/organisations'
|
4
|
-
|
5
|
-
describe GdsApi::Organisations do
|
6
|
-
include GdsApi::TestHelpers::Organisations
|
7
|
-
|
8
|
-
before do
|
9
|
-
@base_api_url = GdsApi::TestHelpers::Organisations::ORGANISATIONS_API_ENDPOINT
|
10
|
-
@api = GdsApi::Organisations.new(@base_api_url)
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "fetching list of organisations" do
|
14
|
-
it "should get the organisations" do
|
15
|
-
organisation_slugs = %w(ministry-of-fun, tea-agency)
|
16
|
-
organisations_api_has_organisations(organisation_slugs)
|
17
|
-
|
18
|
-
response = @api.organisations
|
19
|
-
assert_equal organisation_slugs, response.map { |r| r['details']['slug'] }
|
20
|
-
assert_equal "Tea Agency", response['results'][1]['title']
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should handle the pagination" do
|
24
|
-
organisation_slugs = (1..50).map { |n| "organisation-#{n}" }
|
25
|
-
organisations_api_has_organisations(organisation_slugs)
|
26
|
-
|
27
|
-
response = @api.organisations
|
28
|
-
assert_equal(
|
29
|
-
organisation_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/organisations").to_return(status: 404)
|
36
|
-
assert_raises GdsApi::HTTPNotFound do
|
37
|
-
@api.organisations
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "fetching an organisation" do
|
43
|
-
it "should return the details" do
|
44
|
-
organisations_api_has_organisation('ministry-of-fun')
|
45
|
-
|
46
|
-
response = @api.organisation('ministry-of-fun')
|
47
|
-
assert_equal 'Ministry Of Fun', response['title']
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should raise for a non-existent organisation" do
|
51
|
-
organisations_api_does_not_have_organisation('non-existent')
|
52
|
-
|
53
|
-
assert_raises(GdsApi::HTTPNotFound) do
|
54
|
-
@api.organisation('non-existent')
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,118 +0,0 @@
|
|
1
|
-
require_relative 'test_helper'
|
2
|
-
require 'gds_api/panopticon'
|
3
|
-
require 'gds_api/test_helpers/panopticon'
|
4
|
-
require 'ostruct'
|
5
|
-
|
6
|
-
describe GdsApi::Panopticon::Registerer do
|
7
|
-
include GdsApi::TestHelpers::Panopticon
|
8
|
-
|
9
|
-
describe "creating an instance of the panopticon client" do
|
10
|
-
describe "setting the platform" do
|
11
|
-
it "should create an instance using the current Plek environment as the platform by default" do
|
12
|
-
Plek.stubs(:current).returns(stub(find: "http://thisplace"))
|
13
|
-
|
14
|
-
GdsApi::Panopticon.expects(:new).with("http://thisplace", anything).returns(:panopticon_instance)
|
15
|
-
r = GdsApi::Panopticon::Registerer.new({})
|
16
|
-
assert_equal :panopticon_instance, r.send(:panopticon)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should pass through the endpoint url" do
|
20
|
-
Plek.stubs(:current).returns(stub(find: "http://thisplace"))
|
21
|
-
|
22
|
-
GdsApi::Panopticon.expects(:new).with("http://otherplace", anything).returns(:panopticon_instance)
|
23
|
-
r = GdsApi::Panopticon::Registerer.new(endpoint_url: "http://otherplace")
|
24
|
-
assert_equal :panopticon_instance, r.send(:panopticon)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe "setting other options" do
|
29
|
-
it "should create an instance with a default timeout of 10 seconds" do
|
30
|
-
GdsApi::Panopticon.expects(:new).with(anything, timeout: 10).returns(:panopticon_instance)
|
31
|
-
r = GdsApi::Panopticon::Registerer.new({})
|
32
|
-
assert_equal :panopticon_instance, r.send(:panopticon)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should allow overriding the timeout" do
|
36
|
-
GdsApi::Panopticon.expects(:new).with(anything, timeout: 15).returns(:panopticon_instance)
|
37
|
-
r = GdsApi::Panopticon::Registerer.new(timeout: 15)
|
38
|
-
assert_equal :panopticon_instance, r.send(:panopticon)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "shoule merge in the api credentials" do
|
42
|
-
GdsApi::Panopticon::Registerer.any_instance.stubs(:panopticon_api_credentials).returns(foo: "Bar", baz: "kablooie")
|
43
|
-
GdsApi::Panopticon.expects(:new).with(anything, timeout: 10, foo: "Bar", baz: "kablooie").returns(:panopticon_instance)
|
44
|
-
r = GdsApi::Panopticon::Registerer.new({})
|
45
|
-
assert_equal :panopticon_instance, r.send(:panopticon)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should memoize the panopticon instance" do
|
50
|
-
GdsApi::Panopticon.expects(:new).once.returns(:panopticon_instance)
|
51
|
-
r = GdsApi::Panopticon::Registerer.new({})
|
52
|
-
|
53
|
-
assert_equal :panopticon_instance, r.send(:panopticon)
|
54
|
-
assert_equal :panopticon_instance, r.send(:panopticon)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should register artefacts" do
|
59
|
-
request = stub_artefact_registration('beards',
|
60
|
-
slug: 'beards',
|
61
|
-
owning_app: 'whitehall',
|
62
|
-
kind: 'detailed-guide',
|
63
|
-
name: 'A guide to beards',
|
64
|
-
description: '5 tips for keeping your beard in check',
|
65
|
-
state: 'draft',
|
66
|
-
need_ids: %w(100001 100002),
|
67
|
-
public_timestamp: "2014-01-01T12:00:00+00:00",
|
68
|
-
latest_change_note: 'Added more stubble',
|
69
|
-
content_id: 'f47b4fab-46fa-4020-97a2-3413a5d75402'
|
70
|
-
)
|
71
|
-
|
72
|
-
GdsApi::Panopticon::Registerer.new(
|
73
|
-
owning_app: 'whitehall',
|
74
|
-
kind: 'detailed-guide'
|
75
|
-
).register(
|
76
|
-
OpenStruct.new(
|
77
|
-
slug: 'beards',
|
78
|
-
title: 'A guide to beards',
|
79
|
-
description: '5 tips for keeping your beard in check',
|
80
|
-
state: 'draft',
|
81
|
-
need_ids: %w(100001 100002),
|
82
|
-
primary_section: "tax/vat",
|
83
|
-
sections: ["tax/vat", "tax/capital-gains"],
|
84
|
-
specialist_sectors: ["oil-and-gas/wells", "oil-and-gas/licensing"],
|
85
|
-
public_timestamp: DateTime.parse('2014-01-01 12:00:00 +00:00'),
|
86
|
-
latest_change_note: 'Added more stubble',
|
87
|
-
content_id: 'f47b4fab-46fa-4020-97a2-3413a5d75402'
|
88
|
-
)
|
89
|
-
)
|
90
|
-
|
91
|
-
assert_requested(request)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "should support deprecated fields" do
|
95
|
-
request = stub_artefact_registration('beards',
|
96
|
-
slug: 'beards',
|
97
|
-
owning_app: 'whitehall',
|
98
|
-
kind: 'detailed-guide',
|
99
|
-
name: 'A guide to beards',
|
100
|
-
description: '5 tips for keeping your beard in check',
|
101
|
-
state: 'draft',
|
102
|
-
)
|
103
|
-
|
104
|
-
GdsApi::Panopticon::Registerer.new(
|
105
|
-
owning_app: 'whitehall',
|
106
|
-
kind: 'detailed-guide'
|
107
|
-
).register(
|
108
|
-
OpenStruct.new(
|
109
|
-
slug: 'beards',
|
110
|
-
title: 'A guide to beards',
|
111
|
-
description: '5 tips for keeping your beard in check',
|
112
|
-
state: 'draft',
|
113
|
-
)
|
114
|
-
)
|
115
|
-
|
116
|
-
assert_requested(request)
|
117
|
-
end
|
118
|
-
end
|
data/test/panopticon_test.rb
DELETED
@@ -1,190 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'gds_api/panopticon'
|
3
|
-
require 'gds_api/test_helpers/panopticon'
|
4
|
-
|
5
|
-
describe GdsApi::Panopticon do
|
6
|
-
include GdsApi::TestHelpers::Panopticon
|
7
|
-
|
8
|
-
let(:base_api_endpoint) { GdsApi::TestHelpers::Panopticon::PANOPTICON_ENDPOINT }
|
9
|
-
let(:api) { GdsApi::Panopticon.new(base_api_endpoint) }
|
10
|
-
|
11
|
-
let(:basic_artefact) {
|
12
|
-
{
|
13
|
-
name: 'An artefact',
|
14
|
-
slug: 'a-basic-artefact'
|
15
|
-
}
|
16
|
-
}
|
17
|
-
let(:artefact_with_contact) {
|
18
|
-
{
|
19
|
-
name: 'An artefact',
|
20
|
-
slug: 'an-artefact-with-contact',
|
21
|
-
contact: {
|
22
|
-
name: 'Department for Environment, Food and Rural Affairs (Defra)',
|
23
|
-
email_address: 'helpline@defra.gsi.gov.uk'
|
24
|
-
}
|
25
|
-
}
|
26
|
-
}
|
27
|
-
let(:registerable_artefact) {
|
28
|
-
{
|
29
|
-
slug: 'foo',
|
30
|
-
owning_app: 'my-app',
|
31
|
-
kind: 'custom-application',
|
32
|
-
name: 'MyFoo',
|
33
|
-
description: 'A custom foo of great customness.',
|
34
|
-
state: 'live'
|
35
|
-
}
|
36
|
-
}
|
37
|
-
|
38
|
-
it 'fetches an artefact given a slug' do
|
39
|
-
panopticon_has_metadata(basic_artefact)
|
40
|
-
|
41
|
-
artefact = api.artefact_for_slug(basic_artefact[:slug])
|
42
|
-
assert_equal 'An artefact', artefact['name']
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'fetches an artefact as a hash given a slug' do
|
46
|
-
panopticon_has_metadata(basic_artefact)
|
47
|
-
artefact = api.artefact_for_slug(basic_artefact[:slug], as_hash: true)
|
48
|
-
assert_equal basic_artefact[:name], artefact['name']
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'fetches and parses JSON into a hash' do
|
52
|
-
url = "#{base_api_endpoint}/some.json"
|
53
|
-
stub_request(:get, url).to_return(body: { a: 1 }.to_json)
|
54
|
-
|
55
|
-
assert_equal 1, api.get_json(url)['a']
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'raises if the endpoint returns 404' do
|
59
|
-
url = "#{base_api_endpoint}/some.json"
|
60
|
-
stub_request(:get, url).to_return(status: Rack::Utils.status_code(:not_found))
|
61
|
-
|
62
|
-
assert_raises(GdsApi::HTTPNotFound) do
|
63
|
-
api.get_json(url)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'constructs the correct URL for a slug' do
|
68
|
-
assert_equal "#{base_api_endpoint}/artefacts/slug.json", api.url_for_slug('slug')
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'deserialises contacts into whole objects' do
|
72
|
-
panopticon_has_metadata(artefact_with_contact)
|
73
|
-
|
74
|
-
artefact = api.artefact_for_slug(artefact_with_contact[:slug])
|
75
|
-
assert_equal(
|
76
|
-
'Department for Environment, Food and Rural Affairs (Defra)',
|
77
|
-
artefact['contact']['name']
|
78
|
-
)
|
79
|
-
assert_equal(
|
80
|
-
'helpline@defra.gsi.gov.uk',
|
81
|
-
artefact['contact']['email_address']
|
82
|
-
)
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'creates a new artefact' do
|
86
|
-
url = "#{base_api_endpoint}/artefacts.json"
|
87
|
-
stub_request(:post, url)
|
88
|
-
.with(body: basic_artefact.to_json)
|
89
|
-
.to_return(body: basic_artefact.merge(id: 1).to_json)
|
90
|
-
|
91
|
-
api.create_artefact(basic_artefact)
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'updates an existing artefact' do
|
95
|
-
url = "#{base_api_endpoint}/artefacts/1.json"
|
96
|
-
stub_request(:put, url)
|
97
|
-
.with(body: basic_artefact.to_json)
|
98
|
-
.to_return(status: 200, body: '{}')
|
99
|
-
|
100
|
-
api.update_artefact(1, basic_artefact)
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'deletes an artefact' do
|
104
|
-
url = "#{base_api_endpoint}/artefacts/1.json"
|
105
|
-
stub_request(:delete, url)
|
106
|
-
.with(body: "")
|
107
|
-
.to_return(status: 200, body: '{}')
|
108
|
-
|
109
|
-
api.delete_artefact!(1)
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'uses basic auth' do
|
113
|
-
credentials = { user: 'fred', password: 'secret' }
|
114
|
-
api = GdsApi::Panopticon.new('http://some.url', basic_auth: credentials)
|
115
|
-
url = "http://#{credentials[:user]}:#{credentials[:password]}@some.url/artefacts/1.json"
|
116
|
-
stub_request(:put, url)
|
117
|
-
.to_return(status: 200, body: '{}')
|
118
|
-
|
119
|
-
api.update_artefact(1, basic_artefact)
|
120
|
-
end
|
121
|
-
|
122
|
-
it 'registers new artefacts en masse' do
|
123
|
-
r = GdsApi::Panopticon::Registerer.new(endpoint_url: base_api_endpoint, owning_app: 'my-app')
|
124
|
-
artefact = registerable_artefact
|
125
|
-
panopticon_has_no_metadata_for('foo')
|
126
|
-
|
127
|
-
stub_request(:put, "#{base_api_endpoint}/artefacts/foo.json")
|
128
|
-
.with(body: artefact.to_json)
|
129
|
-
.to_return(body: artefact.merge(id: 1).to_json)
|
130
|
-
|
131
|
-
url = "#{base_api_endpoint}/artefacts.json"
|
132
|
-
stub_request(:post, url)
|
133
|
-
.with(body: artefact.to_json)
|
134
|
-
.to_return(body: artefact.merge(id: 1).to_json)
|
135
|
-
|
136
|
-
record = OpenStruct.new(artefact.merge(title: artefact[:name]))
|
137
|
-
r.register(record)
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'registers existing artefacts en masse' do
|
141
|
-
artefact = registerable_artefact
|
142
|
-
r = GdsApi::Panopticon::Registerer.new(endpoint_url: base_api_endpoint, owning_app: 'my-app')
|
143
|
-
|
144
|
-
panopticon_has_metadata(artefact)
|
145
|
-
url = "#{base_api_endpoint}/artefacts/foo.json"
|
146
|
-
stub_request(:put, url)
|
147
|
-
.with(body: artefact.to_json)
|
148
|
-
.to_return(status: 200, body: '{}')
|
149
|
-
|
150
|
-
record = OpenStruct.new(artefact.merge(title: artefact[:name]))
|
151
|
-
r.register(record)
|
152
|
-
end
|
153
|
-
|
154
|
-
describe 'tags' do
|
155
|
-
let(:tag) {
|
156
|
-
{ tag_type: 'section', tag_id: 'housing', title: 'Housing', description: 'Housing', parent_id: nil }
|
157
|
-
}
|
158
|
-
|
159
|
-
it 'creates a tag' do
|
160
|
-
url = "#{base_api_endpoint}/tags.json"
|
161
|
-
req = stub_request(:post, url)
|
162
|
-
.with(body: tag.to_json)
|
163
|
-
.to_return(status: 201, body: tag.to_json)
|
164
|
-
|
165
|
-
api.create_tag(tag)
|
166
|
-
assert_requested(req)
|
167
|
-
end
|
168
|
-
|
169
|
-
it 'updates a tag' do
|
170
|
-
url = "#{base_api_endpoint}/tags/section/citizenship/passports.json"
|
171
|
-
fields_to_update = { title: 'Passports' }
|
172
|
-
|
173
|
-
req = stub_request(:put, url)
|
174
|
-
.with(body: fields_to_update.to_json)
|
175
|
-
.to_return(status: 200)
|
176
|
-
|
177
|
-
api.put_tag('section', 'citizenship/passports', fields_to_update)
|
178
|
-
assert_requested(req)
|
179
|
-
end
|
180
|
-
|
181
|
-
it 'publishes a tag' do
|
182
|
-
url = "#{base_api_endpoint}/tags/section/citizenship/passports/publish.json"
|
183
|
-
req = stub_request(:post, url).with(body: {}.to_json)
|
184
|
-
.to_return(status: 200)
|
185
|
-
|
186
|
-
api.publish_tag('section', 'citizenship/passports')
|
187
|
-
assert_requested(req)
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
data/test/pp_data_in_test.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'gds_api/performance_platform/data_in'
|
3
|
-
require 'gds_api/test_helpers/performance_platform/data_in'
|
4
|
-
|
5
|
-
describe GdsApi::PerformancePlatform::DataIn do
|
6
|
-
include GdsApi::TestHelpers::PerformancePlatform::DataIn
|
7
|
-
|
8
|
-
before do
|
9
|
-
@base_api_url = GdsApi::TestHelpers::PerformancePlatform::DataIn::PP_DATA_IN_ENDPOINT
|
10
|
-
@api = GdsApi::PerformancePlatform::DataIn.new(@base_api_url)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "can submit a day aggregate for service feedback for a particular slug" do
|
14
|
-
request_details = { "some" => "data" }
|
15
|
-
|
16
|
-
stub_post = stub_service_feedback_day_aggregate_submission("some-slug", request_details)
|
17
|
-
|
18
|
-
@api.submit_service_feedback_day_aggregate("some-slug", request_details)
|
19
|
-
|
20
|
-
assert_requested(stub_post)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "can submit entries counts for corporate content problem reports" do
|
24
|
-
entries = %w(some entries)
|
25
|
-
|
26
|
-
stub_post = stub_corporate_content_problem_report_count_submission(entries)
|
27
|
-
|
28
|
-
@api.corporate_content_problem_report_count(entries)
|
29
|
-
|
30
|
-
assert_requested(stub_post)
|
31
|
-
end
|
32
|
-
|
33
|
-
it "can submit the corporate content urls with the most problem reports" do
|
34
|
-
entries = %w(some entries)
|
35
|
-
|
36
|
-
stub_post = stub_corporate_content_urls_with_the_most_problem_reports_submission(entries)
|
37
|
-
|
38
|
-
@api.corporate_content_urls_with_the_most_problem_reports(entries)
|
39
|
-
|
40
|
-
assert_requested(stub_post)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "throws an exception when the support app isn't available" do
|
44
|
-
stub_pp_isnt_available
|
45
|
-
assert_raises(GdsApi::HTTPServerError) { @api.submit_service_feedback_day_aggregate("doesnt_matter", {}) }
|
46
|
-
end
|
47
|
-
|
48
|
-
it "throws an exception when the the bucket for that slug hasn't been defined" do
|
49
|
-
stub_service_feedback_bucket_unavailable_for("some_transaction")
|
50
|
-
assert_raises(GdsApi::PerformancePlatformDatasetNotConfigured) { @api.submit_service_feedback_day_aggregate("some_transaction", {}) }
|
51
|
-
end
|
52
|
-
end
|
data/test/pp_data_out_test.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'gds_api/performance_platform/data_out'
|
3
|
-
require 'gds_api/test_helpers/performance_platform/data_out'
|
4
|
-
|
5
|
-
describe GdsApi::PerformancePlatform::DataOut do
|
6
|
-
include GdsApi::TestHelpers::PerformancePlatform::DataOut
|
7
|
-
|
8
|
-
before do
|
9
|
-
@base_api_url = GdsApi::TestHelpers::PerformancePlatform::DataOut::PP_DATA_OUT_ENDPOINT
|
10
|
-
@api = GdsApi::PerformancePlatform::DataOut.new(@base_api_url)
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:transaction_slug) { 'register-to-vote' }
|
14
|
-
|
15
|
-
it "calls the service feedback endpoint for a particular slug" do
|
16
|
-
request_details = { "some" => "data" }
|
17
|
-
|
18
|
-
stub_post = stub_service_feedback(transaction_slug, request_details)
|
19
|
-
|
20
|
-
@api.service_feedback(transaction_slug)
|
21
|
-
|
22
|
-
assert_requested(stub_post)
|
23
|
-
end
|
24
|
-
end
|
@@ -1,104 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require "gds_api/publishing_api/special_route_publisher"
|
3
|
-
require File.dirname(__FILE__) + '/../../lib/gds_api/test_helpers/publishing_api_v2'
|
4
|
-
|
5
|
-
describe GdsApi::PublishingApi::SpecialRoutePublisher do
|
6
|
-
include ::GdsApi::TestHelpers::PublishingApiV2
|
7
|
-
|
8
|
-
let(:content_id) { 'a-content-id-of-sorts' }
|
9
|
-
let(:special_route) {
|
10
|
-
{
|
11
|
-
content_id: content_id,
|
12
|
-
title: "A title",
|
13
|
-
description: "A description",
|
14
|
-
base_path: "/favicon.ico",
|
15
|
-
type: "exact",
|
16
|
-
publishing_app: "static-publisher",
|
17
|
-
rendering_app: "static-frontend",
|
18
|
-
}
|
19
|
-
}
|
20
|
-
|
21
|
-
let(:publisher) { GdsApi::PublishingApi::SpecialRoutePublisher.new }
|
22
|
-
let(:endpoint) { Plek.current.find('publishing-api') }
|
23
|
-
|
24
|
-
describe ".publish" do
|
25
|
-
before do
|
26
|
-
stub_any_publishing_api_call
|
27
|
-
end
|
28
|
-
|
29
|
-
it "publishes the special routes" do
|
30
|
-
Timecop.freeze(Time.now) do
|
31
|
-
publisher.publish(special_route)
|
32
|
-
|
33
|
-
expected_payload = {
|
34
|
-
base_path: special_route[:base_path],
|
35
|
-
document_type: "special_route",
|
36
|
-
schema_name: "special_route",
|
37
|
-
title: special_route[:title],
|
38
|
-
description: special_route[:description],
|
39
|
-
routes: [
|
40
|
-
{
|
41
|
-
path: special_route[:base_path],
|
42
|
-
type: special_route[:type],
|
43
|
-
}
|
44
|
-
],
|
45
|
-
publishing_app: special_route[:publishing_app],
|
46
|
-
rendering_app: special_route[:rendering_app],
|
47
|
-
public_updated_at: Time.now.iso8601,
|
48
|
-
}
|
49
|
-
|
50
|
-
assert_requested(:put, "#{endpoint}/v2/content/#{content_id}", body: expected_payload)
|
51
|
-
assert_publishing_api_publish(content_id, update_type: 'major')
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
it "publishes links" do
|
56
|
-
links = {
|
57
|
-
links: {
|
58
|
-
organisations: ['org-content-id']
|
59
|
-
}
|
60
|
-
}
|
61
|
-
|
62
|
-
publisher.publish(special_route.merge(links))
|
63
|
-
|
64
|
-
assert_requested(:patch, "#{endpoint}/v2/links/#{content_id}", body: links)
|
65
|
-
end
|
66
|
-
|
67
|
-
describe 'Timezone handling' do
|
68
|
-
let(:publishing_api) {
|
69
|
-
stub(:publishing_api, put_content_item: nil)
|
70
|
-
}
|
71
|
-
let(:publisher) {
|
72
|
-
GdsApi::PublishingApi::SpecialRoutePublisher.new(publishing_api: publishing_api)
|
73
|
-
}
|
74
|
-
|
75
|
-
it "is robust to Time.zone returning nil" do
|
76
|
-
Timecop.freeze(Time.now) do
|
77
|
-
Time.stubs(:zone).returns(nil)
|
78
|
-
publishing_api.expects(:put_content).with(
|
79
|
-
anything,
|
80
|
-
has_entries(public_updated_at: Time.now.iso8601)
|
81
|
-
)
|
82
|
-
publishing_api.expects(:publish)
|
83
|
-
|
84
|
-
publisher.publish(special_route)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
it "uses Time.zone if available" do
|
89
|
-
Timecop.freeze(Time.now) do
|
90
|
-
time_in_zone = stub("Time in zone", now: Time.parse("2010-01-01 10:10:10 +04:00"))
|
91
|
-
Time.stubs(:zone).returns(time_in_zone)
|
92
|
-
|
93
|
-
publishing_api.expects(:put_content).with(
|
94
|
-
anything,
|
95
|
-
has_entries(public_updated_at: time_in_zone.now.iso8601)
|
96
|
-
)
|
97
|
-
publishing_api.expects(:publish)
|
98
|
-
|
99
|
-
publisher.publish(special_route)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|