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.Chat.MessageReferenceTest do
6 use Pleroma.DataCase, async: true
9 alias Pleroma.Chat.MessageReference
10 alias Pleroma.Web.CommonAPI
12 import Pleroma.Factory
14 describe "messages" do
15 test "it returns the last message in a chat" do
17 recipient = insert(:user)
19 {:ok, _message_1} = CommonAPI.post_chat_message(user, recipient, "hey")
20 {:ok, _message_2} = CommonAPI.post_chat_message(recipient, user, "ho")
22 {:ok, chat} = Chat.get_or_create(user.id, recipient.ap_id)
24 message = MessageReference.last_message_for_chat(chat)
26 assert message.object.data["content"] == "ho"