Merge back 2.4.5
This commit is contained in:
commit
7d68d64d63
5598 changed files with 55535 additions and 18588 deletions
|
|
@ -1,9 +1,9 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.NotificationTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: false
|
||||
|
||||
import Pleroma.Factory
|
||||
import Mock
|
||||
|
|
@ -32,20 +32,26 @@ defmodule Pleroma.NotificationTest do
|
|||
refute {:ok, [nil]} == Notification.create_notifications(activity)
|
||||
end
|
||||
|
||||
test "creates a notification for a report" do
|
||||
test "creates a report notification only for privileged users" do
|
||||
reporting_user = insert(:user)
|
||||
reported_user = insert(:user)
|
||||
{:ok, moderator_user} = insert(:user) |> User.admin_api_update(%{is_moderator: true})
|
||||
moderator_user = insert(:user, is_moderator: true)
|
||||
|
||||
{:ok, activity} = CommonAPI.report(reporting_user, %{account_id: reported_user.id})
|
||||
clear_config([:instance, :moderator_privileges], [])
|
||||
{:ok, activity1} = CommonAPI.report(reporting_user, %{account_id: reported_user.id})
|
||||
{:ok, []} = Notification.create_notifications(activity1)
|
||||
|
||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||
clear_config([:instance, :moderator_privileges], [:reports_manage_reports])
|
||||
{:ok, activity2} = CommonAPI.report(reporting_user, %{account_id: reported_user.id})
|
||||
{:ok, [notification]} = Notification.create_notifications(activity2)
|
||||
|
||||
assert notification.user_id == moderator_user.id
|
||||
assert notification.type == "pleroma:report"
|
||||
end
|
||||
|
||||
test "suppresses notification to reporter if reporter is an admin" do
|
||||
test "suppresses notifications for own reports" do
|
||||
clear_config([:instance, :admin_privileges], [:reports_manage_reports])
|
||||
|
||||
reporting_admin = insert(:user, is_admin: true)
|
||||
reported_user = insert(:user)
|
||||
other_admin = insert(:user, is_admin: true)
|
||||
|
|
@ -127,6 +133,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
|
||||
|
|
@ -826,6 +867,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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue