all tests passed
[akkoma] / test / formatter_test.exs
index e37b17879565300b411870c51a95c4f593f89571..d5c74a321eeb165341975b944fb20ef819af4adf 100644 (file)
@@ -1,8 +1,13 @@
 defmodule Pleroma.FormatterTest do
   alias Pleroma.Formatter
+  alias Pleroma.User
   use Pleroma.DataCase
 
   import Pleroma.Factory
+  setup_all do
+    Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
+    :ok
+  end
 
   describe ".add_hashtag_links" do
     test "turns hashtags into links" do
@@ -109,7 +114,7 @@ defmodule Pleroma.FormatterTest do
       archaeme =
         insert(:user, %{
           nickname: "archaeme",
-          info: %{"source_data" => %{"url" => "https://archeme/@archaeme"}}
+          info: %Pleroma.User.Info{source_data: %{"url" => "https://archeme/@archaeme"}}
         })
 
       archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"})
@@ -131,6 +136,24 @@ defmodule Pleroma.FormatterTest do
       assert expected_text == Formatter.finalize({subs, text})
     end
 
+    test "gives a replacement for user links when the user is using Osada" do
+      mike = User.get_or_fetch("mike@osada.macgirvin.com")
+
+      text = "@mike@osada.macgirvin.com test"
+
+      mentions = Formatter.parse_mentions(text)
+
+      {subs, text} = Formatter.add_user_links({[], text}, mentions)
+
+      assert length(subs) == 1
+      Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end)
+
+      expected_text =
+        "<span><a class='mention' href='#{mike.ap_id}'>@<span>mike</span></a></span> test"
+
+      assert expected_text == Formatter.finalize({subs, text})
+    end
+
     test "gives a replacement for single-character local nicknames" do
       text = "@o hi"
       o = insert(:user, %{nickname: "o"})