From bc4eaa72d80b20bdadb5ea7fa8688e9898d4e18b Mon Sep 17 00:00:00 2001 From: Ben Thorner Date: Tue, 19 Mar 2019 12:09:28 +0000 Subject: [PATCH] Make publishing_app optional in unreserve stub This reduces the amount of boilerplate we need to write when testing against this feature. --- lib/gds_api/test_helpers/publishing_api.rb | 6 +++--- test/test_helpers/publishing_api_test.rb | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/gds_api/test_helpers/publishing_api.rb b/lib/gds_api/test_helpers/publishing_api.rb index 96350408..bc860fab 100644 --- a/lib/gds_api/test_helpers/publishing_api.rb +++ b/lib/gds_api/test_helpers/publishing_api.rb @@ -11,15 +11,15 @@ module PublishingApi PUBLISHING_API_ENDPOINT = Plek.current.find('publishing-api') - def stub_publishing_api_unreserve_path(base_path, publishing_app) + 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) + 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) + def stub_publishing_api_unreserve_path_invalid(base_path, publishing_app = /.*/) stub_publishing_api_unreserve_path_with_code(base_path, publishing_app, 422) end diff --git a/test/test_helpers/publishing_api_test.rb b/test/test_helpers/publishing_api_test.rb index 83987d93..bda872a9 100644 --- a/test/test_helpers/publishing_api_test.rb +++ b/test/test_helpers/publishing_api_test.rb @@ -13,6 +13,12 @@ api_response = publishing_api.unreserve_path("/foo", "myapp") assert_equal(api_response.code, 200) end + + it "stubs for any app if not specified" do + stub_publishing_api_unreserve_path("/foo") + 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 @@ -23,6 +29,14 @@ publishing_api.unreserve_path("/foo", "myapp") end end + + it "stubs for any app if not specified" do + stub_publishing_api_unreserve_path_not_found("/foo") + + assert_raises GdsApi::HTTPNotFound do + publishing_api.unreserve_path("/foo", "myapp") + end + end end describe "#stub_publishing_api_unreserve_path_invalid" do @@ -33,6 +47,14 @@ publishing_api.unreserve_path("/foo", "myapp") end end + + it "stubs for any app if not specified" do + stub_publishing_api_unreserve_path_invalid("/foo") + + assert_raises GdsApi::HTTPUnprocessableEntity do + publishing_api.unreserve_path("/foo", "myapp") + end + end end describe '#request_json_matching predicate' do