summaryrefslogtreecommitdiff
path: root/spec/services/customer_relations/organizations/create_service_spec.rb
blob: 3b1ae5606b15b61c081e431120cac6958e197acd (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe CustomerRelations::Organizations::CreateService, feature_category: :service_desk do
  describe '#execute' do
    let_it_be(:user) { create(:user) }

    let(:group) { create(:group, :crm_enabled) }
    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_developer(user)

      expect(response).to be_success
    end

    it 'returns an error when user does not have permission' do
      group.add_reporter(user)

      expect(response).to be_error
      expect(response.message).to match_array(['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_developer(user)
      params[:name] = nil

      expect(response).to be_error
      expect(response.message).to match_array(["Name can't be blank"])
    end
  end
end