logo

pleroma

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

message_reference_view_test.exs (2380B)


  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.Chat.MessageReferenceViewTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.Chat
  7. alias Pleroma.Chat.MessageReference
  8. alias Pleroma.Object
  9. alias Pleroma.Web.ActivityPub.ActivityPub
  10. alias Pleroma.Web.CommonAPI
  11. alias Pleroma.Web.PleromaAPI.Chat.MessageReferenceView
  12. import Pleroma.Factory
  13. test "it displays a chat message" do
  14. user = insert(:user)
  15. recipient = insert(:user)
  16. file = %Plug.Upload{
  17. content_type: "image/jpg",
  18. path: Path.absname("test/fixtures/image.jpg"),
  19. filename: "an_image.jpg"
  20. }
  21. {:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
  22. {:ok, activity} = CommonAPI.post_chat_message(user, recipient, "kippis :firefox:")
  23. chat = Chat.get(user.id, recipient.ap_id)
  24. object = Object.normalize(activity)
  25. cm_ref = MessageReference.for_chat_and_object(chat, object)
  26. chat_message = MessageReferenceView.render("show.json", chat_message_reference: cm_ref)
  27. assert chat_message[:id] == cm_ref.id
  28. assert chat_message[:content] == "kippis :firefox:"
  29. assert chat_message[:account_id] == user.id
  30. assert chat_message[:chat_id]
  31. assert chat_message[:created_at]
  32. assert chat_message[:unread] == false
  33. assert match?([%{shortcode: "firefox"}], chat_message[:emojis])
  34. clear_config([:rich_media, :enabled], true)
  35. Tesla.Mock.mock(fn
  36. %{url: "https://example.com/ogp"} ->
  37. %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}
  38. end)
  39. {:ok, activity} =
  40. CommonAPI.post_chat_message(recipient, user, "gkgkgk https://example.com/ogp",
  41. media_id: upload.id
  42. )
  43. object = Object.normalize(activity)
  44. cm_ref = MessageReference.for_chat_and_object(chat, object)
  45. chat_message_two = MessageReferenceView.render("show.json", chat_message_reference: cm_ref)
  46. assert chat_message_two[:id] == cm_ref.id
  47. assert chat_message_two[:content] == object.data["content"]
  48. assert chat_message_two[:account_id] == recipient.id
  49. assert chat_message_two[:chat_id] == chat_message[:chat_id]
  50. assert chat_message_two[:attachment]
  51. assert chat_message_two[:unread] == true
  52. assert chat_message_two[:card]
  53. end
  54. end