2016-11-15 15:50:27 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Gitlab::SlashCommands::IssueShow do
|
2016-11-15 15:50:27 -05:00
|
|
|
describe '#execute' do
|
2017-01-10 13:43:58 -05:00
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
let(:project) { create(:empty_project) }
|
2016-11-17 06:06:45 -05:00
|
|
|
let(:user) { issue.author }
|
2016-11-16 12:28:38 -05:00
|
|
|
let(:regex_match) { described_class.match("issue show #{issue.iid}") }
|
2016-11-15 15:50:27 -05:00
|
|
|
|
2016-11-17 06:06:45 -05:00
|
|
|
before do
|
|
|
|
project.team << [user, :master]
|
|
|
|
end
|
2016-11-15 15:50:27 -05:00
|
|
|
|
2016-11-17 06:06:45 -05:00
|
|
|
subject do
|
|
|
|
described_class.new(project, user).execute(regex_match)
|
|
|
|
end
|
2016-11-15 15:50:27 -05:00
|
|
|
|
|
|
|
context 'the issue exists' do
|
2017-01-10 13:43:58 -05:00
|
|
|
let(:title) { subject[:attachments].first[:title] }
|
|
|
|
|
2016-11-15 15:50:27 -05:00
|
|
|
it 'returns the issue' do
|
2017-01-10 13:43:58 -05:00
|
|
|
expect(subject[:response_type]).to be(:in_channel)
|
2017-01-19 03:22:09 -05:00
|
|
|
expect(title).to start_with(issue.title)
|
2016-11-15 15:50:27 -05:00
|
|
|
end
|
2016-11-21 16:27:10 -05:00
|
|
|
|
|
|
|
context 'when its reference is given' do
|
|
|
|
let(:regex_match) { described_class.match("issue show #{issue.to_reference}") }
|
|
|
|
|
|
|
|
it 'shows the issue' do
|
2017-01-10 13:43:58 -05:00
|
|
|
expect(subject[:response_type]).to be(:in_channel)
|
2017-01-19 03:22:09 -05:00
|
|
|
expect(title).to start_with(issue.title)
|
2016-11-21 16:27:10 -05:00
|
|
|
end
|
|
|
|
end
|
2016-11-15 15:50:27 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'the issue does not exist' do
|
2016-11-17 09:30:04 -05:00
|
|
|
let(:regex_match) { described_class.match("issue show 2343242") }
|
2016-11-15 15:50:27 -05:00
|
|
|
|
2017-01-10 13:43:58 -05:00
|
|
|
it "returns not found" do
|
|
|
|
expect(subject[:response_type]).to be(:ephemeral)
|
|
|
|
expect(subject[:text]).to match("not found")
|
2016-11-15 15:50:27 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-11-17 06:06:45 -05:00
|
|
|
|
2017-01-10 13:43:58 -05:00
|
|
|
describe '.match' do
|
2016-11-17 06:06:45 -05:00
|
|
|
it 'matches the iid' do
|
|
|
|
match = described_class.match("issue show 123")
|
|
|
|
|
|
|
|
expect(match[:iid]).to eq("123")
|
|
|
|
end
|
2017-01-10 13:43:58 -05:00
|
|
|
|
|
|
|
it 'accepts a reference' do
|
|
|
|
match = described_class.match("issue show #{Issue.reference_prefix}123")
|
|
|
|
|
|
|
|
expect(match[:iid]).to eq("123")
|
|
|
|
end
|
2016-11-17 06:06:45 -05:00
|
|
|
end
|
2016-11-15 15:50:27 -05:00
|
|
|
end
|