logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

ensure_re_prepended_test.exs (2736B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrependedTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.Activity
  7. alias Pleroma.Object
  8. alias Pleroma.Web.ActivityPub.MRF.EnsureRePrepended
  9. describe "rewrites summary" do
  10. test "it adds `re:` to summary object when child summary and parent summary equal" do
  11. message = %{
  12. "type" => "Create",
  13. "object" => %{
  14. "summary" => "object-summary",
  15. "inReplyTo" => %Activity{object: %Object{data: %{"summary" => "object-summary"}}}
  16. }
  17. }
  18. assert {:ok, res} = EnsureRePrepended.filter(message)
  19. assert res["object"]["summary"] == "re: object-summary"
  20. end
  21. test "it adds `re:` to summary object when child summary containts re-subject of parent summary " do
  22. message = %{
  23. "type" => "Create",
  24. "object" => %{
  25. "summary" => "object-summary",
  26. "inReplyTo" => %Activity{object: %Object{data: %{"summary" => "re: object-summary"}}}
  27. }
  28. }
  29. assert {:ok, res} = EnsureRePrepended.filter(message)
  30. assert res["object"]["summary"] == "re: object-summary"
  31. end
  32. end
  33. describe "skip filter" do
  34. test "it skip if type isn't 'Create'" do
  35. message = %{
  36. "type" => "Annotation",
  37. "object" => %{"summary" => "object-summary"}
  38. }
  39. assert {:ok, res} = EnsureRePrepended.filter(message)
  40. assert res == message
  41. end
  42. test "it skip if summary is empty" do
  43. message = %{
  44. "type" => "Create",
  45. "object" => %{
  46. "inReplyTo" => %Activity{object: %Object{data: %{"summary" => "summary"}}}
  47. }
  48. }
  49. assert {:ok, res} = EnsureRePrepended.filter(message)
  50. assert res == message
  51. end
  52. test "it skip if inReplyTo is empty" do
  53. message = %{"type" => "Create", "object" => %{"summary" => "summary"}}
  54. assert {:ok, res} = EnsureRePrepended.filter(message)
  55. assert res == message
  56. end
  57. test "it skip if parent and child summary isn't equal" do
  58. message = %{
  59. "type" => "Create",
  60. "object" => %{
  61. "summary" => "object-summary",
  62. "inReplyTo" => %Activity{object: %Object{data: %{"summary" => "summary"}}}
  63. }
  64. }
  65. assert {:ok, res} = EnsureRePrepended.filter(message)
  66. assert res == message
  67. end
  68. test "it skips if the object is only a reference" do
  69. message = %{
  70. "type" => "Create",
  71. "object" => "somereference"
  72. }
  73. assert {:ok, res} = EnsureRePrepended.filter(message)
  74. assert res == message
  75. end
  76. end
  77. end