BigW Consortium Gitlab

issue_show_spec.rb 1.58 KB
Newer Older
1 2
require 'spec_helper'

3
describe Gitlab::ChatCommands::IssueShow, service: true do
4
  describe '#execute' do
5 6
    let(:issue) { create(:issue, project: project) }
    let(:project) { create(:empty_project) }
7
    let(:user) { issue.author }
8
    let(:regex_match) { described_class.match("issue show #{issue.iid}") }
9

10 11 12
    before do
      project.team << [user, :master]
    end
13

14 15 16
    subject do
      described_class.new(project, user).execute(regex_match)
    end
17 18

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

21
      it 'returns the issue' do
22
        expect(subject[:response_type]).to be(:in_channel)
Z.J. van de Weg committed
23
        expect(title).to start_with(issue.title)
24
      end
25 26 27 28 29

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

        it 'shows the issue' do
30
          expect(subject[:response_type]).to be(:in_channel)
Z.J. van de Weg committed
31
          expect(title).to start_with(issue.title)
32 33
        end
      end
34 35 36
    end

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

39 40 41
      it "returns not found" do
        expect(subject[:response_type]).to be(:ephemeral)
        expect(subject[:text]).to match("not found")
42 43 44
      end
    end
  end
45

46
  describe '.match' do
47 48 49 50 51
    it 'matches the iid' do
      match = described_class.match("issue show 123")

      expect(match[:iid]).to eq("123")
    end
52 53 54 55 56 57

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

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