diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 13:18:24 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 13:18:24 +0000 |
commit | 0653e08efd039a5905f3fa4f6e9cef9f5d2f799c (patch) | |
tree | 4dcc884cf6d81db44adae4aa99f8ec1233a41f55 /spec/graphql/mutations/customer_relations | |
parent | 744144d28e3e7fddc117924fef88de5d9674fe4c (diff) | |
download | gitlab-ce-0653e08efd039a5905f3fa4f6e9cef9f5d2f799c.tar.gz |
Add latest changes from gitlab-org/gitlab@14-3-stable-eev14.3.0-rc42
Diffstat (limited to 'spec/graphql/mutations/customer_relations')
-rw-r--r-- | spec/graphql/mutations/customer_relations/organizations/create_spec.rb | 74 | ||||
-rw-r--r-- | spec/graphql/mutations/customer_relations/organizations/update_spec.rb | 74 |
2 files changed, 148 insertions, 0 deletions
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 |