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')
-rw-r--r--spec/graphql/mutations/custom_emoji/destroy_spec.rb79
-rw-r--r--spec/graphql/mutations/customer_relations/organizations/create_spec.rb74
-rw-r--r--spec/graphql/mutations/customer_relations/organizations/update_spec.rb74
-rw-r--r--spec/graphql/mutations/dependency_proxy/image_ttl_group_policy/update_spec.rb110
4 files changed, 337 insertions, 0 deletions
diff --git a/spec/graphql/mutations/custom_emoji/destroy_spec.rb b/spec/graphql/mutations/custom_emoji/destroy_spec.rb
new file mode 100644
index 00000000000..4667812cc80
--- /dev/null
+++ b/spec/graphql/mutations/custom_emoji/destroy_spec.rb
@@ -0,0 +1,79 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Mutations::CustomEmoji::Destroy do
+ let_it_be(:group) { create(:group) }
+ let_it_be(:user) { create(:user) }
+ let_it_be_with_reload(:custom_emoji) { create(:custom_emoji, group: group) }
+
+ let(:args) { { id: custom_emoji.to_global_id } }
+ let(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) }
+
+ context 'field tests' do
+ subject { described_class }
+
+ it { is_expected.to have_graphql_arguments(:id) }
+ it { is_expected.to have_graphql_field(:custom_emoji) }
+ end
+
+ shared_examples 'does not delete custom emoji' do
+ it 'raises exception' do
+ expect { subject }
+ .to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ end
+ end
+
+ shared_examples 'deletes custom emoji' do
+ it 'returns deleted custom emoji' do
+ result = subject
+
+ expect(result[:custom_emoji][:name]).to eq(custom_emoji.name)
+ end
+ end
+
+ describe '#resolve' do
+ subject { mutation.resolve(**args) }
+
+ context 'when the user' do
+ context 'has no permissions' do
+ it_behaves_like 'does not delete custom emoji'
+ end
+
+ context 'when the user is developer and not the owner of custom emoji' do
+ before do
+ group.add_developer(user)
+ end
+
+ it_behaves_like 'does not delete custom emoji'
+ end
+ end
+
+ context 'when user' do
+ context 'is maintainer' do
+ before do
+ group.add_maintainer(user)
+ end
+
+ it_behaves_like 'deletes custom emoji'
+ end
+
+ context 'is owner' do
+ before do
+ group.add_owner(user)
+ end
+
+ it_behaves_like 'deletes custom emoji'
+ end
+
+ context 'is developer and creator of the emoji' do
+ before do
+ group.add_developer(user)
+ custom_emoji.update_attribute(:creator, user)
+ end
+
+ it_behaves_like 'deletes custom emoji'
+ end
+ end
+ end
+end
diff --git a/spec/graphql/mutations/customer_relations/organizations/create_spec.rb b/spec/graphql/mutations/customer_relations/organizations/create_spec.rb
new file mode 100644
index 00000000000..ab430b9240b
--- /dev/null
+++ b/spec/graphql/mutations/customer_relations/organizations/create_spec.rb
@@ -0,0 +1,74 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Mutations::CustomerRelations::Organizations::Create do
+ let_it_be(:user) { create(:user) }
+
+ let(:valid_params) do
+ attributes_for(:organization,
+ group: group,
+ description: 'This company is super important!',
+ default_rate: 1_000
+ )
+ end
+
+ describe 'create organizations mutation' do
+ describe '#resolve' do
+ subject(:resolve_mutation) do
+ described_class.new(object: nil, context: { current_user: user }, field: nil).resolve(
+ **valid_params,
+ group_id: group.to_global_id
+ )
+ end
+
+ context 'when the user does not have permission' do
+ let_it_be(:group) { create(:group) }
+
+ before do
+ group.add_guest(user)
+ end
+
+ it 'raises an error' do
+ expect { resolve_mutation }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ end
+ end
+
+ context 'when the user has permission' do
+ let_it_be(:group) { create(:group) }
+
+ before_all do
+ group.add_reporter(user)
+ end
+
+ context 'when the feature is disabled' do
+ before do
+ stub_feature_flags(customer_relations: false)
+ end
+
+ it 'raises an error' do
+ expect { resolve_mutation }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ end
+ end
+
+ context 'when the params are invalid' do
+ before do
+ valid_params[:name] = nil
+ end
+
+ it 'returns the validation error' do
+ expect(resolve_mutation[:errors]).to eq(["Name can't be blank"])
+ end
+ end
+
+ context 'when the user has permission to create an organization' do
+ it 'creates organization with correct values' do
+ expect(resolve_mutation[:organization]).to have_attributes(valid_params)
+ end
+ end
+ end
+ end
+ end
+
+ specify { expect(described_class).to require_graphql_authorizations(:admin_organization) }
+end
diff --git a/spec/graphql/mutations/customer_relations/organizations/update_spec.rb b/spec/graphql/mutations/customer_relations/organizations/update_spec.rb
new file mode 100644
index 00000000000..f5aa6c00301
--- /dev/null
+++ b/spec/graphql/mutations/customer_relations/organizations/update_spec.rb
@@ -0,0 +1,74 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Mutations::CustomerRelations::Organizations::Update do
+ let_it_be(:user) { create(:user) }
+ let_it_be(:name) { 'GitLab' }
+ let_it_be(:default_rate) { 1000.to_f }
+ let_it_be(:description) { 'VIP' }
+
+ let(:organization) { create(:organization, group: group) }
+ let(:attributes) do
+ {
+ id: organization.to_global_id,
+ name: name,
+ default_rate: default_rate,
+ description: description
+ }
+ end
+
+ describe '#resolve' do
+ subject(:resolve_mutation) do
+ described_class.new(object: nil, context: { current_user: user }, field: nil).resolve(
+ attributes
+ )
+ end
+
+ context 'when the user does not have permission to update an organization' do
+ let_it_be(:group) { create(:group) }
+
+ before do
+ group.add_guest(user)
+ end
+
+ it 'raises an error' do
+ expect { resolve_mutation }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ end
+ end
+
+ context 'when the organization does not exist' do
+ let_it_be(:group) { create(:group) }
+
+ it 'raises an error' do
+ attributes[:id] = 'gid://gitlab/CustomerRelations::Organization/999'
+
+ expect { resolve_mutation }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ end
+ end
+
+ context 'when the user has permission to update an organization' do
+ let_it_be(:group) { create(:group) }
+
+ before_all do
+ group.add_reporter(user)
+ end
+
+ it 'updates the organization with correct values' do
+ expect(resolve_mutation[:organization]).to have_attributes(attributes)
+ end
+
+ context 'when the feature is disabled' do
+ before do
+ stub_feature_flags(customer_relations: false)
+ end
+
+ it 'raises an error' do
+ expect { resolve_mutation }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ end
+ end
+ end
+ end
+
+ specify { expect(described_class).to require_graphql_authorizations(:admin_organization) }
+end
diff --git a/spec/graphql/mutations/dependency_proxy/image_ttl_group_policy/update_spec.rb b/spec/graphql/mutations/dependency_proxy/image_ttl_group_policy/update_spec.rb
new file mode 100644
index 00000000000..792e87f0d25
--- /dev/null
+++ b/spec/graphql/mutations/dependency_proxy/image_ttl_group_policy/update_spec.rb
@@ -0,0 +1,110 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Mutations::DependencyProxy::ImageTtlGroupPolicy::Update do
+ using RSpec::Parameterized::TableSyntax
+
+ let_it_be_with_reload(:group) { create(:group) }
+ let_it_be(:user) { create(:user) }
+
+ let(:params) { { group_path: group.full_path } }
+
+ specify { expect(described_class).to require_graphql_authorizations(:admin_dependency_proxy) }
+
+ describe '#resolve' do
+ subject { described_class.new(object: group, context: { current_user: user }, field: nil).resolve(**params) }
+
+ shared_examples 'returning a success' do
+ it 'returns the dependency proxy image ttl group policy with no errors' do
+ expect(subject).to eq(
+ dependency_proxy_image_ttl_policy: ttl_policy,
+ errors: []
+ )
+ end
+ end
+
+ shared_examples 'updating the dependency proxy image ttl policy' do
+ it_behaves_like 'updating the dependency proxy image ttl policy attributes',
+ from: { enabled: true, ttl: 90 },
+ to: { enabled: false, ttl: 2 }
+
+ it_behaves_like 'returning a success'
+
+ context 'with invalid params' do
+ let_it_be(:params) { { group_path: group.full_path, enabled: nil } }
+
+ it "doesn't create the dependency proxy image ttl policy" do
+ expect { subject }.not_to change { DependencyProxy::ImageTtlGroupPolicy.count }
+ end
+
+ it 'does not update' do
+ expect { subject }
+ .not_to change { ttl_policy.reload.enabled }
+ end
+
+ it 'returns an error' do
+ expect(subject).to eq(
+ dependency_proxy_image_ttl_policy: nil,
+ errors: ['Enabled is not included in the list']
+ )
+ end
+ end
+ end
+
+ shared_examples 'denying access to dependency proxy image ttl policy' do
+ it 'raises Gitlab::Graphql::Errors::ResourceNotAvailable' do
+ expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ end
+ end
+
+ before do
+ stub_config(dependency_proxy: { enabled: true })
+ end
+
+ context 'with existing dependency proxy image ttl policy' do
+ let_it_be(:ttl_policy) { create(:image_ttl_group_policy, group: group) }
+ let_it_be(:params) do
+ { group_path: group.full_path,
+ enabled: false,
+ ttl: 2 }
+ end
+
+ where(:user_role, :shared_examples_name) do
+ :maintainer | 'updating the dependency proxy image ttl policy'
+ :developer | 'updating the dependency proxy image ttl policy'
+ :reporter | 'denying access to dependency proxy image ttl policy'
+ :guest | 'denying access to dependency proxy image ttl policy'
+ :anonymous | 'denying access to dependency proxy image ttl policy'
+ end
+
+ with_them do
+ before do
+ group.send("add_#{user_role}", user) unless user_role == :anonymous
+ end
+
+ it_behaves_like params[:shared_examples_name]
+ end
+ end
+
+ context 'without existing dependency proxy image ttl policy' do
+ let_it_be(:ttl_policy) { group.dependency_proxy_image_ttl_policy }
+
+ where(:user_role, :shared_examples_name) do
+ :maintainer | 'creating the dependency proxy image ttl policy'
+ :developer | 'creating the dependency proxy image ttl policy'
+ :reporter | 'denying access to dependency proxy image ttl policy'
+ :guest | 'denying access to dependency proxy image ttl policy'
+ :anonymous | 'denying access to dependency proxy image ttl policy'
+ end
+
+ with_them do
+ before do
+ group.send("add_#{user_role}", user) unless user_role == :anonymous
+ end
+
+ it_behaves_like params[:shared_examples_name]
+ end
+ end
+ end
+end