From 003a9f2e7bee8c9f6815d77df441bc1a005355d2 Mon Sep 17 00:00:00 2001 From: Ryan Brown Date: Fri, 5 Apr 2024 10:31:00 +0100 Subject: [PATCH] Added a new stub for attempting to delete a missing asset This is needed for testing how publishing applications react to attempting to delete a missing asset. At the moment they are not handling not found errors, meaning that the state of the publishing application remains out of sync with asset manager and causing other logical issues. This commit also adds some test coverage for other asset deletion stubs and makes byebug available in the testing runtime. --- lib/gds_api/test_helpers/asset_manager.rb | 5 ++++ test/test_helpers/asset_manager_test.rb | 35 +++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/lib/gds_api/test_helpers/asset_manager.rb b/lib/gds_api/test_helpers/asset_manager.rb index bf3f788f..6c40ed7e 100644 --- a/lib/gds_api/test_helpers/asset_manager.rb +++ b/lib/gds_api/test_helpers/asset_manager.rb @@ -92,6 +92,11 @@ def stub_asset_manager_delete_asset(asset_id, body = {}) .to_return(body: body.to_json, status: 200) end + def stub_asset_manager_delete_asset_missing(asset_id) + stub_request(:delete, "#{ASSET_MANAGER_ENDPOINT}/assets/#{asset_id}") + .to_return(status: 404) + end + def stub_asset_manager_delete_asset_failure(asset_id) stub_request(:delete, "#{ASSET_MANAGER_ENDPOINT}/assets/#{asset_id}").to_return(status: 500) end diff --git a/test/test_helpers/asset_manager_test.rb b/test/test_helpers/asset_manager_test.rb index 36f774df..d9393756 100644 --- a/test/test_helpers/asset_manager_test.rb +++ b/test/test_helpers/asset_manager_test.rb @@ -64,4 +64,39 @@ end end end + + describe "#stub_asset_manager_delete_asset" do + it "returns an ok response and the provided body" do + asset_id = "some-asset-id" + body = { key: "value" } + stub_asset_manager_delete_asset(asset_id, body) + + response = stub_asset_manager.delete_asset(asset_id) + + assert_equal 200, response.code + assert_equal body[:key], response["key"] + end + end + + describe "#stub_asset_manager_delete_asset_missing" do + it "raises a not found error" do + asset_id = "some-asset-id" + stub_asset_manager_delete_asset_missing(asset_id) + + assert_raises GdsApi::HTTPNotFound do + stub_asset_manager.delete_asset(asset_id) + end + end + end + + describe "#stub_asset_manager_delete_asset_failure" do + it "raises an internal server error" do + asset_id = "some-asset-id" + stub_asset_manager_delete_asset_failure(asset_id) + + assert_raises GdsApi::HTTPInternalServerError do + stub_asset_manager.delete_asset(asset_id) + end + end + end end