2019-08-22 06:57:44 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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) }
|
2018-02-22 12:34:04 -05:00
|
|
|
let(:chat_name) { double(:chat_name, user: user) }
|
2016-11-25 09:41:28 -05:00
|
|
|
let(:regex_match) { described_class.match("issue search find") }
|
|
|
|
|
|
|
|
subject do
|
2018-02-22 12:34:04 -05:00
|
|
|
described_class.new(project, chat_name).execute(regex_match)
|
2016-11-25 09:41:28 -05:00
|
|
|
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
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(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" }
|
2019-12-12 07:07:33 -05:00
|
|
|
|
2016-11-25 09:41:28 -05:00
|
|
|
it 'matches the query' do
|
|
|
|
match = described_class.match("issue search #{query}")
|
|
|
|
|
|
|
|
expect(match[:query]).to eq(query)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|