remove all endpoints marked as deprecated (#91)
[akkoma] / test / pleroma / web / mastodon_api / controllers / notification_controller_test.exs
index 70ef0e8b5012aa9a15f7fe1fab7fc39015f325f7..6507835871f736694b756ad6bf0fc34c169c4e66 100644 (file)
@@ -1,5 +1,5 @@
 # Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
@@ -44,9 +44,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
       |> get("/api/v1/notifications")
 
     expected_response =
-      "hi <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{user.id}\" href=\"#{
-        user.ap_id
-      }\" rel=\"ugc\">@<span>#{user.nickname}</span></a></span>"
+      "hi <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{user.id}\" href=\"#{user.ap_id}\" rel=\"ugc\">@<span>#{user.nickname}</span></a></span>"
 
     assert [%{"status" => %{"content" => response}} | _rest] =
              json_response_and_validate_schema(conn, 200)
@@ -75,40 +73,68 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
     assert [_] = result
   end
 
-  test "getting a single notification" do
+  test "by default, does not contain pleroma:report" do
     %{user: user, conn: conn} = oauth_access(["read:notifications"])
     other_user = insert(:user)
+    third_user = insert(:user)
 
-    {:ok, activity} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
+    user
+    |> User.admin_api_update(%{is_moderator: true})
 
-    {:ok, [notification]} = Notification.create_notifications(activity)
+    {:ok, activity} = CommonAPI.post(other_user, %{status: "hey"})
 
-    conn = get(conn, "/api/v1/notifications/#{notification.id}")
+    {:ok, _report} =
+      CommonAPI.report(third_user, %{account_id: other_user.id, status_ids: [activity.id]})
 
-    expected_response =
-      "hi <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{user.id}\" href=\"#{
-        user.ap_id
-      }\" rel=\"ugc\">@<span>#{user.nickname}</span></a></span>"
+    result =
+      conn
+      |> get("/api/v1/notifications")
+      |> json_response_and_validate_schema(200)
 
-    assert %{"status" => %{"content" => response}} = json_response_and_validate_schema(conn, 200)
-    assert response == expected_response
+    assert [] == result
+
+    result =
+      conn
+      |> get("/api/v1/notifications?include_types[]=pleroma:report")
+      |> json_response_and_validate_schema(200)
+
+    assert [_] = result
   end
 
-  test "dismissing a single notification (deprecated endpoint)" do
-    %{user: user, conn: conn} = oauth_access(["write:notifications"])
-    other_user = insert(:user)
+  test "excludes mentions from blockers when blockers_visible is false" do
+    clear_config([:activitypub, :blockers_visible], false)
 
-    {:ok, activity} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
+    %{user: user, conn: conn} = oauth_access(["read:notifications"])
+    blocker = insert(:user)
 
-    {:ok, [notification]} = Notification.create_notifications(activity)
+    {:ok, _} = CommonAPI.block(blocker, user)
+    {:ok, activity} = CommonAPI.post(blocker, %{status: "hi @#{user.nickname}"})
+
+    {:ok, [_notification]} = Notification.create_notifications(activity)
 
     conn =
       conn
       |> assign(:user, user)
-      |> put_req_header("content-type", "application/json")
-      |> post("/api/v1/notifications/dismiss", %{"id" => to_string(notification.id)})
+      |> get("/api/v1/notifications")
 
-    assert %{} = json_response_and_validate_schema(conn, 200)
+    assert [] == json_response_and_validate_schema(conn, 200)
+  end
+
+  test "getting a single notification" do
+    %{user: user, conn: conn} = oauth_access(["read:notifications"])
+    other_user = insert(:user)
+
+    {:ok, activity} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
+
+    {:ok, [notification]} = Notification.create_notifications(activity)
+
+    conn = get(conn, "/api/v1/notifications/#{notification.id}")
+
+    expected_response =
+      "hi <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{user.id}\" href=\"#{user.ap_id}\" rel=\"ugc\">@<span>#{user.nickname}</span></a></span>"
+
+    assert %{"status" => %{"content" => response}} = json_response_and_validate_schema(conn, 200)
+    assert response == expected_response
   end
 
   test "dismissing a single notification" do
@@ -502,7 +528,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
 
     assert length(json_response_and_validate_schema(ret_conn, 200)) == 1
 
-    {:ok, _user_relationships} = User.mute(user, user2, false)
+    {:ok, _user_relationships} = User.mute(user, user2, %{notifications: false})
 
     conn = get(conn, "/api/v1/notifications")
 
@@ -527,24 +553,11 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
     assert length(json_response_and_validate_schema(conn, 200)) == 1
   end
 
-  @tag capture_log: true
   test "see move notifications" do
     old_user = insert(:user)
     new_user = insert(:user, also_known_as: [old_user.ap_id])
     %{user: follower, conn: conn} = oauth_access(["read:notifications"])
 
-    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)
-
     User.follow(follower, old_user)
     Pleroma.Web.ActivityPub.ActivityPub.move(old_user, new_user)
     Pleroma.Tests.ObanHelpers.perform_all()