Fix MRF policies to also work with Update
[akkoma] / test / pleroma / web / activity_pub / mrf / hashtag_policy_test.exs
index 13415bb79ef168d13b4e1f3009bb91deb3db07ed..b88090869fe2fa23644ca6a1d8c9e264e3a14efc 100644 (file)
@@ -20,6 +20,76 @@ defmodule Pleroma.Web.ActivityPub.MRF.HashtagPolicyTest do
     assert modified["object"]["sensitive"]
   end
 
+  test "it is history-aware" do
+    activity = %{
+      "type" => "Create",
+      "object" => %{
+        "content" => "hey",
+        "tag" => []
+      }
+    }
+
+    activity_data =
+      activity
+      |> put_in(
+        ["object", "formerRepresentations"],
+        %{
+          "type" => "OrderedCollection",
+          "orderedItems" => [
+            Map.put(
+              activity["object"],
+              "tag",
+              [%{"type" => "Hashtag", "name" => "#nsfw"}]
+            )
+          ]
+        }
+      )
+
+    {:ok, modified} =
+      Pleroma.Web.ActivityPub.MRF.filter_one(
+        Pleroma.Web.ActivityPub.MRF.HashtagPolicy,
+        activity_data
+      )
+
+    refute modified["object"]["sensitive"]
+    assert Enum.at(modified["object"]["formerRepresentations"]["orderedItems"], 0)["sensitive"]
+  end
+
+  test "it works with Update" do
+    activity = %{
+      "type" => "Update",
+      "object" => %{
+        "content" => "hey",
+        "tag" => []
+      }
+    }
+
+    activity_data =
+      activity
+      |> put_in(
+        ["object", "formerRepresentations"],
+        %{
+          "type" => "OrderedCollection",
+          "orderedItems" => [
+            Map.put(
+              activity["object"],
+              "tag",
+              [%{"type" => "Hashtag", "name" => "#nsfw"}]
+            )
+          ]
+        }
+      )
+
+    {:ok, modified} =
+      Pleroma.Web.ActivityPub.MRF.filter_one(
+        Pleroma.Web.ActivityPub.MRF.HashtagPolicy,
+        activity_data
+      )
+
+    refute modified["object"]["sensitive"]
+    assert Enum.at(modified["object"]["formerRepresentations"]["orderedItems"], 0)["sensitive"]
+  end
+
   test "it doesn't sets the sensitive property with irrelevant hashtags" do
     user = insert(:user)