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

zoom_meeting_spec.rb « models « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d3d75a19fed4366e1fc8ff1513f03741ae533775 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ZoomMeeting do
  let(:project) { build(:project) }

  describe 'Factory' do
    subject { build(:zoom_meeting) }

    it { is_expected.to be_valid }
  end

  describe 'Associations' do
    it { is_expected.to belong_to(:project) }
    it { is_expected.to belong_to(:issue) }
  end

  describe 'scopes' do
    let(:issue) { create(:issue, project: project) }
    let!(:added_meeting) { create(:zoom_meeting, :added_to_issue, issue: issue) }
    let!(:removed_meeting) { create(:zoom_meeting, :removed_from_issue, issue: issue) }

    describe '.added_to_issue' do
      it 'gets only added meetings' do
        meetings_added = described_class.added_to_issue.pluck(:id)

        expect(meetings_added).to include(added_meeting.id)
        expect(meetings_added).not_to include(removed_meeting.id)
      end
    end

    describe '.removed_from_issue' do
      it 'gets only removed meetings' do
        meetings_removed = described_class.removed_from_issue.pluck(:id)

        expect(meetings_removed).to include(removed_meeting.id)
        expect(meetings_removed).not_to include(added_meeting.id)
      end
    end
  end

  describe 'Validations' do
    it { is_expected.to validate_presence_of(:project) }
    it { is_expected.to validate_presence_of(:issue) }

    describe 'when importing' do
      subject { build(:zoom_meeting, importing: true) }

      it { is_expected.not_to validate_presence_of(:project) }
      it { is_expected.not_to validate_presence_of(:issue) }
    end

    describe 'url' do
      it { is_expected.to validate_presence_of(:url) }
      it { is_expected.to validate_length_of(:url).is_at_most(255) }

      shared_examples 'invalid Zoom URL' do
        it do
          expect(subject).to be_invalid
          expect(subject.errors[:url])
            .to contain_exactly('must contain one valid Zoom URL')
        end
      end

      context 'with non-Zoom URL' do
        before do
          subject.url = %{https://non-zoom.url}
        end

        include_examples 'invalid Zoom URL'
      end

      context 'with multiple Zoom-URLs' do
        before do
          subject.url = %{https://zoom.us/j/123 https://zoom.us/j/456}
        end

        include_examples 'invalid Zoom URL'
      end
    end

    describe 'issue association' do
      let(:issue) { build(:issue, project: project) }

      subject { build(:zoom_meeting, project: project, issue: issue) }

      context 'for the same project' do
        it { is_expected.to be_valid }
      end

      context 'for a different project' do
        let(:issue) { build(:issue) }

        it do
          expect(subject).to be_invalid
          expect(subject.errors[:issue])
            .to contain_exactly('must associate the same project')
        end
      end
    end
  end

  describe 'limit number of meetings per issue' do
    shared_examples 'can add meetings' do
      it 'can add new Zoom meetings' do
        create(:zoom_meeting, :added_to_issue, issue: issue)
      end
    end

    shared_examples 'can remove meetings' do
      it 'can remove Zoom meetings' do
        create(:zoom_meeting, :removed_from_issue, issue: issue)
      end
    end

    shared_examples 'cannot add meetings' do
      it 'fails to add a new meeting' do
        expect do
          create(:zoom_meeting, :added_to_issue, issue: issue)
        end.to raise_error ActiveRecord::RecordNotUnique
      end
    end

    let(:issue) { create(:issue, project: project) }

    context 'without meetings' do
      it_behaves_like 'can add meetings'
    end

    context 'when no other meeting is added' do
      before do
        create(:zoom_meeting, :removed_from_issue, issue: issue)
      end

      it_behaves_like 'can add meetings'
    end

    context 'when meeting is added' do
      before do
        create(:zoom_meeting, :added_to_issue, issue: issue)
      end

      it_behaves_like 'cannot add meetings'
    end

    context 'when meeting is added to another issue' do
      let(:another_issue) { create(:issue, project: project) }

      before do
        create(:zoom_meeting, :added_to_issue, issue: another_issue)
      end

      it_behaves_like 'can add meetings'
    end

    context 'when second meeting is removed' do
      before do
        create(:zoom_meeting, :removed_from_issue, issue: issue)
      end

      it_behaves_like 'can remove meetings'
    end
  end
end