X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Fpush%2Fimpl_test.exs;h=9f931c941e0cdfc0d9f2bcb902c57cc68eb2e7fe;hb=9bae9b1b1bf4f48e20ce0b2d9b670648d052e069;hp=6bac2c9f6e383c8cfc581ae644aa49a8e6d3739a;hpb=0f2f7d2cec8297b1b5645643d7584cde561ce628;p=akkoma
diff --git a/test/web/push/impl_test.exs b/test/web/push/impl_test.exs
index 6bac2c9f6..9f931c941 100644
--- a/test/web/push/impl_test.exs
+++ b/test/web/push/impl_test.exs
@@ -1,10 +1,13 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Push.ImplTest do
use Pleroma.DataCase
+ alias Pleroma.Object
+ alias Pleroma.User
+ alias Pleroma.Web.CommonAPI
alias Pleroma.Web.Push.Impl
alias Pleroma.Web.Push.Subscription
@@ -52,16 +55,12 @@ defmodule Pleroma.Web.Push.ImplTest do
data: %{alerts: %{"follow" => true, "mention" => false}}
)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => " "Create",
- "actor" => user.ap_id,
- "object" => %{"content" => "
+ "Lorem ipsum dolor sit amet, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
+ })
+
+ object = Object.normalize(activity)
+
assert Impl.format_body(
%{
- activity: %{
- data: %{
- "type" => "Create",
- "object" => %{
- "content" =>
- "Lorem ipsum dolor sit amet, consectetur :bear: adipiscing elit. Fusce sagittis finibus turpis."
- }
- }
- }
+ activity: activity
},
- %{nickname: "Bob"}
+ user,
+ object
) ==
"@Bob: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini..."
+
+ assert Impl.format_title(%{activity: activity}) ==
+ "New Mention"
end
- test "renders body for follow activity" do
- assert Impl.format_body(%{activity: %{data: %{"type" => "Follow"}}}, %{nickname: "Bob"}) ==
- "@Bob has followed you"
+ test "renders title and body for follow activity" do
+ user = insert(:user, nickname: "Bob")
+ other_user = insert(:user)
+ {:ok, _, _, activity} = CommonAPI.follow(user, other_user)
+ object = Object.normalize(activity, false)
+
+ assert Impl.format_body(%{activity: activity}, user, object) == "@Bob has followed you"
+
+ assert Impl.format_title(%{activity: activity}) ==
+ "New Follower"
end
- test "renders body for announce activity" do
+ test "renders title and body for announce activity" do
user = insert(:user)
- note =
- insert(:note, %{
- data: %{
- "content" =>
- "Lorem ipsum dolor sit amet, consectetur :bear: adipiscing elit. Fusce sagittis finibus turpis."
- }
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" =>
+ "Lorem ipsum dolor sit amet, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
})
- note_activity = insert(:note_activity, %{note: note})
- announce_activity = insert(:announce_activity, %{user: user, note_activity: note_activity})
+ {:ok, announce_activity, _} = CommonAPI.repeat(activity.id, user)
+ object = Object.normalize(activity)
- assert Impl.format_body(%{activity: announce_activity}, user) ==
+ assert Impl.format_body(%{activity: announce_activity}, user, object) ==
"@#{user.nickname} repeated: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini..."
+
+ assert Impl.format_title(%{activity: announce_activity}) ==
+ "New Repeat"
+ end
+
+ test "renders title and body for like activity" do
+ user = insert(:user, nickname: "Bob")
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" =>
+ "Lorem ipsum dolor sit amet, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
+ })
+
+ {:ok, activity, _} = CommonAPI.favorite(activity.id, user)
+ object = Object.normalize(activity)
+
+ assert Impl.format_body(%{activity: activity}, user, object) == "@Bob has favorited your post"
+
+ assert Impl.format_title(%{activity: activity}) ==
+ "New Favorite"
+ end
+
+ test "renders title for create activity with direct visibility" do
+ user = insert(:user, nickname: "Bob")
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "visibility" => "direct",
+ "status" => "This is just between you and me, pal"
+ })
+
+ assert Impl.format_title(%{activity: activity}) ==
+ "New Direct Message"
end
- test "renders body for like activity" do
- assert Impl.format_body(%{activity: %{data: %{"type" => "Like"}}}, %{nickname: "Bob"}) ==
- "@Bob has favorited your post"
+ describe "build_content/3" do
+ test "returns info content for direct message with enabled privacy option" do
+ user = insert(:user, nickname: "Bob")
+ user2 = insert(:user, nickname: "Rob", notification_settings: %{privacy_option: true})
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "visibility" => "direct",
+ "status" => " "direct",
+ "status" =>
+ "Lorem ipsum dolor sit amet, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
+ })
+
+ notif = insert(:notification, user: user2, activity: activity)
+
+ actor = User.get_cached_by_ap_id(notif.activity.data["actor"])
+ object = Object.normalize(activity)
+
+ assert Impl.build_content(notif, actor, object) == %{
+ body:
+ "@Bob: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini...",
+ title: "New Direct Message"
+ }
+ end
end
end