2020-01-03 13:21:52 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-01-03 13:21:52 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.Metadata.UtilsTest do
|
2022-09-06 19:24:02 +00:00
|
|
|
use Pleroma.DataCase, async: false
|
2020-01-03 13:21:52 +00:00
|
|
|
import Pleroma.Factory
|
|
|
|
alias Pleroma.Web.Metadata.Utils
|
|
|
|
|
|
|
|
describe "scrub_html_and_truncate/1" do
|
2022-08-23 12:49:05 +00:00
|
|
|
test "it returns content text without encode HTML if summary is nil" do
|
2020-01-03 13:21:52 +00:00
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
note =
|
|
|
|
insert(:note, %{
|
|
|
|
data: %{
|
|
|
|
"actor" => user.ap_id,
|
|
|
|
"id" => "https://pleroma.gov/objects/whatever",
|
2022-08-23 12:49:05 +00:00
|
|
|
"summary" => nil,
|
2020-01-03 13:21:52 +00:00
|
|
|
"content" => "Pleroma's really cool!"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
assert Utils.scrub_html_and_truncate(note) == "Pleroma's really cool!"
|
|
|
|
end
|
2022-09-06 19:24:02 +00:00
|
|
|
|
2022-08-23 12:49:05 +00:00
|
|
|
test "it returns context text without encode HTML if summary is empty" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
note =
|
|
|
|
insert(:note, %{
|
|
|
|
data: %{
|
|
|
|
"actor" => user.ap_id,
|
|
|
|
"id" => "https://pleroma.gov/objects/whatever",
|
|
|
|
"summary" => "",
|
|
|
|
"content" => "Pleroma's really cool!"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
assert Utils.scrub_html_and_truncate(note) == "Pleroma's really cool!"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it returns summary text without encode HTML if summary is filled" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
note =
|
|
|
|
insert(:note, %{
|
|
|
|
data: %{
|
|
|
|
"actor" => user.ap_id,
|
|
|
|
"id" => "https://pleroma.gov/objects/whatever",
|
|
|
|
"summary" => "Public service announcement on caffeine consumption",
|
|
|
|
"content" => "cofe"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
assert Utils.scrub_html_and_truncate(note) ==
|
|
|
|
"Public service announcement on caffeine consumption"
|
|
|
|
end
|
|
|
|
|
2022-09-06 19:24:02 +00:00
|
|
|
test "it does not return old content after editing" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, activity} = Pleroma.Web.CommonAPI.post(user, %{status: "mew mew #def"})
|
|
|
|
|
|
|
|
object = Pleroma.Object.normalize(activity)
|
|
|
|
assert Utils.scrub_html_and_truncate(object) == "mew mew #def"
|
|
|
|
|
|
|
|
{:ok, update} = Pleroma.Web.CommonAPI.update(user, activity, %{status: "mew mew #abc"})
|
|
|
|
update = Pleroma.Activity.normalize(update)
|
|
|
|
object = Pleroma.Object.normalize(update)
|
|
|
|
assert Utils.scrub_html_and_truncate(object) == "mew mew #abc"
|
|
|
|
end
|
2020-01-03 13:21:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "scrub_html_and_truncate/2" do
|
|
|
|
test "it returns text without encode HTML" do
|
|
|
|
assert Utils.scrub_html_and_truncate("Pleroma's really cool!") == "Pleroma's really cool!"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|