Welcome to mirror list, hosted at ThFree Co, Russian Federation.

create_spec.rb « organizations « customer_relations « mutations « graphql « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ffc9632350aba820aef1929f40f25d228b2444eb (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
57
58
59
60
61
62
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Mutations::CustomerRelations::Organizations::Create do
  let_it_be(:user) { create(:user) }
  let_it_be(:group) { create(:group, :crm_enabled) }

  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
        before do
          group.add_reporter(user)
        end

        it 'raises an error' do
          expect { resolve_mutation }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
            .with_message(Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR)
        end
      end

      context 'when the user has permission' do
        before_all do
          group.add_developer(user)
        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_crm_organization) }
end