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

id_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: d71031c6e1a35d59a12d7c59394f7e4579268744 (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
# frozen_string_literal: true

require 'fast_spec_helper'

require_relative '../../../../rubocop/cop/graphql/id_type'

RSpec.describe RuboCop::Cop::Graphql::IDType do
  subject(:cop) { described_class.new }

  it 'adds an offense when GraphQL::Types::ID is used as a param to #argument' do
    expect_offense(<<~TYPE)
      argument :some_arg, GraphQL::Types::ID, some: other, params: do_not_matter
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use GraphQL::Types::ID, use a specific GlobalIDType instead
    TYPE
  end

  context 'whitelisted arguments' do
    RuboCop::Cop::Graphql::IDType::WHITELISTED_ARGUMENTS.each do |arg|
      it "does not add an offense for calls to #argument with #{arg} as argument name" do
        expect_no_offenses(<<~TYPE.strip)
          argument #{arg}, GraphQL::Types::ID, some: other, params: do_not_matter
        TYPE
      end
    end
  end

  it 'does not add an offense for calls to #argument without GraphQL::Types::ID' do
    expect_no_offenses(<<~TYPE.strip)
      argument :some_arg, ::Types::GlobalIDType[::Awardable], some: other, params: do_not_matter
    TYPE
  end
end