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:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-05-10 18:10:24 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-05-10 18:10:24 +0300
commitbd5eb9f0201cf39ecfb0e754787a2297d5fdf051 (patch)
treeb3770a3806de9bf16a106474e4e8b0b57f4076a3 /spec/graphql
parent0ecdc32a425d18a762fb7723c2063e864065b571 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/graphql')
-rw-r--r--spec/graphql/mutations/merge_requests/set_draft_spec.rb55
-rw-r--r--spec/graphql/types/merge_request_type_spec.rb2
-rw-r--r--spec/graphql/types/mutation_type_spec.rb18
3 files changed, 69 insertions, 6 deletions
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/types/merge_request_type_spec.rb b/spec/graphql/types/merge_request_type_spec.rb
index 3314ea62324..fa33b32c6c8 100644
--- a/spec/graphql/types/merge_request_type_spec.rb
+++ b/spec/graphql/types/merge_request_type_spec.rb
@@ -16,7 +16,7 @@ RSpec.describe GitlabSchema.types['MergeRequest'] do
notes discussions user_permissions id iid title title_html description
description_html state created_at updated_at source_project target_project
project project_id source_project_id target_project_id source_branch
- target_branch work_in_progress merge_when_pipeline_succeeds diff_head_sha
+ target_branch work_in_progress draft merge_when_pipeline_succeeds diff_head_sha
merge_commit_sha user_notes_count user_discussions_count should_remove_source_branch
diff_refs diff_stats diff_stats_summary
force_remove_source_branch merge_status in_progress_merge_commit_sha
diff --git a/spec/graphql/types/mutation_type_spec.rb b/spec/graphql/types/mutation_type_spec.rb
index 41993327577..e4144e4fa97 100644
--- a/spec/graphql/types/mutation_type_spec.rb
+++ b/spec/graphql/types/mutation_type_spec.rb
@@ -3,8 +3,16 @@
require 'spec_helper'
RSpec.describe Types::MutationType do
- it 'is expected to have the MergeRequestSetWip' do
- expect(described_class).to have_graphql_mutation(Mutations::MergeRequests::SetWip)
+ it 'is expected to have the deprecated MergeRequestSetWip' do
+ field = get_field('MergeRequestSetWip')
+
+ expect(field).to be_present
+ expect(field.deprecation_reason).to be_present
+ expect(field.resolver).to eq(Mutations::MergeRequests::SetWip)
+ end
+
+ it 'is expected to have the MergeRequestSetDraft' do
+ expect(described_class).to have_graphql_mutation(Mutations::MergeRequests::SetDraft)
end
describe 'deprecated and aliased mutations' do
@@ -27,9 +35,9 @@ RSpec.describe Types::MutationType do
it { expect(alias_field.resolver.fields).to eq(canonical_field.resolver.fields) }
it { expect(alias_field.resolver.arguments).to eq(canonical_field.resolver.arguments) }
end
+ end
- def get_field(name)
- described_class.fields[GraphqlHelpers.fieldnamerize(name)]
- end
+ def get_field(name)
+ described_class.fields[GraphqlHelpers.fieldnamerize(name)]
end
end