diff options
Diffstat (limited to 'spec/services/feature_flags')
-rw-r--r-- | spec/services/feature_flags/disable_service_spec.rb | 92 | ||||
-rw-r--r-- | spec/services/feature_flags/enable_service_spec.rb | 154 | ||||
-rw-r--r-- | spec/services/feature_flags/update_service_spec.rb | 145 |
3 files changed, 0 insertions, 391 deletions
diff --git a/spec/services/feature_flags/disable_service_spec.rb b/spec/services/feature_flags/disable_service_spec.rb deleted file mode 100644 index 4b2137be35c..00000000000 --- a/spec/services/feature_flags/disable_service_spec.rb +++ /dev/null @@ -1,92 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe FeatureFlags::DisableService do - include FeatureFlagHelpers - - let_it_be(:project) { create(:project) } - let_it_be(:user) { create(:user) } - - let(:params) { {} } - let(:service) { described_class.new(project, user, params) } - - before_all do - project.add_developer(user) - end - - describe '#execute' do - subject { service.execute } - - context 'with params to disable default strategy on prd scope' do - let(:params) do - { - name: 'awesome', - environment_scope: 'prd', - strategy: { name: 'userWithId', parameters: { 'userIds': 'User:1' } }.deep_stringify_keys - } - end - - context 'when there is a persisted feature flag' do - let!(:feature_flag) { create_flag(project, params[:name]) } - - context 'when there is a persisted scope' do - let!(:scope) do - create_scope(feature_flag, params[:environment_scope], true, strategies) - end - - context 'when there is a persisted strategy' do - let(:strategies) do - [ - { name: 'userWithId', parameters: { 'userIds': 'User:1' } }.deep_stringify_keys, - { name: 'userWithId', parameters: { 'userIds': 'User:2' } }.deep_stringify_keys - ] - end - - it 'deletes the specified strategy' do - subject - - scope.reload - expect(scope.strategies.count).to eq(1) - expect(scope.strategies).not_to include(params[:strategy]) - end - - context 'when strategies will be empty' do - let(:strategies) { [params[:strategy]] } - - it 'deletes the persisted scope' do - subject - - expect(feature_flag.scopes.exists?(environment_scope: params[:environment_scope])) - .to eq(false) - end - end - end - - context 'when there is no persisted strategy' do - let(:strategies) { [{ name: 'default', parameters: {} }] } - - it 'returns error' do - expect(subject[:status]).to eq(:error) - expect(subject[:message]).to include('Strategy not found') - end - end - end - - context 'when there is no persisted scope' do - it 'returns error' do - expect(subject[:status]).to eq(:error) - expect(subject[:message]).to include('Feature Flag Scope not found') - end - end - end - - context 'when there is no persisted feature flag' do - it 'returns error' do - expect(subject[:status]).to eq(:error) - expect(subject[:message]).to include('Feature Flag not found') - end - end - end - end -end diff --git a/spec/services/feature_flags/enable_service_spec.rb b/spec/services/feature_flags/enable_service_spec.rb deleted file mode 100644 index c0008b1933f..00000000000 --- a/spec/services/feature_flags/enable_service_spec.rb +++ /dev/null @@ -1,154 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe FeatureFlags::EnableService do - include FeatureFlagHelpers - - let_it_be(:project) { create(:project) } - let_it_be(:user) { create(:user) } - - let(:params) { {} } - let(:service) { described_class.new(project, user, params) } - - before_all do - project.add_developer(user) - end - - describe '#execute' do - subject { service.execute } - - context 'with params to enable default strategy on prd scope' do - let(:params) do - { - name: 'awesome', - environment_scope: 'prd', - strategy: { name: 'default', parameters: {} }.stringify_keys - } - end - - context 'when there is no persisted feature flag' do - it 'creates a new feature flag with scope' do - feature_flag = subject[:feature_flag] - scope = feature_flag.scopes.find_by_environment_scope(params[:environment_scope]) - expect(subject[:status]).to eq(:success) - expect(feature_flag.name).to eq(params[:name]) - expect(feature_flag.default_scope).not_to be_active - expect(scope).to be_active - expect(scope.strategies).to include(params[:strategy]) - end - - context 'when params include default scope' do - let(:params) do - { - name: 'awesome', - environment_scope: '*', - strategy: { name: 'userWithId', parameters: { 'userIds': 'abc' } }.deep_stringify_keys - } - end - - it 'create a new feature flag with an active default scope with the specified strategy' do - feature_flag = subject[:feature_flag] - expect(subject[:status]).to eq(:success) - expect(feature_flag.default_scope).to be_active - expect(feature_flag.default_scope.strategies).to include(params[:strategy]) - end - end - end - - context 'when there is a persisted feature flag' do - let!(:feature_flag) { create_flag(project, params[:name]) } - - context 'when there is no persisted scope' do - it 'creates a new scope for the persisted feature flag' do - feature_flag = subject[:feature_flag] - scope = feature_flag.scopes.find_by_environment_scope(params[:environment_scope]) - expect(subject[:status]).to eq(:success) - expect(feature_flag.name).to eq(params[:name]) - expect(scope).to be_active - expect(scope.strategies).to include(params[:strategy]) - end - end - - context 'when there is a persisted scope' do - let!(:feature_flag_scope) do - create_scope(feature_flag, params[:environment_scope], active, strategies) - end - - let(:active) { true } - - context 'when the persisted scope does not have the specified strategy yet' do - let(:strategies) { [{ name: 'userWithId', parameters: { 'userIds': 'abc' } }] } - - it 'adds the specified strategy to the scope' do - subject - - feature_flag_scope.reload - expect(feature_flag_scope.strategies).to include(params[:strategy]) - end - - context 'when the persisted scope is inactive' do - let(:active) { false } - - it 'reactivates the scope' do - expect { subject } - .to change { feature_flag_scope.reload.active }.from(false).to(true) - end - end - end - - context 'when the persisted scope has the specified strategy already' do - let(:strategies) { [params[:strategy]] } - - it 'does not add a duplicated strategy to the scope' do - expect { subject } - .not_to change { feature_flag_scope.reload.strategies.count } - end - end - end - end - end - - context 'when strategy is not specified in params' do - let(:params) do - { - name: 'awesome', - environment_scope: 'prd' - } - end - - it 'returns error' do - expect(subject[:status]).to eq(:error) - expect(subject[:message]).to include('Scopes strategies must be an array of strategy hashes') - end - end - - context 'when environment scope is not specified in params' do - let(:params) do - { - name: 'awesome', - strategy: { name: 'default', parameters: {} }.stringify_keys - } - end - - it 'returns error' do - expect(subject[:status]).to eq(:error) - expect(subject[:message]).to include("Scopes environment scope can't be blank") - end - end - - context 'when name is not specified in params' do - let(:params) do - { - environment_scope: 'prd', - strategy: { name: 'default', parameters: {} }.stringify_keys - } - end - - it 'returns error' do - expect(subject[:status]).to eq(:error) - expect(subject[:message]).to include("Name can't be blank") - end - end - end -end diff --git a/spec/services/feature_flags/update_service_spec.rb b/spec/services/feature_flags/update_service_spec.rb index 1a127a0d472..d838549891a 100644 --- a/spec/services/feature_flags/update_service_spec.rb +++ b/spec/services/feature_flags/update_service_spec.rb @@ -121,150 +121,5 @@ RSpec.describe FeatureFlags::UpdateService do subject end end - - context 'when scope active state is changed' do - let(:params) do - { - scopes_attributes: [{ id: feature_flag.scopes.first.id, active: false }] - } - end - - it 'creates audit event about changing active state' do - expect { subject }.to change { AuditEvent.count }.by(1) - expect(audit_event_message).to( - include("Updated rule <strong>*</strong> active state "\ - "from <strong>true</strong> to <strong>false</strong>.") - ) - end - end - - context 'when scope is renamed' do - let(:changed_scope) { feature_flag.scopes.create!(environment_scope: 'review', active: true) } - let(:params) do - { - scopes_attributes: [{ id: changed_scope.id, environment_scope: 'staging' }] - } - end - - it 'creates audit event with changed name' do - expect { subject }.to change { AuditEvent.count }.by(1) - expect(audit_event_message).to( - include("Updated rule <strong>staging</strong> environment scope "\ - "from <strong>review</strong> to <strong>staging</strong>.") - ) - end - - context 'when scope can not be updated' do - let(:params) do - { - scopes_attributes: [{ id: changed_scope.id, environment_scope: '' }] - } - end - - it 'returns error status' do - expect(subject[:status]).to eq(:error) - end - - it 'returns error messages' do - expect(subject[:message]).to include("Scopes environment scope can't be blank") - end - - it 'does not create audit event' do - expect { subject }.not_to change { AuditEvent.count } - end - end - end - - context 'when scope is deleted' do - let(:deleted_scope) { feature_flag.scopes.create!(environment_scope: 'review', active: true) } - let(:params) do - { - scopes_attributes: [{ id: deleted_scope.id, '_destroy': true }] - } - end - - it 'creates audit event with deleted scope' do - expect { subject }.to change { AuditEvent.count }.by(1) - expect(audit_event_message).to include("Deleted rule <strong>review</strong>.") - end - - context 'when scope can not be deleted' do - before do - allow(deleted_scope).to receive(:destroy).and_return(false) - end - - it 'does not create audit event' do - expect do - subject - end.to not_change { AuditEvent.count }.and raise_error(ActiveRecord::RecordNotDestroyed) - end - end - end - - context 'when new scope is being added' do - let(:new_environment_scope) { 'review' } - let(:params) do - { - scopes_attributes: [{ environment_scope: new_environment_scope, active: true }] - } - end - - it 'creates audit event with new scope' do - expected = 'Created rule <strong>review</strong> and set it as <strong>active</strong> '\ - 'with strategies <strong>[{"name"=>"default", "parameters"=>{}}]</strong>.' - - subject - - expect(audit_event_message).to include(expected) - end - - context 'when scope can not be created' do - let(:new_environment_scope) { '' } - - it 'returns error status' do - expect(subject[:status]).to eq(:error) - end - - it 'returns error messages' do - expect(subject[:message]).to include("Scopes environment scope can't be blank") - end - - it 'does not create audit event' do - expect { subject }.not_to change { AuditEvent.count } - end - end - end - - context 'when the strategy is changed' do - let(:scope) do - create(:operations_feature_flag_scope, - feature_flag: feature_flag, - environment_scope: 'sandbox', - strategies: [{ name: "default", parameters: {} }]) - end - - let(:params) do - { - scopes_attributes: [{ - id: scope.id, - environment_scope: 'sandbox', - strategies: [{ - name: 'gradualRolloutUserId', - parameters: { - groupId: 'mygroup', - percentage: "40" - } - }] - }] - } - end - - it 'creates an audit event' do - expected = %r{Updated rule <strong>sandbox</strong> strategies from <strong>.*</strong> to <strong>.*</strong>.} - - expect { subject }.to change { AuditEvent.count }.by(1) - expect(audit_event_message).to match(expected) - end - end end end |