3daf852fba8d75c3783ac66b3f2212344b4a40ae
[anni] / test / pleroma / web / metadata / utils_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.Metadata.UtilsTest do
6   use Pleroma.DataCase, async: false
7   import Pleroma.Factory
8   alias Pleroma.Web.Metadata.Utils
9
10   describe "scrub_html_and_truncate/1" do
11     test "it returns content text without encode HTML if summary is nil" do
12       user = insert(:user)
13
14       note =
15         insert(:note, %{
16           data: %{
17             "actor" => user.ap_id,
18             "id" => "https://pleroma.gov/objects/whatever",
19             "summary" => nil,
20             "content" => "Pleroma's really cool!"
21           }
22         })
23
24       assert Utils.scrub_html_and_truncate(note) == "Pleroma's really cool!"
25     end
26
27     test "it returns context text without encode HTML if summary is empty" do
28       user = insert(:user)
29
30       note =
31         insert(:note, %{
32           data: %{
33             "actor" => user.ap_id,
34             "id" => "https://pleroma.gov/objects/whatever",
35             "summary" => "",
36             "content" => "Pleroma's really cool!"
37           }
38         })
39
40       assert Utils.scrub_html_and_truncate(note) == "Pleroma's really cool!"
41     end
42
43     test "it returns summary text without encode HTML if summary is filled" do
44       user = insert(:user)
45
46       note =
47         insert(:note, %{
48           data: %{
49             "actor" => user.ap_id,
50             "id" => "https://pleroma.gov/objects/whatever",
51             "summary" => "Public service announcement on caffeine consumption",
52             "content" => "cofe"
53           }
54         })
55
56       assert Utils.scrub_html_and_truncate(note) ==
57                "Public service announcement on caffeine consumption"
58     end
59
60     test "it does not return old content after editing" do
61       user = insert(:user)
62
63       {:ok, activity} = Pleroma.Web.CommonAPI.post(user, %{status: "mew mew #def"})
64
65       object = Pleroma.Object.normalize(activity)
66       assert Utils.scrub_html_and_truncate(object) == "mew mew #def"
67
68       {:ok, update} = Pleroma.Web.CommonAPI.update(user, activity, %{status: "mew mew #abc"})
69       update = Pleroma.Activity.normalize(update)
70       object = Pleroma.Object.normalize(update)
71       assert Utils.scrub_html_and_truncate(object) == "mew mew #abc"
72     end
73   end
74
75   describe "scrub_html_and_truncate/3" do
76     test "it returns text without encode HTML" do
77       assert Utils.scrub_html_and_truncate("Pleroma's really cool!") == "Pleroma's really cool!"
78     end
79   end
80 end