2016-11-25 09:41:28 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Gitlab::SlashCommands::IssueSearch do
|
2016-11-25 09:41:28 -05:00
|
|
|
describe '#execute' do
|
2017-01-10 13:43:58 -05:00
|
|
|
let!(:issue) { create(:issue, project: project, title: 'find me') }
|
2016-11-25 09:41:28 -05:00
|
|
|
let!(:confidential) { create(:issue, :confidential, project: project, title: 'mepmep find') }
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2017-08-04 13:14:04 -04:00
|
|
|
let(:user) { create(:user) }
|
2016-11-25 09:41:28 -05:00
|
|
|
let(:regex_match) { described_class.match("issue search find") }
|
|
|
|
|
|
|
|
subject do
|
|
|
|
described_class.new(project, user).execute(regex_match)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user has no access' do
|
|
|
|
it 'only returns the open issues' do
|
2017-01-10 13:43:58 -05:00
|
|
|
expect(subject[:response_type]).to be(:ephemeral)
|
|
|
|
expect(subject[:text]).to match("not found")
|
2016-11-25 09:41:28 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'the user has access' do
|
|
|
|
before do
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_master(user)
|
2016-11-25 09:41:28 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns all results' do
|
2017-01-10 13:43:58 -05:00
|
|
|
expect(subject).to have_key(:attachments)
|
2017-01-19 03:22:09 -05:00
|
|
|
expect(subject[:text]).to eq("Here are the 2 issues I found:")
|
2016-11-25 09:41:28 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without hits on the query' do
|
|
|
|
it 'returns an empty collection' do
|
2017-01-10 13:43:58 -05:00
|
|
|
expect(subject[:text]).to match("not found")
|
2016-11-25 09:41:28 -05:00
|
|
|
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
|