diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-31 00:08:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-31 00:08:47 +0300 |
commit | c8f773a8593926f4f2dec6f446a3b3e59e9c9909 (patch) | |
tree | 4e5ea1d3b861ff99015f6112da567de7873868aa /spec/graphql/features | |
parent | 929b887e5391dea7cb53b88b77b9a35351c87d99 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/graphql/features')
-rw-r--r-- | spec/graphql/features/authorization_spec.rb | 35 | ||||
-rw-r--r-- | spec/graphql/features/feature_flag_spec.rb | 36 |
2 files changed, 38 insertions, 33 deletions
diff --git a/spec/graphql/features/authorization_spec.rb b/spec/graphql/features/authorization_spec.rb index 7ad6a622b4b..5ef1bced179 100644 --- a/spec/graphql/features/authorization_spec.rb +++ b/spec/graphql/features/authorization_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' describe 'Gitlab::Graphql::Authorization' do + include GraphqlHelpers + set(:user) { create(:user) } let(:permission_single) { :foo } @@ -300,37 +302,4 @@ describe 'Gitlab::Graphql::Authorization' do allow(Ability).to receive(:allowed?).with(user, permission, test_object).and_return(true) end end - - def type_factory - Class.new(Types::BaseObject) do - graphql_name 'TestType' - - field :name, GraphQL::STRING_TYPE, null: true - - yield(self) if block_given? - end - end - - def query_factory - Class.new(Types::BaseObject) do - graphql_name 'TestQuery' - - yield(self) if block_given? - end - end - - def execute_query(query_type) - schema = Class.new(GraphQL::Schema) do - use Gitlab::Graphql::Authorize - use Gitlab::Graphql::Connections - - query(query_type) - end - - schema.execute( - query_string, - context: { current_user: user }, - variables: {} - ) - end end diff --git a/spec/graphql/features/feature_flag_spec.rb b/spec/graphql/features/feature_flag_spec.rb new file mode 100644 index 00000000000..13b1e472fab --- /dev/null +++ b/spec/graphql/features/feature_flag_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'Graphql Field feature flags' do + include GraphqlHelpers + + let_it_be(:user) { create(:user) } + + let(:feature_flag) { 'test_feature' } + let(:test_object) { double(name: 'My name') } + let(:query_string) { '{ item() { name } }' } + let(:result) { execute_query(query_type)['data'] } + + subject { result } + + describe 'Feature flagged field' do + let(:type) { type_factory } + + let(:query_type) do + query_factory do |query| + query.field :item, type, null: true, feature_flag: feature_flag, resolve: ->(obj, args, ctx) { test_object } + end + end + + it 'returns the value when feature is enabled' do + expect(subject['item']).to eq('name' => test_object.name) + end + + it 'returns nil when the feature is disabled' do + stub_feature_flags(feature_flag => false) + + expect(subject).to be_nil + end + end +end |