diff options
Diffstat (limited to 'spec/services/customer_relations')
-rw-r--r-- | spec/services/customer_relations/organizations/create_service_spec.rb | 33 | ||||
-rw-r--r-- | spec/services/customer_relations/organizations/update_service_spec.rb | 56 |
2 files changed, 89 insertions, 0 deletions
diff --git a/spec/services/customer_relations/organizations/create_service_spec.rb b/spec/services/customer_relations/organizations/create_service_spec.rb new file mode 100644 index 00000000000..b4764f6b97a --- /dev/null +++ b/spec/services/customer_relations/organizations/create_service_spec.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe CustomerRelations::Organizations::CreateService do + describe '#execute' do + let_it_be(:user) { create(:user) } + + let(:group) { create(:group) } + let(:params) { attributes_for(:organization, group: group) } + + subject(:response) { described_class.new(group: group, current_user: user, params: params).execute } + + it 'creates an organization' do + group.add_reporter(user) + + expect(response).to be_success + end + + it 'returns an error when user does not have permission' do + expect(response).to be_error + expect(response.message).to eq('You have insufficient permissions to create an organization for this group') + end + + it 'returns an error when the organization is not persisted' do + group.add_reporter(user) + params[:name] = nil + + expect(response).to be_error + expect(response.message).to eq(["Name can't be blank"]) + end + end +end diff --git a/spec/services/customer_relations/organizations/update_service_spec.rb b/spec/services/customer_relations/organizations/update_service_spec.rb new file mode 100644 index 00000000000..eb253540863 --- /dev/null +++ b/spec/services/customer_relations/organizations/update_service_spec.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe CustomerRelations::Organizations::UpdateService do + let_it_be(:user) { create(:user) } + + let(:organization) { create(:organization, name: 'Test', group: group) } + + subject(:update) { described_class.new(group: group, current_user: user, params: params).execute(organization) } + + describe '#execute' do + context 'when the user has no permission' do + let_it_be(:group) { create(:group) } + + let(:params) { { name: 'GitLab' } } + + it 'returns an error' do + response = update + + expect(response).to be_error + expect(response.message).to eq('You have insufficient permissions to update an organization for this group') + end + end + + context 'when user has permission' do + let_it_be(:group) { create(:group) } + + before_all do + group.add_reporter(user) + end + + context 'when name is changed' do + let(:params) { { name: 'GitLab' } } + + it 'updates the organization' do + response = update + + expect(response).to be_success + expect(response.payload.name).to eq('GitLab') + end + end + + context 'when the organization is invalid' do + let(:params) { { name: nil } } + + it 'returns an error' do + response = update + + expect(response).to be_error + expect(response.message).to eq(["Name can't be blank"]) + end + end + end + end +end |