summaryrefslogtreecommitdiff
path: root/test/pleroma/web/metadata/utils_test.exs
blob: 85ef6033a7c77b47d7e315ab28272d5efd9f0f5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Web.Metadata.UtilsTest do
  use Pleroma.DataCase, async: false
  import Pleroma.Factory
  alias Pleroma.Web.Metadata.Utils

  describe "scrub_html_and_truncate/1" do
    test "it returns content text without encode HTML if summary is nil" do
      user = insert(:user)

      note =
        insert(:note, %{
          data: %{
            "actor" => user.ap_id,
            "id" => "https://pleroma.gov/objects/whatever",
            "summary" => nil,
            "content" => "Pleroma's really cool!"
          }
        })

      assert Utils.scrub_html_and_truncate(note) == "Pleroma's really cool!"
    end

    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

    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
  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