honkoma/test/pleroma/web/mastodon_api/views/conversation_view_test.exs

47 lines
1.5 KiB
Elixir
Raw Normal View History

# Pleroma: A lightweight social networking server
2020-03-03 22:44:49 +00:00
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.ConversationViewTest do
use Pleroma.DataCase
alias Pleroma.Conversation.Participation
2019-08-05 14:11:23 +00:00
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.MastodonAPI.ConversationView
import Pleroma.Factory
test "represents a Mastodon Conversation entity" do
user = insert(:user)
other_user = insert(:user)
{:ok, parent} = CommonAPI.post(user, %{status: "parent"})
{:ok, activity} =
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})
[participation] = Participation.for_user_with_last_activity_id(user)
assert participation
conversation =
ConversationView.render("participation.json", %{participation: participation, for: user})
assert conversation.id == participation.id |> to_string()
assert conversation.last_status.id == activity.id
2020-10-30 12:37:15 +00:00
assert conversation.last_status.account.id == user.id
2020-10-18 19:12:42 +00:00
account_ids = Enum.map(conversation.accounts, & &1.id)
2020-10-30 12:37:15 +00:00
assert length(conversation.accounts) == 1
2020-10-18 16:01:17 +00:00
assert other_user.id in account_ids
assert conversation.last_status.pleroma.direct_conversation_id == participation.id
end
end