aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Tashkinov <ivantashkinov@gmail.com>2020-04-08 21:26:22 +0300
committerIvan Tashkinov <ivantashkinov@gmail.com>2020-04-08 21:26:22 +0300
commitf35c28bf070014dfba4b988bfc47fbf93baef81f (patch)
treea07d11d2379f959d1797d02bbb424288412e7004
parent1a4875adfa8fa8f65f1db7b4ec3cf868b7e3dee7 (diff)
downloadpleroma-f35c28bf070014dfba4b988bfc47fbf93baef81f.tar.gz
[#1559] Added / fixed tests for follow / follow_request notifications.
-rw-r--r--test/notification_test.exs80
1 files changed, 70 insertions, 10 deletions
diff --git a/test/notification_test.exs b/test/notification_test.exs
index 837a9dacd..0877aaaaf 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -11,8 +11,10 @@ defmodule Pleroma.NotificationTest do
alias Pleroma.Notification
alias Pleroma.Tests.ObanHelpers
alias Pleroma.User
+ alias Pleroma.FollowingRelationship
alias Pleroma.Web.ActivityPub.Transmogrifier
alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.MastodonAPI.NotificationView
alias Pleroma.Web.Push
alias Pleroma.Web.Streamer
@@ -272,16 +274,6 @@ defmodule Pleroma.NotificationTest do
refute Notification.create_notification(activity, author)
end
- test "it doesn't create a notification for follow-unfollow-follow chains" do
- user = insert(:user)
- followed_user = insert(:user)
- {:ok, _, _, activity} = CommonAPI.follow(user, followed_user)
- Notification.create_notification(activity, followed_user)
- CommonAPI.unfollow(user, followed_user)
- {:ok, _, _, activity_dupe} = CommonAPI.follow(user, followed_user)
- refute Notification.create_notification(activity_dupe, followed_user)
- end
-
test "it doesn't create duplicate notifications for follow+subscribed users" do
user = insert(:user)
subscriber = insert(:user)
@@ -304,6 +296,74 @@ defmodule Pleroma.NotificationTest do
end
end
+ describe "follow / follow_request notifications" do
+ test "it creates `follow` notification for approved Follow activity" do
+ user = insert(:user)
+ followed_user = insert(:user, locked: false)
+
+ {:ok, _, _, _activity} = CommonAPI.follow(user, followed_user)
+ assert FollowingRelationship.following?(user, followed_user)
+ assert [notification] = Notification.for_user(followed_user)
+
+ assert %{type: "follow"} =
+ NotificationView.render("show.json", %{
+ notification: notification,
+ for: followed_user
+ })
+ end
+
+ test "if `follow_request` notifications are enabled, " <>
+ "it creates `follow_request` notification for pending Follow activity" do
+ clear_config([:notifications, :enable_follow_request_notifications], true)
+ user = insert(:user)
+ followed_user = insert(:user, locked: true)
+
+ {:ok, _, _, _activity} = CommonAPI.follow(user, followed_user)
+ refute FollowingRelationship.following?(user, followed_user)
+ assert [notification] = Notification.for_user(followed_user)
+
+ render_opts = %{notification: notification, for: followed_user}
+ assert %{type: "follow_request"} = NotificationView.render("show.json", render_opts)
+
+ # After request is accepted, the same notification is rendered with type "follow":
+ assert {:ok, _} = CommonAPI.accept_follow_request(user, followed_user)
+
+ notification_id = notification.id
+ assert [%{id: ^notification_id}] = Notification.for_user(followed_user)
+ assert %{type: "follow"} = NotificationView.render("show.json", render_opts)
+ end
+
+ test "if `follow_request` notifications are disabled, " <>
+ "it does NOT create `follow*` notification for pending Follow activity" do
+ clear_config([:notifications, :enable_follow_request_notifications], false)
+ user = insert(:user)
+ followed_user = insert(:user, locked: true)
+
+ {:ok, _, _, _activity} = CommonAPI.follow(user, followed_user)
+ refute FollowingRelationship.following?(user, followed_user)
+ assert [] = Notification.for_user(followed_user)
+
+ # After request is accepted, no new notifications are generated:
+ assert {:ok, _} = CommonAPI.accept_follow_request(user, followed_user)
+ assert [] = Notification.for_user(followed_user)
+ end
+
+ test "it doesn't create a notification for follow-unfollow-follow chains" do
+ user = insert(:user)
+ followed_user = insert(:user, locked: false)
+
+ {:ok, _, _, _activity} = CommonAPI.follow(user, followed_user)
+ assert FollowingRelationship.following?(user, followed_user)
+ assert [notification] = Notification.for_user(followed_user)
+
+ CommonAPI.unfollow(user, followed_user)
+ {:ok, _, _, _activity_dupe} = CommonAPI.follow(user, followed_user)
+
+ notification_id = notification.id
+ assert [%{id: ^notification_id}] = Notification.for_user(followed_user)
+ end
+ end
+
describe "get notification" do
test "it gets a notification that belongs to the user" do
user = insert(:user)