debian-mirror-gitlab/spec/rubocop/cop/graphql/enum_values_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

80 lines
1.9 KiB
Ruby
Raw Permalink Normal View History

2023-01-13 00:05:48 +05:30
# frozen_string_literal: true
require 'rubocop_spec_helper'
require_relative '../../../../rubocop/cop/graphql/enum_values'
RSpec.describe RuboCop::Cop::Graphql::EnumValues do
it 'adds an offense when enum value is not uppercase' do
expect_offense(<<~ENUM)
module Types
class FakeEnum < BaseEnum
graphql_name 'Fake'
value 'downcase', description: "Downcase."
^^^^^^^^^^ #{described_class::MSG}
end
end
ENUM
end
context 'when values are set dynamically' do
it 'adds an offense when enum value is set without `:upcase`' do
expect_offense(<<~ENUM)
VALUES = ['FOO', 'bar']
module Types
class FakeEnum < BaseEnum
graphql_name 'Fake'
VALUES.each do |val|
value val, description: "Dynamic value."
^^^ #{described_class::MSG}
end
end
end
ENUM
end
it 'adds no offense when enum value is deprecated' do
expect_no_offenses(<<~ENUM)
module Types
class FakeEnum < BaseEnum
graphql_name 'Fake'
value 'foo', deprecated: { reason: 'Use something else' }
end
end
ENUM
end
it 'adds no offense when enum value is uppercased literally' do
expect_no_offenses(<<~'ENUM')
module Types
class FakeEnum < BaseEnum
graphql_name 'Fake'
value 'FOO'
end
end
ENUM
end
it 'adds no offense when enum value is calling upcased' do
expect_no_offenses(<<~'ENUM')
VALUES = ['FOO', 'bar']
module Types
class FakeEnum < BaseEnum
graphql_name 'Fake'
VALUES.each do |val|
value val.underscore.upcase, description: "Dynamic value."
value "#{field.upcase.tr(' ', '_')}_ASC"
end
end
end
ENUM
end
end
end