Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/requests/api/graphql/mutations')
-rw-r--r--spec/requests/api/graphql/mutations/alert_management/alerts/create_alert_issue_spec.rb6
-rw-r--r--spec/requests/api/graphql/mutations/merge_requests/accept_spec.rb44
-rw-r--r--spec/requests/api/graphql/mutations/notes/create/diff_note_spec.rb23
-rw-r--r--spec/requests/api/graphql/mutations/release_asset_links/create_spec.rb59
-rw-r--r--spec/requests/api/graphql/mutations/user_callouts/create_spec.rb29
5 files changed, 154 insertions, 7 deletions
diff --git a/spec/requests/api/graphql/mutations/alert_management/alerts/create_alert_issue_spec.rb b/spec/requests/api/graphql/mutations/alert_management/alerts/create_alert_issue_spec.rb
index 6141a172253..f637ca98353 100644
--- a/spec/requests/api/graphql/mutations/alert_management/alerts/create_alert_issue_spec.rb
+++ b/spec/requests/api/graphql/mutations/alert_management/alerts/create_alert_issue_spec.rb
@@ -20,7 +20,9 @@ RSpec.describe 'Create an alert issue from an alert' do
errors
alert {
iid
- issueIid
+ issue {
+ iid
+ }
}
issue {
iid
@@ -46,7 +48,7 @@ RSpec.describe 'Create an alert issue from an alert' do
expect(mutation_response.slice('alert', 'issue')).to eq(
'alert' => {
'iid' => alert.iid.to_s,
- 'issueIid' => new_issue.iid.to_s
+ 'issue' => { 'iid' => new_issue.iid.to_s }
},
'issue' => {
'iid' => new_issue.iid.to_s,
diff --git a/spec/requests/api/graphql/mutations/merge_requests/accept_spec.rb b/spec/requests/api/graphql/mutations/merge_requests/accept_spec.rb
new file mode 100644
index 00000000000..2725b33d528
--- /dev/null
+++ b/spec/requests/api/graphql/mutations/merge_requests/accept_spec.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe 'accepting a merge request', :request_store do
+ include GraphqlHelpers
+
+ let_it_be(:current_user) { create(:user) }
+ let_it_be(:project) { create(:project, :public, :repository) }
+ let!(:merge_request) { create(:merge_request, source_project: project) }
+ let(:input) do
+ {
+ project_path: project.full_path,
+ iid: merge_request.iid.to_s,
+ sha: merge_request.diff_head_sha
+ }
+ end
+
+ let(:mutation) { graphql_mutation(:merge_request_accept, input, 'mergeRequest { state }') }
+ let(:mutation_response) { graphql_mutation_response(:merge_request_accept) }
+
+ context 'when the user is not allowed to accept a merge request' do
+ before do
+ project.add_reporter(current_user)
+ end
+
+ it_behaves_like 'a mutation that returns a top-level access error'
+ end
+
+ context 'when user has permissions to create a merge request' do
+ before do
+ project.add_maintainer(current_user)
+ end
+
+ it 'merges the merge request' do
+ post_graphql_mutation(mutation, current_user: current_user)
+
+ expect(response).to have_gitlab_http_status(:success)
+ expect(mutation_response['mergeRequest']).to include(
+ 'state' => 'merged'
+ )
+ end
+ end
+end
diff --git a/spec/requests/api/graphql/mutations/notes/create/diff_note_spec.rb b/spec/requests/api/graphql/mutations/notes/create/diff_note_spec.rb
index 7dd897f6466..b5aaf304812 100644
--- a/spec/requests/api/graphql/mutations/notes/create/diff_note_spec.rb
+++ b/spec/requests/api/graphql/mutations/notes/create/diff_note_spec.rb
@@ -9,8 +9,9 @@ RSpec.describe 'Adding a DiffNote' do
let(:noteable) { create(:merge_request, source_project: project, target_project: project) }
let(:project) { create(:project, :repository) }
let(:diff_refs) { noteable.diff_refs }
- let(:mutation) do
- variables = {
+
+ let(:base_variables) do
+ {
noteable_id: GitlabSchema.id_from_object(noteable).to_s,
body: 'Body text',
position: {
@@ -18,16 +19,16 @@ RSpec.describe 'Adding a DiffNote' do
old_path: 'files/ruby/popen.rb',
new_path: 'files/ruby/popen2.rb'
},
- new_line: 14,
base_sha: diff_refs.base_sha,
head_sha: diff_refs.head_sha,
start_sha: diff_refs.start_sha
}
}
-
- graphql_mutation(:create_diff_note, variables)
end
+ let(:variables) { base_variables.deep_merge({ position: { new_line: 14 } }) }
+ let(:mutation) { graphql_mutation(:create_diff_note, variables) }
+
def mutation_response
graphql_mutation_response(:create_diff_note)
end
@@ -41,6 +42,18 @@ RSpec.describe 'Adding a DiffNote' do
it_behaves_like 'a Note mutation that creates a Note'
+ context 'add comment to old line' do
+ let(:variables) { base_variables.deep_merge({ position: { old_line: 14 } }) }
+
+ it_behaves_like 'a Note mutation that creates a Note'
+ end
+
+ context 'add a comment with a position without lines' do
+ let(:variables) { base_variables }
+
+ it_behaves_like 'a Note mutation that does not create a Note'
+ end
+
it_behaves_like 'a Note mutation when there are active record validation errors', model: DiffNote
it_behaves_like 'a Note mutation when there are rate limit validation errors'
diff --git a/spec/requests/api/graphql/mutations/release_asset_links/create_spec.rb b/spec/requests/api/graphql/mutations/release_asset_links/create_spec.rb
new file mode 100644
index 00000000000..c7a4cb1ebce
--- /dev/null
+++ b/spec/requests/api/graphql/mutations/release_asset_links/create_spec.rb
@@ -0,0 +1,59 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe 'Creation of a new release asset link' do
+ include GraphqlHelpers
+
+ let_it_be(:project) { create(:project, :private, :repository) }
+ let_it_be(:release) { create(:release, project: project, tag: 'v13.10') }
+ let_it_be(:developer) { create(:user).tap { |u| project.add_developer(u) } }
+
+ let(:current_user) { developer }
+
+ let(:mutation_name) { :release_asset_link_create }
+
+ let(:mutation_arguments) do
+ {
+ projectPath: project.full_path,
+ tagName: release.tag,
+ name: 'awesome-app.dmg',
+ url: 'https://example.com/download/awesome-app.dmg',
+ directAssetPath: '/binaries/awesome-app.dmg',
+ linkType: 'PACKAGE'
+ }
+ end
+
+ let(:mutation) do
+ graphql_mutation(mutation_name, mutation_arguments, <<~FIELDS)
+ link {
+ id
+ name
+ url
+ linkType
+ directAssetUrl
+ external
+ }
+ errors
+ FIELDS
+ end
+
+ let(:create_link) { post_graphql_mutation(mutation, current_user: current_user) }
+ let(:mutation_response) { graphql_mutation_response(mutation_name)&.with_indifferent_access }
+
+ it 'creates and returns a new asset link associated to the provided release', :aggregate_failures do
+ create_link
+
+ expected_response = {
+ id: start_with("gid://gitlab/Releases::Link/"),
+ name: mutation_arguments[:name],
+ url: mutation_arguments[:url],
+ linkType: mutation_arguments[:linkType],
+ directAssetUrl: end_with(mutation_arguments[:directAssetPath]),
+ external: true
+ }.with_indifferent_access
+
+ expect(mutation_response[:link]).to include(expected_response)
+ expect(mutation_response[:errors]).to eq([])
+ end
+end
diff --git a/spec/requests/api/graphql/mutations/user_callouts/create_spec.rb b/spec/requests/api/graphql/mutations/user_callouts/create_spec.rb
new file mode 100644
index 00000000000..cb67a60ebe4
--- /dev/null
+++ b/spec/requests/api/graphql/mutations/user_callouts/create_spec.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe 'Create a user callout' do
+ include GraphqlHelpers
+
+ let_it_be(:current_user) { create(:user) }
+ let(:feature_name) { ::UserCallout.feature_names.each_key.first }
+
+ let(:input) do
+ {
+ 'featureName' => feature_name
+ }
+ end
+
+ let(:mutation) { graphql_mutation(:userCalloutCreate, input) }
+ let(:mutation_response) { graphql_mutation_response(:userCalloutCreate) }
+
+ it 'creates user callout' do
+ freeze_time do
+ post_graphql_mutation(mutation, current_user: current_user)
+
+ expect(response).to have_gitlab_http_status(:success)
+ expect(mutation_response['userCallout']['featureName']).to eq(feature_name.upcase)
+ expect(mutation_response['userCallout']['dismissedAt']).to eq(Time.current.iso8601)
+ end
+ end
+end