DEV: Chat hashtag test (#25638)

Followup a2a2785f0b, moving
stuff to an existing test.
This commit is contained in:
Martin Brennan 2024-02-12 12:32:52 +10:00 committed by GitHub
parent cf4d92f686
commit d80345fa83
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 12 deletions

View File

@ -24,6 +24,16 @@ RSpec.describe Chat::ChannelHashtagDataSource do
messages_count: 78, messages_count: 78,
) )
end end
fab!(:channel3) do
Fabricate(
:chat_channel,
slug: "music",
name: "Tunes",
chatable: category,
description: "A place for music lovers",
messages_count: 437,
)
end
let!(:guardian) { Guardian.new(user) } let!(:guardian) { Guardian.new(user) }
before { SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:trust_level_1] } before { SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:trust_level_1] }
@ -86,6 +96,31 @@ RSpec.describe Chat::ChannelHashtagDataSource do
SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:staff] SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:staff]
expect(described_class.lookup(Guardian.new(user), ["random"])).to be_empty expect(described_class.lookup(Guardian.new(user), ["random"])).to be_empty
end end
it "can return multiple channels" do
expect(described_class.lookup(guardian, %w[music random]).map(&:to_h)).to contain_exactly(
{
description: "Just weird stuff",
icon: "comment",
id: channel1.id,
ref: nil,
relative_url: channel1.relative_url,
slug: "random",
text: "Zany Things",
type: "channel",
},
{
description: "A place for music lovers",
icon: "comment",
id: channel3.id,
ref: nil,
relative_url: channel3.relative_url,
slug: "music",
text: "Tunes",
type: "channel",
},
)
end
end end
describe "#search" do describe "#search" do

View File

@ -3,11 +3,7 @@
RSpec.describe HashtagAutocompleteService do RSpec.describe HashtagAutocompleteService do
subject(:service) { described_class.new(guardian) } subject(:service) { described_class.new(guardian) }
fab!(:channel1) { Fabricate(:chat_channel, name: "Music Lounge", slug: "music") } before { SiteSetting.chat_enabled = true }
fab!(:channel2) { Fabricate(:chat_channel, name: "Random", slug: "random") }
fab!(:admin)
let(:guardian) { Guardian.new(admin) }
describe ".enabled_data_sources" do describe ".enabled_data_sources" do
it "only returns data sources that are enabled" do it "only returns data sources that are enabled" do
@ -16,11 +12,4 @@ RSpec.describe HashtagAutocompleteService do
) )
end end
end end
describe "#lookup" do
it "returns hashtags for channels" do
result = service.lookup(%w[music::channel random::channel], ["channel"])
expect(result[:channel].map(&:slug)).to contain_exactly("music", "random")
end
end
end end