diff options
Diffstat (limited to 'spec/services/security/ci_configuration/sast_create_service_spec.rb')
-rw-r--r-- | spec/services/security/ci_configuration/sast_create_service_spec.rb | 75 |
1 files changed, 16 insertions, 59 deletions
diff --git a/spec/services/security/ci_configuration/sast_create_service_spec.rb b/spec/services/security/ci_configuration/sast_create_service_spec.rb index ff7ab614e08..44f8f07a5be 100644 --- a/spec/services/security/ci_configuration/sast_create_service_spec.rb +++ b/spec/services/security/ci_configuration/sast_create_service_spec.rb @@ -3,67 +3,24 @@ require 'spec_helper' RSpec.describe Security::CiConfiguration::SastCreateService, :snowplow do - describe '#execute' do - let_it_be(:project) { create(:project, :repository) } - let_it_be(:user) { create(:user) } - let(:params) { {} } + subject(:result) { described_class.new(project, user, params).execute } - subject(:result) { described_class.new(project, user, params).execute } + let(:branch_name) { 'set-sast-config-1' } - context 'user does not belong to project' do - it 'returns an error status' do - expect(result[:status]).to eq(:error) - expect(result[:success_path]).to be_nil - end - - it 'does not track a snowplow event' do - subject - - expect_no_snowplow_event - end - end - - context 'user belongs to project' do - before do - project.add_developer(user) - end - - it 'does track the snowplow event' do - subject - - expect_snowplow_event( - category: 'Security::CiConfiguration::SastCreateService', - action: 'create', - label: 'false' - ) - end - - it 'raises exception if the user does not have permission to create a new branch' do - allow(project).to receive(:repository).and_raise(Gitlab::Git::PreReceiveError, "You are not allowed to create protected branches on this project.") - - expect { subject }.to raise_error(Gitlab::Git::PreReceiveError) - end - - context 'with no parameters' do - it 'returns the path to create a new merge request' do - expect(result[:status]).to eq(:success) - expect(result[:success_path]).to match(/#{Gitlab::Routing.url_helpers.project_new_merge_request_url(project, {})}(.*)description(.*)source_branch/) - end - end - - context 'with parameters' do - let(:params) do - { 'stage' => 'security', - 'SEARCH_MAX_DEPTH' => 1, - 'SECURE_ANALYZERS_PREFIX' => 'new_registry', - 'SAST_EXCLUDED_PATHS' => 'spec,docs' } - end + let(:non_empty_params) do + { 'stage' => 'security', + 'SEARCH_MAX_DEPTH' => 1, + 'SECURE_ANALYZERS_PREFIX' => 'new_registry', + 'SAST_EXCLUDED_PATHS' => 'spec,docs' } + end - it 'returns the path to create a new merge request' do - expect(result[:status]).to eq(:success) - expect(result[:success_path]).to match(/#{Gitlab::Routing.url_helpers.project_new_merge_request_url(project, {})}(.*)description(.*)source_branch/) - end - end - end + let(:snowplow_event) do + { + category: 'Security::CiConfiguration::SastCreateService', + action: 'create', + label: 'false' + } end + + include_examples 'services security ci configuration create service' end |