diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /spec/graphql/mutations/incident_management/timeline_event/destroy_spec.rb | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/graphql/mutations/incident_management/timeline_event/destroy_spec.rb')
-rw-r--r-- | spec/graphql/mutations/incident_management/timeline_event/destroy_spec.rb | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/spec/graphql/mutations/incident_management/timeline_event/destroy_spec.rb b/spec/graphql/mutations/incident_management/timeline_event/destroy_spec.rb new file mode 100644 index 00000000000..4dd7b2ccb14 --- /dev/null +++ b/spec/graphql/mutations/incident_management/timeline_event/destroy_spec.rb @@ -0,0 +1,66 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Mutations::IncidentManagement::TimelineEvent::Destroy do + let_it_be(:current_user) { create(:user) } + let_it_be(:project) { create(:project) } + let_it_be(:incident) { create(:incident, project: project) } + + let(:timeline_event) { create(:incident_management_timeline_event, incident: incident, project: project) } + let(:args) { { id: timeline_event.to_global_id } } + + specify { expect(described_class).to require_graphql_authorizations(:admin_incident_management_timeline_event) } + + describe '#resolve' do + subject(:resolve) { mutation_for(project, current_user).resolve(**args) } + + context 'when a user has permissions to delete timeline event' do + before do + project.add_developer(current_user) + end + + context 'when TimelineEvents::DestroyService responds with success' do + it 'returns the timeline event with no errors' do + expect(resolve).to eq( + timeline_event: timeline_event, + errors: [] + ) + end + end + + context 'when TimelineEvents::DestroyService responds with an error' do + before do + allow_next_instance_of(::IncidentManagement::TimelineEvents::DestroyService) do |service| + allow(service) + .to receive(:execute) + .and_return(ServiceResponse.error(payload: { timeline_event: nil }, message: 'An error has occurred')) + end + end + + it 'returns errors' do + expect(resolve).to eq( + timeline_event: nil, + errors: ['An error has occurred'] + ) + end + end + end + + context 'when a user has no permissions to delete timeline event' do + before do + project.add_guest(current_user) + end + + it 'raises an error' do + expect { resolve }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + end + end + end + + private + + def mutation_for(project, user) + described_class.new(object: project, context: { current_user: user }, field: nil) + end +end |