2021-01-29 00:20:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'fast_spec_helper'
|
|
|
|
require 'rubocop'
|
|
|
|
|
|
|
|
require_relative '../../../../rubocop/cop/graphql/resolver_type'
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
RSpec.describe RuboCop::Cop::Graphql::ResolverType do
|
2021-01-29 00:20:46 +05:30
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
it 'adds an offense when there is no type annotation' do
|
|
|
|
expect_offense(<<~SRC)
|
2021-01-29 00:20:46 +05:30
|
|
|
module Resolvers
|
|
|
|
class FooResolver < BaseResolver
|
2021-03-11 19:13:27 +05:30
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Missing type annotation: Please add `type` DSL method call. e.g: type UserType.connection_type, null: true
|
2021-01-29 00:20:46 +05:30
|
|
|
def resolve(**args)
|
|
|
|
[:thing]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
SRC
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not add an offense for resolvers that have a type call' do
|
|
|
|
expect_no_offenses(<<-SRC)
|
|
|
|
module Resolvers
|
|
|
|
class FooResolver < BaseResolver
|
|
|
|
type [SomeEnum], null: true
|
|
|
|
|
|
|
|
def resolve(**args)
|
|
|
|
[:thing]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
SRC
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'ignores type calls on other objects' do
|
2021-03-11 19:13:27 +05:30
|
|
|
expect_offense(<<~SRC)
|
2021-01-29 00:20:46 +05:30
|
|
|
module Resolvers
|
|
|
|
class FooResolver < BaseResolver
|
2021-03-11 19:13:27 +05:30
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Missing type annotation: Please add `type` DSL method call. e.g: type UserType.connection_type, null: true
|
2021-01-29 00:20:46 +05:30
|
|
|
class FalsePositive < BaseObject
|
|
|
|
type RedHerringType, null: true
|
|
|
|
end
|
|
|
|
|
|
|
|
def resolve(**args)
|
|
|
|
[:thing]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
SRC
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not add an offense unless the class is named using the Resolver convention' do
|
|
|
|
expect_no_offenses(<<-TYPE)
|
|
|
|
module Resolvers
|
|
|
|
class FooThingy
|
|
|
|
def something_other_than_resolve(**args)
|
|
|
|
[:thing]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
TYPE
|
|
|
|
end
|
|
|
|
end
|