Merge branch 'develop' into refactor/notification_settings
[akkoma] / test / web / twitter_api / util_controller_test.exs
index 30e54bebd067eca25ea56b2a1fe737ec592090fa..109c1e63766f8ae68837629f45e9832c5dcc3941 100644 (file)
@@ -95,6 +95,30 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
         end
       end
     end
+
+    test "it imports follows with different nickname variations", %{conn: conn} do
+      [user2, user3, user4, user5, user6] = insert_list(5, :user)
+
+      identifiers =
+        [
+          user2.ap_id,
+          user3.nickname,
+          "  ",
+          "@" <> user4.nickname,
+          user5.nickname <> "@localhost",
+          "@" <> user6.nickname <> "@localhost"
+        ]
+        |> Enum.join("\n")
+
+      response =
+        conn
+        |> post("/api/pleroma/follow_import", %{"list" => identifiers})
+        |> json_response(:ok)
+
+      assert response == "job started"
+      assert [{:ok, job_result}] = ObanHelpers.perform_all()
+      assert job_result == [user2, user3, user4, user5, user6]
+    end
   end
 
   describe "POST /api/pleroma/blocks_import" do
@@ -136,6 +160,29 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
                )
       end
     end
+
+    test "it imports blocks with different nickname variations", %{conn: conn} do
+      [user2, user3, user4, user5, user6] = insert_list(5, :user)
+
+      identifiers =
+        [
+          user2.ap_id,
+          user3.nickname,
+          "@" <> user4.nickname,
+          user5.nickname <> "@localhost",
+          "@" <> user6.nickname <> "@localhost"
+        ]
+        |> Enum.join(" ")
+
+      response =
+        conn
+        |> post("/api/pleroma/blocks_import", %{"list" => identifiers})
+        |> json_response(:ok)
+
+      assert response == "job started"
+      assert [{:ok, job_result}] = ObanHelpers.perform_all()
+      assert job_result == [user2, user3, user4, user5, user6]
+    end
   end
 
   describe "PUT /api/pleroma/notification_settings" do
@@ -144,7 +191,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
     test "it updates notification settings", %{user: user, conn: conn} do
       conn
       |> put("/api/pleroma/notification_settings", %{
-        "followers" => false,
+        "block_from_strangers" => true,
         "bar" => 1
       })
       |> json_response(:ok)
@@ -152,130 +199,25 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
       user = refresh_record(user)
 
       assert %Pleroma.User.NotificationSetting{
-               followers: false,
-               follows: true,
-               non_follows: true,
-               non_followers: true,
-               privacy_option: false
+               block_from_strangers: true,
+               hide_notification_contents: false
              } == user.notification_settings
     end
 
-    test "it updates notification privacy option", %{user: user, conn: conn} do
+    test "it updates notification settings to enable hiding contents", %{user: user, conn: conn} do
       conn
-      |> put("/api/pleroma/notification_settings", %{"privacy_option" => "1"})
+      |> put("/api/pleroma/notification_settings", %{"hide_notification_contents" => "1"})
       |> json_response(:ok)
 
       user = refresh_record(user)
 
       assert %Pleroma.User.NotificationSetting{
-               followers: true,
-               follows: true,
-               non_follows: true,
-               non_followers: true,
-               privacy_option: true
+               block_from_strangers: false,
+               hide_notification_contents: true
              } == user.notification_settings
     end
   end
 
