summaryrefslogtreecommitdiff
path: root/spec/services/customer_relations/organizations/update_service_spec.rb
blob: eb253540863774bafa955eca6011ef85147400be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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