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/graphql/mutations/issues/update_spec.rb')
-rw-r--r--spec/graphql/mutations/issues/update_spec.rb79
1 files changed, 72 insertions, 7 deletions
diff --git a/spec/graphql/mutations/issues/update_spec.rb b/spec/graphql/mutations/issues/update_spec.rb
index 9a847476e2e..15c15afd9b7 100644
--- a/spec/graphql/mutations/issues/update_spec.rb
+++ b/spec/graphql/mutations/issues/update_spec.rb
@@ -3,16 +3,23 @@
require 'spec_helper'
RSpec.describe Mutations::Issues::Update do
- let(:issue) { create(:issue) }
- let(:user) { create(:user) }
+ let_it_be(:project) { create(:project) }
+ let_it_be(:user) { create(:user) }
+ let_it_be(:project_label) { create(:label, project: project) }
+ let_it_be(:issue) { create(:issue, project: project, labels: [project_label]) }
+ let_it_be(:milestone) { create(:milestone, project: project) }
+
let(:expected_attributes) do
{
title: 'new title',
description: 'new description',
confidential: true,
- due_date: Date.tomorrow
+ due_date: Date.tomorrow,
+ discussion_locked: true,
+ milestone_id: milestone.id
}
end
+
let(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) }
let(:mutated_issue) { subject[:issue] }
@@ -21,20 +28,22 @@ RSpec.describe Mutations::Issues::Update do
describe '#resolve' do
let(:mutation_params) do
{
- project_path: issue.project.full_path,
+ project_path: project.full_path,
iid: issue.iid
}.merge(expected_attributes)
end
subject { mutation.resolve(mutation_params) }
- it 'raises an error if the resource is not accessible to the user' do
- expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ context 'when the user cannot access the issue' do
+ it 'raises an error' do
+ expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ end
end
context 'when the user can update the issue' do
before do
- issue.project.add_developer(user)
+ project.add_developer(user)
end
it 'updates issue with correct values' do
@@ -50,6 +59,62 @@ RSpec.describe Mutations::Issues::Update do
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end
+
+ context 'when setting milestone to nil' do
+ let(:expected_attributes) { { milestone_id: nil } }
+
+ it 'changes the milestone corrrectly' do
+ issue.update_column(:milestone_id, milestone.id)
+
+ expect { subject }.to change { issue.reload.milestone }.from(milestone).to(nil)
+ end
+ end
+
+ context 'when changing labels' do
+ let_it_be(:label_1) { create(:label, project: project) }
+ let_it_be(:label_2) { create(:label, project: project) }
+ let_it_be(:external_label) { create(:label, project: create(:project)) }
+
+ it 'adds and removes labels correctly' do
+ mutation_params[:add_label_ids] = [label_1.id, label_2.id]
+ mutation_params[:remove_label_ids] = [project_label.id]
+
+ subject
+
+ expect(issue.reload.labels).to match_array([label_1, label_2])
+ end
+
+ it 'does not add label if label id is nil' do
+ mutation_params[:add_label_ids] = [nil, label_2.id]
+
+ subject
+
+ expect(issue.reload.labels).to match_array([project_label, label_2])
+ end
+
+ it 'does not add label if label is not found' do
+ mutation_params[:add_label_ids] = [external_label.id, label_2.id]
+
+ subject
+
+ expect(issue.reload.labels).to match_array([project_label, label_2])
+ end
+
+ it 'does not modify labels if label is already present' do
+ mutation_params[:add_label_ids] = [project_label.id]
+
+ expect(issue.reload.labels).to match_array([project_label])
+ end
+
+ it 'does not modify labels if label is addded and removed in the same request' do
+ mutation_params[:add_label_ids] = [label_1.id, label_2.id]
+ mutation_params[:remove_label_ids] = [label_1.id]
+
+ subject
+
+ expect(issue.reload.labels).to match_array([project_label, label_2])
+ end
+ end
end
end
end