1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.PleromaAPI.ChatViewTest do
10 alias Pleroma.Web.CommonAPI
11 alias Pleroma.Web.CommonAPI.Utils
12 alias Pleroma.Web.MastodonAPI.AccountView
13 alias Pleroma.Web.PleromaAPI.ChatMessageView
14 alias Pleroma.Web.PleromaAPI.ChatView
16 import Pleroma.Factory
18 test "it represents a chat" do
20 recipient = insert(:user)
22 {:ok, chat} = Chat.get_or_create(user.id, recipient.ap_id)
24 represented_chat = ChatView.render("show.json", chat: chat)
26 assert represented_chat == %{
28 account: AccountView.render("show.json", user: recipient),
31 updated_at: Utils.to_masto_date(chat.updated_at)
34 {:ok, chat_message_creation} = CommonAPI.post_chat_message(user, recipient, "hello")
36 chat_message = Object.normalize(chat_message_creation, false)
38 {:ok, chat} = Chat.get_or_create(user.id, recipient.ap_id)
40 represented_chat = ChatView.render("show.json", chat: chat)
42 assert represented_chat[:last_message] ==
43 ChatMessageView.render("show.json", chat: chat, object: chat_message)