diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /spec/services/system_notes | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/services/system_notes')
-rw-r--r-- | spec/services/system_notes/incidents_service_spec.rb | 88 | ||||
-rw-r--r-- | spec/services/system_notes/time_tracking_service_spec.rb | 24 |
2 files changed, 112 insertions, 0 deletions
diff --git a/spec/services/system_notes/incidents_service_spec.rb b/spec/services/system_notes/incidents_service_spec.rb new file mode 100644 index 00000000000..d1b831e9c4c --- /dev/null +++ b/spec/services/system_notes/incidents_service_spec.rb @@ -0,0 +1,88 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe SystemNotes::IncidentsService do + include Gitlab::Routing + + let_it_be(:project) { create(:project) } + let_it_be(:user) { create(:user) } + let_it_be(:author) { create(:user) } + let_it_be(:incident) { create(:incident, project: project, author: user) } + let_it_be(:timeline_event) do + create(:incident_management_timeline_event, project: project, incident: incident, author: author) + end + + describe '#add_timeline_event' do + subject { described_class.new(noteable: incident).add_timeline_event(timeline_event) } + + it_behaves_like 'a system note' do + let(:noteable) { incident } + let(:action) { 'timeline_event' } + end + + it 'posts the correct text to the system note' do + path = project_issues_incident_path(project, incident, anchor: "timeline_event_#{timeline_event.id}") + expect(subject.note).to match("added an [incident timeline event](#{path})") + end + end + + describe '#edit_timeline_event' do + let(:was_changed) { :unknown } + let(:path) { project_issues_incident_path(project, incident, anchor: "timeline_event_#{timeline_event.id}") } + + subject do + described_class.new(noteable: incident).edit_timeline_event(timeline_event, author, was_changed: was_changed) + end + + it_behaves_like 'a system note' do + let(:noteable) { incident } + let(:action) { 'timeline_event' } + end + + context "when only timeline event's occurred_at was changed" do + let(:was_changed) { :occurred_at } + + it 'posts the correct text to the system note' do + expect(subject.note).to match("edited the event time/date on [incident timeline event](#{path})") + end + end + + context "when only timeline event's note was changed" do + let(:was_changed) { :note } + + it 'posts the correct text to the system note' do + expect(subject.note).to match("edited the text on [incident timeline event](#{path})") + end + end + + context "when both timeline events occurred_at and note was changed" do + let(:was_changed) { :occurred_at_and_note } + + it 'posts the correct text to the system note' do + expect(subject.note).to match("edited the event time/date and text on [incident timeline event](#{path})") + end + end + + context "when was changed reason is unknown" do + let(:was_changed) { :unknown } + + it 'posts the correct text to the system note' do + expect(subject.note).to match("edited [incident timeline event](#{path})") + end + end + end + + describe '#delete_timeline_event' do + subject { described_class.new(noteable: incident).delete_timeline_event(author) } + + it_behaves_like 'a system note' do + let(:noteable) { incident } + let(:action) { 'timeline_event' } + end + + it 'posts the correct text to the system note' do + expect(subject.note).to match('deleted an incident timeline event') + end + end +end diff --git a/spec/services/system_notes/time_tracking_service_spec.rb b/spec/services/system_notes/time_tracking_service_spec.rb index ec126cb5447..fdf18f4f29a 100644 --- a/spec/services/system_notes/time_tracking_service_spec.rb +++ b/spec/services/system_notes/time_tracking_service_spec.rb @@ -106,6 +106,30 @@ RSpec.describe ::SystemNotes::TimeTrackingService do end end + describe '#remove_timelog' do + subject { described_class.new(noteable: noteable, project: project, author: author).remove_timelog(timelog) } + + context 'when the timelog has a positive time spent value' do + let_it_be(:noteable, reload: true) { create(:issue, project: project) } + + let(:timelog) { create(:timelog, user: author, issue: noteable, time_spent: 1800, spent_at: '2022-03-30T00:00:00.000Z')} + + it 'sets the note text' do + expect(subject.note).to eq "deleted 30m of spent time from 2022-03-30" + end + end + + context 'when the timelog has a negative time spent value' do + let_it_be(:noteable, reload: true) { create(:issue, project: project) } + + let(:timelog) { create(:timelog, user: author, issue: noteable, time_spent: -1800, spent_at: '2022-03-30T00:00:00.000Z')} + + it 'sets the note text' do + expect(subject.note).to eq "deleted -30m of spent time from 2022-03-30" + end + end + end + describe '#change_time_spent' do subject { described_class.new(noteable: noteable, project: project, author: author).change_time_spent } |