make conversation-id deterministic (#154)
[akkoma] / test / pleroma / web / mastodon_api / views / status_view_test.exs
index caf2594c0330c6052d94ccc4eb9ddd6aa9206479..130de1b179bb55152c26dc6f7a781a361eee568f 100644 (file)
@@ -14,7 +14,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
   alias Pleroma.User
   alias Pleroma.UserRelationship
   alias Pleroma.Web.CommonAPI
-  alias Pleroma.Web.CommonAPI.Utils
   alias Pleroma.Web.MastodonAPI.AccountView
   alias Pleroma.Web.MastodonAPI.StatusView
 
@@ -240,7 +239,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
     object_data = Object.normalize(note, fetch: false).data
     user = User.get_cached_by_ap_id(note.data["actor"])
 
-    convo_id = Utils.context_to_conversation_id(object_data["context"])
+    convo_id = :erlang.crc32(object_data["context"])
 
     status = StatusView.render("show.json", %{activity: note})
 
@@ -305,7 +304,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
       },
       akkoma: %{
         source: HTML.filter_tags(object_data["content"])
-      }
+      },
+      quote_id: nil,
+      quote: nil
     }
 
     assert status == expected
@@ -393,6 +394,30 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
     assert status.in_reply_to_id == to_string(note.id)
   end
 
+  test "a quote" do
+    note = insert(:note_activity)
+    user = insert(:user)
+
+    {:ok, activity} = CommonAPI.post(user, %{status: "hehe", quote_id: note.id})
+
+    status = StatusView.render("show.json", %{activity: activity})
+
+    assert status.quote_id == to_string(note.id)
+
+    [status] = StatusView.render("index.json", %{activities: [activity], as: :activity})
+
+    assert status.quote_id == to_string(note.id)
+  end
+
+  test "a quote that we can't resolve" do
+    note = insert(:note_activity, quoteUri: "oopsie")
+
+    status = StatusView.render("show.json", %{activity: note})
+
+    assert is_nil(status.quote_id)
+    assert is_nil(status.quote)
+  end
+
   test "contains mentions" do
     user = insert(:user)
     mentioned = insert(:user)