debian-mirror-gitlab/spec/services/feature_flags/destroy_service_spec.rb

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

68 lines
1.8 KiB
Ruby
Raw Normal View History

2021-01-03 14:25:43 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe FeatureFlags::DestroyService, feature_category: :feature_flags do
2021-01-03 14:25:43 +05:30
include FeatureFlagHelpers
let_it_be(:project) { create(:project) }
let_it_be(:developer) { create(:user) }
let_it_be(:reporter) { create(:user) }
2021-06-08 01:23:25 +05:30
2021-01-03 14:25:43 +05:30
let(:user) { developer }
let!(:feature_flag) { create(:operations_feature_flag, project: project) }
before_all do
project.add_developer(developer)
project.add_reporter(reporter)
end
describe '#execute' do
subject { described_class.new(project, user, params).execute(feature_flag) }
2023-05-27 22:25:52 +05:30
let(:audit_event_details) { AuditEvent.last.details }
let(:audit_event_message) { audit_event_details[:custom_message] }
2021-01-03 14:25:43 +05:30
let(:params) { {} }
it 'returns status success' do
expect(subject[:status]).to eq(:success)
end
it 'destroys feature flag' do
expect { subject }.to change { Operations::FeatureFlag.count }.by(-1)
end
2023-03-17 16:20:25 +05:30
it 'creates audit log', :with_license do
2021-01-03 14:25:43 +05:30
expect { subject }.to change { AuditEvent.count }.by(1)
2021-07-02 01:05:55 +05:30
expect(audit_event_message).to eq("Deleted feature flag #{feature_flag.name}.")
2021-01-03 14:25:43 +05:30
end
2022-08-13 15:12:31 +05:30
it_behaves_like 'update feature flag client'
2021-01-03 14:25:43 +05:30
context 'when user is reporter' do
let(:user) { reporter }
it 'returns error status' do
expect(subject[:status]).to eq(:error)
expect(subject[:message]).to eq('Access Denied')
end
end
context 'when feature flag can not be destroyed' do
before do
allow(feature_flag).to receive(:destroy).and_return(false)
end
it 'returns status error' do
expect(subject[:status]).to eq(:error)
end
it 'does not create audit log' do
expect { subject }.not_to change { AuditEvent.count }
end
2022-08-13 15:12:31 +05:30
it_behaves_like 'does not update feature flag client'
2021-01-03 14:25:43 +05:30
end
end
end