summaryrefslogtreecommitdiff
path: root/spec/graphql/mutations
diff options
context:
space:
mode:
Diffstat (limited to 'spec/graphql/mutations')
-rw-r--r--spec/graphql/mutations/alert_management/alerts/todo/create_spec.rb1
-rw-r--r--spec/graphql/mutations/alert_management/create_alert_issue_spec.rb1
-rw-r--r--spec/graphql/mutations/alert_management/http_integration/create_spec.rb1
-rw-r--r--spec/graphql/mutations/alert_management/http_integration/destroy_spec.rb1
-rw-r--r--spec/graphql/mutations/alert_management/http_integration/reset_token_spec.rb1
-rw-r--r--spec/graphql/mutations/alert_management/http_integration/update_spec.rb1
-rw-r--r--spec/graphql/mutations/alert_management/prometheus_integration/create_spec.rb1
-rw-r--r--spec/graphql/mutations/alert_management/prometheus_integration/reset_token_spec.rb1
-rw-r--r--spec/graphql/mutations/alert_management/prometheus_integration/update_spec.rb1
-rw-r--r--spec/graphql/mutations/alert_management/update_alert_status_spec.rb1
-rw-r--r--spec/graphql/mutations/boards/lists/update_spec.rb58
-rw-r--r--spec/graphql/mutations/commits/create_spec.rb10
-rw-r--r--spec/graphql/mutations/issues/create_spec.rb13
-rw-r--r--spec/graphql/mutations/issues/set_due_date_spec.rb19
-rw-r--r--spec/graphql/mutations/issues/update_spec.rb38
-rw-r--r--spec/graphql/mutations/merge_requests/set_draft_spec.rb55
-rw-r--r--spec/graphql/mutations/merge_requests/set_locked_spec.rb2
-rw-r--r--spec/graphql/mutations/merge_requests/set_wip_spec.rb2
-rw-r--r--spec/graphql/mutations/namespace/package_settings/update_spec.rb12
-rw-r--r--spec/graphql/mutations/security/ci_configuration/configure_sast_spec.rb115
-rw-r--r--spec/graphql/mutations/security/ci_configuration/configure_secret_detection_spec.rb13
21 files changed, 168 insertions, 179 deletions
diff --git a/spec/graphql/mutations/alert_management/alerts/todo/create_spec.rb b/spec/graphql/mutations/alert_management/alerts/todo/create_spec.rb
index a10c3725ba2..8ec99070c91 100644
--- a/spec/graphql/mutations/alert_management/alerts/todo/create_spec.rb
+++ b/spec/graphql/mutations/alert_management/alerts/todo/create_spec.rb
@@ -7,6 +7,7 @@ RSpec.describe Mutations::AlertManagement::Alerts::Todo::Create do
let_it_be(:alert) { create(:alert_management_alert) }
let_it_be(:project) { alert.project }
+
let(:current_user) { project.owner }
let(:args) { { project_path: project.full_path, iid: alert.iid } }
diff --git a/spec/graphql/mutations/alert_management/create_alert_issue_spec.rb b/spec/graphql/mutations/alert_management/create_alert_issue_spec.rb
index 47ee338ad34..4758ac526a5 100644
--- a/spec/graphql/mutations/alert_management/create_alert_issue_spec.rb
+++ b/spec/graphql/mutations/alert_management/create_alert_issue_spec.rb
@@ -6,6 +6,7 @@ RSpec.describe Mutations::AlertManagement::CreateAlertIssue do
let_it_be(:current_user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:alert) { create(:alert_management_alert, project: project, status: 'triggered') }
+
let(:args) { { project_path: project.full_path, iid: alert.iid } }
specify { expect(described_class).to require_graphql_authorizations(:update_alert_management_alert) }
diff --git a/spec/graphql/mutations/alert_management/http_integration/create_spec.rb b/spec/graphql/mutations/alert_management/http_integration/create_spec.rb
index 9aa89761aaf..be6c627e376 100644
--- a/spec/graphql/mutations/alert_management/http_integration/create_spec.rb
+++ b/spec/graphql/mutations/alert_management/http_integration/create_spec.rb
@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe Mutations::AlertManagement::HttpIntegration::Create do
let_it_be(:current_user) { create(:user) }
let_it_be(:project) { create(:project) }
+
let(:args) { { project_path: project.full_path, active: true, name: 'HTTP Integration' } }
specify { expect(described_class).to require_graphql_authorizations(:admin_operations) }
diff --git a/spec/graphql/mutations/alert_management/http_integration/destroy_spec.rb b/spec/graphql/mutations/alert_management/http_integration/destroy_spec.rb
index acd7070d0d3..1aeeba1009e 100644
--- a/spec/graphql/mutations/alert_management/http_integration/destroy_spec.rb
+++ b/spec/graphql/mutations/alert_management/http_integration/destroy_spec.rb
@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe Mutations::AlertManagement::HttpIntegration::Destroy do
let_it_be(:current_user) { create(:user) }
let_it_be(:project) { create(:project) }
+
let(:integration) { create(:alert_management_http_integration, project: project) }
let(:args) { { id: GitlabSchema.id_from_object(integration) } }
diff --git a/spec/graphql/mutations/alert_management/http_integration/reset_token_spec.rb b/spec/graphql/mutations/alert_management/http_integration/reset_token_spec.rb
index 96974c2aa6f..5a2af9e0be8 100644
--- a/spec/graphql/mutations/alert_management/http_integration/reset_token_spec.rb
+++ b/spec/graphql/mutations/alert_management/http_integration/reset_token_spec.rb
@@ -6,6 +6,7 @@ RSpec.describe Mutations::AlertManagement::HttpIntegration::ResetToken do
let_it_be(:current_user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:integration) { create(:alert_management_http_integration, project: project) }
+
let(:args) { { id: GitlabSchema.id_from_object(integration) } }
specify { expect(described_class).to require_graphql_authorizations(:admin_operations) }
diff --git a/spec/graphql/mutations/alert_management/http_integration/update_spec.rb b/spec/graphql/mutations/alert_management/http_integration/update_spec.rb
index d6318e3161d..805996bf9e9 100644
--- a/spec/graphql/mutations/alert_management/http_integration/update_spec.rb
+++ b/spec/graphql/mutations/alert_management/http_integration/update_spec.rb
@@ -6,6 +6,7 @@ RSpec.describe Mutations::AlertManagement::HttpIntegration::Update do
let_it_be(:current_user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:integration) { create(:alert_management_http_integration, project: project) }
+
let(:args) { { id: GitlabSchema.id_from_object(integration), active: false, name: 'New Name' } }
specify { expect(described_class).to require_graphql_authorizations(:admin_operations) }
diff --git a/spec/graphql/mutations/alert_management/prometheus_integration/create_spec.rb b/spec/graphql/mutations/alert_management/prometheus_integration/create_spec.rb
index 02a5e2e74e2..7ab0f43d674 100644
--- a/spec/graphql/mutations/alert_management/prometheus_integration/create_spec.rb
+++ b/spec/graphql/mutations/alert_management/prometheus_integration/create_spec.rb
@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe Mutations::AlertManagement::PrometheusIntegration::Create do
let_it_be(:current_user) { create(:user) }
let_it_be(:project) { create(:project) }
+
let(:args) { { project_path: project.full_path, active: true, api_url: 'http://prometheus.com/' } }
specify { expect(described_class).to require_graphql_authorizations(:admin_project) }
diff --git a/spec/graphql/mutations/alert_management/prometheus_integration/reset_token_spec.rb b/spec/graphql/mutations/alert_management/prometheus_integration/reset_token_spec.rb
index ddf23909035..c9e1bf4162c 100644
--- a/spec/graphql/mutations/alert_management/prometheus_integration/reset_token_spec.rb
+++ b/spec/graphql/mutations/alert_management/prometheus_integration/reset_token_spec.rb
@@ -6,6 +6,7 @@ RSpec.describe Mutations::AlertManagement::PrometheusIntegration::ResetToken do
let_it_be(:current_user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:integration) { create(:prometheus_service, project: project) }
+
let(:args) { { id: GitlabSchema.id_from_object(integration) } }
specify { expect(described_class).to require_graphql_authorizations(:admin_project) }
diff --git a/spec/graphql/mutations/alert_management/prometheus_integration/update_spec.rb b/spec/graphql/mutations/alert_management/prometheus_integration/update_spec.rb
index eab4474d827..19e0d53b75f 100644
--- a/spec/graphql/mutations/alert_management/prometheus_integration/update_spec.rb
+++ b/spec/graphql/mutations/alert_management/prometheus_integration/update_spec.rb
@@ -6,6 +6,7 @@ RSpec.describe Mutations::AlertManagement::PrometheusIntegration::Update do
let_it_be(:current_user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:integration) { create(:prometheus_service, project: project) }
+
let(:args) { { id: GitlabSchema.id_from_object(integration), active: false, api_url: 'http://new-url.com' } }
specify { expect(described_class).to require_graphql_authorizations(:admin_project) }
diff --git a/spec/graphql/mutations/alert_management/update_alert_status_spec.rb b/spec/graphql/mutations/alert_management/update_alert_status_spec.rb
index 8465393f299..2c2518e046a 100644
--- a/spec/graphql/mutations/alert_management/update_alert_status_spec.rb
+++ b/spec/graphql/mutations/alert_management/update_alert_status_spec.rb
@@ -6,6 +6,7 @@ RSpec.describe Mutations::AlertManagement::UpdateAlertStatus do
let_it_be(:current_user) { create(:user) }
let_it_be(:alert) { create(:alert_management_alert, :triggered) }
let_it_be(:project) { alert.project }
+
let(:new_status) { Types::AlertManagement::StatusEnum.values['ACKNOWLEDGED'].value }
let(:args) { { status: new_status, project_path: project.full_path, iid: alert.iid } }
diff --git a/spec/graphql/mutations/boards/lists/update_spec.rb b/spec/graphql/mutations/boards/lists/update_spec.rb
index d5d8a2af6bf..c82cbbfdd83 100644
--- a/spec/graphql/mutations/boards/lists/update_spec.rb
+++ b/spec/graphql/mutations/boards/lists/update_spec.rb
@@ -3,54 +3,14 @@
require 'spec_helper'
RSpec.describe Mutations::Boards::Lists::Update do
- let_it_be(:group) { create(:group, :private) }
- let_it_be(:board) { create(:board, group: group) }
- let_it_be(:reporter) { create(:user) }
- let_it_be(:guest) { create(:user) }
- let_it_be(:list) { create(:list, board: board, position: 0) }
- let_it_be(:list2) { create(:list, board: board) }
- let(:mutation) { described_class.new(object: nil, context: { current_user: current_user }, field: nil) }
- let(:list_update_params) { { position: 1, collapsed: true } }
-
- before_all do
- group.add_reporter(reporter)
- group.add_guest(guest)
- list.update_preferences_for(reporter, collapsed: false)
- end
-
- subject { mutation.resolve(list: list, **list_update_params) }
-
- describe '#resolve' do
- context 'with permission to admin board lists' do
- let(:current_user) { reporter }
-
- it 'updates the list position and collapsed state as expected' do
- subject
-
- reloaded_list = list.reload
- expect(reloaded_list.position).to eq(1)
- expect(reloaded_list.collapsed?(current_user)).to eq(true)
- end
- end
-
- context 'with permission to read board lists' do
- let(:current_user) { guest }
-
- it 'updates the list collapsed state but not the list position' do
- subject
-
- reloaded_list = list.reload
- expect(reloaded_list.position).to eq(0)
- expect(reloaded_list.collapsed?(current_user)).to eq(true)
- end
- end
-
- context 'without permission to read board lists' do
- let(:current_user) { create(:user) }
-
- it 'raises Resource Not Found error' do
- expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
- end
- end
+ context 'on group issue boards' do
+ let_it_be(:group) { create(:group, :private) }
+ let_it_be(:board) { create(:board, group: group) }
+ let_it_be(:reporter) { create(:user) }
+ let_it_be(:guest) { create(:user) }
+ let_it_be(:list) { create(:list, board: board, position: 0) }
+ let_it_be(:list2) { create(:list, board: board) }
+
+ it_behaves_like 'update board list mutation'
end
end
diff --git a/spec/graphql/mutations/commits/create_spec.rb b/spec/graphql/mutations/commits/create_spec.rb
index 82a5e3a62f5..152b5d87da0 100644
--- a/spec/graphql/mutations/commits/create_spec.rb
+++ b/spec/graphql/mutations/commits/create_spec.rb
@@ -24,11 +24,12 @@ RSpec.describe Mutations::Commits::Create do
let(:branch) { 'master' }
let(:start_branch) { nil }
let(:message) { 'Commit message' }
+ let(:file_path) { "#{SecureRandom.uuid}.md" }
let(:actions) do
[
{
action: 'create',
- file_path: 'NEW_FILE.md',
+ file_path: file_path,
content: 'Hello'
}
]
@@ -68,12 +69,17 @@ RSpec.describe Mutations::Commits::Create do
end
context 'when service successfully creates a new commit' do
+ it "returns the ETag path for the commit's pipeline" do
+ commit_pipeline_path = subject[:commit_pipeline_path]
+ expect(commit_pipeline_path).to match(%r(pipelines/sha/\w+))
+ end
+
it 'returns a new commit' do
expect(mutated_commit).to have_attributes(message: message, project: project)
expect(subject[:errors]).to be_empty
expect_to_contain_deltas([
- a_hash_including(a_mode: '0', b_mode: '100644', new_file: true, new_path: 'NEW_FILE.md')
+ a_hash_including(a_mode: '0', b_mode: '100644', new_file: true, new_path: file_path)
])
end
end
diff --git a/spec/graphql/mutations/issues/create_spec.rb b/spec/graphql/mutations/issues/create_spec.rb
index 422ad40a9cb..b32f0991959 100644
--- a/spec/graphql/mutations/issues/create_spec.rb
+++ b/spec/graphql/mutations/issues/create_spec.rb
@@ -19,7 +19,8 @@ RSpec.describe Mutations::Issues::Create do
description: 'new description',
confidential: true,
due_date: Date.tomorrow,
- discussion_locked: true
+ discussion_locked: true,
+ issue_type: 'issue'
}
end
@@ -93,6 +94,16 @@ RSpec.describe Mutations::Issues::Create do
expect(mutated_issue.iid).not_to eq(special_params[:iid])
end
end
+
+ context 'when creating a non-default issue type' do
+ before do
+ mutation_params[:issue_type] = 'incident'
+ end
+
+ it 'creates issue with correct values' do
+ expect(mutated_issue.issue_type).to eq('incident')
+ end
+ end
end
context 'when creating an issue as owner' do
diff --git a/spec/graphql/mutations/issues/set_due_date_spec.rb b/spec/graphql/mutations/issues/set_due_date_spec.rb
index 9f8d0d6c405..263122e5d5f 100644
--- a/spec/graphql/mutations/issues/set_due_date_spec.rb
+++ b/spec/graphql/mutations/issues/set_due_date_spec.rb
@@ -3,8 +3,9 @@
require 'spec_helper'
RSpec.describe Mutations::Issues::SetDueDate do
- let(:issue) { create(:issue) }
- let(:user) { create(:user) }
+ let(:issue) { create(:issue, due_date: '2021-05-01') }
+
+ let_it_be(:user) { create(:user) }
subject(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) }
@@ -23,17 +24,25 @@ RSpec.describe Mutations::Issues::SetDueDate do
issue.project.add_developer(user)
end
- it 'returns the issue with updated due date' do
+ it 'returns the issue with updated due date', :aggregate_failures do
expect(mutated_issue).to eq(issue)
expect(mutated_issue.due_date).to eq(Date.today + 2.days)
expect(subject[:errors]).to be_empty
end
+ context 'when due date is nil' do
+ let(:due_date) { nil }
+
+ it 'updates due date to be nil' do
+ expect(mutated_issue.due_date).to be nil
+ end
+ end
+
context 'when passing incorrect due date value' do
let(:due_date) { 'test' }
- it 'does not update due date' do
- expect(mutated_issue.due_date).to eq(issue.due_date)
+ it 'updates due date to be nil' do
+ expect(mutated_issue.due_date).to be nil
end
end
end
diff --git a/spec/graphql/mutations/issues/update_spec.rb b/spec/graphql/mutations/issues/update_spec.rb
index f10e257e153..6d6a5b94219 100644
--- a/spec/graphql/mutations/issues/update_spec.rb
+++ b/spec/graphql/mutations/issues/update_spec.rb
@@ -69,17 +69,33 @@ RSpec.describe Mutations::Issues::Update do
context 'when changing state' do
let_it_be_with_refind(:issue) { create(:issue, project: project, state: :opened) }
- it 'closes issue' do
- mutation_params[:state_event] = 'close'
+ before do
+ mutation_params[:state_event] = state_event
+ end
+
+ context 'when state_event is close' do
+ let_it_be(:removable_label) { create(:label, project: project, remove_on_close: true, issues: [issue]) }
- expect { subject }.to change { issue.reload.state }.from('opened').to('closed')
+ let(:state_event) { 'close' }
+
+ it 'closes issue' do
+ expect do
+ subject
+ issue.reload
+ end.to change(issue, :state).from('opened').to('closed').and(
+ change { issue.label_ids }.from([removable_label.id]).to([])
+ )
+ end
end
- it 'reopens issue' do
- issue.close
- mutation_params[:state_event] = 'reopen'
+ context 'when state_event is reopen' do
+ let(:state_event) { 'reopen' }
+
+ it 'reopens issue' do
+ issue.close
- expect { subject }.to change { issue.reload.state }.from('closed').to('opened')
+ expect { subject }.to change { issue.reload.state }.from('closed').to('opened')
+ end
end
end
@@ -128,6 +144,14 @@ RSpec.describe Mutations::Issues::Update do
expect(issue.reload.labels).to match_array([project_label, label_2])
end
end
+
+ context 'when changing type' do
+ it 'changes the type of the issue' do
+ mutation_params[:issue_type] = 'incident'
+
+ expect { subject }.to change { issue.reload.issue_type }.from('issue').to('incident')
+ end
+ end
end
end
end
diff --git a/spec/graphql/mutations/merge_requests/set_draft_spec.rb b/spec/graphql/mutations/merge_requests/set_draft_spec.rb
new file mode 100644
index 00000000000..697b2e5b007
--- /dev/null
+++ b/spec/graphql/mutations/merge_requests/set_draft_spec.rb
@@ -0,0 +1,55 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Mutations::MergeRequests::SetDraft do
+ let_it_be(:merge_request) { create(:merge_request) }
+ let_it_be(:user) { create(:user) }
+
+ subject(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) }
+
+ specify { expect(described_class).to require_graphql_authorizations(:update_merge_request) }
+
+ describe '#resolve' do
+ let(:draft) { true }
+ let(:mutated_merge_request) { subject[:merge_request] }
+
+ subject { mutation.resolve(project_path: merge_request.project.full_path, iid: merge_request.iid, draft: draft) }
+
+ it_behaves_like 'permission level for merge request mutation is correctly verified'
+
+ context 'when the user can update the merge request' do
+ before do
+ merge_request.project.add_developer(user)
+ end
+
+ it 'returns the merge request as a draft' do
+ expect(mutated_merge_request).to eq(merge_request)
+ expect(mutated_merge_request).to be_draft
+ expect(subject[:errors]).to be_empty
+ end
+
+ it 'returns errors if/when merge request could not be updated' do
+ # Make the merge request invalid
+ merge_request.allow_broken = true
+ merge_request.update!(source_project: nil)
+
+ expect(subject[:errors]).not_to be_empty
+ end
+
+ context 'when passing draft as false' do
+ let(:draft) { false }
+
+ it 'removes `Draft` from the title' do
+ merge_request.update!(title: "Draft: working on it")
+
+ expect(mutated_merge_request).not_to be_draft
+ end
+
+ it 'does not do anything if the title did not start with draft' do
+ expect(mutated_merge_request).not_to be_draft
+ end
+ end
+ end
+ end
+end
diff --git a/spec/graphql/mutations/merge_requests/set_locked_spec.rb b/spec/graphql/mutations/merge_requests/set_locked_spec.rb
index 03c709e9bb3..68bb7aa0aa4 100644
--- a/spec/graphql/mutations/merge_requests/set_locked_spec.rb
+++ b/spec/graphql/mutations/merge_requests/set_locked_spec.rb
@@ -41,7 +41,7 @@ RSpec.describe Mutations::MergeRequests::SetLocked do
let(:locked) { false }
it 'unlocks the discussion' do
- merge_request.update(discussion_locked: true)
+ merge_request.update!(discussion_locked: true)
expect(mutated_merge_request).not_to be_discussion_locked
end
diff --git a/spec/graphql/mutations/merge_requests/set_wip_spec.rb b/spec/graphql/mutations/merge_requests/set_wip_spec.rb
index 69f6a4328b8..fae9c4f7fe0 100644
--- a/spec/graphql/mutations/merge_requests/set_wip_spec.rb
+++ b/spec/graphql/mutations/merge_requests/set_wip_spec.rb
@@ -41,7 +41,7 @@ RSpec.describe Mutations::MergeRequests::SetWip do
let(:wip) { false }
it 'removes `wip` from the title' do
- merge_request.update(title: "WIP: working on it")
+ merge_request.update!(title: "WIP: working on it")
expect(mutated_merge_request).not_to be_work_in_progress
end
diff --git a/spec/graphql/mutations/namespace/package_settings/update_spec.rb b/spec/graphql/mutations/namespace/package_settings/update_spec.rb
index bd0d38cb49f..978c81fadfa 100644
--- a/spec/graphql/mutations/namespace/package_settings/update_spec.rb
+++ b/spec/graphql/mutations/namespace/package_settings/update_spec.rb
@@ -25,7 +25,9 @@ RSpec.describe Mutations::Namespace::PackageSettings::Update do
end
RSpec.shared_examples 'updating the namespace package setting' do
- it_behaves_like 'updating the namespace package setting attributes', from: { maven_duplicates_allowed: true, maven_duplicate_exception_regex: 'SNAPSHOT' }, to: { maven_duplicates_allowed: false, maven_duplicate_exception_regex: 'RELEASE' }
+ it_behaves_like 'updating the namespace package setting attributes',
+ from: { maven_duplicates_allowed: true, maven_duplicate_exception_regex: 'SNAPSHOT', generic_duplicates_allowed: true, generic_duplicate_exception_regex: 'foo' },
+ to: { maven_duplicates_allowed: false, maven_duplicate_exception_regex: 'RELEASE', generic_duplicates_allowed: false, generic_duplicate_exception_regex: 'bar' }
it_behaves_like 'returning a success'
@@ -56,7 +58,13 @@ RSpec.describe Mutations::Namespace::PackageSettings::Update do
context 'with existing namespace package setting' do
let_it_be(:package_settings) { create(:namespace_package_setting, namespace: namespace) }
- let_it_be(:params) { { namespace_path: namespace.full_path, maven_duplicates_allowed: false, maven_duplicate_exception_regex: 'RELEASE' } }
+ let_it_be(:params) do
+ { namespace_path: namespace.full_path,
+ maven_duplicates_allowed: false,
+ maven_duplicate_exception_regex: 'RELEASE',
+ generic_duplicates_allowed: false,
+ generic_duplicate_exception_regex: 'bar' }
+ end
where(:user_role, :shared_examples_name) do
:maintainer | 'updating the namespace package setting'
diff --git a/spec/graphql/mutations/security/ci_configuration/configure_sast_spec.rb b/spec/graphql/mutations/security/ci_configuration/configure_sast_spec.rb
index ed03a1cb906..7c3b552480f 100644
--- a/spec/graphql/mutations/security/ci_configuration/configure_sast_spec.rb
+++ b/spec/graphql/mutations/security/ci_configuration/configure_sast_spec.rb
@@ -3,118 +3,11 @@
require 'spec_helper'
RSpec.describe Mutations::Security::CiConfiguration::ConfigureSast do
- subject(:mutation) { described_class.new(object: nil, context: context, field: nil) }
+ include GraphqlHelpers
- let_it_be(:project) { create(:project, :public, :repository) }
- let_it_be(:user) { create(:user) }
+ let(:service) { ::Security::CiConfiguration::SastCreateService }
- let_it_be(:service_result_json) do
- {
- status: "success",
- success_path: "http://127.0.0.1:3000/root/demo-historic-secrets/-/merge_requests/new?",
- errors: nil
- }
- end
+ subject { resolve(described_class, args: { project_path: project.full_path, configuration: {} }, ctx: { current_user: user }) }
- let_it_be(:service_error_result_json) do
- {
- status: "error",
- success_path: nil,
- errors: %w(error1 error2)
- }
- end
-
- let(:context) do
- GraphQL::Query::Context.new(
- query: OpenStruct.new(schema: nil),
- values: { current_user: user },
- object: nil
- )
- end
-
- specify { expect(described_class).to require_graphql_authorizations(:push_code) }
-
- describe '#resolve' do
- subject { mutation.resolve(project_path: project.full_path, configuration: {}) }
-
- let(:result) { subject }
-
- it 'raises an error if the resource is not accessible to the user' do
- expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
- end
-
- context 'when user does not have enough permissions' do
- before do
- project.add_guest(user)
- end
-
- it 'raises an error' do
- expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
- end
- end
-
- context 'when user is a maintainer of a different project' do
- before do
- create(:project_empty_repo).add_maintainer(user)
- end
-
- it 'raises an error' do
- expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
- end
- end
-
- context 'when the user does not have permission to create a new branch' do
- before_all do
- project.add_developer(user)
- end
-
- let(:error_message) { 'You are not allowed to create protected branches on this project.' }
-
- it 'returns an array of errors' do
- allow_next_instance_of(::Files::MultiService) do |multi_service|
- allow(multi_service).to receive(:execute).and_raise(Gitlab::Git::PreReceiveError.new("GitLab: #{error_message}"))
- end
-
- expect(result).to match(
- status: :error,
- success_path: nil,
- errors: match_array([error_message])
- )
- end
- end
-
- context 'when the user can create a merge request' do
- before_all do
- project.add_developer(user)
- end
-
- context 'when service successfully generates a path to create a new merge request' do
- it 'returns a success path' do
- allow_next_instance_of(::Security::CiConfiguration::SastCreateService) do |service|
- allow(service).to receive(:execute).and_return(service_result_json)
- end
-
- expect(result).to match(
- status: 'success',
- success_path: service_result_json[:success_path],
- errors: []
- )
- end
- end
-
- context 'when service can not generate any path to create a new merge request' do
- it 'returns an array of errors' do
- allow_next_instance_of(::Security::CiConfiguration::SastCreateService) do |service|
- allow(service).to receive(:execute).and_return(service_error_result_json)
- end
-
- expect(result).to match(
- status: 'error',
- success_path: be_nil,
- errors: match_array(service_error_result_json[:errors])
- )
- end
- end
- end
- end
+ include_examples 'graphql mutations security ci configuration'
end
diff --git a/spec/graphql/mutations/security/ci_configuration/configure_secret_detection_spec.rb b/spec/graphql/mutations/security/ci_configuration/configure_secret_detection_spec.rb
new file mode 100644
index 00000000000..5b4a7d5918c
--- /dev/null
+++ b/spec/graphql/mutations/security/ci_configuration/configure_secret_detection_spec.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Mutations::Security::CiConfiguration::ConfigureSecretDetection do
+ include GraphqlHelpers
+
+ let(:service) { ::Security::CiConfiguration::SecretDetectionCreateService }
+
+ subject { resolve(described_class, args: { project_path: project.full_path }, ctx: { current_user: user }) }
+
+ include_examples 'graphql mutations security ci configuration'
+end