gitlab-org--gitlab-foss/spec/lib/gitlab/chat_commands/command_spec.rb

55 lines
1.6 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe Gitlab::ChatCommands::Command, service: true do
2016-11-18 09:00:40 +00:00
let(:project) { create(:empty_project) }
2016-11-17 14:30:04 +00:00
let(:user) { create(:user) }
subject { described_class.new(project, user, params).execute }
2016-11-17 11:57:27 +00:00
describe '#execute' do
2016-11-18 10:38:54 +00:00
context 'when no command is available' do
2016-11-17 14:30:04 +00:00
let(:params) { { text: 'issue show 1' } }
2016-11-17 11:57:27 +00:00
let(:project) { create(:project, has_external_issue_tracker: true) }
2016-11-17 11:57:27 +00:00
it 'displays the help message' do
expect(subject[:response_type]).to be(:ephemeral)
2016-11-17 14:30:04 +00:00
expect(subject[:text]).to start_with('404 not found')
2016-11-17 11:57:27 +00:00
end
end
context 'when an unknown command is triggered' do
let(:params) { { text: "unknown command 123" } }
it 'displays the help message' do
expect(subject[:response_type]).to be(:ephemeral)
expect(subject[:text]).to start_with('Available commands')
end
end
2016-11-17 14:30:04 +00:00
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
2016-11-17 14:30:04 +00:00
context 'issue is succesfully created' do
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
2016-11-18 10:38:54 +00:00
it 'shows a link to the new issue' do
expect(subject[:text]).to match(/\/issues\/\d+/)
end
2016-11-17 14:30:04 +00:00
end
end
end