Skip to content

Commit

Permalink
Fix stub_any_publishing_api_call methods using only V2 endpoint
Browse files Browse the repository at this point in the history
These stubs now apply to all Publishing API calls as one would expect
from the method name.
  • Loading branch information
kevindew committed Feb 7, 2020
1 parent 25520c6 commit c7418aa
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Unreleased

* 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
11 changes: 5 additions & 6 deletions lib/gds_api/test_helpers/publishing_api.rb
Original file line number Diff line number Diff line change
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
21 changes: 17 additions & 4 deletions test/test_helpers/publishing_api_test.rb
Original file line number Diff line number Diff line change
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

0 comments on commit c7418aa

Please sign in to comment.