Merge remote-tracking branch 'origin/develop' into notice-routes
[akkoma] / test / pleroma / web / o_status / o_status_controller_test.exs
index 65b2c22dbe45bb16ac9a5335f5a3f5ae8675603d..b243e16921f1c856ba64eb31e7c7e5cf49fa7b67 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.OStatus.OStatusControllerTest do
@@ -72,7 +72,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
 
     test "redirects to /notice/id for html format", %{conn: conn} do
       note_activity = insert(:note_activity)
-      object = Object.normalize(note_activity)
+      object = Object.normalize(note_activity, fetch: false)
       [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
       url = "/objects/#{uuid}"
 
@@ -82,7 +82,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
 
     test "404s on private objects", %{conn: conn} do
       note_activity = insert(:direct_note_activity)
-      object = Object.normalize(note_activity)
+      object = Object.normalize(note_activity, fetch: false)
       [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
 
       conn
@@ -133,7 +133,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
       conn: conn
     } do
       note_activity = insert(:note_activity)
-      expected_redirect_url = Object.normalize(note_activity).data["id"]
+      expected_redirect_url = Object.normalize(note_activity, fetch: false).data["id"]
 
       redirect_url =
         conn
@@ -144,13 +144,19 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
       assert redirect_url == expected_redirect_url
     end
 
-    test "returns a 404 on remote notice when json requested", %{conn: conn} do
+    test "redirects to a proper object URL when json requested and the object is remote", %{
+      conn: conn
+    } do
       note_activity = insert(:note_activity, local: false)
+      expected_redirect_url = Object.normalize(note_activity, fetch: false).data["id"]
 
-      conn
-      |> put_req_header("accept", "application/activity+json")
-      |> get("/notice/#{note_activity.id}")
-      |> response(404)
+      redirect_url =
+        conn
+        |> put_req_header("accept", "application/activity+json")
+        |> get("/notice/#{note_activity.id}")
+        |> redirected_to()
+
+      assert redirect_url == expected_redirect_url
     end
 
     test "500s when actor not found", %{conn: conn} do
@@ -176,7 +182,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
         |> response(200)
 
       assert resp =~
-               "<meta content=\"#{Pleroma.Web.base_url()}/notice/#{note_activity.id}\" property=\"og:url\">"
+               "<meta content=\"#{Pleroma.Web.Endpoint.url()}/notice/#{note_activity.id}\" property=\"og:url\">"
 
       user = insert(:user)
 
@@ -230,7 +236,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
   describe "GET /notice/:id/embed_player" do
     setup do
       note_activity = insert(:note_activity)
-      object = Pleroma.Object.normalize(note_activity)
+      object = Pleroma.Object.normalize(note_activity, fetch: false)
 
       object_data =
         Map.put(object.data, "attachment", [
@@ -287,7 +293,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
 
     test "404s when attachment is empty", %{conn: conn} do
       note_activity = insert(:note_activity)
-      object = Pleroma.Object.normalize(note_activity)
+      object = Pleroma.Object.normalize(note_activity, fetch: false)
       object_data = Map.put(object.data, "attachment", [])
 
       object
@@ -301,7 +307,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
 
     test "404s when attachment isn't audio or video", %{conn: conn} do
       note_activity = insert(:note_activity)
-      object = Pleroma.Object.normalize(note_activity)
+      object = Pleroma.Object.normalize(note_activity, fetch: false)
 
       object_data =
         Map.put(object.data, "attachment", [
@@ -337,4 +343,54 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
       |> response(200)
     end
   end
+
+  describe "notice compatibility routes" do
+    test "Soapbox FE", %{conn: conn} do
+      user = insert(:user)
+      note_activity = insert(:note_activity, user: user)
+
+      resp =
+        conn
+        |> put_req_header("accept", "text/html")
+        |> get("/@#{user.nickname}/posts/#{note_activity.id}")
+        |> response(200)
+
+      expected =
+        "<meta content=\"#{Pleroma.Web.base_url()}/notice/#{note_activity.id}\" property=\"og:url\">"
+
+      assert resp =~ expected
+    end
+
+    test "Mastodon", %{conn: conn} do
+      user = insert(:user)
+      note_activity = insert(:note_activity, user: user)
+
+      resp =
+        conn
+        |> put_req_header("accept", "text/html")
+        |> get("/@#{user.nickname}/#{note_activity.id}")
+        |> response(200)
+
+      expected =
+        "<meta content=\"#{Pleroma.Web.base_url()}/notice/#{note_activity.id}\" property=\"og:url\">"
+
+      assert resp =~ expected
+    end
+
+    test "Twitter", %{conn: conn} do
+      user = insert(:user)
+      note_activity = insert(:note_activity, user: user)
+
+      resp =
+        conn
+        |> put_req_header("accept", "text/html")
+        |> get("/#{user.nickname}/status/#{note_activity.id}")
+        |> response(200)
+
+      expected =
+        "<meta content=\"#{Pleroma.Web.base_url()}/notice/#{note_activity.id}\" property=\"og:url\">"
+
+      assert resp =~ expected
+    end
+  end
 end