X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=test%2Fpleroma%2Fnotification_test.exs;h=721836a2c1e83ca2ff0d067d6e57ed64187817d9;hb=e03206a9a0f0171f5a61e73b6ef2a6a878b5d0d4;hp=ed2cd219da5d60a760dba3439f07f96b9c8b9b18;hpb=cf99b1c1fd89553f072cc5a466aaebbe59d3e618;p=akkoma
diff --git a/test/pleroma/notification_test.exs b/test/pleroma/notification_test.exs
index ed2cd219d..721836a2c 100644
--- a/test/pleroma/notification_test.exs
+++ b/test/pleroma/notification_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.NotificationTest do
@@ -45,6 +45,20 @@ defmodule Pleroma.NotificationTest do
assert notification.type == "pleroma:report"
end
+ test "suppresses notification to reporter if reporter is an admin" do
+ reporting_admin = insert(:user, is_admin: true)
+ reported_user = insert(:user)
+ other_admin = insert(:user, is_admin: true)
+
+ {:ok, activity} = CommonAPI.report(reporting_admin, %{account_id: reported_user.id})
+
+ {:ok, [notification]} = Notification.create_notifications(activity)
+
+ refute notification.user_id == reporting_admin.id
+ assert notification.user_id == other_admin.id
+ assert notification.type == "pleroma:report"
+ end
+
test "creates a notification for an emoji reaction" do
user = insert(:user)
other_user = insert(:user)
@@ -113,6 +127,41 @@ defmodule Pleroma.NotificationTest do
subscriber_notifications = Notification.for_user(subscriber)
assert Enum.empty?(subscriber_notifications)
end
+
+ test "it sends edited notifications to those who repeated a status" do
+ user = insert(:user)
+ repeated_user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity_one} =
+ CommonAPI.post(user, %{
+ status: "hey @#{other_user.nickname}!"
+ })
+
+ {:ok, _activity_two} = CommonAPI.repeat(activity_one.id, repeated_user)
+
+ {:ok, _edit_activity} =
+ CommonAPI.update(user, activity_one, %{
+ status: "hey @#{other_user.nickname}! mew mew"
+ })
+
+ assert [%{type: "reblog"}] = Notification.for_user(user)
+ assert [%{type: "update"}] = Notification.for_user(repeated_user)
+ assert [%{type: "mention"}] = Notification.for_user(other_user)
+ end
+ end
+
+ test "create_poll_notifications/1" do
+ [user1, user2, user3, _, _] = insert_list(5, :user)
+ question = insert(:question, user: user1)
+ activity = insert(:question_activity, question: question)
+
+ {:ok, _, _} = CommonAPI.vote(user2, question, [0])
+ {:ok, _, _} = CommonAPI.vote(user3, question, [1])
+
+ {:ok, notifications} = Notification.create_poll_notifications(activity)
+
+ assert [user2.id, user3.id, user1.id] == Enum.map(notifications, & &1.user_id)
end
describe "CommonApi.post/2 notification-related functionality" do
@@ -197,7 +246,7 @@ defmodule Pleroma.NotificationTest do
task =
Task.async(fn ->
{:ok, _topic} = Streamer.get_topic_and_add_socket("user", user, oauth_token)
- assert_receive {:render_with_user, _, _, _}, 4_000
+ assert_receive {:render_with_user, _, _, _, "user"}, 4_000
end)
task_user_notification =
@@ -205,7 +254,7 @@ defmodule Pleroma.NotificationTest do
{:ok, _topic} =
Streamer.get_topic_and_add_socket("user:notification", user, oauth_token)
- assert_receive {:render_with_user, _, _, _}, 4_000
+ assert_receive {:render_with_user, _, _, _, "user:notification"}, 4_000
end)
activity = insert(:note_activity)
@@ -400,13 +449,12 @@ defmodule Pleroma.NotificationTest do
{:ok, _, _, _activity} = CommonAPI.follow(user, followed_user)
assert FollowingRelationship.following?(user, followed_user)
- assert [notification] = Notification.for_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)
+ assert Enum.count(Notification.for_user(followed_user)) == 1
end
test "dismisses the notification on follow request rejection" do
@@ -493,6 +541,25 @@ defmodule Pleroma.NotificationTest do
end
end
+ describe "destroy_multiple_from_types/2" do
+ test "clears all notifications of a certain type for a given user" do
+ report_activity = insert(:report_activity)
+ user1 = insert(:user, is_moderator: true, is_admin: true)
+ user2 = insert(:user, is_moderator: true, is_admin: true)
+ {:ok, _} = Notification.create_notifications(report_activity)
+
+ {:ok, _} =
+ CommonAPI.post(user2, %{
+ status: "hey @#{user1.nickname} !"
+ })
+
+ Notification.destroy_multiple_from_types(user1, ["pleroma:report"])
+
+ assert [%Pleroma.Notification{type: "mention"}] = Notification.for_user(user1)
+ assert [%Pleroma.Notification{type: "pleroma:report"}] = Notification.for_user(user2)
+ end
+ end
+
describe "set_read_up_to()" do
test "it sets all notifications as read up to a specified notification ID" do
user = insert(:user)
@@ -610,6 +677,8 @@ defmodule Pleroma.NotificationTest do
"actor" => user.ap_id,
"object" => %{
"type" => "Note",
+ "id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
"content" => "message with a Mention tag, but no explicit tagging",
"tag" => [
%{
@@ -641,6 +710,9 @@ defmodule Pleroma.NotificationTest do
"actor" => user.ap_id,
"object" => %{
"type" => "Note",
+ "id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "cc" => [other_user.ap_id],
"content" => "hi everyone",
"attributedTo" => user.ap_id
}
@@ -779,7 +851,7 @@ defmodule Pleroma.NotificationTest do
other_user = insert(:user)
{:ok, other_user} = User.block_domain(other_user, blocked_domain)
- {:ok, other_user} = User.follow(other_user, user)
+ {:ok, other_user, user} = User.follow(other_user, user)
{:ok, activity} = CommonAPI.post(user, %{status: "hey @#{other_user.nickname}!"})
@@ -788,6 +860,30 @@ defmodule Pleroma.NotificationTest do
assert [other_user] == enabled_receivers
assert [] == disabled_receivers
end
+
+ test "it sends edited notifications to those who repeated a status" do
+ user = insert(:user)
+ repeated_user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity_one} =
+ CommonAPI.post(user, %{
+ status: "hey @#{other_user.nickname}!"
+ })
+
+ {:ok, _activity_two} = CommonAPI.repeat(activity_one.id, repeated_user)
+
+ {:ok, edit_activity} =
+ CommonAPI.update(user, activity_one, %{
+ status: "hey @#{other_user.nickname}! mew mew"
+ })
+
+ {enabled_receivers, _disabled_receivers} =
+ Notification.get_notified_from_activity(edit_activity)
+
+ assert repeated_user in enabled_receivers
+ assert other_user not in enabled_receivers
+ end
end
describe "notification lifecycle" do
@@ -937,6 +1033,7 @@ defmodule Pleroma.NotificationTest do
"cc" => [],
"object" => %{
"type" => "Note",
+ "id" => remote_user.ap_id <> "/objects/test",
"content" => "Hello!",
"tag" => [
%{
@@ -976,7 +1073,6 @@ defmodule Pleroma.NotificationTest do
assert Enum.empty?(Notification.for_user(local_user))
end
- @tag capture_log: true
test "move activity generates a notification" do
%{ap_id: old_ap_id} = old_user = insert(:user)
%{ap_id: new_ap_id} = new_user = insert(:user, also_known_as: [old_ap_id])
@@ -986,18 +1082,6 @@ defmodule Pleroma.NotificationTest do
User.follow(follower, old_user)
User.follow(other_follower, old_user)
- old_user_url = old_user.ap_id
-
- body =
- File.read!("test/fixtures/users_mock/localhost.json")
- |> String.replace("{{nickname}}", old_user.nickname)
- |> Jason.encode!()
-
- Tesla.Mock.mock(fn
- %{method: :get, url: ^old_user_url} ->
- %Tesla.Env{status: 200, body: body}
- end)
-
Pleroma.Web.ActivityPub.ActivityPub.move(old_user, new_user)
ObanHelpers.perform_all()
@@ -1065,18 +1149,6 @@ defmodule Pleroma.NotificationTest do
assert Notification.for_user(user) == []
end
- test "it returns notifications for domain-blocked but followed user" do
- user = insert(:user)
- blocked = insert(:user, ap_id: "http://some-domain.com")
-
- {:ok, user} = User.block_domain(user, "some-domain.com")
- {:ok, _} = User.follow(user, blocked)
-
- {:ok, _activity} = CommonAPI.post(blocked, %{status: "hey @#{user.nickname}"})
-
- assert length(Notification.for_user(user)) == 1
- end
-
test "it doesn't return notifications for muted thread", %{user: user} do
another_user = insert(:user)