Skip to content

Commit

Permalink
Merge pull request #1248 from alphagov/add-delete-asset-404-stub
Browse files Browse the repository at this point in the history
Added a new stub for attempting to delete a missing asset
  • Loading branch information
ryanb-gds committed Apr 11, 2024
2 parents b8ad90e + 316621f commit af3f7f7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,6 @@
# Unreleased
* Added stub for attempting to delete a missing asset from Asset Manager

# 95.0.1
* Update Pact specs to match the publishing-api [PR](https://github.com/alphagov/publishing-api/pull/2669)

Expand Down
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 af3f7f7

Please sign in to comment.