diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-19 14:01:45 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-19 14:01:45 +0300 |
commit | 9297025d0b7ddf095eb618dfaaab2ff8f2018d8b (patch) | |
tree | 865198c01d1824a9b098127baa3ab980c9cd2c06 /spec/services/organizations/update_service_spec.rb | |
parent | 6372471f43ee03c05a7c1f8b0c6ac6b8a7431dbe (diff) |
Add latest changes from gitlab-org/gitlab@16-7-stable-eev16.7.0-rc42
Diffstat (limited to 'spec/services/organizations/update_service_spec.rb')
-rw-r--r-- | spec/services/organizations/update_service_spec.rb | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/spec/services/organizations/update_service_spec.rb b/spec/services/organizations/update_service_spec.rb new file mode 100644 index 00000000000..148840770db --- /dev/null +++ b/spec/services/organizations/update_service_spec.rb @@ -0,0 +1,76 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Organizations::UpdateService, feature_category: :cell do + describe '#execute' do + let_it_be(:user) { create(:user) } + let_it_be_with_reload(:organization) { create(:organization) } + + let_it_be(:current_user) { user } # due to use in before_all + let(:name) { 'Name' } + let(:path) { 'path' } + let(:description) { nil } + let(:avatar_filename) { nil } + let(:params) { { name: name, path: path }.merge(extra_params) } + let(:extra_params) { {} } + let(:updated_organization) { response.payload[:organization] } + + subject(:response) do + described_class.new(organization, current_user: current_user, params: params).execute + end + + context 'when user does not have permission' do + let(:current_user) { nil } + + it 'returns an error' do + expect(response).to be_error + + expect(response.message).to match_array(['You have insufficient permissions to update the organization']) + end + end + + context 'when user has permission' do + before_all do + create(:organization_user, organization: organization, user: current_user) + end + + shared_examples 'updating an organization' do + it 'updates the organization' do + expect(response).to be_success + expect(updated_organization.name).to eq(name) + expect(updated_organization.path).to eq(path) + expect(updated_organization.description).to eq(description) + expect(updated_organization.avatar.filename).to eq(avatar_filename) + end + end + + context 'with description' do + let(:description) { 'Organization description' } + let(:extra_params) { { description: description } } + + it_behaves_like 'updating an organization' + end + + context 'with avatar' do + let(:avatar_filename) { 'dk.png' } + let(:avatar) { fixture_file_upload("spec/fixtures/#{avatar_filename}") } + let(:extra_params) { { avatar: avatar } } + + it_behaves_like 'updating an organization' + end + + include_examples 'updating an organization' + + context 'when the organization is not updated' do + let(:extra_params) { { name: nil } } + + it 'returns an error' do + expect(response).to be_error + expect(updated_organization).to be_instance_of Organizations::Organization + expect(response.message).to match_array(["Name can't be blank"]) + end + end + end + end +end |