+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.ActivityPub.VisibilityTest do
use Pleroma.DataCase
+ alias Pleroma.Activity
alias Pleroma.Web.ActivityPub.Visibility
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
assert Visibility.get_visibility(direct) == "direct"
assert Visibility.get_visibility(unlisted) == "unlisted"
end
+
+ test "get_visibility with directMessage flag" do
+ assert Visibility.get_visibility(%{data: %{"directMessage" => true}}) == "direct"
+ end
+
+ describe "entire_thread_visible_for_user?/2" do
+ test "returns false if not found activity", %{user: user} do
+ refute Visibility.entire_thread_visible_for_user?(%Activity{}, user)
+ end
+
+ test "returns true if activity hasn't 'Create' type", %{user: user} do
+ activity = insert(:like_activity)
+ assert Visibility.entire_thread_visible_for_user?(activity, user)
+ end
+
+ test "returns false when invalid recipients", %{user: user} do
+ author = insert(:user)
+
+ activity =
+ insert(:note_activity,
+ note:
+ insert(:note,
+ user: author,
+ data: %{"to" => ["test-user"]}
+ )
+ )
+
+ refute Visibility.entire_thread_visible_for_user?(activity, user)
+ end
+
+ test "returns true if user following to author" do
+ author = insert(:user)
+ user = insert(:user, following: [author.ap_id])
+
+ activity =
+ insert(:note_activity,
+ note:
+ insert(:note,
+ user: author,
+ data: %{"to" => [user.ap_id]}
+ )
+ )
+
+ assert Visibility.entire_thread_visible_for_user?(activity, user)
+ end
+ end
end