Fix snippet repository storage move API when snippet does not exist

parent dc288940
---
title: Fix snippet repository storage move API when snippet does not exist
merge_request: 53211
author:
type: fixed
......@@ -58,9 +58,14 @@ module API
resource :snippets do
helpers do
def user_snippet
Snippet.find_by(id: params[:id]) # rubocop: disable CodeReuse/ActiveRecord
@user_snippet ||= Snippet.find_by(id: params[:id]) # rubocop: disable CodeReuse/ActiveRecord
end
end
before do
not_found!('Snippet') unless user_snippet
end
desc 'Get a list of all snippets repository storage moves' do
detail 'This feature was introduced in GitLab 13.8.'
success Entities::SnippetRepositoryStorageMove
......
......@@ -85,14 +85,37 @@ RSpec.shared_examples 'repository_storage_moves API' do |container_type|
end
describe "GET /#{container_type}/:id/repository_storage_moves" do
it_behaves_like 'get container repository storage move list' do
let(:url) { "/#{container_type}/#{container.id}/repository_storage_moves" }
let(:container_id) { container.id }
let(:url) { "/#{container_type}/#{container_id}/repository_storage_moves" }
it_behaves_like 'get container repository storage move list'
context 'non-existent container' do
let(:container_id) { non_existing_record_id }
it 'returns not found' do
get api(url, user)
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
describe "GET /#{container_type}/:id/repository_storage_moves/:repository_storage_move_id" do
it_behaves_like 'get single container repository storage move' do
let(:url) { "/#{container_type}/#{container.id}/repository_storage_moves/#{repository_storage_move_id}" }
let(:container_id) { container.id }
let(:url) { "/#{container_type}/#{container_id}/repository_storage_moves/#{repository_storage_move_id}" }
it_behaves_like 'get single container repository storage move'
context 'non-existent container' do
let(:container_id) { non_existing_record_id }
let(:repository_storage_move_id) { storage_move.id }
it 'returns not found' do
get api(url, user)
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
......@@ -109,7 +132,8 @@ RSpec.shared_examples 'repository_storage_moves API' do |container_type|
end
describe "POST /#{container_type}/:id/repository_storage_moves" do
let(:url) { "/#{container_type}/#{container.id}/repository_storage_moves" }
let(:container_id) { container.id }
let(:url) { "/#{container_type}/#{container_id}/repository_storage_moves" }
let(:destination_storage_name) { 'test_second_storage' }
def create_container_repository_storage_move
......@@ -154,6 +178,16 @@ RSpec.shared_examples 'repository_storage_moves API' do |container_type|
expect(json_response['destination_storage_name']).to be_present
end
end
context 'when container does not exist' do
let(:container_id) { non_existing_record_id }
it 'returns not found' do
create_container_repository_storage_move
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
describe "POST /#{container_type.singularize}_repository_storage_moves" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment