2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe 'Graphql Field feature flags' do
|
2020-03-13 15:44:24 +05:30
|
|
|
include GraphqlHelpers
|
2021-04-17 20:07:23 +05:30
|
|
|
include Graphql::ResolverFactories
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
|
|
|
|
let(:feature_flag) { 'test_feature' }
|
|
|
|
let(:test_object) { double(name: 'My name') }
|
2020-04-22 19:07:51 +05:30
|
|
|
let(:query_string) { '{ item { name } }' }
|
2020-03-13 15:44:24 +05:30
|
|
|
let(:result) { execute_query(query_type)['data'] }
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
before do
|
|
|
|
skip_feature_flags_yaml_validation
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
subject { result }
|
|
|
|
|
|
|
|
describe 'Feature flagged field' do
|
|
|
|
let(:type) { type_factory }
|
|
|
|
|
|
|
|
let(:query_type) do
|
|
|
|
query_factory do |query|
|
2021-04-17 20:07:23 +05:30
|
|
|
query.field :item, type, null: true, feature_flag: feature_flag, resolver: new_resolver(test_object)
|
2020-03-13 15:44:24 +05:30
|
|
|
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
|