1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.PleromaAPI.ChatViewTest do
6 use Pleroma.DataCase, async: true
9 alias Pleroma.Chat.MessageReference
11 alias Pleroma.Web.CommonAPI
12 alias Pleroma.Web.CommonAPI.Utils
13 alias Pleroma.Web.MastodonAPI.AccountView
14 alias Pleroma.Web.PleromaAPI.Chat.MessageReferenceView
15 alias Pleroma.Web.PleromaAPI.ChatView
17 import Pleroma.Factory
19 test "it represents a chat" do
21 recipient = insert(:user)
23 {:ok, chat} = Chat.get_or_create(user.id, recipient.ap_id)
25 represented_chat = ChatView.render("show.json", chat: chat)
27 assert represented_chat == %{
30 AccountView.render("show.json", user: recipient, skip_visibility_check: true),
33 updated_at: Utils.to_masto_date(chat.updated_at)
36 {:ok, chat_message_creation} = CommonAPI.post_chat_message(user, recipient, "hello")
38 chat_message = Object.normalize(chat_message_creation, fetch: false)
40 {:ok, chat} = Chat.get_or_create(user.id, recipient.ap_id)
42 represented_chat = ChatView.render("show.json", chat: chat)
44 cm_ref = MessageReference.for_chat_and_object(chat, chat_message)
46 assert represented_chat[:last_message] ==
47 MessageReferenceView.render("show.json", chat_message_reference: cm_ref)