purge chat and shout endpoints
[akkoma] / test / pleroma / web / mastodon_api / controllers / subscription_controller_test.exs
index 955cd9912fb2cecf8283273a8ec99037c651868d..1335656b4d1dc0d2d5c8c3e20d97f54a7cb453c4 100644 (file)
@@ -1,9 +1,9 @@
 # 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.SubscriptionControllerTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
   import Pleroma.Factory
 
@@ -45,15 +45,44 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do
     end
   end
 
-  describe "creates push subscription" do
-    test "does not return unsupported types", %{conn: conn} do
+  describe "when disabled" do
+    test "POST returns error", %{conn: conn} do
       assert_error_when_disable_push do
         conn
-        |> post("/api/v1/push/subscription", %{subscription: @sub})
+        |> post("/api/v1/push/subscription", %{
+          "data" => %{"alerts" => %{"mention" => true}},
+          "subscription" => @sub
+        })
         |> json_response_and_validate_schema(403)
       end
     end
 
+    test "GET returns error", %{conn: conn} do
+      assert_error_when_disable_push do
+        conn
+        |> get("/api/v1/push/subscription", %{})
+        |> json_response_and_validate_schema(403)
+      end
+    end
+
+    test "PUT returns error", %{conn: conn} do
+      assert_error_when_disable_push do
+        conn
+        |> put("/api/v1/push/subscription", %{data: %{"alerts" => %{"mention" => false}}})
+        |> json_response_and_validate_schema(403)
+      end
+    end
+
+    test "DELETE returns error", %{conn: conn} do
+      assert_error_when_disable_push do
+        conn
+        |> delete("/api/v1/push/subscription", %{})
+        |> json_response_and_validate_schema(403)
+      end
+    end
+  end
+
+  describe "creates push subscription" do
     test "ignores unsupported types", %{conn: conn} do
       result =
         conn
@@ -84,7 +113,6 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do
               "favourite" => true,
               "follow" => true,
               "reblog" => true,
-              "pleroma:chat_mention" => true,
               "pleroma:emoji_reaction" => true
             }
           },
@@ -100,7 +128,6 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do
                  "favourite" => true,
                  "follow" => true,
                  "reblog" => true,
-                 "pleroma:chat_mention" => true,
                  "pleroma:emoji_reaction" => true
                },
                "endpoint" => subscription.endpoint,
@@ -111,14 +138,6 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do
   end
 
   describe "gets a user subscription" do
-    test "returns error when push disabled ", %{conn: conn} do
-      assert_error_when_disable_push do
-        conn
-        |> get("/api/v1/push/subscription", %{})
-        |> json_response_and_validate_schema(403)
-      end
-    end
-
     test "returns error when user hasn't subscription", %{conn: conn} do
       res =
         conn
@@ -164,7 +183,6 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do
               "favourite" => true,
               "follow" => true,
               "reblog" => true,
-              "pleroma:chat_mention" => true,
               "pleroma:emoji_reaction" => true
             }
           }
@@ -173,23 +191,6 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do
       %{conn: conn, user: user, token: token, subscription: subscription}
     end
 
-    test "returns error when push disabled ", %{conn: conn} do
-      assert_error_when_disable_push do
-        conn
-        |> put("/api/v1/push/subscription", %{
-          data: %{
-            "mention" => false,
-            "favourite" => false,
-            "follow" => false,
-            "reblog" => false,
-            "pleroma:chat_mention" => false,
-            "pleroma:emoji_reaction" => false
-          }
-        })
-        |> json_response_and_validate_schema(403)
-      end
-    end
-
     test "returns updated subsciption", %{conn: conn, subscription: subscription} do
       res =
         conn
@@ -200,7 +201,6 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do
               "favourite" => false,
               "follow" => false,
               "reblog" => false,
-              "pleroma:chat_mention" => false,
               "pleroma:emoji_reaction" => false
             }
           }
@@ -213,7 +213,6 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do
           "favourite" => false,
           "follow" => false,
           "reblog" => false,
-          "pleroma:chat_mention" => false,
           "pleroma:emoji_reaction" => false
         },
         "endpoint" => "https://example.com/example/1234",
@@ -226,14 +225,6 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do
   end
 
   describe "deletes the user subscription" do
-    test "returns error when push disabled ", %{conn: conn} do
-      assert_error_when_disable_push do
-        conn
-        |> delete("/api/v1/push/subscription", %{})
-        |> json_response_and_validate_schema(403)
-      end
-    end
-
     test "returns error when user hasn't subscription", %{conn: conn} do
       res =
         conn