2023-05-21 22:09:14 -04:00
|
|
|
#frozen_string_literal: true
|
|
|
|
|
|
|
|
require_relative "../../../../support/openai_completions_inference_stubs"
|
|
|
|
|
|
|
|
RSpec.describe DiscourseAi::AiBot::Commands::SearchCommand do
|
2023-08-28 20:43:58 -04:00
|
|
|
let(:bot_user) { User.find(DiscourseAi::AiBot::EntryPoint::GPT3_5_TURBO_ID) }
|
2023-05-21 22:09:14 -04:00
|
|
|
|
|
|
|
before { SearchIndexer.enable }
|
|
|
|
after { SearchIndexer.disable }
|
|
|
|
|
|
|
|
describe "#process" do
|
2023-05-22 01:14:26 -04:00
|
|
|
it "can handle no results" do
|
|
|
|
post1 = Fabricate(:post)
|
2023-08-14 02:30:12 -04:00
|
|
|
search = described_class.new(bot_user: bot_user, post: post1, args: nil)
|
2023-05-22 01:14:26 -04:00
|
|
|
|
2023-08-03 19:37:58 -04:00
|
|
|
results = search.process(query: "order:fake ABDDCDCEDGDG")
|
|
|
|
|
|
|
|
expect(results[:args]).to eq({ query: "order:fake ABDDCDCEDGDG" })
|
2023-06-21 03:10:30 -04:00
|
|
|
expect(results[:rows]).to eq([])
|
2023-06-19 18:45:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "supports subfolder properly" do
|
|
|
|
Discourse.stubs(:base_path).returns("/subfolder")
|
|
|
|
|
|
|
|
post1 = Fabricate(:post)
|
|
|
|
|
2023-08-14 02:30:12 -04:00
|
|
|
search = described_class.new(bot_user: bot_user, post: post1, args: nil)
|
2023-06-19 18:45:31 -04:00
|
|
|
|
2023-08-03 19:37:58 -04:00
|
|
|
results = search.process(limit: 1, user: post1.user.username)
|
2023-06-19 18:45:31 -04:00
|
|
|
expect(results[:rows].to_s).to include("/subfolder" + post1.url)
|
2023-05-22 01:14:26 -04:00
|
|
|
end
|
|
|
|
|
2023-05-21 22:09:14 -04:00
|
|
|
it "can handle limits" do
|
|
|
|
post1 = Fabricate(:post)
|
|
|
|
_post2 = Fabricate(:post, user: post1.user)
|
|
|
|
_post3 = Fabricate(:post, user: post1.user)
|
|
|
|
|
|
|
|
# search has no built in support for limit: so handle it from the outside
|
2023-08-14 02:30:12 -04:00
|
|
|
search = described_class.new(bot_user: bot_user, post: post1, args: nil)
|
2023-05-21 22:09:14 -04:00
|
|
|
|
2023-08-03 19:37:58 -04:00
|
|
|
results = search.process(limit: 2, user: post1.user.username)
|
2023-05-21 22:09:14 -04:00
|
|
|
|
2023-06-19 18:45:31 -04:00
|
|
|
expect(results[:column_names].length).to eq(4)
|
|
|
|
expect(results[:rows].length).to eq(2)
|
2023-05-23 09:08:17 -04:00
|
|
|
|
|
|
|
# just searching for everything
|
2023-08-03 19:37:58 -04:00
|
|
|
results = search.process(order: "latest_topic")
|
2023-06-19 18:45:31 -04:00
|
|
|
expect(results[:rows].length).to be > 1
|
2023-05-21 22:09:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|