command_spec.rb 1.64 KB
Newer Older
1 2
require 'spec_helper'

3
describe Gitlab::ChatCommands::Command, service: true do
4
  let(:project) { create(:empty_project) }
5
  let(:user) { create(:user) }
6 7 8

  subject { described_class.new(project, user, params).execute }

9
  describe '#execute' do
10
    context 'when no command is available' do
11
      let(:params) { { text: 'issue show 1' } }
12
      let(:project) { create(:project, has_external_issue_tracker: true) }
13

Z.J. van de Weg's avatar
Z.J. van de Weg committed
14
      it 'displays 404 messages' do
15
        expect(subject[:response_type]).to be(:ephemeral)
16
        expect(subject[:text]).to start_with('404 not found')
17 18 19 20
      end
    end

    context 'when an unknown command is triggered' do
Z.J. van de Weg's avatar
Z.J. van de Weg committed
21
      let(:params) { { command: '/gitlab', text: "unknown command 123" } }
22 23 24 25

      it 'displays the help message' do
        expect(subject[:response_type]).to be(:ephemeral)
        expect(subject[:text]).to start_with('Available commands')
Z.J. van de Weg's avatar
Z.J. van de Weg committed
26
        expect(subject[:text]).to match('/gitlab issue show')
27 28
      end
    end
29

30 31 32 33 34 35 36 37 38
    context 'the user can not create an issue' do
      let(:params) { { text: "issue create my new issue" } }

      it 'rejects the actions' do
        expect(subject[:response_type]).to be(:ephemeral)
        expect(subject[:text]).to start_with('Whoops! That action is not allowed')
      end
    end

Z.J. van de Weg's avatar
Z.J. van de Weg committed
39
    context 'issue is successfully created' do
40 41 42 43 44 45 46 47 48
      let(:params) { { text: "issue create my new issue" } }

      before do
        project.team << [user, :master]
      end

      it 'presents the issue' do
        expect(subject[:text]).to match("my new issue")
      end
49 50 51 52

      it 'shows a link to the new issue' do
        expect(subject[:text]).to match(/\/issues\/\d+/)
      end
53
    end
54 55
  end
end