summaryrefslogtreecommitdiff
path: root/spec/services/zoom_notes_service_spec.rb
blob: 419ecf3f374f0d7c33d979c3714dc5e2c10e2bf1 (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
# frozen_string_literal: true

require 'spec_helper'

describe ZoomNotesService do
  describe '#execute' do
    let(:issue) { OpenStruct.new(description: description) }
    let(:project) { Object.new }
    let(:user) { Object.new }
    let(:description) { 'an issue description' }
    let(:old_description) { nil }

    subject { described_class.new(issue, project, user, old_description: old_description) }

    shared_examples 'no notifications' do
      it "doesn't create notifications" do
        expect(SystemNoteService).not_to receive(:zoom_link_added)
        expect(SystemNoteService).not_to receive(:zoom_link_removed)

        subject.execute
      end
    end

    it_behaves_like 'no notifications'

    context 'when the zoom link exists in both description and old_description' do
      let(:description) { 'a changed issue description https://zoom.us/j/123' }
      let(:old_description) { 'an issue description https://zoom.us/j/123' }

      it_behaves_like 'no notifications'
    end

    context "when the zoom link doesn't exist in both description and old_description" do
      let(:description) { 'a changed issue description' }
      let(:old_description) { 'an issue description' }

      it_behaves_like 'no notifications'
    end

    context 'when description == old_description' do
      let(:old_description) { 'an issue description' }

      it_behaves_like 'no notifications'
    end

    context 'when the description contains a zoom link and old_description is nil' do
      let(:description) { 'a changed issue description https://zoom.us/j/123' }

      it 'creates a zoom_link_added notification' do
        expect(SystemNoteService).to receive(:zoom_link_added).with(issue, project, user)
        expect(SystemNoteService).not_to receive(:zoom_link_removed)

        subject.execute
      end
    end

    context 'when the zoom link has been added to the description' do
      let(:description) { 'a changed issue description https://zoom.us/j/123' }
      let(:old_description) { 'an issue description' }

      it 'creates a zoom_link_added notification' do
        expect(SystemNoteService).to receive(:zoom_link_added).with(issue, project, user)
        expect(SystemNoteService).not_to receive(:zoom_link_removed)

        subject.execute
      end
    end

    context 'when the zoom link has been removed from the description' do
      let(:description) { 'a changed issue description' }
      let(:old_description) { 'an issue description https://zoom.us/j/123' }

      it 'creates a zoom_link_removed notification' do
        expect(SystemNoteService).not_to receive(:zoom_link_added).with(issue, project, user)
        expect(SystemNoteService).to receive(:zoom_link_removed)

        subject.execute
      end
    end
  end
end