debian-mirror-gitlab/spec/graphql/types/permission_types/base_permission_type_spec.rb

55 lines
1.4 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2018-11-08 19:23:39 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Types::PermissionTypes::BasePermissionType do
2018-11-08 19:23:39 +05:30
let(:permitable) { double('permittable') }
let(:current_user) { build(:user) }
let(:context) { { current_user: current_user } }
2020-01-01 13:55:28 +05:30
2018-11-08 19:23:39 +05:30
subject(:test_type) do
Class.new(described_class) do
graphql_name 'TestClass'
2021-02-22 17:27:13 +05:30
permission_field :do_stuff
2018-11-08 19:23:39 +05:30
ability_field(:read_issue)
abilities :admin_issue
2021-02-22 17:27:13 +05:30
define_method :do_stuff do
true
end
2018-11-08 19:23:39 +05:30
end
end
describe '.permission_field' do
it 'adds a field for the required permission' do
2020-04-22 19:07:51 +05:30
expect(test_type).to have_graphql_field(:do_stuff)
2018-11-08 19:23:39 +05:30
end
end
describe '.ability_field' do
it 'adds a field for the required permission' do
2020-04-22 19:07:51 +05:30
expect(test_type).to have_graphql_field(:read_issue)
2018-11-08 19:23:39 +05:30
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,
2021-10-27 15:23:28 +05:30
type: GraphQL::Types::Boolean,
2018-11-08 19:23:39 +05:30
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
2020-04-22 19:07:51 +05:30
expect(test_type).to have_graphql_field(:admin_issue)
2018-11-08 19:23:39 +05:30
end
end
end