debian-mirror-gitlab/spec/rubocop/cop/graphql/authorize_types_spec.rb

70 lines
1.5 KiB
Ruby
Raw Normal View History

2019-09-30 21:07:59 +05:30
# frozen_string_literal: true
require 'fast_spec_helper'
require 'rubocop'
2020-07-28 23:09:34 +05:30
2019-09-30 21:07:59 +05:30
require_relative '../../../../rubocop/cop/graphql/authorize_types'
2020-07-28 23:09:34 +05:30
RSpec.describe RuboCop::Cop::Graphql::AuthorizeTypes, type: :rubocop do
2019-09-30 21:07:59 +05:30
include CopHelper
subject(:cop) { described_class.new }
2020-07-28 23:09:34 +05:30
it 'adds an offense when there is no authorize call' do
inspect_source(<<~TYPE)
module Types
class AType < BaseObject
field :a_thing
field :another_thing
2019-09-30 21:07:59 +05:30
end
2020-07-28 23:09:34 +05:30
end
TYPE
2019-09-30 21:07:59 +05:30
2020-07-28 23:09:34 +05:30
expect(cop.offenses.size).to eq 1
end
2019-09-30 21:07:59 +05:30
2020-07-28 23:09:34 +05:30
it 'does not add an offense for classes that have an authorize call' do
expect_no_offenses(<<~TYPE.strip)
module Types
class AType < BaseObject
graphql_name 'ATypeName'
2019-09-30 21:07:59 +05:30
2020-07-28 23:09:34 +05:30
authorize :an_ability, :second_ability
2019-09-30 21:07:59 +05:30
2020-07-28 23:09:34 +05:30
field :a_thing
2019-09-30 21:07:59 +05:30
end
2020-07-28 23:09:34 +05:30
end
TYPE
end
2019-09-30 21:07:59 +05:30
2020-07-28 23:09:34 +05:30
it 'does not add an offense for classes that only have an authorize call' do
expect_no_offenses(<<~TYPE.strip)
module Types
class AType < SuperClassWithFields
authorize :an_ability
2019-09-30 21:07:59 +05:30
end
2020-07-28 23:09:34 +05:30
end
TYPE
end
2019-09-30 21:07:59 +05:30
2020-07-28 23:09:34 +05:30
it 'does not add an offense for base types' do
expect_no_offenses(<<~TYPE)
module Types
class AType < BaseEnum
field :a_thing
2019-09-30 21:07:59 +05:30
end
2020-07-28 23:09:34 +05:30
end
TYPE
end
2020-01-01 13:55:28 +05:30
2020-07-28 23:09:34 +05:30
it 'does not add an offense for Enums' do
expect_no_offenses(<<~TYPE)
module Types
class ATypeEnum < AnotherEnum
field :a_thing
2020-01-01 13:55:28 +05:30
end
2020-07-28 23:09:34 +05:30
end
TYPE
2019-09-30 21:07:59 +05:30
end
end