debian-mirror-gitlab/spec/graphql/mutations/container_repositories/destroy_spec.rb

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

61 lines
2 KiB
Ruby
Raw Normal View History

2021-01-29 00:20:46 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Mutations::ContainerRepositories::Destroy do
using RSpec::Parameterized::TableSyntax
let_it_be_with_reload(:container_repository) { create(:container_repository) }
let_it_be(:user) { create(:user) }
let(:project) { container_repository.project }
2022-07-16 23:28:13 +05:30
let(:id) { container_repository.to_global_id }
2021-01-29 00:20:46 +05:30
specify { expect(described_class).to require_graphql_authorizations(:destroy_container_image) }
describe '#resolve' do
subject do
described_class.new(object: nil, context: { current_user: user }, field: nil)
.resolve(id: id)
end
shared_examples 'destroying the container repository' do
2023-01-13 00:05:48 +05:30
it 'marks the repository as delete_scheduled' do
2021-01-29 00:20:46 +05:30
expect(::Packages::CreateEventService)
.to receive(:new).with(nil, user, event_name: :delete_repository, scope: :container).and_call_original
2023-01-13 00:05:48 +05:30
expect(DeleteContainerRepositoryWorker).not_to receive(:perform_async)
2021-01-29 00:20:46 +05:30
2023-06-20 00:43:36 +05:30
subject
2021-01-29 00:20:46 +05:30
expect(container_repository.reload.delete_scheduled?).to be true
end
end
shared_examples 'denying access to container respository' do
it 'raises an error' do
expect(DeleteContainerRepositoryWorker)
.not_to receive(:perform_async).with(user.id, container_repository.id)
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end
context 'with valid id' do
where(:user_role, :shared_examples_name) do
:maintainer | 'destroying the container repository'
:developer | 'destroying the container repository'
:reporter | 'denying access to container respository'
:guest | 'denying access to container respository'
:anonymous | 'denying access to container respository'
end
with_them do
before do
project.send("add_#{user_role}", user) unless user_role == :anonymous
end
it_behaves_like params[:shared_examples_name]
end
end
end
end