Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/graphql/mutations/timelogs/delete_spec.rb')
-rw-r--r--spec/graphql/mutations/timelogs/delete_spec.rb93
1 files changed, 93 insertions, 0 deletions
diff --git a/spec/graphql/mutations/timelogs/delete_spec.rb b/spec/graphql/mutations/timelogs/delete_spec.rb
new file mode 100644
index 00000000000..f4a258e0f78
--- /dev/null
+++ b/spec/graphql/mutations/timelogs/delete_spec.rb
@@ -0,0 +1,93 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Mutations::Timelogs::Delete do
+ include GraphqlHelpers
+
+ let_it_be(:author) { create(:user) }
+ let_it_be(:maintainer) { create(:user) }
+ let_it_be(:administrator) { create(:user, :admin) }
+ let_it_be(:project) { create(:project, :public) }
+ let_it_be(:issue) { create(:issue, project: project) }
+ let_it_be_with_reload(:timelog) { create(:timelog, user: author, issue: issue, time_spent: 1800) }
+
+ let(:mutation) { described_class.new(object: nil, context: { current_user: current_user }, field: nil) }
+ let(:timelog_id) { global_id_of(timelog) }
+ let(:mutation_arguments) { { id: timelog_id } }
+
+ describe '#resolve' do
+ subject(:resolve) do
+ mutation.resolve(**mutation_arguments)
+ end
+
+ context 'when the timelog id is not valid' do
+ let(:current_user) { author }
+ let(:timelog_id) { global_id_of(model_name: 'Timelog', id: non_existing_record_id) }
+
+ it 'raises Gitlab::Graphql::Errors::ResourceNotAvailable' do
+ expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ end
+ end
+
+ context 'when the current user is not the timelog\'s author, not a maintainer and not an admin' do
+ let(:current_user) { create(:user) }
+
+ it 'raises Gitlab::Graphql::Errors::ResourceNotAvailable' do
+ expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ end
+ end
+
+ context 'when the current user is the timelog\'s author' do
+ let(:current_user) { author }
+
+ it 'deletes the timelog' do
+ expect { subject }.to change { Timelog.count }.by(-1)
+ end
+
+ it 'returns the deleted timelog' do
+ expect(subject[:timelog]).to eq(timelog)
+ end
+
+ it 'returns no errors' do
+ expect(subject[:errors]).to be_empty
+ end
+ end
+
+ context 'when the current user is not the timelog\'s author but a maintainer of the project' do
+ let(:current_user) { maintainer }
+
+ before do
+ project.add_maintainer(maintainer)
+ end
+
+ it 'deletes the timelog' do
+ expect { subject }.to change { Timelog.count }.by(-1)
+ end
+
+ it 'returns the deleted timelog' do
+ expect(subject[:timelog]).to eq(timelog)
+ end
+
+ it 'returns no errors' do
+ expect(subject[:errors]).to be_empty
+ end
+ end
+
+ context 'when the current user is not the timelog\'s author, not a maintainer but an admin', :enable_admin_mode do
+ let(:current_user) { administrator }
+
+ it 'deletes the timelog' do
+ expect { subject }.to change { Timelog.count }.by(-1)
+ end
+
+ it 'returns the deleted timelog' do
+ expect(subject[:timelog]).to eq(timelog)
+ end
+
+ it 'returns no errors' do
+ expect(subject[:errors]).to be_empty
+ end
+ end
+ end
+end