Add collection fetching module
[akkoma] / test / pleroma / user_test.exs
index 6cd93c34c28d598a7f83daf9ca27e73307d97058..756281a461724ac12dd86be39db5bbc8ac7d786d 100644 (file)
@@ -5,6 +5,7 @@
 defmodule Pleroma.UserTest do
   alias Pleroma.Activity
   alias Pleroma.Builders.UserBuilder
+  alias Pleroma.Notification
   alias Pleroma.Object
   alias Pleroma.Repo
   alias Pleroma.Tests.ObanHelpers
@@ -1649,6 +1650,7 @@ defmodule Pleroma.UserTest do
         ap_enabled: true,
         is_moderator: true,
         is_admin: true,
+        mastofe_settings: %{"a" => "b"},
         mascot: %{"a" => "b"},
         emoji: %{"a" => "b"},
         pleroma_settings_store: %{"q" => "x"},
@@ -1690,6 +1692,7 @@ defmodule Pleroma.UserTest do
              ap_enabled: false,
              is_moderator: false,
              is_admin: false,
+             mastofe_settings: nil,
              mascot: nil,
              emoji: %{},
              pleroma_settings_store: %{},
@@ -2151,6 +2154,26 @@ defmodule Pleroma.UserTest do
       assert {:ok, user} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
       assert %User{bio: "test-bio"} = User.get_cached_by_ap_id(user.ap_id)
     end
+
+    test "removes report notifs when user isn't superuser any more" do
+      report_activity = insert(:report_activity)
+      user = insert(:user, is_moderator: true, is_admin: true)
+      {:ok, _} = Notification.create_notifications(report_activity)
+
+      assert [%Pleroma.Notification{type: "pleroma:report"}] = Notification.for_user(user)
+
+      {:ok, user} = user |> User.admin_api_update(%{is_moderator: false})
+      # is still superuser because still admin
+      assert [%Pleroma.Notification{type: "pleroma:report"}] = Notification.for_user(user)
+
+      {:ok, user} = user |> User.admin_api_update(%{is_moderator: true, is_admin: false})
+      # is still superuser because still moderator
+      assert [%Pleroma.Notification{type: "pleroma:report"}] = Notification.for_user(user)
+
+      {:ok, user} = user |> User.admin_api_update(%{is_moderator: false})
+      # is not a superuser any more
+      assert [] = Notification.for_user(user)
+    end
   end
 
   describe "following/followers synchronization" do