2020-04-15 16:23:16 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-04-15 16:23:16 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-06-23 15:16:47 +00:00
|
|
|
defmodule Pleroma.Web.PleromaAPI.ChatMessageReferenceViewTest do
|
2020-04-15 16:23:16 +00:00
|
|
|
use Pleroma.DataCase
|
|
|
|
|
|
|
|
alias Pleroma.Chat
|
2020-06-06 09:51:10 +00:00
|
|
|
alias Pleroma.Chat.MessageReference
|
2020-04-15 16:23:16 +00:00
|
|
|
alias Pleroma.Object
|
2020-05-06 14:31:21 +00:00
|
|
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
2020-04-15 16:23:16 +00:00
|
|
|
alias Pleroma.Web.CommonAPI
|
2020-06-06 09:51:10 +00:00
|
|
|
alias Pleroma.Web.PleromaAPI.Chat.MessageReferenceView
|
2020-04-15 16:23:16 +00:00
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
test "it displays a chat message" do
|
|
|
|
user = insert(:user)
|
|
|
|
recipient = insert(:user)
|
2020-05-06 14:12:36 +00:00
|
|
|
|
|
|
|
file = %Plug.Upload{
|
2020-10-13 15:37:24 +00:00
|
|
|
content_type: "image/jpeg",
|
2020-05-06 14:12:36 +00:00
|
|
|
path: Path.absname("test/fixtures/image.jpg"),
|
|
|
|
filename: "an_image.jpg"
|
|
|
|
}
|
|
|
|
|
|
|
|
{:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
|
2020-10-31 02:50:48 +00:00
|
|
|
|
|
|
|
{:ok, activity} =
|
|
|
|
CommonAPI.post_chat_message(user, recipient, "kippis :firefox:", idempotency_key: "123")
|
2020-04-15 16:23:16 +00:00
|
|
|
|
|
|
|
chat = Chat.get(user.id, recipient.ap_id)
|
|
|
|
|
2021-01-04 12:38:31 +00:00
|
|
|
object = Object.normalize(activity, fetch: false)
|
2020-04-15 16:23:16 +00:00
|
|
|
|
2020-06-06 09:51:10 +00:00
|
|
|
cm_ref = MessageReference.for_chat_and_object(chat, object)
|
2020-04-15 16:23:16 +00:00
|
|
|
|
2020-06-06 09:51:10 +00:00
|
|
|
chat_message = MessageReferenceView.render("show.json", chat_message_reference: cm_ref)
|
2020-06-03 10:30:12 +00:00
|
|
|
|
|
|
|
assert chat_message[:id] == cm_ref.id
|
2020-04-20 12:38:53 +00:00
|
|
|
assert chat_message[:content] == "kippis :firefox:"
|
2020-04-27 15:48:34 +00:00
|
|
|
assert chat_message[:account_id] == user.id
|
2020-04-15 16:23:16 +00:00
|
|
|
assert chat_message[:chat_id]
|
2020-04-20 12:38:53 +00:00
|
|
|
assert chat_message[:created_at]
|
2020-06-03 16:58:58 +00:00
|
|
|
assert chat_message[:unread] == false
|
2020-04-20 12:38:53 +00:00
|
|
|
assert match?([%{shortcode: "firefox"}], chat_message[:emojis])
|
2020-10-31 02:50:48 +00:00
|
|
|
assert chat_message[:idempotency_key] == "123"
|
2020-04-15 16:23:16 +00:00
|
|
|
|
2020-07-30 17:57:26 +00:00
|
|
|
clear_config([:rich_media, :enabled], true)
|
|
|
|
|
2020-09-10 07:54:57 +00:00
|
|
|
Tesla.Mock.mock_global(fn
|
2020-07-30 17:57:26 +00:00
|
|
|
%{url: "https://example.com/ogp"} ->
|
|
|
|
%Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}
|
|
|
|
end)
|
|
|
|
|
|
|
|
{:ok, activity} =
|
|
|
|
CommonAPI.post_chat_message(recipient, user, "gkgkgk https://example.com/ogp",
|
|
|
|
media_id: upload.id
|
|
|
|
)
|
2020-04-15 16:23:16 +00:00
|
|
|
|
2021-01-04 12:38:31 +00:00
|
|
|
object = Object.normalize(activity, fetch: false)
|
2020-04-15 16:23:16 +00:00
|
|
|
|
2020-06-06 09:51:10 +00:00
|
|
|
cm_ref = MessageReference.for_chat_and_object(chat, object)
|
2020-06-03 10:30:12 +00:00
|
|
|
|
2020-06-06 09:51:10 +00:00
|
|
|
chat_message_two = MessageReferenceView.render("show.json", chat_message_reference: cm_ref)
|
2020-04-15 16:23:16 +00:00
|
|
|
|
2020-06-03 10:30:12 +00:00
|
|
|
assert chat_message_two[:id] == cm_ref.id
|
2020-07-30 17:57:26 +00:00
|
|
|
assert chat_message_two[:content] == object.data["content"]
|
2020-04-27 15:48:34 +00:00
|
|
|
assert chat_message_two[:account_id] == recipient.id
|
2020-04-15 16:23:16 +00:00
|
|
|
assert chat_message_two[:chat_id] == chat_message[:chat_id]
|
2020-05-06 14:12:36 +00:00
|
|
|
assert chat_message_two[:attachment]
|
2020-06-03 16:58:58 +00:00
|
|
|
assert chat_message_two[:unread] == true
|
2020-07-30 17:57:26 +00:00
|
|
|
assert chat_message_two[:card]
|
2020-04-15 16:23:16 +00:00
|
|
|
end
|
|
|
|
end
|