diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 11:43:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 11:43:02 +0300 |
commit | d9ab72d6080f594d0b3cae15f14b3ef2c6c638cb (patch) | |
tree | 2341ef426af70ad1e289c38036737e04b0aa5007 /spec/requests/api/graphql/mutations | |
parent | d6e514dd13db8947884cd58fe2a9c2a063400a9b (diff) |
Add latest changes from gitlab-org/gitlab@14-4-stable-eev14.4.0-rc42
Diffstat (limited to 'spec/requests/api/graphql/mutations')
6 files changed, 204 insertions, 2 deletions
diff --git a/spec/requests/api/graphql/mutations/ci/runners_registration_token/reset_spec.rb b/spec/requests/api/graphql/mutations/ci/runners_registration_token/reset_spec.rb index 07b05ead651..0fd8fdc3f59 100644 --- a/spec/requests/api/graphql/mutations/ci/runners_registration_token/reset_spec.rb +++ b/spec/requests/api/graphql/mutations/ci/runners_registration_token/reset_spec.rb @@ -89,7 +89,7 @@ RSpec.describe 'RunnersRegistrationTokenReset' do end include_context 'when authorized', 'group' do - let_it_be(:user) { create_default(:group_member, :maintainer, user: create(:user), group: group ).user } + let_it_be(:user) { create_default(:group_member, :owner, user: create(:user), group: group ).user } def get_token group.reload.runners_token diff --git a/spec/requests/api/graphql/mutations/clusters/agent_tokens/agent_tokens/create_spec.rb b/spec/requests/api/graphql/mutations/clusters/agent_tokens/agent_tokens/create_spec.rb new file mode 100644 index 00000000000..aac8eb22771 --- /dev/null +++ b/spec/requests/api/graphql/mutations/clusters/agent_tokens/agent_tokens/create_spec.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Create a new cluster agent token' do + include GraphqlHelpers + + let_it_be(:cluster_agent) { create(:cluster_agent) } + let_it_be(:current_user) { create(:user) } + + let(:description) { 'create token' } + let(:name) { 'token name' } + let(:mutation) do + graphql_mutation( + :cluster_agent_token_create, + { cluster_agent_id: cluster_agent.to_global_id.to_s, description: description, name: name } + ) + end + + def mutation_response + graphql_mutation_response(:cluster_agent_token_create) + end + + context 'without user permissions' do + it_behaves_like 'a mutation that returns top-level errors', + errors: ["The resource that you are attempting to access does not exist "\ + "or you don't have permission to perform this action"] + + it 'does not create a token' do + expect { post_graphql_mutation(mutation, current_user: current_user) }.not_to change(Clusters::AgentToken, :count) + end + end + + context 'with project permissions' do + before do + cluster_agent.project.add_maintainer(current_user) + end + + it 'creates a new token', :aggregate_failures do + expect { post_graphql_mutation(mutation, current_user: current_user) }.to change { Clusters::AgentToken.count }.by(1) + expect(mutation_response['errors']).to eq([]) + end + + it 'returns token information', :aggregate_failures do + post_graphql_mutation(mutation, current_user: current_user) + + expect(mutation_response['secret']).not_to be_nil + expect(mutation_response.dig('token', 'description')).to eq(description) + expect(mutation_response.dig('token', 'name')).to eq(name) + end + end +end diff --git a/spec/requests/api/graphql/mutations/clusters/agents/create_spec.rb b/spec/requests/api/graphql/mutations/clusters/agents/create_spec.rb new file mode 100644 index 00000000000..c2ef2362d66 --- /dev/null +++ b/spec/requests/api/graphql/mutations/clusters/agents/create_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Create a new cluster agent' do + include GraphqlHelpers + + let(:project) { create(:project, :public, :repository) } + let(:project_name) { 'agent-test' } + let(:current_user) { create(:user) } + + let(:mutation) do + graphql_mutation( + :create_cluster_agent, + { project_path: project.full_path, name: project_name } + ) + end + + def mutation_response + graphql_mutation_response(:create_cluster_agent) + end + + context 'without project permissions' do + it_behaves_like 'a mutation that returns a top-level access error' + + it 'does not create cluster agent' do + expect { post_graphql_mutation(mutation, current_user: current_user) }.not_to change(Clusters::Agent, :count) + end + end + + context 'with user permissions' do + before do + project.add_maintainer(current_user) + end + + it 'creates a new cluster agent', :aggregate_failures do + expect { post_graphql_mutation(mutation, current_user: current_user) }.to change { Clusters::Agent.count }.by(1) + expect(mutation_response.dig('clusterAgent', 'name')).to eq(project_name) + expect(mutation_response['errors']).to eq([]) + end + end +end diff --git a/spec/requests/api/graphql/mutations/clusters/agents/delete_spec.rb b/spec/requests/api/graphql/mutations/clusters/agents/delete_spec.rb new file mode 100644 index 00000000000..5f6822223ca --- /dev/null +++ b/spec/requests/api/graphql/mutations/clusters/agents/delete_spec.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Delete a cluster agent' do + include GraphqlHelpers + + let(:cluster_agent) { create(:cluster_agent) } + let(:project) { cluster_agent.project } + let(:current_user) { create(:user) } + + let(:mutation) do + graphql_mutation( + :cluster_agent_delete, + { id: cluster_agent.to_global_id.uri } + ) + end + + def mutation_response + graphql_mutation_response(:cluster_agent_delete) + end + + context 'without project permissions' do + it_behaves_like 'a mutation that returns top-level errors', + errors: ['The resource that you are attempting to access does not exist '\ + 'or you don\'t have permission to perform this action'] + + it 'does not delete cluster agent' do + expect { cluster_agent.reload }.not_to raise_error(ActiveRecord::RecordNotFound) + end + end + + context 'with project permissions' do + before do + project.add_maintainer(current_user) + end + + it 'deletes a cluster agent', :aggregate_failures do + expect { post_graphql_mutation(mutation, current_user: current_user) }.to change { Clusters::Agent.count }.by(-1) + expect(mutation_response['errors']).to eq([]) + end + end +end diff --git a/spec/requests/api/graphql/mutations/dependency_proxy/group_settings/update_spec.rb b/spec/requests/api/graphql/mutations/dependency_proxy/group_settings/update_spec.rb new file mode 100644 index 00000000000..f05bf23ad27 --- /dev/null +++ b/spec/requests/api/graphql/mutations/dependency_proxy/group_settings/update_spec.rb @@ -0,0 +1,65 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Updating the dependency proxy group settings' do + include GraphqlHelpers + using RSpec::Parameterized::TableSyntax + + let_it_be(:user) { create(:user) } + + let(:params) do + { + group_path: group.full_path, + enabled: false + } + end + + let(:mutation) do + graphql_mutation(:update_dependency_proxy_settings, params) do + <<~QL + dependencyProxySetting { + enabled + } + errors + QL + end + end + + let(:mutation_response) { graphql_mutation_response(:update_dependency_proxy_settings) } + let(:group_settings) { mutation_response['dependencyProxySetting'] } + + before do + stub_config(dependency_proxy: { enabled: true }) + end + + describe 'post graphql mutation' do + subject { post_graphql_mutation(mutation, current_user: user) } + + let_it_be_with_reload(:group) { create(:group) } + let_it_be_with_reload(:group_settings) { create(:dependency_proxy_group_setting, group: group) } + + context 'without permission' do + it 'returns no response' do + subject + + expect(response).to have_gitlab_http_status(:success) + expect(mutation_response).to be_nil + end + end + + context 'with permission' do + before do + group.add_developer(user) + end + + it 'returns the updated dependency proxy settings', :aggregate_failures do + subject + + expect(response).to have_gitlab_http_status(:success) + expect(mutation_response['errors']).to be_empty + expect(group_settings[:enabled]).to eq(false) + end + end + end +end 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 dec9afd1310..608b36e4f15 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 @@ -115,7 +115,7 @@ RSpec.describe 'Setting assignees of a merge request', :assume_throttled do context 'when passing append as true' do let(:mode) { Types::MutationOperationModeEnum.enum[:append] } let(:input) { { assignee_usernames: [assignee2.username], operation_mode: mode } } - let(:db_query_limit) { 21 } + let(:db_query_limit) { 22 } before do # In CE, APPEND is a NOOP as you can't have multiple assignees |