aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/support/factory.ex14
-rw-r--r--test/web/activity_pub/utils_test.exs50
-rw-r--r--test/web/node_info_test.exs6
-rw-r--r--test/web/push/push_test.exs53
-rw-r--r--test/web/rich_media/helpers_test.exs62
5 files changed, 176 insertions, 9 deletions
diff --git a/test/support/factory.ex b/test/support/factory.ex
index d1956d1cd..c025aaf21 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -23,7 +23,7 @@ defmodule Pleroma.Factory do
}
end
- def note_factory do
+ def note_factory(attrs \\ %{}) do
text = sequence(:text, &"This is :moominmamma: note #{&1}")
user = insert(:user)
@@ -46,7 +46,7 @@ defmodule Pleroma.Factory do
}
%Pleroma.Object{
- data: data
+ data: merge_attributes(data, Map.get(attrs, :data, %{}))
}
end
@@ -95,8 +95,8 @@ defmodule Pleroma.Factory do
}
end
- def note_activity_factory do
- note = insert(:note)
+ def note_activity_factory(attrs \\ %{}) do
+ note = attrs[:note] || insert(:note)
data = %{
"id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
@@ -135,9 +135,9 @@ defmodule Pleroma.Factory do
}
end
- def announce_activity_factory do
- note_activity = insert(:note_activity)
- user = insert(:user)
+ def announce_activity_factory(attrs \\ %{}) do
+ note_activity = attrs[:note_activity] || insert(:note_activity)
+ user = attrs[:user] || insert(:user)
data = %{
"type" => "Announce",
diff --git a/test/web/activity_pub/utils_test.exs b/test/web/activity_pub/utils_test.exs
index aeed0564c..2e5e95795 100644
--- a/test/web/activity_pub/utils_test.exs
+++ b/test/web/activity_pub/utils_test.exs
@@ -1,7 +1,10 @@
defmodule Pleroma.Web.ActivityPub.UtilsTest do
use Pleroma.DataCase
+ alias Pleroma.Web.CommonAPI
alias Pleroma.Web.ActivityPub.Utils
+ import Pleroma.Factory
+
describe "determine_explicit_mentions()" do
test "works with an object that has mentions" do
object = %{
@@ -54,4 +57,51 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
assert Utils.determine_explicit_mentions(object) == []
end
end
+
+ describe "make_like_data" do
+ setup do
+ user = insert(:user)
+ other_user = insert(:user)
+ third_user = insert(:user)
+ [user: user, other_user: other_user, third_user: third_user]
+ end
+
+ test "addresses actor's follower address if the activity is public", %{
+ user: user,
+ other_user: other_user,
+ third_user: third_user
+ } do
+ expected_to = Enum.sort([user.ap_id, other_user.follower_address])
+ expected_cc = Enum.sort(["https://www.w3.org/ns/activitystreams#Public", third_user.ap_id])
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" =>
+ "hey @#{other_user.nickname}, @#{third_user.nickname} how about beering together this weekend?"
+ })
+
+ %{"to" => to, "cc" => cc} = Utils.make_like_data(other_user, activity, nil)
+ assert Enum.sort(to) == expected_to
+ assert Enum.sort(cc) == expected_cc
+ end
+
+ test "does not adress actor's follower address if the activity is not public", %{
+ user: user,
+ other_user: other_user,
+ third_user: third_user
+ } do
+ expected_to = Enum.sort([user.ap_id])
+ expected_cc = [third_user.ap_id]
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "@#{other_user.nickname} @#{third_user.nickname} bought a new swimsuit!",
+ "visibility" => "private"
+ })
+
+ %{"to" => to, "cc" => cc} = Utils.make_like_data(other_user, activity, nil)
+ assert Enum.sort(to) == expected_to
+ assert Enum.sort(cc) == expected_cc
+ end
+ end
end
diff --git a/test/web/node_info_test.exs b/test/web/node_info_test.exs
index 763549bd1..038feecc1 100644
--- a/test/web/node_info_test.exs
+++ b/test/web/node_info_test.exs
@@ -8,7 +8,8 @@ defmodule Pleroma.Web.NodeInfoTest do
import Pleroma.Factory
test "nodeinfo shows staff accounts", %{conn: conn} do
- user = insert(:user, %{local: true, info: %{is_moderator: true}})
+ moderator = insert(:user, %{local: true, info: %{is_moderator: true}})
+ admin = insert(:user, %{local: true, info: %{is_admin: true}})
conn =
conn
@@ -16,7 +17,8 @@ defmodule Pleroma.Web.NodeInfoTest do
assert result = json_response(conn, 200)
- assert user.ap_id in result["metadata"]["staffAccounts"]
+ assert moderator.ap_id in result["metadata"]["staffAccounts"]
+ assert admin.ap_id in result["metadata"]["staffAccounts"]
end
test "nodeinfo shows restricted nicknames", %{conn: conn} do
diff --git a/test/web/push/push_test.exs b/test/web/push/push_test.exs
new file mode 100644
index 000000000..5fa97531d
--- /dev/null
+++ b/test/web/push/push_test.exs
@@ -0,0 +1,53 @@
+defmodule Pleroma.Web.PushTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Web.Push
+
+ import Pleroma.Factory
+
+ test "renders body for create activity" do
+ assert Push.format_body(
+ %{
+ activity: %{
+ data: %{
+ "type" => "Create",
+ "object" => %{
+ "content" =>
+ "<span>Lorem ipsum dolor sit amet</span>, consectetur :bear: adipiscing elit. Fusce sagittis finibus turpis."
+ }
+ }
+ }
+ },
+ %{nickname: "Bob"}
+ ) ==
+ "@Bob: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini..."
+ end
+
+ test "renders body for follow activity" do
+ assert Push.format_body(%{activity: %{data: %{"type" => "Follow"}}}, %{nickname: "Bob"}) ==
+ "@Bob has followed you"
+ end
+
+ test "renders body for announce activity" do
+ user = insert(:user)
+
+ note =
+ insert(:note, %{
+ data: %{
+ "content" =>
+ "<span>Lorem ipsum dolor sit amet</span>, consectetur :bear: adipiscing elit. Fusce sagittis finibus turpis."
+ }
+ })
+
+ note_activity = insert(:note_activity, %{note: note})
+ announce_activity = insert(:announce_activity, %{user: user, note_activity: note_activity})
+
+ assert Push.format_body(%{activity: announce_activity}, user) ==
+ "@#{user.nickname} repeated: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini..."
+ end
+
+ test "renders body for like activity" do
+ assert Push.format_body(%{activity: %{data: %{"type" => "Like"}}}, %{nickname: "Bob"}) ==
+ "@Bob has favorited your post"
+ end
+end
diff --git a/test/web/rich_media/helpers_test.exs b/test/web/rich_media/helpers_test.exs
new file mode 100644
index 000000000..60d93768f
--- /dev/null
+++ b/test/web/rich_media/helpers_test.exs
@@ -0,0 +1,62 @@
+defmodule Pleroma.Web.RichMedia.HelpersTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Web.CommonAPI
+
+ import Pleroma.Factory
+ import Tesla.Mock
+
+ setup do
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
+
+ test "refuses to crawl incomplete URLs" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "[test](example.com/ogp)",
+ "content_type" => "text/markdown"
+ })
+
+ Pleroma.Config.put([:rich_media, :enabled], true)
+
+ assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
+
+ Pleroma.Config.put([:rich_media, :enabled], false)
+ end
+
+ test "refuses to crawl malformed URLs" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "[test](example.com[]/ogp)",
+ "content_type" => "text/markdown"
+ })
+
+ Pleroma.Config.put([:rich_media, :enabled], true)
+
+ assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
+
+ Pleroma.Config.put([:rich_media, :enabled], false)
+ end
+
+ test "crawls valid, complete URLs" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "[test](http://example.com/ogp)",
+ "content_type" => "text/markdown"
+ })
+
+ Pleroma.Config.put([:rich_media, :enabled], true)
+
+ assert %{page_url: "http://example.com/ogp", rich_media: _} =
+ Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
+
+ Pleroma.Config.put([:rich_media, :enabled], false)
+ end
+end