mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 13:18:21 +08:00
FIX: serializes interaction for direct messages (#29844)
Prior to this fix it would cause an error as we need to pass the user to get the title of the channel. This commit also adds a test for message interaction serializer.
This commit is contained in:
parent
67ce111861
commit
2fb811a335
|
@ -9,7 +9,7 @@ module Chat
|
|||
end
|
||||
|
||||
def channel
|
||||
{ id: object.message.chat_channel.id, title: object.message.chat_channel.title }
|
||||
{ id: object.message.chat_channel.id, title: object.message.chat_channel.title(scope.user) }
|
||||
end
|
||||
|
||||
def message
|
||||
|
|
|
@ -173,6 +173,11 @@ Fabricator(:chat_reviewable_message, class_name: "Chat::ReviewableMessage") do
|
|||
reviewable_scores { |p| [Fabricate.build(:reviewable_score, reviewable_id: p[:id])] }
|
||||
end
|
||||
|
||||
Fabricator(:chat_message_interaction, class_name: "Chat::MessageInteraction") do
|
||||
message { Fabricate(:chat_message) }
|
||||
user { Fabricate(:user) }
|
||||
end
|
||||
|
||||
Fabricator(:direct_message, class_name: "Chat::DirectMessage") do
|
||||
users { [Fabricate(:user), Fabricate(:user)] }
|
||||
end
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
# frozen_string_literal: true
|
||||
RSpec.describe Chat::MessageInteractionSerializer do
|
||||
subject(:serializer) do
|
||||
interaction =
|
||||
Fabricate(
|
||||
:chat_message_interaction,
|
||||
message:,
|
||||
user:,
|
||||
action: message.blocks.first["elements"].first,
|
||||
)
|
||||
described_class.new(interaction, scope: Guardian.new(user), root: false)
|
||||
end
|
||||
|
||||
fab!(:user)
|
||||
|
||||
let(:message) do
|
||||
Fabricate(
|
||||
:chat_message,
|
||||
chat_channel: channel,
|
||||
user: Discourse.system_user,
|
||||
blocks: [
|
||||
{
|
||||
type: "actions",
|
||||
elements: [
|
||||
{ type: "button", text: { type: "plain_text", text: "Like" }, action_id: "like" },
|
||||
],
|
||||
},
|
||||
],
|
||||
)
|
||||
end
|
||||
let(:message_id) { message.id }
|
||||
let(:params) { { message_id:, action_id: "like" } }
|
||||
|
||||
before do
|
||||
SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:everyone]
|
||||
SiteSetting.direct_message_enabled_groups = Group::AUTO_GROUPS[:everyone]
|
||||
end
|
||||
|
||||
context "when interaction's channel is private" do
|
||||
let(:channel) { Fabricate(:direct_message_channel, users: [user, Fabricate(:user)]) }
|
||||
|
||||
it "serializes the interaction" do
|
||||
expect(serializer.as_json).to match_response_schema("message_interaction")
|
||||
end
|
||||
end
|
||||
|
||||
context "when interaction's channel is public" do
|
||||
let(:channel) { Fabricate(:chat_channel) }
|
||||
|
||||
it "serializes the interaction" do
|
||||
expect(serializer.as_json).to match_response_schema("message_interaction")
|
||||
end
|
||||
end
|
||||
end
|
101
plugins/chat/spec/support/api/schemas/message_interaction.json
Normal file
101
plugins/chat/spec/support/api/schemas/message_interaction.json
Normal file
|
@ -0,0 +1,101 @@
|
|||
{
|
||||
"type": "object",
|
||||
"required": [
|
||||
"action",
|
||||
"channel",
|
||||
"message",
|
||||
"user"
|
||||
],
|
||||
"properties": {
|
||||
"action": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"action_id",
|
||||
"schema_version",
|
||||
"text",
|
||||
"type"
|
||||
],
|
||||
"properties": {
|
||||
"action_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"schema_version": {
|
||||
"type": "integer"
|
||||
},
|
||||
"text": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"text",
|
||||
"type"
|
||||
],
|
||||
"properties": {
|
||||
"text": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"plain_text"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"button"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"channel": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"id",
|
||||
"title"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"title": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"message": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"id",
|
||||
"text",
|
||||
"user_id"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"text": {
|
||||
"type": "string"
|
||||
},
|
||||
"user_id": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"user": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"id",
|
||||
"username"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"username": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user