docs/installation: Update required Elixir version to 1.12
[akkoma] / test / pleroma / web / activity_pub / object_validators / article_note_page_validator_test.exs
index 62526d95203551b8644498c1047cce549921f712..09cd1a964f55b694ff6dd4c784213284bab68a1d 100644 (file)
@@ -71,7 +71,20 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest
     end
 
     test "a misskey MFM status with a content field should work and be linked", _ do
-      local_user = insert(:user, %{nickname: "akkoma_user"})
+      local_user =
+        insert(:user, %{nickname: "akkoma_user", ap_id: "http://localhost:4001/users/akkoma_user"})
+
+      remote_user =
+        insert(:user, %{
+          nickname: "remote_user",
+          ap_id: "http://misskey.local.live/users/remote_user"
+        })
+
+      full_tag_remote_user =
+        insert(:user, %{
+          nickname: "full_tag_remote_user",
+          ap_id: "http://misskey.local.live/users/full_tag_remote_user"
+        })
 
       insert(:user, %{ap_id: "https://misskey.local.live/users/92hzkskwgy"})
 
@@ -80,23 +93,34 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest
         |> File.read!()
         |> Jason.decode!()
 
-      expected_content =
-        "<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{local_user.id}\" href=\"#{local_user.ap_id}\" rel=\"ugc\">@<span>akkoma_user</span></a></span> linkifylink <a class=\"hashtag\" data-tag=\"dancedance\" href=\"http://localhost:4001/tag/dancedance\" rel=\"tag ugc\">#dancedance</a> $[jelly mfm goes here] <br><br>## aaa"
-
       %{
         valid?: true,
         changes: %{
-          content: ^expected_content,
+          content: content,
           source: %{
-            "content" => "@akkoma_user linkifylink #dancedance $[jelly mfm goes here] \n\n## aaa",
+            "content" =>
+              "@akkoma_user @remote_user @full_tag_remote_user@misskey.local.live @oops_not_a_mention linkifylink #dancedance $[jelly mfm goes here] \n\n## aaa",
             "mediaType" => "text/x.misskeymarkdown"
           }
         }
       } = ArticleNotePageValidator.cast_and_validate(note)
+
+      assert content =~
+               "<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{local_user.id}\" href=\"#{local_user.ap_id}\" rel=\"ugc\">@<span>akkoma_user</span></a></span>"
+
+      assert content =~
+               "<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{remote_user.id}\" href=\"#{remote_user.ap_id}\" rel=\"ugc\">@<span>remote_user</span></a></span>"
+
+      assert content =~
+               "<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{full_tag_remote_user.id}\" href=\"#{full_tag_remote_user.ap_id}\" rel=\"ugc\">@<span>full_tag_remote_user</span></a></span>"
+
+      assert content =~ "@oops_not_a_mention"
+      assert content =~ "$[jelly mfm goes here] <br><br>## aaa"
     end
 
     test "a misskey MFM status with a _misskey_content field should work and be linked", _ do
-      local_user = insert(:user, %{nickname: "akkoma_user"})
+      local_user =
+        insert(:user, %{nickname: "akkoma_user", ap_id: "http://localhost:4001/users/akkoma_user"})
 
       insert(:user, %{ap_id: "https://misskey.local.live/users/92hzkskwgy"})
 
@@ -106,18 +130,21 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest
         |> Jason.decode!()
 
       expected_content =
-        "<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{local_user.id}\" href=\"#{local_user.ap_id}\" rel=\"ugc\">@<span>akkoma_user</span></a></span> linkifylink <a class=\"hashtag\" data-tag=\"dancedance\" href=\"http://localhost:4001/tag/dancedance\" rel=\"tag ugc\">#dancedance</a> $[jelly mfm goes here] <br><br>## aaa"
+        "<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{local_user.id}\" href=\"#{local_user.ap_id}\" rel=\"ugc\">@<span>akkoma_user</span></a></span> linkifylink <a class=\"hashtag\" data-tag=\"dancedance\" href=\"http://localhost:4001/tag/dancedance\">#dancedance</a> $[jelly mfm goes here] <br><br>## aaa"
+
+      changes = ArticleNotePageValidator.cast_and_validate(note)
 
       %{
         valid?: true,
         changes: %{
-          content: ^expected_content,
           source: %{
             "content" => "@akkoma_user linkifylink #dancedance $[jelly mfm goes here] \n\n## aaa",
             "mediaType" => "text/x.misskeymarkdown"
           }
         }
-      } = ArticleNotePageValidator.cast_and_validate(note)
+      } = changes
+
+      assert changes.changes[:content] == expected_content
     end
   end
 end