Merge remote-tracking branch 'origin/develop' into benchmark-finishing
[akkoma] / test / notification_test.exs
index 0e2635aad482b6bbf978b8eac5591c5e0762720e..54c0f987753158176467f9a3edca55fba47f4a94 100644 (file)
@@ -1,5 +1,5 @@
 # Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.NotificationTest do
@@ -8,6 +8,7 @@ defmodule Pleroma.NotificationTest do
   import Pleroma.Factory
 
   alias Pleroma.Notification
+  alias Pleroma.Tests.ObanHelpers
   alias Pleroma.User
   alias Pleroma.Web.ActivityPub.Transmogrifier
   alias Pleroma.Web.CommonAPI
@@ -32,16 +33,16 @@ defmodule Pleroma.NotificationTest do
       assert other_notification.activity_id == activity.id
     end
 
-    test "it does not create a notification for subscribed users" do
+    test "it creates a notification for subscribed users" do
       user = insert(:user)
       subscriber = insert(:user)
 
       User.subscribe(subscriber, user)
 
       {:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
-      {:ok, notifications} = Notification.create_notifications(status)
+      {:ok, [notification]} = Notification.create_notifications(status)
 
-      assert notifications == []
+      assert notification.user_id == subscriber.id
     end
 
     test "does not create a notification for subscribed users if status is a reply" do
@@ -68,16 +69,7 @@ defmodule Pleroma.NotificationTest do
   end
 
   describe "create_notification" do
-    setup do
-      GenServer.start(Streamer, %{}, name: Streamer)
-
-      on_exit(fn ->
-        if pid = Process.whereis(Streamer) do
-          Process.exit(pid, :kill)
-        end
-      end)
-    end
-
+    @tag needs_streamer: true
     test "it creates a notification for user and send to the 'user' and the 'user:notification' stream" do
       user = insert(:user)
       task = Task.async(fn -> assert_receive {:text, _}, 4_000 end)
@@ -190,16 +182,14 @@ defmodule Pleroma.NotificationTest do
       refute Notification.create_notification(activity_dupe, followed_user)
     end
 
-    test "it doesn't create notifications for follow+subscribed users" do
+    test "it doesn't create duplicate notifications for follow+subscribed users" do
       user = insert(:user)
       subscriber = insert(:user)
 
       {:ok, _, _, _} = CommonAPI.follow(subscriber, user)
       User.subscribe(subscriber, user)
       {:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
-      {:ok, notifications} = Notification.create_notifications(status)
-
-      assert notifications == []
+      {:ok, [_notif]} = Notification.create_notifications(status)
     end
 
     test "it doesn't create subscription notifications if the recipient cannot see the status" do
@@ -590,7 +580,8 @@ defmodule Pleroma.NotificationTest do
 
       refute Enum.empty?(Notification.for_user(other_user))
 
-      User.delete(user)
+      {:ok, job} = User.delete(user)
+      ObanHelpers.perform(job)
 
       assert Enum.empty?(Notification.for_user(other_user))
     end
@@ -635,6 +626,7 @@ defmodule Pleroma.NotificationTest do
       }
 
       {:ok, _delete_activity} = Transmogrifier.handle_incoming(delete_user_message)
+      ObanHelpers.perform_all()
 
       assert Enum.empty?(Notification.for_user(local_user))
     end