Welcome to mirror list, hosted at ThFree Co, Russian Federation.

incidents_service_spec.rb « system_notes « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5452d51dfc0f295b7fbf0ac95b15f0bfb2b10074 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe SystemNotes::IncidentsService, feature_category: :incident_management do
  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
      expect(subject.note).to match("added an incident timeline event")
    end
  end

  describe '#edit_timeline_event' do
    let(:was_changed) { :unknown }

    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")
      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")
      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")
      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")
      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