Welcome to mirror list, hosted at ThFree Co, Russian Federation.

resolver_type_spec.rb « graphql « cop « rubocop « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ade1bfc2ccae067ed9c8f8b3c501128ab21e64a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# frozen_string_literal: true

require 'rubocop_spec_helper'

require_relative '../../../../rubocop/cop/graphql/resolver_type'

RSpec.describe RuboCop::Cop::Graphql::ResolverType do
  it 'adds an offense when there is no type annotation' do
    expect_offense(<<~SRC)
      module Resolvers
        class FooResolver < BaseResolver
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Missing type annotation: Please add `type` DSL method call. e.g: type UserType.connection_type, null: true
          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
    expect_offense(<<~SRC)
      module Resolvers
        class FooResolver < BaseResolver
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Missing type annotation: Please add `type` DSL method call. e.g: type UserType.connection_type, null: true
          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