Moved account deletion stuff to somewhere that hopefully makes more sense
[akkoma] / test / web / twitter_api / twitter_api_controller_test.exs
index 18a3243f5ff0584caca42caf42b8f02334e4f174..170dda145e6f83502f147305433558036daad98d 100644 (file)
@@ -257,8 +257,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
     end
 
     test "with credentials", %{conn: conn, user: current_user} do
+      other_user = insert(:user)
+
       {:ok, activity} =
-        ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: current_user})
+        ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: other_user})
 
       conn =
         conn
@@ -270,10 +272,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
       assert length(response) == 1
 
       assert response ==
-        NotificationView.render(
-          "notification.json",
-          %{notifications: Notification.for_user(current_user), for: current_user}
-        )
+               NotificationView.render("notification.json", %{
+                 notifications: Notification.for_user(current_user),
+                 for: current_user
+               })
     end
   end
 
@@ -784,4 +786,47 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
       assert status["id"] == activity.id
     end
   end
+
+  test "Convert newlines to <br> in bio", %{conn: conn} do
+    user = insert(:user)
+
+    conn =
+      conn
+      |> assign(:user, user)
+      |> post("/api/account/update_profile.json", %{
+        "description" => "Hello,\r\nWorld! I\n am a test."
+      })
+
+    user = Repo.get!(User, user.id)
+    assert user.bio == "Hello,<br>World! I<br> am a test."
+  end
+
+  describe "POST /api/pleroma/delete_account" do
+    setup [:valid_user]
+
+    test "without credentials", %{conn: conn} do
+      conn = post(conn, "/api/pleroma/delete_account")
+      assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
+    end
+
+    test "with credentials and invalid password", %{conn: conn, user: current_user} do
+      conn =
+        conn
+        |> with_credentials(current_user.nickname, "test")
+        |> post("/api/pleroma/delete_account", %{"password" => "hi"})
+
+      assert json_response(conn, 200) == %{"error" => "Invalid password."}
+    end
+
+    test "with credentials and valid password", %{conn: conn, user: current_user} do
+      conn =
+        conn
+        |> with_credentials(current_user.nickname, "test")
+        |> post("/api/pleroma/delete_account", %{"password" => "test"})
+
+      assert json_response(conn, 200) == %{"status" => "success"}
+      fetched_user = Repo.get(User, current_user.id)
+      assert fetched_user.info == %{"deactivated" => true}
+    end
+  end
 end