logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

chat_view_test.exs (1578B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.PleromaAPI.ChatViewTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.Chat
  7. alias Pleroma.Chat.MessageReference
  8. alias Pleroma.Object
  9. alias Pleroma.Web.CommonAPI
  10. alias Pleroma.Web.CommonAPI.Utils
  11. alias Pleroma.Web.MastodonAPI.AccountView
  12. alias Pleroma.Web.PleromaAPI.Chat.MessageReferenceView
  13. alias Pleroma.Web.PleromaAPI.ChatView
  14. import Pleroma.Factory
  15. test "it represents a chat" do
  16. user = insert(:user)
  17. recipient = insert(:user)
  18. {:ok, chat} = Chat.get_or_create(user.id, recipient.ap_id)
  19. represented_chat = ChatView.render("show.json", chat: chat)
  20. assert represented_chat == %{
  21. id: "#{chat.id}",
  22. account:
  23. AccountView.render("show.json", user: recipient, skip_visibility_check: true),
  24. unread: 0,
  25. last_message: nil,
  26. updated_at: Utils.to_masto_date(chat.updated_at)
  27. }
  28. {:ok, chat_message_creation} = CommonAPI.post_chat_message(user, recipient, "hello")
  29. chat_message = Object.normalize(chat_message_creation, false)
  30. {:ok, chat} = Chat.get_or_create(user.id, recipient.ap_id)
  31. represented_chat = ChatView.render("show.json", chat: chat)
  32. cm_ref = MessageReference.for_chat_and_object(chat, chat_message)
  33. assert represented_chat[:last_message] ==
  34. MessageReferenceView.render("show.json", chat_message_reference: cm_ref)
  35. end
  36. end