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