2019-06-18 14:18:26 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'fast_spec_helper'
|
|
|
|
require 'rubocop'
|
2020-06-22 21:08:42 +00:00
|
|
|
|
2019-06-18 14:18:26 +00:00
|
|
|
require_relative '../../../../rubocop/cop/graphql/authorize_types'
|
|
|
|
|
2020-06-24 06:09:01 +00:00
|
|
|
RSpec.describe RuboCop::Cop::Graphql::AuthorizeTypes, type: :rubocop do
|
2019-06-18 14:18:26 +00:00
|
|
|
include CopHelper
|
|
|
|
|
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
2020-07-02 12:09:02 +00:00
|
|
|
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-06-18 14:18:26 +00:00
|
|
|
end
|
2020-07-02 12:09:02 +00:00
|
|
|
end
|
|
|
|
TYPE
|
2019-06-18 14:18:26 +00:00
|
|
|
|
2020-07-02 12:09:02 +00:00
|
|
|
expect(cop.offenses.size).to eq 1
|
|
|
|
end
|
2019-06-18 14:18:26 +00:00
|
|
|
|
2020-07-02 12:09:02 +00:00
|
|
|
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-06-18 14:18:26 +00:00
|
|
|
|
2020-07-02 12:09:02 +00:00
|
|
|
authorize :an_ability, :second_ability
|
2019-06-18 14:18:26 +00:00
|
|
|
|
2020-07-02 12:09:02 +00:00
|
|
|
field :a_thing
|
2019-06-18 14:18:26 +00:00
|
|
|
end
|
2020-07-02 12:09:02 +00:00
|
|
|
end
|
|
|
|
TYPE
|
|
|
|
end
|
2019-06-18 14:18:26 +00:00
|
|
|
|
2020-07-02 12:09:02 +00:00
|
|
|
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-06-18 14:18:26 +00:00
|
|
|
end
|
2020-07-02 12:09:02 +00:00
|
|
|
end
|
|
|
|
TYPE
|
|
|
|
end
|
2019-06-18 14:18:26 +00:00
|
|
|
|
2020-07-02 12:09:02 +00:00
|
|
|
it 'does not add an offense for base types' do
|
|
|
|
expect_no_offenses(<<~TYPE)
|
|
|
|
module Types
|
|
|
|
class AType < BaseEnum
|
|
|
|
field :a_thing
|
2019-06-18 14:18:26 +00:00
|
|
|
end
|
2020-07-02 12:09:02 +00:00
|
|
|
end
|
|
|
|
TYPE
|
|
|
|
end
|
2019-11-25 12:06:13 +00:00
|
|
|
|
2020-07-02 12:09:02 +00:00
|
|
|
it 'does not add an offense for Enums' do
|
|
|
|
expect_no_offenses(<<~TYPE)
|
|
|
|
module Types
|
|
|
|
class ATypeEnum < AnotherEnum
|
|
|
|
field :a_thing
|
2019-11-25 12:06:13 +00:00
|
|
|
end
|
2020-07-02 12:09:02 +00:00
|
|
|
end
|
|
|
|
TYPE
|
2019-06-18 14:18:26 +00:00
|
|
|
end
|
|
|
|
end
|