debian-mirror-gitlab/spec/lib/gitlab/slash_commands/issue_show_spec.rb

61 lines
1.6 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe Gitlab::SlashCommands::IssueShow do
2017-08-17 22:00:37 +05:30
describe '#execute' do
let(:issue) { create(:issue, project: project) }
2017-09-10 17:25:29 +05:30
let(:project) { create(:project) }
2017-08-17 22:00:37 +05:30
let(:user) { issue.author }
2018-03-27 19:54:05 +05:30
let(:chat_name) { double(:chat_name, user: user) }
2017-08-17 22:00:37 +05:30
let(:regex_match) { described_class.match("issue show #{issue.iid}") }
before do
2018-03-17 18:26:18 +05:30
project.add_master(user)
2017-08-17 22:00:37 +05:30
end
subject do
2018-03-27 19:54:05 +05:30
described_class.new(project, chat_name).execute(regex_match)
2017-08-17 22:00:37 +05:30
end
context 'the issue exists' do
let(:title) { subject[:attachments].first[:title] }
it 'returns the issue' do
expect(subject[:response_type]).to be(:in_channel)
expect(title).to start_with(issue.title)
end
context 'when its reference is given' do
let(:regex_match) { described_class.match("issue show #{issue.to_reference}") }
it 'shows the issue' do
expect(subject[:response_type]).to be(:in_channel)
expect(title).to start_with(issue.title)
end
end
end
context 'the issue does not exist' do
let(:regex_match) { described_class.match("issue show 2343242") }
it "returns not found" do
expect(subject[:response_type]).to be(:ephemeral)
expect(subject[:text]).to match("not found")
end
end
end
describe '.match' do
it 'matches the iid' do
match = described_class.match("issue show 123")
expect(match[:iid]).to eq("123")
end
it 'accepts a reference' do
match = described_class.match("issue show #{Issue.reference_prefix}123")
expect(match[:iid]).to eq("123")
end
end
end