logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

utils_test.exs (2536B)


  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. defmodule Pleroma.Web.Metadata.UtilsTest do
  5. use Pleroma.DataCase, async: false
  6. import Pleroma.Factory
  7. alias Pleroma.Web.Metadata.Utils
  8. describe "scrub_html_and_truncate/1" do
  9. test "it returns content text without encode HTML if summary is nil" do
  10. user = insert(:user)
  11. note =
  12. insert(:note, %{
  13. data: %{
  14. "actor" => user.ap_id,
  15. "id" => "https://pleroma.gov/objects/whatever",
  16. "summary" => nil,
  17. "content" => "Pleroma's really cool!"
  18. }
  19. })
  20. assert Utils.scrub_html_and_truncate(note) == "Pleroma's really cool!"
  21. end
  22. test "it returns context text without encode HTML if summary is empty" do
  23. user = insert(:user)
  24. note =
  25. insert(:note, %{
  26. data: %{
  27. "actor" => user.ap_id,
  28. "id" => "https://pleroma.gov/objects/whatever",
  29. "summary" => "",
  30. "content" => "Pleroma's really cool!"
  31. }
  32. })
  33. assert Utils.scrub_html_and_truncate(note) == "Pleroma's really cool!"
  34. end
  35. test "it returns summary text without encode HTML if summary is filled" do
  36. user = insert(:user)
  37. note =
  38. insert(:note, %{
  39. data: %{
  40. "actor" => user.ap_id,
  41. "id" => "https://pleroma.gov/objects/whatever",
  42. "summary" => "Public service announcement on caffeine consumption",
  43. "content" => "cofe"
  44. }
  45. })
  46. assert Utils.scrub_html_and_truncate(note) ==
  47. "Public service announcement on caffeine consumption"
  48. end
  49. test "it does not return old content after editing" do
  50. user = insert(:user)
  51. {:ok, activity} = Pleroma.Web.CommonAPI.post(user, %{status: "mew mew #def"})
  52. object = Pleroma.Object.normalize(activity)
  53. assert Utils.scrub_html_and_truncate(object) == "mew mew #def"
  54. {:ok, update} = Pleroma.Web.CommonAPI.update(user, activity, %{status: "mew mew #abc"})
  55. update = Pleroma.Activity.normalize(update)
  56. object = Pleroma.Object.normalize(update)
  57. assert Utils.scrub_html_and_truncate(object) == "mew mew #abc"
  58. end
  59. end
  60. describe "scrub_html_and_truncate/3" do
  61. test "it returns text without encode HTML" do
  62. assert Utils.scrub_html_and_truncate("Pleroma's really cool!") == "Pleroma's really cool!"
  63. end
  64. end
  65. end