Module: GdsApi::TestHelpers::PublishingApi
Constant Summary
collapse
- PUBLISHING_API_ENDPOINT =
Plek.current.find('publishing-api')
Instance Method Summary
collapse
-
#assert_publishing_api_put(url, attributes_or_matcher = {}, times = 1) ⇒ Object
-
#assert_publishing_api_put_intent(base_path, attributes_or_matcher = {}, times = 1) ⇒ Object
-
#request_json_including(required_attributes) ⇒ Object
-
#request_json_matching(required_attributes) ⇒ Object
-
#stub_default_publishing_api_path_reservation ⇒ Object
-
#stub_default_publishing_api_put_intent ⇒ Object
-
#stub_publishing_api_destroy_intent(base_path) ⇒ Object
-
#stub_publishing_api_has_path_reservation_for(path, publishing_app) ⇒ Object
(also: #publishing_api_has_path_reservation_for)
-
#stub_publishing_api_isnt_available ⇒ Object
(also: #publishing_api_isnt_available)
-
#stub_publishing_api_put_intent(base_path, body = intent_for_publishing_api(base_path)) ⇒ Object
-
#stub_publishing_api_returns_path_reservation_validation_error_for(path, error_details = nil) ⇒ Object
(also: #publishing_api_returns_path_reservation_validation_error_for)
-
#stub_publishing_api_unreserve_path(base_path, publishing_app = /.*/) ⇒ Object
-
#stub_publishing_api_unreserve_path_invalid(base_path, publishing_app = /.*/) ⇒ Object
-
#stub_publishing_api_unreserve_path_not_found(base_path, publishing_app = /.*/) ⇒ Object
#intent_for_base_path
#content_item_for_base_path, #gone_content_item_for_base_path, #titleize_base_path
Instance Method Details
#assert_publishing_api_put(url, attributes_or_matcher = {}, times = 1) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/gds_api/test_helpers/publishing_api.rb', line 46
def assert_publishing_api_put(url, attributes_or_matcher = {}, times = 1)
if attributes_or_matcher.is_a?(Hash)
matcher = attributes_or_matcher.empty? ? nil : request_json_matching(attributes_or_matcher)
else
matcher = attributes_or_matcher
end
if matcher
assert_requested(:put, url, times: times, &matcher)
else
assert_requested(:put, url, times: times)
end
end
|
#assert_publishing_api_put_intent(base_path, attributes_or_matcher = {}, times = 1) ⇒ Object
41
42
43
44
|
# File 'lib/gds_api/test_helpers/publishing_api.rb', line 41
def assert_publishing_api_put_intent(base_path, attributes_or_matcher = {}, times = 1)
url = PUBLISHING_API_ENDPOINT + "/publish-intent" + base_path
assert_publishing_api_put(url, attributes_or_matcher, times)
end
|
#request_json_including(required_attributes) ⇒ Object
67
68
69
70
71
72
|
# File 'lib/gds_api/test_helpers/publishing_api.rb', line 67
def request_json_including(required_attributes)
->(request) do
data = JSON.parse(request.body)
values_match_recursively(required_attributes, data)
end
end
|
#request_json_matching(required_attributes) ⇒ Object
60
61
62
63
64
65
|
# File 'lib/gds_api/test_helpers/publishing_api.rb', line 60
def request_json_matching(required_attributes)
->(request) do
data = JSON.parse(request.body)
required_attributes.to_a.all? { |key, value| data[key.to_s] == value }
end
end
|
#stub_default_publishing_api_path_reservation ⇒ Object
78
79
80
81
82
83
84
|
# File 'lib/gds_api/test_helpers/publishing_api.rb', line 78
def stub_default_publishing_api_path_reservation
stub_request(:put, %r[\A#{PUBLISHING_API_ENDPOINT}/paths/]).to_return { |request|
base_path = request.uri.path.sub(%r{\A/paths/}, "")
{ status: 200, headers: { content_type: "application/json" },
body: publishing_api_path_data_for(base_path).to_json }
}
end
|
#stub_default_publishing_api_put_intent ⇒ Object
37
38
39
|
# File 'lib/gds_api/test_helpers/publishing_api.rb', line 37
def stub_default_publishing_api_put_intent
stub_request(:put, %r{\A#{PUBLISHING_API_ENDPOINT}/publish-intent})
end
|
#stub_publishing_api_destroy_intent(base_path) ⇒ Object
32
33
34
35
|
# File 'lib/gds_api/test_helpers/publishing_api.rb', line 32
def stub_publishing_api_destroy_intent(base_path)
url = PUBLISHING_API_ENDPOINT + "/publish-intent" + base_path
stub_request(:delete, url).to_return(status: 200, body: '{}', headers: { "Content-Type" => "application/json; charset=utf-8" })
end
|
#stub_publishing_api_has_path_reservation_for(path, publishing_app) ⇒ Object
Also known as:
publishing_api_has_path_reservation_for
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/gds_api/test_helpers/publishing_api.rb', line 86
def stub_publishing_api_has_path_reservation_for(path, publishing_app)
data = publishing_api_path_data_for(path, "publishing_app" => publishing_app)
error_data = data.merge("errors" => { "path" => ["is already reserved by the #{publishing_app} application"] })
stub_request(:put, "#{PUBLISHING_API_ENDPOINT}/paths#{path}").
to_return(status: 422, body: error_data.to_json,
headers: { content_type: "application/json" })
stub_request(:put, "#{PUBLISHING_API_ENDPOINT}/paths#{path}").
with(body: { "publishing_app" => publishing_app }).
to_return(status: 200,
headers: { content_type: "application/json" },
body: data.to_json)
end
|
#stub_publishing_api_isnt_available ⇒ Object
Also known as:
publishing_api_isnt_available
74
75
76
|
# File 'lib/gds_api/test_helpers/publishing_api.rb', line 74
def stub_publishing_api_isnt_available
stub_request(:any, /#{PUBLISHING_API_ENDPOINT}\/.*/).to_return(status: 503)
end
|
#stub_publishing_api_put_intent(base_path, body = intent_for_publishing_api(base_path)) ⇒ Object
26
27
28
29
30
|
# File 'lib/gds_api/test_helpers/publishing_api.rb', line 26
def stub_publishing_api_put_intent(base_path, body = intent_for_publishing_api(base_path))
url = PUBLISHING_API_ENDPOINT + "/publish-intent" + base_path
body = body.to_json unless body.is_a?(String)
stub_request(:put, url).with(body: body).to_return(status: 200, body: '{}', headers: { "Content-Type" => "application/json; charset=utf-8" })
end
|
#stub_publishing_api_returns_path_reservation_validation_error_for(path, error_details = nil) ⇒ Object
Also known as:
publishing_api_returns_path_reservation_validation_error_for
101
102
103
104
105
106
107
|
# File 'lib/gds_api/test_helpers/publishing_api.rb', line 101
def stub_publishing_api_returns_path_reservation_validation_error_for(path, error_details = nil)
error_details ||= { "base" => ["computer says no"] }
error_data = publishing_api_path_data_for(path).merge("errors" => error_details)
stub_request(:put, "#{PUBLISHING_API_ENDPOINT}/paths#{path}").
to_return(status: 422, body: error_data.to_json, headers: { content_type: "application/json" })
end
|
#stub_publishing_api_unreserve_path(base_path, publishing_app = /.*/) ⇒ Object
14
15
16
|
# File 'lib/gds_api/test_helpers/publishing_api.rb', line 14
def stub_publishing_api_unreserve_path(base_path, publishing_app = /.*/)
stub_publishing_api_unreserve_path_with_code(base_path, publishing_app, 200)
end
|
#stub_publishing_api_unreserve_path_invalid(base_path, publishing_app = /.*/) ⇒ Object
22
23
24
|
# File 'lib/gds_api/test_helpers/publishing_api.rb', line 22
def stub_publishing_api_unreserve_path_invalid(base_path, publishing_app = /.*/)
stub_publishing_api_unreserve_path_with_code(base_path, publishing_app, 422)
end
|
#stub_publishing_api_unreserve_path_not_found(base_path, publishing_app = /.*/) ⇒ Object
18
19
20
|
# File 'lib/gds_api/test_helpers/publishing_api.rb', line 18
def stub_publishing_api_unreserve_path_not_found(base_path, publishing_app = /.*/)
stub_publishing_api_unreserve_path_with_code(base_path, publishing_app, 404)
end
|