debian-mirror-gitlab/spec/graphql/mutations/release_asset_links/delete_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

86 lines
2.9 KiB
Ruby
Raw Normal View History

2021-04-29 21:17:54 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe Mutations::ReleaseAssetLinks::Delete, feature_category: :release_orchestration do
2021-04-29 21:17:54 +05:30
include GraphqlHelpers
let_it_be(:project) { create(:project, :private, :repository) }
let_it_be_with_reload(:release) { create(:release, project: project) }
2021-09-30 23:02:18 +05:30
let_it_be(:reporter) { create(:user).tap { |u| project.add_reporter(u) } }
2021-04-29 21:17:54 +05:30
let_it_be(:developer) { create(:user).tap { |u| project.add_developer(u) } }
let_it_be(:maintainer) { create(:user).tap { |u| project.add_maintainer(u) } }
let_it_be_with_reload(:release_link) { create(:release_link, release: release) }
let(:mutation) { described_class.new(object: nil, context: { current_user: current_user }, field: nil) }
let(:mutation_arguments) { { id: release_link.to_global_id } }
describe '#resolve' do
subject(:resolve) do
mutation.resolve(**mutation_arguments)
end
let(:deleted_link) { subject[:link] }
context 'when the current user has access to delete the link' do
2021-09-30 23:02:18 +05:30
let(:current_user) { developer }
2021-04-29 21:17:54 +05:30
it 'deletes the link and returns it', :aggregate_failures do
expect(deleted_link).to eq(release_link)
expect(release.links).to be_empty
end
2021-09-30 23:02:18 +05:30
context 'with protected tag' do
context 'when user has access to the protected tag' do
let!(:protected_tag) { create(:protected_tag, :developers_can_create, name: '*', project: project) }
it 'does not have errors' do
subject
expect(resolve).to include(errors: [])
end
end
context 'when user does not have access to the protected tag' do
let!(:protected_tag) { create(:protected_tag, :maintainers_can_create, name: '*', project: project) }
it 'raises a resource access error' do
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end
end
2021-04-29 21:17:54 +05:30
context "when the link doesn't exist" do
2022-07-16 23:28:13 +05:30
let(:mutation_arguments) do
super().merge(id: global_id_of(id: non_existing_record_id, model_name: release_link.class.name))
2021-04-29 21:17:54 +05:30
end
it 'raises an error' do
2022-07-16 23:28:13 +05:30
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
2021-04-29 21:17:54 +05:30
end
end
2023-05-27 22:25:52 +05:30
context 'when destroy process fails' do
before do
allow_next_instance_of(::Releases::Links::DestroyService) do |service|
allow(service).to receive(:execute).and_return(ServiceResponse.error(message: 'error'))
end
end
it 'returns errors' do
expect(resolve).to include(errors: 'error')
end
end
2021-04-29 21:17:54 +05:30
end
context 'when the current user does not have access to delete the link' do
2021-09-30 23:02:18 +05:30
let(:current_user) { reporter }
2021-04-29 21:17:54 +05:30
it 'raises an error' do
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end
end
end