X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=inline;f=test%2Fpleroma%2Fweb%2Fcommon_api%2Futils_test.exs;h=f56d21c708a336f85538790f85c2670cf817a260;hb=20cd8a0fc4a05b9b47059324e8444203c66efc33;hp=4d6c9ea2610786def850afffaecec5bef223ecf2;hpb=1438fd958325c3d469315c478f06def9e4dd0de3;p=akkoma
diff --git a/test/pleroma/web/common_api/utils_test.exs b/test/pleroma/web/common_api/utils_test.exs
index 4d6c9ea26..f56d21c70 100644
--- a/test/pleroma/web/common_api/utils_test.exs
+++ b/test/pleroma/web/common_api/utils_test.exs
@@ -1,10 +1,9 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.CommonAPI.UtilsTest do
alias Pleroma.Builders.UserBuilder
- alias Pleroma.Object
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.CommonAPI.ActivityDraft
alias Pleroma.Web.CommonAPI.Utils
@@ -160,27 +159,116 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
{output, _, _} = Utils.format_input(text, "text/markdown")
assert output ==
- ~s(
hello world
another @user__test and @user__test google.com paragraph
)
+ ~s(hello world
another @user__test and @user__test google.com paragraph
)
end
end
- describe "context_to_conversation_id" do
- test "creates a mapping object" do
- conversation_id = Utils.context_to_conversation_id("random context")
- object = Object.get_by_ap_id("random context")
+ describe "format_input/3 with markdown" do
+ test "Paragraph" do
+ code = ~s[Hello\n\nWorld!]
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == "Hello
World!
"
+ end
+
+ test "links" do
+ code = "https://en.wikipedia.org/wiki/Animal_Crossing_(video_game)"
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == ~s[#{code}
]
+
+ code = "https://github.com/pragdave/earmark/"
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == ~s[#{code}
]
+ end
+
+ test "link with local mention" do
+ insert(:user, %{nickname: "lain"})
+
+ code = "https://example.com/@lain"
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == ~s[#{code}
]
+ end
+
+ test "local mentions" do
+ mario = insert(:user, %{nickname: "mario"})
+ luigi = insert(:user, %{nickname: "luigi"})
+
+ code = "@mario @luigi yo what's up?"
+ {result, _, []} = Utils.format_input(code, "text/markdown")
+
+ assert result ==
+ ~s[@mario @luigi yo whatâs up?
]
+ end
+
+ test "remote mentions" do
+ mario = insert(:user, %{nickname: "mario@mushroom.world", local: false})
+ luigi = insert(:user, %{nickname: "luigi@mushroom.world", local: false})
+
+ code = "@mario@mushroom.world @luigi@mushroom.world yo what's up?"
+ {result, _, []} = Utils.format_input(code, "text/markdown")
+
+ assert result ==
+ ~s[@mario @luigi yo whatâs up?
]
+ end
+
+ test "raw HTML" do
+ code = ~s[OwO]
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == ~s[OwO]
+ end
+
+ test "rulers" do
+ code = ~s[before\n\n-----\n\nafter]
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == "before
after
"
+ end
+
+ test "blockquote" do
+ code = ~s[> whoms't are you quoting?]
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == "whomsât are you quoting?
"
+ end
+
+ test "code" do
+ code = ~s[`mix`]
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == ~s[mix
]
+
+ code = ~s[``mix``]
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == ~s[mix
]
+
+ code = ~s[```\nputs "Hello World"\n```]
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == ~s[puts "Hello World"
]
+
+ code = ~s[ \n
]
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == ~s[<div>\n</div>
]
+ end
+
+ test "lists" do
+ code = ~s[- one\n- two\n- three\n- four]
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == ""
- assert conversation_id == object.id
+ code = ~s[1. one\n2. two\n3. three\n4. four\n]
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == "- one
- two
- three
- four
"
end
- test "returns an existing mapping for an existing object" do
- {:ok, object} = Object.context_mapping("random context") |> Repo.insert()
- conversation_id = Utils.context_to_conversation_id("random context")
+ test "delegated renderers" do
+ code = ~s[*aaaa~*]
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == ~s[aaaa~
]
+
+ code = ~s[**aaaa~**]
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == ~s[aaaa~
]
- assert conversation_id == object.id
+ # strikethrough
+ code = ~s[~~aaaa~~~]
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == ~s[aaaa~
]
end
end
@@ -204,7 +292,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
assert capture_log(fn ->
assert Utils.date_to_asctime(date) == expected
- end) =~ "[warn] Date #{date} in wrong format, must be ISO 8601"
+ end) =~ "[warning] Date #{date} in wrong format, must be ISO 8601"
end
test "when date is a Unix timestamp" do
@@ -214,7 +302,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
assert capture_log(fn ->
assert Utils.date_to_asctime(date) == expected
- end) =~ "[warn] Date #{date} in wrong format, must be ISO 8601"
+ end) =~ "[warning] Date #{date} in wrong format, must be ISO 8601"
end
test "when date is nil" do
@@ -222,13 +310,13 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
assert capture_log(fn ->
assert Utils.date_to_asctime(nil) == expected
- end) =~ "[warn] Date in wrong format, must be ISO 8601"
+ end) =~ "[warning] Date in wrong format, must be ISO 8601"
end
test "when date is a random string" do
assert capture_log(fn ->
assert Utils.date_to_asctime("foo") == ""
- end) =~ "[warn] Date foo in wrong format, must be ISO 8601"
+ end) =~ "[warning] Date foo in wrong format, must be ISO 8601"
end
end
@@ -407,19 +495,16 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
assert Utils.to_masto_date("2015-01-23T23:50:07.123Z") == "2015-01-23T23:50:07.000Z"
end
- test "returns empty string when date invalid" do
- assert Utils.to_masto_date("2015-01?23T23:50:07.123Z") == ""
+ test "returns unix epoch when date invalid" do
+ assert Utils.to_masto_date("2015-01?23T23:50:07.123Z") == "1970-01-01T00:00:00Z"
end
- end
- describe "conversation_id_to_context/1" do
- test "returns id" do
- object = insert(:note)
- assert Utils.conversation_id_to_context(object.id) == object.data["id"]
+ test "returns unix epoch when date is before the introduction of the Gregorian Calendar" do
+ assert Utils.to_masto_date("0621-01-01T00:00:00Z") == "1970-01-01T00:00:00Z"
end
- test "returns error if object not found" do
- assert Utils.conversation_id_to_context("123") == {:error, "No such conversation"}
+ test "returns unix epoch when date is BCE" do
+ assert Utils.to_masto_date("-0420-01-01T00:00:00Z") == "1970-01-01T00:00:00Z"
end
end
@@ -564,41 +649,6 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
end
end
- describe "make_note_data/1" do
- test "returns note data" do
- user = insert(:user)
- note = insert(:note)
- user2 = insert(:user)
- user3 = insert(:user)
-
- draft = %ActivityDraft{
- user: user,
- to: [user2.ap_id],
- context: "2hu",
- content_html: "This is :moominmamma: note
",
- in_reply_to: note.id,
- tags: [name: "jimm"],
- summary: "test summary",
- cc: [user3.ap_id],
- extra: %{"custom_tag" => "test"}
- }
-
- assert Utils.make_note_data(draft) == %{
- "actor" => user.ap_id,
- "attachment" => [],
- "cc" => [user3.ap_id],
- "content" => "This is :moominmamma: note
",
- "context" => "2hu",
- "sensitive" => false,
- "summary" => "test summary",
- "tag" => ["jimm"],
- "to" => [user2.ap_id],
- "type" => "Note",
- "custom_tag" => "test"
- }
- end
- end
-
describe "maybe_add_attachments/3" do
test "returns parsed results when attachment_links is false" do
assert Utils.maybe_add_attachments(