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

create_spec.rb « organizations « mutations « graphql « api « requests « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ac6b04104bad2ad46e42a3b0cff3d4f04d3c2329 (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
63
64
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Mutations::Organizations::Create, feature_category: :cell do
  include GraphqlHelpers

  let_it_be(:user) { create(:user) }

  let(:mutation) { graphql_mutation(:organization_create, params) }
  let(:name) { 'Name' }
  let(:path) { 'path' }
  let(:params) do
    {
      name: name,
      path: path
    }
  end

  subject(:create_organization) { post_graphql_mutation(mutation, current_user: current_user) }

  it { expect(described_class).to require_graphql_authorizations(:create_organization) }

  def mutation_response
    graphql_mutation_response(:organization_create)
  end

  context 'when the user does not have permission' do
    let(:current_user) { nil }

    it_behaves_like 'a mutation that returns a top-level access error'

    it 'does not create an organization' do
      expect { create_organization }.not_to change { Organizations::Organization.count }
    end
  end

  context 'when the user has permission' do
    let(:current_user) { user }

    context 'when the params are invalid' do
      let(:name) { '' }

      it 'returns the validation error' do
        create_organization

        expect(mutation_response).to include('errors' => ["Name can't be blank"])
      end
    end

    it 'creates an organization' do
      expect { create_organization }.to change { Organizations::Organization.count }.by(1)
    end

    it 'returns the new organization' do
      create_organization

      expect(graphql_data_at(:organization_create, :organization)).to match a_hash_including(
        'name' => name,
        'path' => path
      )
    end
  end
end