-  describe "GET /api/statusnet/config" do
-    test "it returns config in xml format", %{conn: conn} do
-      instance = Config.get(:instance)
-
-      response =
-        conn
-        |> put_req_header("accept", "application/xml")
-        |> get("/api/statusnet/config")
-        |> response(:ok)
-
-      assert response ==
-               "<config>\n<site>\n<name>#{Keyword.get(instance, :name)}</name>\n<site>#{
-                 Pleroma.Web.base_url()
-               }</site>\n<textlimit>#{Keyword.get(instance, :limit)}</textlimit>\n<closed>#{
-                 !Keyword.get(instance, :registrations_open)
-               }</closed>\n</site>\n</config>\n"
-    end
-
-    test "it returns config in json format", %{conn: conn} do
-      instance = Config.get(:instance)
-      Config.put([:instance, :managed_config], true)
-      Config.put([:instance, :registrations_open], false)
-      Config.put([:instance, :invites_enabled], true)
-      Config.put([:instance, :public], false)
-      Config.put([:frontend_configurations, :pleroma_fe], %{theme: "asuka-hospital"})
-
-      response =
-        conn
-        |> put_req_header("accept", "application/json")
-        |> get("/api/statusnet/config")
-        |> json_response(:ok)
-
-      expected_data = %{
-        "site" => %{
-          "accountActivationRequired" => "0",
-          "closed" => "1",
-          "description" => Keyword.get(instance, :description),
-          "invitesEnabled" => "1",
-          "name" => Keyword.get(instance, :name),
-          "pleromafe" => %{"theme" => "asuka-hospital"},
-          "private" => "1",
-          "safeDMMentionsEnabled" => "0",
-          "server" => Pleroma.Web.base_url(),
-          "textlimit" => to_string(Keyword.get(instance, :limit)),
-          "uploadlimit" => %{
-            "avatarlimit" => to_string(Keyword.get(instance, :avatar_upload_limit)),
-            "backgroundlimit" => to_string(Keyword.get(instance, :background_upload_limit)),
-            "bannerlimit" => to_string(Keyword.get(instance, :banner_upload_limit)),
-            "uploadlimit" => to_string(Keyword.get(instance, :upload_limit))
-          },
-          "vapidPublicKey" => Keyword.get(Pleroma.Web.Push.vapid_config(), :public_key)
-        }
-      }
-
-      assert response == expected_data
-    end
-
-    test "returns the state of safe_dm_mentions flag", %{conn: conn} do
-      Config.put([:instance, :safe_dm_mentions], true)
-
-      response =
-        conn
-        |> get("/api/statusnet/config.json")
-        |> json_response(:ok)
-
-      assert response["site"]["safeDMMentionsEnabled"] == "1"
-
-      Config.put([:instance, :safe_dm_mentions], false)
-
-      response =
-        conn
-        |> get("/api/statusnet/config.json")
-        |> json_response(:ok)
-
-      assert response["site"]["safeDMMentionsEnabled"] == "0"
-    end
-
-    test "it returns the managed config", %{conn: conn} do
-      Config.put([:instance, :managed_config], false)
-      Config.put([:frontend_configurations, :pleroma_fe], %{theme: "asuka-hospital"})
-
-      response =
-        conn
-        |> get("/api/statusnet/config.json")
-        |> json_response(:ok)
-
-      refute response["site"]["pleromafe"]
-
-      Config.put([:instance, :managed_config], true)
-
-      response =
-        conn
-        |> get("/api/statusnet/config.json")
-        |> json_response(:ok)
-
-      assert response["site"]["pleromafe"] == %{"theme" => "asuka-hospital"}
-    end
-  end
-
   describe "GET /api/pleroma/frontend_configurations" do
     test "returns everything in :pleroma, :frontend_configurations", %{conn: conn} do
       config = [
@@ -404,28 +346,6 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
     end
   end
 
-  describe "GET /api/statusnet/version" do
-    test "it returns version in xml format", %{conn: conn} do
-      response =
-        conn
-        |> put_req_header("accept", "application/xml")
-        |> get("/api/statusnet/version")
-        |> response(:ok)
-
-      assert response == "<version>#{Pleroma.Application.named_version()}</version>"
-    end
-
-    test "it returns version in json format", %{conn: conn} do
-      response =
-        conn
-        |> put_req_header("accept", "application/json")
-        |> get("/api/statusnet/version")
-        |> json_response(:ok)
-
-      assert response == "#{Pleroma.Application.named_version()}"
-    end
-  end
-
   describe "POST /main/ostatus - remote_subscribe/2" do
     setup do: clear_config([:instance, :federating], true)
 
@@ -641,7 +561,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
 
       assert json_response(conn, 200) == %{"status" => "success"}
       fetched_user = User.get_cached_by_id(user.id)
-      assert Comeonin.Pbkdf2.checkpw("newpass", fetched_user.password_hash) == true
+      assert Pbkdf2.verify_pass("newpass", fetched_user.password_hash) == true
     end
   end