diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 09:16:11 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 09:16:11 +0000 |
commit | edaa33dee2ff2f7ea3fac488d41558eb5f86d68c (patch) | |
tree | 11f143effbfeba52329fb7afbd05e6e2a3790241 /spec/services/issues | |
parent | d8a5691316400a0f7ec4f83832698f1988eb27c1 (diff) | |
download | gitlab-ce-edaa33dee2ff2f7ea3fac488d41558eb5f86d68c.tar.gz |
Add latest changes from gitlab-org/gitlab@14-7-stable-eev14.7.0-rc42
Diffstat (limited to 'spec/services/issues')
-rw-r--r-- | spec/services/issues/build_service_spec.rb | 6 | ||||
-rw-r--r-- | spec/services/issues/create_service_spec.rb | 21 | ||||
-rw-r--r-- | spec/services/issues/move_service_spec.rb | 10 | ||||
-rw-r--r-- | spec/services/issues/set_crm_contacts_service_spec.rb | 2 | ||||
-rw-r--r-- | spec/services/issues/update_service_spec.rb | 123 |
5 files changed, 124 insertions, 38 deletions
diff --git a/spec/services/issues/build_service_spec.rb b/spec/services/issues/build_service_spec.rb index cf75efb5c57..304e4bb3ebb 100644 --- a/spec/services/issues/build_service_spec.rb +++ b/spec/services/issues/build_service_spec.rb @@ -172,9 +172,9 @@ RSpec.describe Issues::BuildService do end describe 'setting issue type' do - context 'with a corresponding WorkItem::Type' do - let_it_be(:type_issue_id) { WorkItem::Type.default_issue_type.id } - let_it_be(:type_incident_id) { WorkItem::Type.default_by_type(:incident).id } + context 'with a corresponding WorkItems::Type' do + let_it_be(:type_issue_id) { WorkItems::Type.default_issue_type.id } + let_it_be(:type_incident_id) { WorkItems::Type.default_by_type(:incident).id } where(:issue_type, :current_user, :work_item_type_id, :resulting_issue_type) do nil | ref(:guest) | ref(:type_issue_id) | 'issue' diff --git a/spec/services/issues/create_service_spec.rb b/spec/services/issues/create_service_spec.rb index 8496bd31e00..b2dcfb5c6d3 100644 --- a/spec/services/issues/create_service_spec.rb +++ b/spec/services/issues/create_service_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' RSpec.describe Issues::CreateService do include AfterNextHelpers - let_it_be(:group) { create(:group) } + let_it_be(:group) { create(:group, :crm_enabled) } let_it_be_with_reload(:project) { create(:project, group: group) } let_it_be(:user) { create(:user) } @@ -61,6 +61,7 @@ RSpec.describe Issues::CreateService do expect(Issuable::CommonSystemNotesService).to receive_message_chain(:new, :execute) expect(issue).to be_persisted + expect(issue).to be_a(::Issue) expect(issue.title).to eq('Awesome issue') expect(issue.assignees).to eq([assignee]) expect(issue.labels).to match_array(labels) @@ -69,6 +70,18 @@ RSpec.describe Issues::CreateService do expect(issue.work_item_type.base_type).to eq('issue') end + context 'when a build_service is provided' do + let(:issue) { described_class.new(project: project, current_user: user, params: opts, spam_params: spam_params, build_service: build_service).execute } + + let(:issue_from_builder) { WorkItem.new(project: project, title: 'Issue from builder') } + let(:build_service) { double(:build_service, execute: issue_from_builder) } + + it 'uses the provided service to build the issue' do + expect(issue).to be_persisted + expect(issue).to be_a(WorkItem) + end + end + context 'when skip_system_notes is true' do let(:issue) { described_class.new(project: project, current_user: user, params: opts, spam_params: spam_params).execute(skip_system_notes: true) } @@ -101,11 +114,11 @@ RSpec.describe Issues::CreateService do end it_behaves_like 'incident issue' - it_behaves_like 'has incident label' + it_behaves_like 'does not have incident label' - it 'does create an incident label' do + it 'does not create an incident label' do expect { subject } - .to change { Label.where(incident_label_attributes).count }.by(1) + .to not_change { Label.where(incident_label_attributes).count } end it 'calls IncidentManagement::Incidents::CreateEscalationStatusService' do diff --git a/spec/services/issues/move_service_spec.rb b/spec/services/issues/move_service_spec.rb index 36af38aef18..ef501f47f0d 100644 --- a/spec/services/issues/move_service_spec.rb +++ b/spec/services/issues/move_service_spec.rb @@ -259,6 +259,16 @@ RSpec.describe Issues::MoveService do it_behaves_like 'copy or reset relative position' end + + context 'issue with escalation status' do + it 'keeps the escalation status' do + escalation_status = create(:incident_management_issuable_escalation_status, issue: old_issue) + + move_service.execute(old_issue, new_project) + + expect(escalation_status.reload.issue).to eq(old_issue) + end + end end describe 'move permissions' do diff --git a/spec/services/issues/set_crm_contacts_service_spec.rb b/spec/services/issues/set_crm_contacts_service_spec.rb index 628f70efad6..2418f317551 100644 --- a/spec/services/issues/set_crm_contacts_service_spec.rb +++ b/spec/services/issues/set_crm_contacts_service_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' RSpec.describe Issues::SetCrmContactsService do let_it_be(:user) { create(:user) } - let_it_be(:group) { create(:group) } + let_it_be(:group) { create(:group, :crm_enabled) } let_it_be(:project) { create(:project, group: group) } let_it_be(:contacts) { create_list(:contact, 4, group: group) } diff --git a/spec/services/issues/update_service_spec.rb b/spec/services/issues/update_service_spec.rb index 4739b7e0f28..11ed47b84d9 100644 --- a/spec/services/issues/update_service_spec.rb +++ b/spec/services/issues/update_service_spec.rb @@ -7,7 +7,7 @@ RSpec.describe Issues::UpdateService, :mailer do let_it_be(:user2) { create(:user) } let_it_be(:user3) { create(:user) } let_it_be(:guest) { create(:user) } - let_it_be(:group) { create(:group, :public) } + let_it_be(:group) { create(:group, :public, :crm_enabled) } let_it_be(:project, reload: true) { create(:project, :repository, group: group) } let_it_be(:label) { create(:label, project: project) } let_it_be(:label2) { create(:label, project: project) } @@ -22,10 +22,10 @@ RSpec.describe Issues::UpdateService, :mailer do end before_all do - project.add_maintainer(user) - project.add_developer(user2) - project.add_developer(user3) - project.add_guest(guest) + group.add_maintainer(user) + group.add_developer(user2) + group.add_developer(user3) + group.add_guest(guest) end describe 'execute' do @@ -191,11 +191,6 @@ RSpec.describe Issues::UpdateService, :mailer do end end - it 'adds a `incident` label if one does not exist' do - expect { update_issue(issue_type: 'incident') }.to change(issue.labels, :count).by(1) - expect(issue.labels.pluck(:title)).to eq(['incident']) - end - it 'creates system note about issue type' do update_issue(issue_type: 'incident') @@ -204,6 +199,13 @@ RSpec.describe Issues::UpdateService, :mailer do expect(note).not_to eq(nil) end + it 'creates an escalation status' do + expect { update_issue(issue_type: 'incident') } + .to change { issue.reload.incident_management_issuable_escalation_status } + .from(nil) + .to(a_kind_of(IncidentManagement::IssuableEscalationStatus)) + end + context 'for an issue with multiple labels' do let(:issue) { create(:incident, project: project, labels: [label_1]) } @@ -215,18 +217,6 @@ RSpec.describe Issues::UpdateService, :mailer do expect(issue.labels).to eq([label_1]) end end - - context 'filtering the incident label' do - let(:params) { { add_label_ids: [] } } - - before do - update_issue(issue_type: 'incident') - end - - it 'creates and add a incident label id to add_label_ids' do - expect(issue.label_ids).to contain_exactly(label_1.id) - end - end end context 'from incident to issue' do @@ -241,10 +231,8 @@ RSpec.describe Issues::UpdateService, :mailer do context 'for an incident with multiple labels' do let(:issue) { create(:incident, project: project, labels: [label_1, label_2]) } - it 'removes an `incident` label if one exists on the incident' do - expect { update_issue(issue_type: 'issue') }.to change(issue, :label_ids) - .from(containing_exactly(label_1.id, label_2.id)) - .to([label_2.id]) + it 'does not remove an `incident` label if one exists on the incident' do + expect { update_issue(issue_type: 'issue') }.to not_change(issue, :label_ids) end end @@ -252,10 +240,8 @@ RSpec.describe Issues::UpdateService, :mailer do let(:issue) { create(:incident, project: project, labels: [label_1, label_2]) } let(:params) { { label_ids: [label_1.id, label_2.id], remove_label_ids: [] } } - it 'adds an incident label id to remove_label_ids for it to be removed' do - expect { update_issue(issue_type: 'issue') }.to change(issue, :label_ids) - .from(containing_exactly(label_1.id, label_2.id)) - .to([label_2.id]) + it 'does not add an incident label id to remove_label_ids for it to be removed' do + expect { update_issue(issue_type: 'issue') }.to not_change(issue, :label_ids) end end end @@ -1157,6 +1143,83 @@ RSpec.describe Issues::UpdateService, :mailer do end end + context 'updating escalation status' do + let(:opts) { { escalation_status: { status: 'acknowledged' } } } + let(:escalation_update_class) { ::IncidentManagement::IssuableEscalationStatuses::AfterUpdateService } + + shared_examples 'updates the escalation status record' do |expected_status| + let(:service_double) { instance_double(escalation_update_class) } + + it 'has correct value' do + expect(escalation_update_class).to receive(:new).with(issue, user).and_return(service_double) + expect(service_double).to receive(:execute) + + update_issue(opts) + + expect(issue.escalation_status.status_name).to eq(expected_status) + end + end + + shared_examples 'does not change the status record' do + it 'retains the original value' do + expected_status = issue.escalation_status&.status_name + + update_issue(opts) + + expect(issue.escalation_status&.status_name).to eq(expected_status) + end + + it 'does not trigger side-effects' do + expect(escalation_update_class).not_to receive(:new) + + update_issue(opts) + end + end + + context 'when issue is an incident' do + let(:issue) { create(:incident, project: project) } + + context 'with an escalation status record' do + before do + create(:incident_management_issuable_escalation_status, issue: issue) + end + + it_behaves_like 'updates the escalation status record', :acknowledged + + context 'with associated alert' do + let!(:alert) { create(:alert_management_alert, issue: issue, project: project) } + + it 'syncs the update back to the alert' do + update_issue(opts) + + expect(issue.escalation_status.status_name).to eq(:acknowledged) + expect(alert.reload.status_name).to eq(:acknowledged) + end + end + + context 'with unsupported status value' do + let(:opts) { { escalation_status: { status: 'unsupported-status' } } } + + it_behaves_like 'does not change the status record' + end + + context 'with status value defined but unchanged' do + let(:opts) { { escalation_status: { status: issue.escalation_status.status_name } } } + + it_behaves_like 'does not change the status record' + end + end + + context 'without an escalation status record' do + it_behaves_like 'does not change the status record' + end + end + + context 'when issue type is not incident' do + it_behaves_like 'does not change the status record' + end + end + context 'duplicate issue' do let(:canonical_issue) { create(:issue, project: project) } |