Post editing (#202)
[akkoma] / test / pleroma / web / metadata / utils_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 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 text without encode HTML" 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 "content" => "Pleroma's really cool!"
20 }
21 })
22
23 assert Utils.scrub_html_and_truncate(note) == "Pleroma's really cool!"
24 end
25
26 test "it does not return old content after editing" do
27 user = insert(:user)
28
29 {:ok, activity} = Pleroma.Web.CommonAPI.post(user, %{status: "mew mew #def"})
30
31 object = Pleroma.Object.normalize(activity)
32 assert Utils.scrub_html_and_truncate(object) == "mew mew #def"
33
34 {:ok, update} = Pleroma.Web.CommonAPI.update(user, activity, %{status: "mew mew #abc"})
35 update = Pleroma.Activity.normalize(update)
36 object = Pleroma.Object.normalize(update)
37 assert Utils.scrub_html_and_truncate(object) == "mew mew #abc"
38 end
39 end
40
41 describe "scrub_html_and_truncate/2" do
42 test "it returns text without encode HTML" do
43 assert Utils.scrub_html_and_truncate("Pleroma's really cool!") == "Pleroma's really cool!"
44 end
45 end
46 end