From 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Mon, 19 Sep 2022 23:18:09 +0000 Subject: Add latest changes from gitlab-org/gitlab@15-4-stable-ee --- .../boards/issues/issue_move_list_spec.rb | 14 ++++ .../api/graphql/mutations/branches/create_spec.rb | 89 +++++++++++++++++----- .../api/graphql/mutations/ci/job/destroy_spec.rb | 54 +++++++++++++ .../mutations/ci/job_artifact/destroy_spec.rb | 47 ++++++++++++ .../graphql/mutations/custom_emoji/create_spec.rb | 14 ++++ .../graphql/mutations/custom_emoji/destroy_spec.rb | 14 ++++ .../timeline_event/promote_from_note_spec.rb | 3 +- .../mutations/merge_requests/set_assignees_spec.rb | 10 +++ .../api/graphql/mutations/releases/update_spec.rb | 11 ++- 9 files changed, 234 insertions(+), 22 deletions(-) create mode 100644 spec/requests/api/graphql/mutations/ci/job/destroy_spec.rb create mode 100644 spec/requests/api/graphql/mutations/ci/job_artifact/destroy_spec.rb (limited to 'spec/requests/api/graphql/mutations') diff --git a/spec/requests/api/graphql/mutations/boards/issues/issue_move_list_spec.rb b/spec/requests/api/graphql/mutations/boards/issues/issue_move_list_spec.rb index 46ec22e7ef8..06093e9f7c2 100644 --- a/spec/requests/api/graphql/mutations/boards/issues/issue_move_list_spec.rb +++ b/spec/requests/api/graphql/mutations/boards/issues/issue_move_list_spec.rb @@ -100,6 +100,20 @@ RSpec.describe 'Reposition and move issue within board lists' do expect(response_issue['labels']['edges'][0]['node']['title']).to eq(testing.title) end end + + context 'when moving an issue using position_in_list' do + let(:issue_move_params) { { from_list_id: list1.id, to_list_id: list2.id, position_in_list: 0 } } + + it 'repositions an issue' do + post_graphql_mutation(mutation(params), current_user: current_user) + + expect(response).to have_gitlab_http_status(:success) + response_issue = json_response['data'][mutation_result_identifier]['issue'] + expect(response_issue['iid']).to eq(issue1.iid.to_s) + expect(response_issue['labels']['edges'][0]['node']['title']).to eq(testing.title) + expect(response_issue['relativePosition']).to be < existing_issue1.relative_position + end + end end context 'when user has no access to resources' do diff --git a/spec/requests/api/graphql/mutations/branches/create_spec.rb b/spec/requests/api/graphql/mutations/branches/create_spec.rb index 6a098002963..9ee2f41e8fc 100644 --- a/spec/requests/api/graphql/mutations/branches/create_spec.rb +++ b/spec/requests/api/graphql/mutations/branches/create_spec.rb @@ -5,26 +5,18 @@ require 'spec_helper' RSpec.describe 'Creation of a new branch' do include GraphqlHelpers + let_it_be(:group) { create(:group, :public) } let_it_be(:current_user) { create(:user) } - let_it_be(:project) { create(:project, :public, :empty_repo) } let(:input) { { project_path: project.full_path, name: new_branch, ref: ref } } - let(:new_branch) { 'new_branch' } + let(:new_branch) { "new_branch_#{SecureRandom.hex(4)}" } let(:ref) { 'master' } let(:mutation) { graphql_mutation(:create_branch, input) } let(:mutation_response) { graphql_mutation_response(:create_branch) } - context 'the user is not allowed to create a branch' do - it_behaves_like 'a mutation that returns a top-level access error' - end - - context 'when user has permissions to create a branch' do - before do - project.add_developer(current_user) - end - - it 'creates a new branch' do + shared_examples 'creates a new branch' do + specify do post_graphql_mutation(mutation, current_user: current_user) expect(response).to have_gitlab_http_status(:success) @@ -33,14 +25,75 @@ RSpec.describe 'Creation of a new branch' do 'commit' => a_hash_including('id') ) end + end + + context 'when project is public' do + let_it_be(:project) { create(:project, :public, :empty_repo) } + + context 'when user is not allowed to create a branch' do + it_behaves_like 'a mutation that returns a top-level access error' + end + + context 'when user is a direct project member' do + context 'and user is a developer' do + before do + project.add_developer(current_user) + end + + it_behaves_like 'creates a new branch' + + context 'when ref is not correct' do + err_msg = 'Failed to create branch \'another_branch\': invalid reference name \'unknown\'' + let(:new_branch) { 'another_branch' } + let(:ref) { 'unknown' } + + it_behaves_like 'a mutation that returns errors in the response', errors: [err_msg] + end + end + end + + context 'when user is an inherited member from the group' do + context 'when project has a private repository' do + let_it_be(:project) { create(:project, :public, :empty_repo, :repository_private, group: group) } + + context 'and user is a guest' do + before do + group.add_guest(current_user) + end + + it_behaves_like 'a mutation that returns a top-level access error' + end + + context 'and user is a developer' do + before do + group.add_developer(current_user) + end + + it_behaves_like 'creates a new branch' + end + end + end + end + + context 'when project is private' do + let_it_be(:project) { create(:project, :private, :empty_repo, group: group) } + + context 'when user is an inherited member from the group' do + context 'and user is a guest' do + before do + group.add_guest(current_user) + end + + it_behaves_like 'a mutation that returns a top-level access error' + end - context 'when ref is not correct' do - err_msg = 'Failed to create branch \'another_branch\': invalid reference name \'unknown\'' - let(:new_branch) { 'another_branch' } - let(:ref) { 'unknown' } + context 'and user is a developer' do + before do + group.add_developer(current_user) + end - it_behaves_like 'a mutation that returns errors in the response', - errors: [err_msg] + it_behaves_like 'creates a new branch' + end end end end diff --git a/spec/requests/api/graphql/mutations/ci/job/destroy_spec.rb b/spec/requests/api/graphql/mutations/ci/job/destroy_spec.rb new file mode 100644 index 00000000000..5855eb6bb51 --- /dev/null +++ b/spec/requests/api/graphql/mutations/ci/job/destroy_spec.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'JobArtifactsDestroy' do + include GraphqlHelpers + + let_it_be(:user) { create(:user) } + let_it_be(:job) { create(:ci_build) } + + let(:mutation) do + variables = { + id: job.to_global_id.to_s + } + graphql_mutation(:job_artifacts_destroy, variables, <<~FIELDS) + job { + name + } + destroyedArtifactsCount + errors + FIELDS + end + + before do + create(:ci_job_artifact, :archive, job: job) + create(:ci_job_artifact, :junit, job: job) + end + + it 'returns an error if the user is not allowed to destroy the job artifacts' do + post_graphql_mutation(mutation, current_user: user) + + expect(graphql_errors).not_to be_empty + expect(job.reload.job_artifacts.count).to be(2) + end + + it 'destroys the job artifacts and returns the expected data' do + job.project.add_maintainer(user) + expected_data = { + 'jobArtifactsDestroy' => { + 'errors' => [], + 'destroyedArtifactsCount' => 2, + 'job' => { + 'name' => job.name + } + } + } + + post_graphql_mutation(mutation, current_user: user) + + expect(response).to have_gitlab_http_status(:success) + expect(graphql_data).to eq(expected_data) + expect(job.reload.job_artifacts.count).to be(0) + end +end diff --git a/spec/requests/api/graphql/mutations/ci/job_artifact/destroy_spec.rb b/spec/requests/api/graphql/mutations/ci/job_artifact/destroy_spec.rb new file mode 100644 index 00000000000..a5ec9ea343d --- /dev/null +++ b/spec/requests/api/graphql/mutations/ci/job_artifact/destroy_spec.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'ArtifactDestroy' do + include GraphqlHelpers + + let(:user) { create(:user) } + let(:artifact) { create(:ci_job_artifact) } + + let(:mutation) do + variables = { + id: artifact.to_global_id.to_s + } + graphql_mutation(:artifact_destroy, variables, 'errors') + end + + it 'returns an error if the user is not allowed to destroy the artifact' do + post_graphql_mutation(mutation, current_user: user) + + expect(graphql_errors).not_to be_empty + end + + context 'when the user is allowed to destroy the artifact' do + before do + artifact.job.project.add_maintainer(user) + end + + it 'destroys the artifact' do + post_graphql_mutation(mutation, current_user: user) + + expect(response).to have_gitlab_http_status(:success) + expect { artifact.reload }.to raise_error(ActiveRecord::RecordNotFound) + end + + it 'returns error if destory fails' do + allow_next_found_instance_of(Ci::JobArtifact) do |instance| + allow(instance).to receive(:destroy).and_return(false) + allow(instance).to receive_message_chain(:errors, :full_messages).and_return(['cannot be removed']) + end + + post_graphql_mutation(mutation, current_user: user) + + expect(graphql_data_at(:artifact_destroy, :errors)).to contain_exactly('cannot be removed') + end + end +end diff --git a/spec/requests/api/graphql/mutations/custom_emoji/create_spec.rb b/spec/requests/api/graphql/mutations/custom_emoji/create_spec.rb index c91437fa355..66facdebe78 100644 --- a/spec/requests/api/graphql/mutations/custom_emoji/create_spec.rb +++ b/spec/requests/api/graphql/mutations/custom_emoji/create_spec.rb @@ -39,5 +39,19 @@ RSpec.describe 'Creation of a new Custom Emoji' do expect(gql_response['customEmoji']['name']).to eq(attributes[:name]) expect(gql_response['customEmoji']['url']).to eq(attributes[:url]) end + + context 'when the custom_emoji feature flag is disabled' do + before do + stub_feature_flags(custom_emoji: false) + end + + it 'does nothing and returns and error' do + expect do + post_graphql_mutation(mutation, current_user: current_user) + end.to not_change(CustomEmoji, :count) + + expect_graphql_errors_to_include('Custom emoji feature is disabled') + end + end end end diff --git a/spec/requests/api/graphql/mutations/custom_emoji/destroy_spec.rb b/spec/requests/api/graphql/mutations/custom_emoji/destroy_spec.rb index 07fd57a2cee..7d25206e617 100644 --- a/spec/requests/api/graphql/mutations/custom_emoji/destroy_spec.rb +++ b/spec/requests/api/graphql/mutations/custom_emoji/destroy_spec.rb @@ -68,6 +68,20 @@ RSpec.describe 'Deletion of custom emoji' do end it_behaves_like 'deletes custom emoji' + + context 'when the custom_emoji feature flag is disabled' do + before do + stub_feature_flags(custom_emoji: false) + end + + it_behaves_like 'does not delete custom emoji' + + it 'returns an error' do + post_graphql_mutation(mutation, current_user: current_user) + + expect_graphql_errors_to_include('Custom emoji feature is disabled') + end + end end end end diff --git a/spec/requests/api/graphql/mutations/incident_management/timeline_event/promote_from_note_spec.rb b/spec/requests/api/graphql/mutations/incident_management/timeline_event/promote_from_note_spec.rb index 9272e218172..85eaec90f47 100644 --- a/spec/requests/api/graphql/mutations/incident_management/timeline_event/promote_from_note_spec.rb +++ b/spec/requests/api/graphql/mutations/incident_management/timeline_event/promote_from_note_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' RSpec.describe 'Promote an incident timeline event from a comment' do include GraphqlHelpers + include NotesHelper let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project) } @@ -53,7 +54,7 @@ RSpec.describe 'Promote an incident timeline event from a comment' do 'promotedFromNote' => { 'id' => comment.to_global_id.to_s }, - 'note' => comment.note, + 'note' => "@#{comment.author.username} [commented](#{noteable_note_url(comment)}): '#{comment.note}'", 'action' => 'comment', 'editable' => true, 'occurredAt' => comment.created_at.iso8601 diff --git a/spec/requests/api/graphql/mutations/merge_requests/set_assignees_spec.rb b/spec/requests/api/graphql/mutations/merge_requests/set_assignees_spec.rb index 608b36e4f15..8cec5867aca 100644 --- a/spec/requests/api/graphql/mutations/merge_requests/set_assignees_spec.rb +++ b/spec/requests/api/graphql/mutations/merge_requests/set_assignees_spec.rb @@ -93,6 +93,16 @@ RSpec.describe 'Setting assignees of a merge request', :assume_throttled do expect(response).to have_gitlab_http_status(:success) expect(mutation_assignee_nodes).to match_array(expected_result) end + + it 'triggers webhooks', :sidekiq_inline do + hook = create(:project_hook, merge_requests_events: true, project: merge_request.project) + + expect(WebHookWorker).to receive(:perform_async).with(hook.id, anything, 'merge_request_hooks', anything) + + post_graphql_mutation(mutation, current_user: current_user) + + expect(response).to have_gitlab_http_status(:success) + end end context 'when passing an empty list of assignees' do diff --git a/spec/requests/api/graphql/mutations/releases/update_spec.rb b/spec/requests/api/graphql/mutations/releases/update_spec.rb index 33d4e57904c..240db764f40 100644 --- a/spec/requests/api/graphql/mutations/releases/update_spec.rb +++ b/spec/requests/api/graphql/mutations/releases/update_spec.rb @@ -22,9 +22,14 @@ RSpec.describe 'Updating an existing release' do let_it_be(:milestones) { [milestone_12_3, milestone_12_4] } let_it_be(:release) do - create(:release, project: project, tag: tag_name, name: name, - description: description, released_at: Time.parse(released_at).utc, - created_at: Time.parse(created_at).utc, milestones: milestones) + create(:release, + project: project, + tag: tag_name, + name: name, + description: description, + released_at: Time.parse(released_at).utc, + created_at: Time.parse(created_at).utc, + milestones: milestones) end let(:mutation_name) { :release_update } -- cgit v1.2.3