mix format
[akkoma] / test / pleroma / web / twitter_api / util_controller_test.exs
index fb7da93f8fd6c0ab28986c88ee252670e5f7e342..3f839568d24c9e2a8d5edcacbb56d45672d92d56 100644 (file)
@@ -77,11 +77,11 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
     end
   end
 
-  describe "/api/pleroma/emoji" do
+  describe "/api/v1/pleroma/emoji" do
     test "returns json with custom emoji with tags", %{conn: conn} do
       emoji =
         conn
-        |> get("/api/pleroma/emoji")
+        |> get("/api/v1/pleroma/emoji")
         |> json_response_and_validate_schema(200)
 
       assert Enum.all?(emoji, fn
@@ -95,7 +95,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
     end
   end
 
-  describe "GET /api/pleroma/healthcheck" do
+  describe "GET /api/v1/pleroma/healthcheck" do
     setup do: clear_config([:instance, :healthcheck])
 
     test "returns 503 when healthcheck disabled", %{conn: conn} do
@@ -103,7 +103,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
 
       response =
         conn
-        |> get("/api/pleroma/healthcheck")
+        |> get("/api/v1/pleroma/healthcheck")
         |> json_response_and_validate_schema(503)
 
       assert response == %{}
@@ -116,7 +116,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
         system_info: fn -> %Pleroma.Healthcheck{healthy: true} end do
         response =
           conn
-          |> get("/api/pleroma/healthcheck")
+          |> get("/api/v1/pleroma/healthcheck")
           |> json_response_and_validate_schema(200)
 
         assert %{
@@ -136,7 +136,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
         system_info: fn -> %Pleroma.Healthcheck{healthy: false} end do
         response =
           conn
-          |> get("/api/pleroma/healthcheck")
+          |> get("/api/v1/pleroma/healthcheck")
           |> json_response_and_validate_schema(503)
 
         assert %{
@@ -233,12 +233,108 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
     end
   end
 
+  describe "POST /main/ostatus - remote_subscribe/2 - with statuses" do
+    setup do: clear_config([:instance, :federating], true)
+
+    test "renders subscribe form", %{conn: conn} do
+      user = insert(:user)
+      status = insert(:note_activity, %{user: user})
+      status_id = status.id
+
+      assert is_binary(status_id)
+
+      response =
+        conn
+        |> post("/main/ostatus", %{"status_id" => status_id, "profile" => ""})
+        |> response(:ok)
+
+      refute response =~ "Could not find status"
+      assert response =~ "Interacting with"
+    end
+
+    test "renders subscribe form with error when status not found", %{conn: conn} do
+      response =
+        conn
+        |> post("/main/ostatus", %{"status_id" => "somerandomid", "profile" => ""})
+        |> response(:ok)
+
+      assert response =~ "Could not find status"
+      refute response =~ "Interacting with"
+    end
+
+    test "it redirect to webfinger url", %{conn: conn} do
+      user = insert(:user)
+      status = insert(:note_activity, %{user: user})
+      status_id = status.id
+      status_ap_id = status.data["object"]
+
+      assert is_binary(status_id)
+      assert is_binary(status_ap_id)
+
+      user2 = insert(:user, ap_id: "shp@social.heldscal.la")
+
+      conn =
+        conn
+        |> post("/main/ostatus", %{
+          "status" => %{"status_id" => status_id, "profile" => user2.ap_id}
+        })
+
+      assert redirected_to(conn) ==
+               "https://social.heldscal.la/main/ostatussub?profile=#{status_ap_id}"
+    end
+
+    test "it renders form with error when status not found", %{conn: conn} do
+      user2 = insert(:user, ap_id: "shp@social.heldscal.la")
+
+      response =
+        conn
+        |> post("/main/ostatus", %{
+          "status" => %{"status_id" => "somerandomid", "profile" => user2.ap_id}
+        })
+        |> response(:ok)
+
+      assert response =~ "Something went wrong."
+    end
+  end
+
+  describe "GET /main/ostatus - show_subscribe_form/2" do
+    setup do: clear_config([:instance, :federating], true)
+
+    test "it works with users", %{conn: conn} do
+      user = insert(:user)
+
+      response =
+        conn
+        |> get("/main/ostatus", %{"nickname" => user.nickname})
+        |> response(:ok)
+
+      refute response =~ "Could not find user"
+      assert response =~ "Remotely follow #{user.nickname}"
+    end
+
+    test "it works with statuses", %{conn: conn} do
+      user = insert(:user)
+      status = insert(:note_activity, %{user: user})
+      status_id = status.id
+
+      assert is_binary(status_id)
+
+      response =
+        conn
+        |> get("/main/ostatus", %{"status_id" => status_id})
+        |> response(:ok)
+
+      refute response =~ "Could not find status"
+      assert response =~ "Interacting with"
+    end
+  end
+
   test "it returns new captcha", %{conn: conn} do
     with_mock Pleroma.Captcha,
       new: fn -> "test_captcha" end do
       resp =
         conn
-        |> get("/api/pleroma/captcha")
+        |> get("/api/v1/pleroma/captcha")
         |> response(200)
 
       assert resp == "\"test_captcha\""
@@ -363,7 +459,10 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
       conn =
         conn
         |> put_req_header("content-type", "multipart/form-data")
-        |> post("/api/pleroma/change_email", %{password: "test", email: "cofe@foobar.com"})
+        |> post("/api/pleroma/change_email", %{
+          password: "test",
+          email: "cofe@foobar.com"
+        })
 
       assert json_response_and_validate_schema(conn, 200) == %{"status" => "success"}
     end
@@ -865,7 +964,9 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
       conn =
         conn
         |> put_req_header("content-type", "application/json")
-        |> delete("/api/pleroma/aliases", %{alias: non_alias_user |> User.full_nickname()})
+        |> delete("/api/pleroma/aliases", %{
+          alias: non_alias_user |> User.full_nickname()
+        })
 
       assert %{"error" => "Account has no such alias."} =
                json_response_and_validate_schema(conn, 404)