X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Fpush%2Fimpl_test.exs;h=8fb7faaa51f9aaa481e36af30a73765f26c7058a;hb=b952f3f37907c735e3426ba43d01027f6f49c5b5;hp=737976f1f635679655525a04eb5d71ff677c5245;hpb=13918cb545d583decfb728300850b307c59e2031;p=akkoma
diff --git a/test/web/push/impl_test.exs b/test/web/push/impl_test.exs
index 737976f1f..8fb7faaa5 100644
--- a/test/web/push/impl_test.exs
+++ b/test/web/push/impl_test.exs
@@ -1,10 +1,11 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 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.Notification
alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.CommonAPI
@@ -13,8 +14,8 @@ defmodule Pleroma.Web.Push.ImplTest do
import Pleroma.Factory
- setup_all do
- Tesla.Mock.mock_global(fn
+ setup do
+ Tesla.Mock.mock(fn
%{method: :post, url: "https://example.com/example/1234"} ->
%Tesla.Env{status: 200}
@@ -55,20 +56,21 @@ defmodule Pleroma.Web.Push.ImplTest do
data: %{alerts: %{"follow" => true, "mention" => false}}
)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "
+ status:
"Lorem ipsum dolor sit amet, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
})
@@ -118,7 +128,7 @@ defmodule Pleroma.Web.Push.ImplTest do
) ==
"@Bob: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini..."
- assert Impl.format_title(%{activity: activity}) ==
+ assert Impl.format_title(%{activity: activity, type: "mention"}) ==
"New Mention"
end
@@ -128,9 +138,10 @@ defmodule Pleroma.Web.Push.ImplTest do
{: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_body(%{activity: activity, type: "follow"}, user, object) ==
+ "@Bob has followed you"
- assert Impl.format_title(%{activity: activity}) ==
+ assert Impl.format_title(%{activity: activity, type: "follow"}) ==
"New Follower"
end
@@ -139,17 +150,17 @@ defmodule Pleroma.Web.Push.ImplTest do
{:ok, activity} =
CommonAPI.post(user, %{
- "status" =>
+ status:
"Lorem ipsum dolor sit amet, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
})
- {:ok, announce_activity, _} = CommonAPI.repeat(activity.id, user)
+ {:ok, announce_activity} = CommonAPI.repeat(activity.id, user)
object = Object.normalize(activity)
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}) ==
+ assert Impl.format_title(%{activity: announce_activity, type: "reblog"}) ==
"New Repeat"
end
@@ -158,16 +169,17 @@ defmodule Pleroma.Web.Push.ImplTest do
{:ok, activity} =
CommonAPI.post(user, %{
- "status" =>
+ status:
"Lorem ipsum dolor sit amet, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
})
- {:ok, activity, _} = CommonAPI.favorite(activity.id, user)
+ {:ok, activity} = CommonAPI.favorite(user, activity.id)
object = Object.normalize(activity)
- assert Impl.format_body(%{activity: activity}, user, object) == "@Bob has favorited your post"
+ assert Impl.format_body(%{activity: activity, type: "favourite"}, user, object) ==
+ "@Bob has favorited your post"
- assert Impl.format_title(%{activity: activity}) ==
+ assert Impl.format_title(%{activity: activity, type: "favourite"}) ==
"New Favorite"
end
@@ -176,8 +188,8 @@ defmodule Pleroma.Web.Push.ImplTest do
{:ok, activity} =
CommonAPI.post(user, %{
- "visibility" => "direct",
- "status" => "This is just between you and me, pal"
+ visibility: "direct",
+ status: "This is just between you and me, pal"
})
assert Impl.format_title(%{activity: activity}) ==
@@ -185,14 +197,30 @@ defmodule Pleroma.Web.Push.ImplTest do
end
describe "build_content/3" do
- test "returns info content for direct message with enabled privacy option" do
+ test "builds content for chat messages" do
+ user = insert(:user)
+ recipient = insert(:user)
+
+ {:ok, chat} = CommonAPI.post_chat_message(user, recipient, "hey")
+ object = Object.normalize(chat, false)
+ [notification] = Notification.for_user(recipient)
+
+ res = Impl.build_content(notification, user, object)
+
+ assert res == %{
+ body: "@#{user.nickname}: hey",
+ title: "New Chat Message"
+ }
+ end
+
+ test "hides details for notifications when privacy option enabled" 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" =>
+ visibility: "direct",
+ status:
"Lorem ipsum dolor sit amet, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
})
@@ -227,6 +280,36 @@ defmodule Pleroma.Web.Push.ImplTest do
"@Bob: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini...",
title: "New Direct Message"
}
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ visibility: "public",
+ status:
+ "Lorem ipsum dolor sit amet, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
+ })
+
+ notif = insert(:notification, user: user2, activity: activity, type: "mention")
+
+ 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 Mention"
+ }
+
+ {:ok, activity} = CommonAPI.favorite(user, activity.id)
+
+ notif = insert(:notification, user: user2, activity: activity, type: "favourite")
+
+ actor = User.get_cached_by_ap_id(notif.activity.data["actor"])
+ object = Object.normalize(activity)
+
+ assert Impl.build_content(notif, actor, object) == %{
+ body: "@Bob has favorited your post",
+ title: "New Favorite"
+ }
end
end
end