Skip to content

Commit

Permalink
Added a new stub for attempting to delete a missing asset
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ryanb-gds committed Apr 8, 2024
1 parent 7097910 commit 003a9f2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/gds_api/test_helpers/asset_manager.rb
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions test/test_helpers/asset_manager_test.rb
Expand Up @@ -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

0 comments on commit 003a9f2

Please sign in to comment.