Reblog content should be ""
[akkoma] / test / pleroma / web / mastodon_api / views / conversation_view_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.MastodonAPI.ConversationViewTest do
6 use Pleroma.DataCase, async: true
7
8 alias Pleroma.Conversation.Participation
9 alias Pleroma.Web.CommonAPI
10 alias Pleroma.Web.MastodonAPI.ConversationView
11
12 import Pleroma.Factory
13
14 test "represents a Mastodon Conversation entity" do
15 user = insert(:user)
16 other_user = insert(:user)
17
18 {:ok, parent} = CommonAPI.post(user, %{status: "parent"})
19
20 {:ok, activity} =
21 CommonAPI.post(user, %{
22 status: "hey @#{other_user.nickname}",
23 visibility: "direct",
24 in_reply_to_id: parent.id
25 })
26
27 {:ok, _reply_activity} =
28 CommonAPI.post(user, %{status: "hu", visibility: "public", in_reply_to_id: parent.id})
29
30 [participation] = Participation.for_user_with_last_activity_id(user)
31
32 assert participation
33
34 conversation =
35 ConversationView.render("participation.json", %{participation: participation, for: user})
36
37 assert conversation.id == participation.id |> to_string()
38 assert conversation.last_status.id == activity.id
39 assert conversation.last_status.account.id == user.id
40
41 assert [account] = conversation.accounts
42 assert account.id == other_user.id
43
44 assert conversation.last_status.pleroma.direct_conversation_id == participation.id
45 end
46 end