Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve some Publishing API test helper inconsistencies #982

Merged
merged 2 commits into from Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,9 @@
# Unreleased

* Add `stub_any_publishing_api_unreserve_path` test helper.
* Fix Publishing API `stub_any_publishing_api_call` methods only operating on
the V2 endpoint.

# 63.3.0

* Change Worldwide API requests to be routed to whitehall-frontend by
Expand Down
15 changes: 9 additions & 6 deletions lib/gds_api/test_helpers/publishing_api.rb
Expand Up @@ -174,20 +174,19 @@ def stub_any_publishing_api_discard_draft
stub_request(:post, %r{\A#{PUBLISHING_API_V2_ENDPOINT}/content/.*/discard-draft})
end

# Stub any version 2 request to the publishing API
# Stub any request to the publishing API
def stub_any_publishing_api_call
stub_request(:any, %r{\A#{PUBLISHING_API_V2_ENDPOINT}})
stub_request(:any, %r{\A#{PUBLISHING_API_ENDPOINT}})
end

# Stub any version 2 request to the publishing API to return a 404 response
# Stub any request to the publishing API to return a 404 response
def stub_any_publishing_api_call_to_return_not_found
stub_request(:any, %r{\A#{PUBLISHING_API_V2_ENDPOINT}})
stub_request(:any, %r{\A#{PUBLISHING_API_ENDPOINT}})
.to_return(status: 404, headers: { "Content-Type" => "application/json; charset=utf-8" })
end

# Stub any version 2 request to the publishing API to return a 503 response
# Stub any request to the publishing API to return a 503 response
def stub_publishing_api_isnt_available
stub_request(:any, /#{PUBLISHING_API_V2_ENDPOINT}\/.*/).to_return(status: 503)
stub_request(:any, /#{PUBLISHING_API_ENDPOINT}\/.*/).to_return(status: 503)
end

Expand Down Expand Up @@ -641,6 +640,10 @@ def stub_publishing_api_unreserve_path_invalid(base_path, publishing_app = /.*/)
stub_publishing_api_unreserve_path_with_code(base_path, publishing_app, 422)
end

def stub_any_publishing_api_unreserve_path
stub_request(:delete, %r{\A#{PUBLISHING_API_ENDPOINT}/paths/})
end

# Stub a PUT /publish-intent/:base_path request with the given base_path
# and request body.
#
Expand Down
30 changes: 26 additions & 4 deletions test/test_helpers/publishing_api_test.rb
Expand Up @@ -328,15 +328,28 @@
end

describe "#stub_publishing_api_isnt_available" do
it "returns a 503 for any request" do
it "raises a GdsApi::HTTPUnavailable for any request" do
stub_publishing_api_isnt_available

assert_raises GdsApi::BaseError do
assert_raises GdsApi::HTTPUnavailable do
publishing_api.get_content_items({})
end
end
end

assert_raises GdsApi::BaseError do
publishing_api.lookup_content_id(base_path: "")
describe "#stub_any_publishing_api_call" do
it "returns a 200 response for any request" do
stub_any_publishing_api_call
response = publishing_api.get_editions
assert_equal(response.code, 200)
end
end

describe "#stub_any_publishing_api_call_to_return_not_found" do
it "returns a GdsApi::HTTPNotFound for any request" do
stub_any_publishing_api_call_to_return_not_found
assert_raises GdsApi::HTTPNotFound do
publishing_api.get_editions
end
end
end
Expand Down Expand Up @@ -414,6 +427,15 @@
end
end

describe "#stub_any_publishing_api_unreserve_path" do
it "stubs a request to unreserve a path" do
stub_any_publishing_api_unreserve_path

api_response = publishing_api.unreserve_path("/foo", "myapp")
assert_equal(api_response.code, 200)
end
end

describe "#stub_any_publishing_api_path_reservation" do
it "stubs a request to reserve a path" do
stub_any_publishing_api_path_reservation
Expand Down