2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe Gitlab::SlashCommands::IssueSearch do
|
2017-08-17 22:00:37 +05:30
|
|
|
describe '#execute' do
|
|
|
|
let!(:issue) { create(:issue, project: project, title: 'find me') }
|
|
|
|
let!(:confidential) { create(:issue, :confidential, project: project, title: 'mepmep find') }
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:project) { create(:project) }
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:user) { create(:user) }
|
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 search find") }
|
|
|
|
|
|
|
|
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 'when the user has no access' do
|
|
|
|
it 'only returns the open issues' do
|
|
|
|
expect(subject[:response_type]).to be(:ephemeral)
|
|
|
|
expect(subject[:text]).to match("not found")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'the user has access' do
|
|
|
|
before do
|
2018-11-18 11:00:15 +05:30
|
|
|
project.add_maintainer(user)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns all results' do
|
|
|
|
expect(subject).to have_key(:attachments)
|
|
|
|
expect(subject[:text]).to eq("Here are the 2 issues I found:")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without hits on the query' do
|
|
|
|
it 'returns an empty collection' do
|
|
|
|
expect(subject[:text]).to match("not found")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'self.match' do
|
|
|
|
let(:query) { "my search keywords" }
|
|
|
|
it 'matches the query' do
|
|
|
|
match = described_class.match("issue search #{query}")
|
|
|
|
|
|
|
|
expect(match[:query]).to eq(query)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|