logo

pleroma

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

chat_message_view_test.exs (1833B)


      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 
      5 defmodule Pleroma.Web.PleromaAPI.ChatMessageViewTest do
      6   use Pleroma.DataCase
      7 
      8   alias Pleroma.Chat
      9   alias Pleroma.Object
     10   alias Pleroma.Web.ActivityPub.ActivityPub
     11   alias Pleroma.Web.CommonAPI
     12   alias Pleroma.Web.PleromaAPI.ChatMessageView
     13 
     14   import Pleroma.Factory
     15 
     16   test "it displays a chat message" do
     17     user = insert(:user)
     18     recipient = insert(:user)
     19 
     20     file = %Plug.Upload{
     21       content_type: "image/jpg",
     22       path: Path.absname("test/fixtures/image.jpg"),
     23       filename: "an_image.jpg"
     24     }
     25 
     26     {:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
     27     {:ok, activity} = CommonAPI.post_chat_message(user, recipient, "kippis :firefox:")
     28 
     29     chat = Chat.get(user.id, recipient.ap_id)
     30 
     31     object = Object.normalize(activity)
     32 
     33     chat_message = ChatMessageView.render("show.json", object: object, for: user, chat: chat)
     34 
     35     assert chat_message[:id] == object.id |> to_string()
     36     assert chat_message[:content] == "kippis :firefox:"
     37     assert chat_message[:account_id] == user.id
     38     assert chat_message[:chat_id]
     39     assert chat_message[:created_at]
     40     assert match?([%{shortcode: "firefox"}], chat_message[:emojis])
     41 
     42     {:ok, activity} = CommonAPI.post_chat_message(recipient, user, "gkgkgk", media_id: upload.id)
     43 
     44     object = Object.normalize(activity)
     45 
     46     chat_message_two = ChatMessageView.render("show.json", object: object, for: user, chat: chat)
     47 
     48     assert chat_message_two[:id] == object.id |> to_string()
     49     assert chat_message_two[:content] == "gkgkgk"
     50     assert chat_message_two[:account_id] == recipient.id
     51     assert chat_message_two[:chat_id] == chat_message[:chat_id]
     52     assert chat_message_two[:attachment]
     53   end
     54 end