Commit 0f1936d6 authored by charlieablett's avatar charlieablett Committed by Jan Provaznik

Add authorize types test

parent b56ae4df
......@@ -7,12 +7,12 @@ module RuboCop
MSG = 'Add an `authorize :ability` call to the type: '\
'https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#type-authorization'
TYPES_DIR = 'app/graphql/types'
# We want to exclude our own basetypes and scalars
WHITELISTED_TYPES = %w[BaseEnum BaseScalar BasePermissionType MutationType
QueryType GraphQL::Schema BaseUnion].freeze
TYPES_DIR = 'app/graphql/types'
def_node_search :authorize?, <<~PATTERN
(send nil? :authorize ...)
PATTERN
......@@ -30,7 +30,7 @@ module RuboCop
def in_type?(node)
path = node.location.expression.source_buffer.name
path.include?(TYPES_DIR)
path.include? TYPES_DIR
end
def whitelisted?(class_node)
......
# frozen_string_literal: true
module RuboCop
module GraphqlHelpers
TYPES_DIR = 'app/graphql/types'
def in_type?(node)
path = node.location.expression.source_buffer.name
path.include?(TYPES_DIR)
end
end
end
......@@ -11,6 +11,23 @@ describe RuboCop::Cop::Graphql::AuthorizeTypes do
subject(:cop) { described_class.new }
context 'when NOT in a type folder' do
before do
allow(cop).to receive(:in_type?).and_return(false)
end
it 'does not add an offense even though there is no authorize call' do
expect_no_offenses(<<~TYPE.strip)
module Types
class AType < BaseObject
field :a_thing
field :another_thing
end
end
TYPE
end
end
context 'when in a type folder' do
before do
allow(cop).to receive(:in_type?).and_return(true)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment