2019-08-22 10:57:44 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-15 20:50:27 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 18:09:03 +00:00
|
|
|
RSpec.describe Gitlab::SlashCommands::IssueNew do
|
2016-11-15 20:50:27 +00:00
|
|
|
describe '#execute' do
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project) { create(:project) }
|
2016-11-17 14:30:04 +00:00
|
|
|
let(:user) { create(:user) }
|
2018-02-22 17:34:04 +00:00
|
|
|
let(:chat_name) { double(:chat_name, user: user) }
|
2016-11-16 17:28:38 +00:00
|
|
|
let(:regex_match) { described_class.match("issue create bird is the word") }
|
2016-11-15 20:50:27 +00:00
|
|
|
|
2016-11-17 11:06:45 +00:00
|
|
|
before do
|
2018-07-11 14:36:08 +00:00
|
|
|
project.add_maintainer(user)
|
2016-11-17 11:06:45 +00:00
|
|
|
end
|
2016-11-15 20:50:27 +00:00
|
|
|
|
2016-11-17 11:06:45 +00:00
|
|
|
subject do
|
2018-02-22 17:34:04 +00:00
|
|
|
described_class.new(project, chat_name).execute(regex_match)
|
2016-11-17 11:06:45 +00:00
|
|
|
end
|
2016-11-15 20:50:27 +00:00
|
|
|
|
|
|
|
context 'without description' do
|
|
|
|
it 'creates the issue' do
|
2016-11-17 14:30:04 +00:00
|
|
|
expect { subject }.to change { project.issues.count }.by(1)
|
2016-11-15 20:50:27 +00:00
|
|
|
|
2017-01-10 18:43:58 +00:00
|
|
|
expect(subject[:response_type]).to be(:in_channel)
|
2016-11-15 20:50:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with description' do
|
|
|
|
let(:description) { "Surfin bird" }
|
2016-11-16 17:28:38 +00:00
|
|
|
let(:regex_match) { described_class.match("issue create bird is the word\n#{description}") }
|
2016-11-15 20:50:27 +00:00
|
|
|
|
2016-11-17 14:30:04 +00:00
|
|
|
it 'creates the issue with description' do
|
2016-11-17 11:06:45 +00:00
|
|
|
subject
|
2016-11-15 20:50:27 +00:00
|
|
|
|
2016-11-17 11:06:45 +00:00
|
|
|
expect(Issue.last.description).to eq(description)
|
2016-11-15 20:50:27 +00:00
|
|
|
end
|
|
|
|
end
|
2016-11-21 19:48:18 +00:00
|
|
|
|
|
|
|
context "with more newlines between the title and the description" do
|
|
|
|
let(:description) { "Surfin bird" }
|
|
|
|
let(:regex_match) { described_class.match("issue create bird is the word\n\n#{description}\n") }
|
|
|
|
|
|
|
|
it 'creates the issue' do
|
|
|
|
expect { subject }.to change { project.issues.count }.by(1)
|
|
|
|
end
|
|
|
|
end
|
2017-01-10 18:43:58 +00:00
|
|
|
|
|
|
|
context 'issue cannot be created' do
|
2019-01-16 12:09:29 +00:00
|
|
|
let!(:issue) { create(:issue, project: project, title: 'bird is the word') }
|
2017-01-10 18:43:58 +00:00
|
|
|
let(:regex_match) { described_class.match("issue create #{'a' * 512}}") }
|
|
|
|
|
|
|
|
it 'displays the errors' do
|
|
|
|
expect(subject[:response_type]).to be(:ephemeral)
|
|
|
|
expect(subject[:text]).to match("- Title is too long")
|
|
|
|
end
|
|
|
|
end
|
2016-11-15 20:50:27 +00:00
|
|
|
end
|
2016-11-17 11:06:45 +00:00
|
|
|
|
2016-11-18 10:38:54 +00:00
|
|
|
describe '.match' do
|
2016-11-17 11:06:45 +00:00
|
|
|
it 'matches the title without description' do
|
|
|
|
match = described_class.match("issue create my title")
|
|
|
|
|
|
|
|
expect(match[:title]).to eq('my title')
|
|
|
|
expect(match[:description]).to eq("")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'matches the title with description' do
|
|
|
|
match = described_class.match("issue create my title\n\ndescription")
|
|
|
|
|
|
|
|
expect(match[:title]).to eq('my title')
|
|
|
|
expect(match[:description]).to eq('description')
|
|
|
|
end
|
2016-11-28 12:18:06 +00:00
|
|
|
|
|
|
|
it 'matches the alias new' do
|
|
|
|
match = described_class.match("issue new my title")
|
|
|
|
|
|
|
|
expect(match).not_to be_nil
|
|
|
|
expect(match[:title]).to eq('my title')
|
|
|
|
end
|
2016-11-17 11:06:45 +00:00
|
|
|
end
|
2016-11-15 20:50:27 +00:00
|
|
|
end
|