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

base_permission_type_spec.rb « permission_types « types « graphql « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 68632a509eebace3e185490b7680fa05c437d48c (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Types::PermissionTypes::BasePermissionType do
  let(:permitable) { double('permittable') }
  let(:current_user) { build(:user) }
  let(:context) { { current_user: current_user } }

  subject(:test_type) do
    Class.new(described_class) do
      graphql_name 'TestClass'

      permission_field :do_stuff
      ability_field(:read_issue)
      abilities :admin_issue

      define_method :do_stuff do
        true
      end
    end
  end

  describe '.permission_field' do
    it 'adds a field for the required permission' do
      expect(test_type).to have_graphql_field(:do_stuff)
    end
  end

  describe '.ability_field' do
    it 'adds a field for the required permission' do
      expect(test_type).to have_graphql_field(:read_issue)
    end

    it 'does not add a resolver block if another resolving param is passed' do
      expected_keywords = {
        name: :resolve_using_hash,
        hash_key: :the_key,
        type: GraphQL::BOOLEAN_TYPE,
        description: "custom description",
        null: false
      }
      expect(test_type).to receive(:field).with(expected_keywords)

      test_type.ability_field :resolve_using_hash, hash_key: :the_key, description: "custom description"
    end
  end

  describe '.abilities' do
    it 'adds a field for the passed permissions' do
      expect(test_type).to have_graphql_field(:admin_issue)
    end
  end
end