X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=inline;f=test%2Fweb%2Fcommon_api%2Fcommon_api_utils_test.exs;h=e67c10b93645db18c4a2df1859330bb6f0b562b1;hb=9c672ecbb5d4477cd16d2139a2cb66d3923ac5c8;hp=b21445fe9a857defd8378176a6d9a496645ff8c7;hpb=6e6f95c6aed77cbde1a58edcdbb5cc4f68416bca;p=akkoma
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index b21445fe9..e67c10b93 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -14,18 +14,41 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
@public_address "https://www.w3.org/ns/activitystreams#Public"
- test "it adds attachment links to a given text and attachment set" do
- name =
- "Sakura%20Mana%20%E2%80%93%20Turned%20on%20by%20a%20Senior%20OL%20with%20a%20Temptating%20Tight%20Skirt-s%20Full%20Hipline%20and%20Panty%20Shot-%20Beautiful%20Thick%20Thighs-%20and%20Erotic%20Ass-%20-2015-%20--%20Oppaitime%208-28-2017%206-50-33%20PM.png"
+ describe "add_attachments/2" do
+ setup do
+ name =
+ "Sakura Mana â Turned on by a Senior OL with a Temptating Tight Skirt-s Full Hipline and Panty Shot- Beautiful Thick Thighs- and Erotic Ass- -2015- -- Oppaitime 8-28-2017 6-50-33 PM.png"
- attachment = %{
- "url" => [%{"href" => name}]
- }
+ attachment = %{
+ "url" => [%{"href" => URI.encode(name)}]
+ }
- res = Utils.add_attachments("", [attachment])
+ %{name: name, attachment: attachment}
+ end
+
+ test "it adds attachment links to a given text and attachment set", %{
+ name: name,
+ attachment: attachment
+ } do
+ len = 10
+ clear_config([Pleroma.Upload, :filename_display_max_length], len)
+
+ expected =
+ "
#{String.slice(name, 0..len)}â¦"
+
+ assert Utils.add_attachments("", [attachment]) == expected
+ end
+
+ test "doesn't truncate file name if config for truncate is set to 0", %{
+ name: name,
+ attachment: attachment
+ } do
+ clear_config([Pleroma.Upload, :filename_display_max_length], 0)
- assert res ==
- "
Sakura Mana â Turned on by a Seâ¦"
+ expected = "
#{name}"
+
+ assert Utils.add_attachments("", [attachment]) == expected
+ end
end
describe "it confirms the password given is the current users password" do
@@ -228,7 +251,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
user = insert(:user)
mentioned_user = insert(:user)
third_user = insert(:user)
- {:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
+ {:ok, activity} = CommonAPI.post(third_user, %{status: "uguu"})
mentions = [mentioned_user.ap_id]
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "public", nil)
@@ -261,7 +284,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
user = insert(:user)
mentioned_user = insert(:user)
third_user = insert(:user)
- {:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
+ {:ok, activity} = CommonAPI.post(third_user, %{status: "uguu"})
mentions = [mentioned_user.ap_id]
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "unlisted", nil)
@@ -292,16 +315,15 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
user = insert(:user)
mentioned_user = insert(:user)
third_user = insert(:user)
- {:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
+ {:ok, activity} = CommonAPI.post(third_user, %{status: "uguu"})
mentions = [mentioned_user.ap_id]
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "private", nil)
- assert length(to) == 3
+ assert length(to) == 2
assert Enum.empty?(cc)
assert mentioned_user.ap_id in to
- assert third_user.ap_id in to
assert user.follower_address in to
end
@@ -322,36 +344,25 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
user = insert(:user)
mentioned_user = insert(:user)
third_user = insert(:user)
- {:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
+ {:ok, activity} = CommonAPI.post(third_user, %{status: "uguu"})
mentions = [mentioned_user.ap_id]
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "direct", nil)
- assert length(to) == 2
+ assert length(to) == 1
assert Enum.empty?(cc)
assert mentioned_user.ap_id in to
- assert third_user.ap_id in to
- end
- end
- describe "get_by_id_or_ap_id/1" do
- test "get activity by id" do
- activity = insert(:note_activity)
- %Pleroma.Activity{} = note = Utils.get_by_id_or_ap_id(activity.id)
- assert note.id == activity.id
- end
+ {:ok, direct_activity} = CommonAPI.post(third_user, %{status: "uguu", visibility: "direct"})
- test "get activity by ap_id" do
- activity = insert(:note_activity)
- %Pleroma.Activity{} = note = Utils.get_by_id_or_ap_id(activity.data["object"])
- assert note.id == activity.id
- end
+ {to, cc} = Utils.get_to_and_cc(user, mentions, direct_activity, "direct", nil)
- test "get activity by object when type isn't `Create` " do
- activity = insert(:like_activity)
- %Pleroma.Activity{} = like = Utils.get_by_id_or_ap_id(activity.id)
- assert like.data["object"] == activity.data["object"]
+ assert length(to) == 2
+ assert Enum.empty?(cc)
+
+ assert mentioned_user.ap_id in to
+ assert third_user.ap_id in to
end
end
@@ -483,8 +494,8 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
desc = Jason.encode!(%{object.id => "test-desc"})
assert Utils.attachments_from_ids(%{
- "media_ids" => ["#{object.id}"],
- "descriptions" => desc
+ media_ids: ["#{object.id}"],
+ descriptions: desc
}) == [
Map.merge(object.data, %{"name" => "test-desc"})
]
@@ -492,7 +503,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
test "returns attachments without descs" do
object = insert(:note)
- assert Utils.attachments_from_ids(%{"media_ids" => ["#{object.id}"]}) == [object.data]
+ assert Utils.attachments_from_ids(%{media_ids: ["#{object.id}"]}) == [object.data]
end
test "returns [] when not pass media_ids" do