Skip to content

Commit

Permalink
Add test helpers to complement new adapter method
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Thorner committed Mar 15, 2019
1 parent 57c317f commit c7be09a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 deletions.
18 changes: 18 additions & 0 deletions lib/gds_api/test_helpers/publishing_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ module PublishingApi

PUBLISHING_API_ENDPOINT = Plek.current.find('publishing-api')

def stub_publishing_api_unreserve_path(base_path, publishing_app)
stub_publishing_api_unreserve_path_with_code(base_path, publishing_app, 200)
end

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

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_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)
Expand Down Expand Up @@ -101,6 +113,12 @@ def stub_publishing_api_returns_path_reservation_validation_error_for(path, erro

private

def stub_publishing_api_unreserve_path_with_code(base_path, publishing_app, code)
url = PUBLISHING_API_ENDPOINT + "/paths" + base_path
body = { publishing_app: publishing_app }
stub_request(:delete, url).with(body: body).to_return(status: code, body: '{}', headers: { "Content-Type" => "application/json; charset=utf-8" })
end

def values_match_recursively(expected_value, actual_value)
case expected_value
when Hash
Expand Down
12 changes: 6 additions & 6 deletions test/publishing_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@
},
)

assert_raises GdsApi::HTTPNotFound do
@api_client.unreserve_path(base_path, publishing_app)
end
assert_raises GdsApi::HTTPNotFound do
@api_client.unreserve_path(base_path, publishing_app)
end
end

it "raises an error if the reservation is with another app" do
Expand All @@ -90,9 +90,9 @@
},
)

assert_raises GdsApi::HTTPUnprocessableEntity do
@api_client.unreserve_path(base_path, publishing_app)
end
assert_raises GdsApi::HTTPUnprocessableEntity do
@api_client.unreserve_path(base_path, publishing_app)
end
end
end

Expand Down
28 changes: 28 additions & 0 deletions test/test_helpers/publishing_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,34 @@
let(:base_api_url) { Plek.current.find("publishing-api") }
let(:publishing_api) { GdsApi::PublishingApi.new(base_api_url) }

describe "#stub_publishing_api_unreserve_path" do
it "stubs the unreserve path API call" do
stub_publishing_api_unreserve_path("/foo", "myapp")
api_response = publishing_api.unreserve_path("/foo", "myapp")
assert_equal(api_response.code, 200)
end
end

describe "#stub_publishing_api_unreserve_path_not_found" do
it "stubs the unreserve path API call" do
stub_publishing_api_unreserve_path_not_found("/foo", "myapp")

assert_raises GdsApi::HTTPNotFound do
publishing_api.unreserve_path("/foo", "myapp")
end
end
end

describe "#stub_publishing_api_unreserve_path_invalid" do
it "stubs the unreserve path API call" do
stub_publishing_api_unreserve_path_invalid("/foo", "myapp")

assert_raises GdsApi::HTTPUnprocessableEntity do
publishing_api.unreserve_path("/foo", "myapp")
end
end
end

describe '#request_json_matching predicate' do
describe "nested required attribute" do
let(:matcher) { request_json_matching("a" => { "b" => 1 }) }
Expand Down

0 comments on commit c7be09a

Please sign in to comment.