conversation_view_test.exs 1.4 KB
Newer Older
1
# Pleroma: A lightweight social networking server
feld's avatar
feld committed
2
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3
4
5
6
7
8
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Web.MastodonAPI.ConversationViewTest do
  use Pleroma.DataCase

  alias Pleroma.Conversation.Participation
lain's avatar
lain committed
9
  alias Pleroma.Web.CommonAPI
10
11
12
13
14
15
16
17
  alias Pleroma.Web.MastodonAPI.ConversationView

  import Pleroma.Factory

  test "represents a Mastodon Conversation entity" do
    user = insert(:user)
    other_user = insert(:user)

18
19
    {:ok, parent} = CommonAPI.post(user, %{status: "parent"})

20
    {:ok, activity} =
21
22
23
24
25
26
27
28
      CommonAPI.post(user, %{
        status: "hey @#{other_user.nickname}",
        visibility: "direct",
        in_reply_to_id: parent.id
      })

    {:ok, _reply_activity} =
      CommonAPI.post(user, %{status: "hu", visibility: "public", in_reply_to_id: parent.id})
29
30
31
32
33
34

    [participation] = Participation.for_user_with_last_activity_id(user)

    assert participation

    conversation =
35
      ConversationView.render("participation.json", %{participation: participation, for: user})
36
37
38

    assert conversation.id == participation.id |> to_string()
    assert conversation.last_status.id == activity.id
a1batross's avatar
a1batross committed
39
    assert conversation.last_status.account.id == user.id
40

lain's avatar
lain committed
41
42
43
    assert [account] = conversation.accounts
    assert account.id == other_user.id

44
    assert conversation.last_status.pleroma.direct_conversation_id == participation.id
45
46
  end
end