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>2022-02-18 12:45:46 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-02-18 12:45:46 +0300
commita7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch)
tree7452bd5c3545c2fa67a28aa013835fb4fa071baf /spec/services/system_notes
parentee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff)
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
Diffstat (limited to 'spec/services/system_notes')
-rw-r--r--spec/services/system_notes/alert_management_service_spec.rb38
-rw-r--r--spec/services/system_notes/incident_service_spec.rb24
-rw-r--r--spec/services/system_notes/issuables_service_spec.rb48
3 files changed, 85 insertions, 25 deletions
diff --git a/spec/services/system_notes/alert_management_service_spec.rb b/spec/services/system_notes/alert_management_service_spec.rb
index 6e6bfeaa205..039975c1bf6 100644
--- a/spec/services/system_notes/alert_management_service_spec.rb
+++ b/spec/services/system_notes/alert_management_service_spec.rb
@@ -21,14 +21,26 @@ RSpec.describe ::SystemNotes::AlertManagementService do
end
describe '#change_alert_status' do
- subject { described_class.new(noteable: noteable, project: project, author: author).change_alert_status(noteable) }
+ subject { described_class.new(noteable: noteable, project: project, author: author).change_alert_status(reason) }
- it_behaves_like 'a system note' do
- let(:action) { 'status' }
+ context 'with no specified reason' do
+ let(:reason) { nil }
+
+ it_behaves_like 'a system note' do
+ let(:action) { 'status' }
+ end
+
+ it 'has the appropriate message' do
+ expect(subject.note).to eq("changed the status to **Acknowledged**")
+ end
end
- it 'has the appropriate message' do
- expect(subject.note).to eq("changed the status to **Acknowledged**")
+ context 'with reason provided' do
+ let(:reason) { ' by changing incident status' }
+
+ it 'has the appropriate message' do
+ expect(subject.note).to eq("changed the status to **Acknowledged** by changing incident status")
+ end
end
end
@@ -42,21 +54,7 @@ RSpec.describe ::SystemNotes::AlertManagementService do
end
it 'has the appropriate message' do
- expect(subject.note).to eq("created issue #{issue.to_reference(project)} for this alert")
- end
- end
-
- describe '#closed_alert_issue' do
- let_it_be(:issue) { noteable.issue }
-
- subject { described_class.new(noteable: noteable, project: project, author: author).closed_alert_issue(issue) }
-
- it_behaves_like 'a system note' do
- let(:action) { 'status' }
- end
-
- it 'has the appropriate message' do
- expect(subject.note).to eq("changed the status to **Resolved** by closing issue #{issue.to_reference(project)}")
+ expect(subject.note).to eq("created incident #{issue.to_reference(project)} for this alert")
end
end
diff --git a/spec/services/system_notes/incident_service_spec.rb b/spec/services/system_notes/incident_service_spec.rb
index 669e357b7a4..5de352ad8fa 100644
--- a/spec/services/system_notes/incident_service_spec.rb
+++ b/spec/services/system_notes/incident_service_spec.rb
@@ -57,13 +57,27 @@ RSpec.describe ::SystemNotes::IncidentService do
end
end
- describe '#resolve_incident_status' do
- subject(:resolve_incident_status) { described_class.new(noteable: noteable, project: project, author: author).resolve_incident_status }
+ describe '#change_incident_status' do
+ let_it_be(:escalation_status) { create(:incident_management_issuable_escalation_status, issue: noteable) }
- it 'creates a new note about resolved incident', :aggregate_failures do
- expect { resolve_incident_status }.to change { noteable.notes.count }.by(1)
+ let(:service) { described_class.new(noteable: noteable, project: project, author: author) }
- expect(noteable.notes.last.note).to eq('changed the status to **Resolved** by closing the incident')
+ context 'with a provided reason' do
+ subject(:change_incident_status) { service.change_incident_status(' by changing the alert status') }
+
+ it 'creates a new note for an incident status change', :aggregate_failures do
+ expect { change_incident_status }.to change { noteable.notes.count }.by(1)
+ expect(noteable.notes.last.note).to eq("changed the incident status to **Triggered** by changing the alert status")
+ end
+ end
+
+ context 'without provided reason' do
+ subject(:change_incident_status) { service.change_incident_status(nil) }
+
+ it 'creates a new note for an incident status change', :aggregate_failures do
+ expect { change_incident_status }.to change { noteable.notes.count }.by(1)
+ expect(noteable.notes.last.note).to eq("changed the incident status to **Triggered**")
+ end
end
end
end
diff --git a/spec/services/system_notes/issuables_service_spec.rb b/spec/services/system_notes/issuables_service_spec.rb
index 7e53e66303b..e1c97026418 100644
--- a/spec/services/system_notes/issuables_service_spec.rb
+++ b/spec/services/system_notes/issuables_service_spec.rb
@@ -188,6 +188,54 @@ RSpec.describe ::SystemNotes::IssuablesService do
end
end
+ describe '#change_issuable_contacts' do
+ subject { service.change_issuable_contacts(1, 1) }
+
+ let_it_be(:noteable) { create(:issue, project: project) }
+
+ it_behaves_like 'a system note' do
+ let(:action) { 'contact' }
+ end
+
+ def build_note(added_count, removed_count)
+ service.change_issuable_contacts(added_count, removed_count).note
+ end
+
+ it 'builds a correct phrase when one contact is added' do
+ expect(build_note(1, 0)).to eq "added 1 contact"
+ end
+
+ it 'builds a correct phrase when one contact is removed' do
+ expect(build_note(0, 1)).to eq "removed 1 contact"
+ end
+
+ it 'builds a correct phrase when one contact is added and one contact is removed' do
+ expect(build_note(1, 1)).to(
+ eq("added 1 contact and removed 1 contact")
+ )
+ end
+
+ it 'builds a correct phrase when three contacts are added and one removed' do
+ expect(build_note(3, 1)).to(
+ eq("added 3 contacts and removed 1 contact")
+ )
+ end
+
+ it 'builds a correct phrase when three contacts are removed and one added' do
+ expect(build_note(1, 3)).to(
+ eq("added 1 contact and removed 3 contacts")
+ )
+ end
+
+ it 'builds a correct phrase when the locale is different' do
+ Gitlab::I18n.with_locale('pt-BR') do
+ expect(build_note(1, 3)).to(
+ eq("added 1 contact and removed 3 contacts")
+ )
+ end
+ end
+ end
+
describe '#change_status' do
subject { service.change_status(status, source) }