2020-01-30 16:08:47 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-16 14:09:01 -04:00
|
|
|
RSpec.describe 'Graphql Field feature flags' do
|
2020-01-30 16:08:47 -05:00
|
|
|
include GraphqlHelpers
|
2021-03-03 04:10:53 -05:00
|
|
|
include Graphql::ResolverFactories
|
2020-01-30 16:08:47 -05:00
|
|
|
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
|
|
|
|
let(:feature_flag) { 'test_feature' }
|
|
|
|
let(:test_object) { double(name: 'My name') }
|
2020-03-18 14:09:35 -04:00
|
|
|
let(:query_string) { '{ item { name } }' }
|
2020-01-30 16:08:47 -05:00
|
|
|
let(:result) { execute_query(query_type)['data'] }
|
|
|
|
|
2020-09-21 08:09:34 -04:00
|
|
|
before do
|
|
|
|
skip_feature_flags_yaml_validation
|
|
|
|
end
|
|
|
|
|
2020-01-30 16:08:47 -05:00
|
|
|
subject { result }
|
|
|
|
|
|
|
|
describe 'Feature flagged field' do
|
|
|
|
let(:type) { type_factory }
|
|
|
|
|
|
|
|
let(:query_type) do
|
|
|
|
query_factory do |query|
|
2021-03-03 04:10:53 -05:00
|
|
|
query.field :item, type, null: true, feature_flag: feature_flag, resolver: new_resolver(test_object)
|
2020-01-30 16:08:47 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-12 11:09:19 -04:00
|
|
|
it 'checks YAML definition for default_enabled' do
|
|
|
|
# Exception is indicative of a check for YAML definition
|
|
|
|
expect { subject }.to raise_error(Feature::InvalidFeatureFlagError, /The feature flag YAML definition for '#{feature_flag}' does not exist/)
|
2020-01-30 16:08:47 -05:00
|
|
|
end
|
|
|
|
|
2021-07-12 11:09:19 -04:00
|
|
|
context 'skipping YAML check' do
|
|
|
|
before do
|
|
|
|
skip_default_enabled_yaml_check
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the value when feature is enabled' do
|
|
|
|
expect(subject['item']).to eq('name' => test_object.name)
|
|
|
|
end
|
2020-01-30 16:08:47 -05:00
|
|
|
|
2021-07-12 11:09:19 -04:00
|
|
|
it 'returns nil when the feature is disabled' do
|
|
|
|
stub_feature_flags(feature_flag => false)
|
|
|
|
|
|
|
|
expect(subject).to be_nil
|
|
|
|
end
|
2020-01-30 16:08:47 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|