diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 18:42:06 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 18:42:06 +0000 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/services/issues | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) | |
download | gitlab-ce-6e4e1050d9dba2b7b2523fdd1768823ab85feef4.tar.gz |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/services/issues')
-rw-r--r-- | spec/services/issues/build_service_spec.rb | 14 | ||||
-rw-r--r-- | spec/services/issues/close_service_spec.rb | 35 | ||||
-rw-r--r-- | spec/services/issues/move_service_spec.rb | 66 | ||||
-rw-r--r-- | spec/services/issues/update_service_spec.rb | 32 |
4 files changed, 104 insertions, 43 deletions
diff --git a/spec/services/issues/build_service_spec.rb b/spec/services/issues/build_service_spec.rb index 68b226b02da..93eef8a2732 100644 --- a/spec/services/issues/build_service_spec.rb +++ b/spec/services/issues/build_service_spec.rb @@ -147,5 +147,19 @@ RSpec.describe Issues::BuildService do expect(issue.milestone).to be_nil end + + context 'setting issue type' do + it 'sets the issue_type on the issue' do + issue = build_issue(issue_type: 'incident') + + expect(issue.issue_type).to eq('incident') + end + + it 'defaults to issue if issue_type not given' do + issue = build_issue + + expect(issue.issue_type).to eq('issue') + end + end end end diff --git a/spec/services/issues/close_service_spec.rb b/spec/services/issues/close_service_spec.rb index 6678d831775..7ca7d3be99c 100644 --- a/spec/services/issues/close_service_spec.rb +++ b/spec/services/issues/close_service_spec.rb @@ -252,6 +252,41 @@ RSpec.describe Issues::CloseService do expect(todo.reload).to be_done end + context 'when there is an associated Alert Management Alert' do + context 'when alert can be resolved' do + let!(:alert) { create(:alert_management_alert, issue: issue, project: project) } + + it 'resolves an alert and sends a system note' do + expect_next_instance_of(SystemNotes::AlertManagementService) do |notes_service| + expect(notes_service).to receive(:closed_alert_issue).with(issue) + end + + close_issue + + expect(alert.reload.resolved?).to eq(true) + end + end + + context 'when alert cannot be resolved' do + let!(:alert) { create(:alert_management_alert, :with_validation_errors, issue: issue, project: project) } + + before do + allow(Gitlab::AppLogger).to receive(:warn).and_call_original + end + + it 'writes a warning into the log' do + close_issue + + expect(Gitlab::AppLogger).to have_received(:warn).with( + message: 'Cannot resolve an associated Alert Management alert', + issue_id: issue.id, + alert_id: alert.id, + alert_errors: { hosts: ['hosts array is over 255 chars'] } + ) + end + end + end + it 'deletes milestone issue counters cache' do issue.update(milestone: create(:milestone, project: project)) diff --git a/spec/services/issues/move_service_spec.rb b/spec/services/issues/move_service_spec.rb index 8929907a179..5f944d1213b 100644 --- a/spec/services/issues/move_service_spec.rb +++ b/spec/services/issues/move_service_spec.rb @@ -3,15 +3,15 @@ require 'spec_helper' RSpec.describe Issues::MoveService do - let(:user) { create(:user) } - let(:author) { create(:user) } - let(:title) { 'Some issue' } - let(:description) { "Some issue description with mention to #{user.to_reference}" } - let(:group) { create(:group, :private) } - let(:sub_group_1) { create(:group, :private, parent: group) } - let(:sub_group_2) { create(:group, :private, parent: group) } - let(:old_project) { create(:project, namespace: sub_group_1) } - let(:new_project) { create(:project, namespace: sub_group_2) } + let_it_be(:user) { create(:user) } + let_it_be(:author) { create(:user) } + let_it_be(:title) { 'Some issue' } + let_it_be(:description) { "Some issue description with mention to #{user.to_reference}" } + let_it_be(:group) { create(:group, :private) } + let_it_be(:sub_group_1) { create(:group, :private, parent: group) } + let_it_be(:sub_group_2) { create(:group, :private, parent: group) } + let_it_be(:old_project) { create(:project, namespace: sub_group_1) } + let_it_be(:new_project) { create(:project, namespace: sub_group_2) } let(:old_issue) do create(:issue, title: title, description: description, project: old_project, author: author) @@ -30,15 +30,10 @@ RSpec.describe Issues::MoveService do describe '#execute' do shared_context 'issue move executed' do - let!(:award_emoji) { create(:award_emoji, awardable: old_issue) } - let!(:new_issue) { move_service.execute(old_issue, new_project) } end context 'issue movable' do - let!(:note_with_mention) { create(:note, noteable: old_issue, author: author, project: old_project, note: "note with mention #{user.to_reference}") } - let!(:note_with_no_mention) { create(:note, noteable: old_issue, author: author, project: old_project, note: "note without mention") } - include_context 'user can move issue' context 'generic issue' do @@ -48,11 +43,11 @@ RSpec.describe Issues::MoveService do expect(new_issue.project).to eq new_project end - it 'rewrites issue title' do + it 'copies issue title' do expect(new_issue.title).to eq title end - it 'rewrites issue description' do + it 'copies issue description' do expect(new_issue.description).to eq description end @@ -93,23 +88,21 @@ RSpec.describe Issues::MoveService do it 'preserves create time' do expect(old_issue.created_at).to eq new_issue.created_at end + end - it 'moves the award emoji' do - expect(old_issue.award_emoji.first.name).to eq new_issue.reload.award_emoji.first.name - end + context 'issue with award emoji' do + let!(:award_emoji) { create(:award_emoji, awardable: old_issue) } - context 'when issue has notes with mentions' do - it 'saves user mentions with actual mentions for new issue' do - expect(new_issue.user_mentions.find_by(note_id: nil).mentioned_users_ids).to match_array([user.id]) - expect(new_issue.user_mentions.where.not(note_id: nil).first.mentioned_users_ids).to match_array([user.id]) - expect(new_issue.user_mentions.where.not(note_id: nil).count).to eq 1 - expect(new_issue.user_mentions.count).to eq 2 - end + it 'copies the award emoji' do + old_issue.reload + new_issue = move_service.execute(old_issue, new_project) + + expect(old_issue.award_emoji.first.name).to eq new_issue.reload.award_emoji.first.name end end context 'issue with assignee' do - let(:assignee) { create(:user) } + let_it_be(:assignee) { create(:user) } before do old_issue.assignees = [assignee] @@ -154,6 +147,25 @@ RSpec.describe Issues::MoveService do .not_to raise_error # Sidekiq::Worker::EnqueueFromTransactionError end end + + # These tests verify that notes are copied. More thorough tests are in + # the unit test for Notes::CopyService. + context 'issue with notes' do + let!(:notes) do + [ + create(:note, noteable: old_issue, project: old_project, created_at: 2.weeks.ago, updated_at: 1.week.ago), + create(:note, noteable: old_issue, project: old_project) + ] + end + + let(:copied_notes) { new_issue.notes.limit(notes.size) } # Remove the system note added by the copy itself + + include_context 'issue move executed' + + it 'copies existing notes in order' do + expect(copied_notes.order('id ASC').pluck(:note)).to eq(notes.map(&:note)) + end + end end describe 'move permissions' do diff --git a/spec/services/issues/update_service_spec.rb b/spec/services/issues/update_service_spec.rb index 77bd540e22f..42452e95f6b 100644 --- a/spec/services/issues/update_service_spec.rb +++ b/spec/services/issues/update_service_spec.rb @@ -840,27 +840,27 @@ RSpec.describe Issues::UpdateService, :mailer do end context 'real-time updates' do - let(:update_params) { { assignee_ids: [user2.id] } } + using RSpec::Parameterized::TableSyntax - context 'when broadcast_issue_updates is enabled' do - before do - stub_feature_flags(broadcast_issue_updates: true) - end - - it 'broadcasts to the issues channel' do - expect(IssuesChannel).to receive(:broadcast_to).with(issue, event: 'updated') + let(:update_params) { { assignee_ids: [user2.id] } } - update_issue(update_params) - end + where(:action_cable_in_app_enabled, :feature_flag_enabled, :should_broadcast) do + true | true | true + true | false | true + false | true | true + false | false | false end - context 'when broadcast_issue_updates is disabled' do - before do - stub_feature_flags(broadcast_issue_updates: false) - end + with_them do + it 'broadcasts to the issues channel based on ActionCable and feature flag values' do + expect(Gitlab::ActionCable::Config).to receive(:in_app?).and_return(action_cable_in_app_enabled) + stub_feature_flags(broadcast_issue_updates: feature_flag_enabled) - it 'does not broadcast to the issues channel' do - expect(IssuesChannel).not_to receive(:broadcast_to) + if should_broadcast + expect(IssuesChannel).to receive(:broadcast_to).with(issue, event: 'updated') + else + expect(IssuesChannel).not_to receive(:broadcast_to) + end update_issue(update_params) end |