Merge branch 'develop' into issue/1276
[akkoma] / test / notification_test.exs
index a7282c929d6976cdd144341c7626cc025644bbb8..c3d70c51febd92ef719e066f004d4ca3a016f4dc 100644 (file)
@@ -45,6 +45,9 @@ defmodule Pleroma.NotificationTest do
       assert notified_ids == [other_user.id, third_user.id]
       assert notification.activity_id == activity.id
       assert other_notification.activity_id == activity.id
+
+      assert [%Pleroma.Marker{unread_count: 2}] =
+               Pleroma.Marker.get_markers(other_user, ["notifications"])
     end
 
     test "it creates a notification for subscribed users" do
@@ -410,6 +413,16 @@ defmodule Pleroma.NotificationTest do
       assert n1.seen == true
       assert n2.seen == true
       assert n3.seen == false
+
+      assert %Pleroma.Marker{} =
+               m =
+               Pleroma.Repo.get_by(
+                 Pleroma.Marker,
+                 user_id: other_user.id,
+                 timeline: "notifications"
+               )
+
+      assert m.last_read_id == to_string(n2.id)
     end
   end
 
@@ -784,12 +797,20 @@ defmodule Pleroma.NotificationTest do
         "object" => remote_user.ap_id
       }
 
+      remote_user_url = remote_user.ap_id
+
+      Tesla.Mock.mock(fn
+        %{method: :get, url: ^remote_user_url} ->
+          %Tesla.Env{status: 404, body: ""}
+      end)
+
       {:ok, _delete_activity} = Transmogrifier.handle_incoming(delete_user_message)
       ObanHelpers.perform_all()
 
       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])
@@ -799,20 +820,28 @@ 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()
 
-      assert [] = Notification.for_user(follower)
-
       assert [
                %{
                  activity: %{
                    data: %{"type" => "Move", "actor" => ^old_ap_id, "target" => ^new_ap_id}
                  }
                }
-             ] = Notification.for_user(follower, %{with_move: true})
-
-      assert [] = Notification.for_user(other_follower)
+             ] = Notification.for_user(follower)
 
       assert [
                %{
@@ -820,7 +849,7 @@ defmodule Pleroma.NotificationTest do
                    data: %{"type" => "Move", "actor" => ^old_ap_id, "target" => ^new_ap_id}
                  }
                }
-             ] = Notification.for_user(other_follower, %{with_move: true})
+             ] = Notification.for_user(other_follower)
     end
   end