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

issue_show_spec.rb « slash_commands « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b1db1638237a5ff7e886c1bbd6213a71ee7cebfb (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
require 'spec_helper'

describe Gitlab::SlashCommands::IssueShow do
  describe '#execute' do
    let(:issue) { create(:issue, project: project) }
    let(:project) { create(:project) }
    let(:user) { issue.author }
    let(:chat_name) { double(:chat_name, user: user) }
    let(:regex_match) { described_class.match("issue show #{issue.iid}") }

    before do
      project.add_master(user)
    end

    subject do
      described_class.new(project, chat_name).execute(regex_match)
    end

    context 'the issue exists' do
      let(:title) { subject[:attachments].first[:title] }

      it 'returns the issue' do
        expect(subject[:response_type]).to be(:in_channel)
        expect(title).to start_with(issue.title)
      end

      context 'when its reference is given' do
        let(:regex_match) { described_class.match("issue show #{issue.to_reference}") }

        it 'shows the issue' do
          expect(subject[:response_type]).to be(:in_channel)
          expect(title).to start_with(issue.title)
        end
      end
    end

    context 'the issue does not exist' do
      let(:regex_match) { described_class.match("issue show 2343242") }

      it "returns not found" do
        expect(subject[:response_type]).to be(:ephemeral)
        expect(subject[:text]).to match("not found")
      end
    end
  end

  describe '.match' do
    it 'matches the iid' do
      match = described_class.match("issue show 123")

      expect(match[:iid]).to eq("123")
    end

    it 'accepts a reference' do
      match = described_class.match("issue show #{Issue.reference_prefix}123")

      expect(match[:iid]).to eq("123")
    end
  end
end