FIX: Serialize channel title for DMs (#90)

This commit is contained in:
Roman Rizzi 2023-06-16 14:37:16 -03:00 committed by GitHub
parent 68bc80e19d
commit 9e901dbfbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 1 deletions

View File

@ -1,5 +1,11 @@
# frozen_string_literal: true
class AiChatChannelSerializer < ApplicationSerializer
attributes :id, :chatable, :chatable_type, :chatable_url, :title, :slug
attributes :id, :chatable, :chatable_type, :chatable_url, :slug
def title
# Display all participants for a DM.
# For category channels, the argument is ignored.
object.title(nil)
end
end

View File

@ -0,0 +1,27 @@
# frozen_string_literal: true
RSpec.describe AiChatChannelSerializer do
fab!(:admin) { Fabricate(:admin) }
describe "#title" do
context "when the channel is a DM" do
fab!(:dm_channel) { Fabricate(:direct_message_channel) }
it "display every participant" do
serialized = described_class.new(dm_channel, scope: Guardian.new(admin), root: nil)
expect(serialized.title).to eq(dm_channel.title(nil))
end
end
context "when the channel is a regular one" do
fab!(:channel) { Fabricate(:chat_channel) }
it "displays the category title" do
serialized = described_class.new(channel, scope: Guardian.new(admin), root: nil)
expect(serialized.title).to eq(channel.title)
end
end
end
end