logo

pleroma

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

object_view_test.exs (2655B)


  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.ObjectViewTest do
  5. use Pleroma.DataCase
  6. import Pleroma.Factory
  7. alias Pleroma.Object
  8. alias Pleroma.Web.ActivityPub.ObjectView
  9. alias Pleroma.Web.CommonAPI
  10. test "renders a note object" do
  11. note = insert(:note)
  12. result = ObjectView.render("object.json", %{object: note})
  13. assert result["id"] == note.data["id"]
  14. assert result["to"] == note.data["to"]
  15. assert result["content"] == note.data["content"]
  16. assert result["type"] == "Note"
  17. assert result["@context"]
  18. end
  19. test "renders a note activity" do
  20. note = insert(:note_activity)
  21. object = Object.normalize(note)
  22. result = ObjectView.render("object.json", %{object: note})
  23. assert result["id"] == note.data["id"]
  24. assert result["to"] == note.data["to"]
  25. assert result["object"]["type"] == "Note"
  26. assert result["object"]["content"] == object.data["content"]
  27. assert result["type"] == "Create"
  28. assert result["@context"]
  29. end
  30. describe "note activity's `replies` collection rendering" do
  31. setup do: clear_config([:activitypub, :note_replies_output_limit], 5)
  32. test "renders `replies` collection for a note activity" do
  33. user = insert(:user)
  34. activity = insert(:note_activity, user: user)
  35. {:ok, self_reply1} =
  36. CommonAPI.post(user, %{status: "self-reply 1", in_reply_to_status_id: activity.id})
  37. replies_uris = [self_reply1.object.data["id"]]
  38. result = ObjectView.render("object.json", %{object: refresh_record(activity)})
  39. assert %{"type" => "Collection", "items" => ^replies_uris} =
  40. get_in(result, ["object", "replies"])
  41. end
  42. end
  43. test "renders a like activity" do
  44. note = insert(:note_activity)
  45. object = Object.normalize(note)
  46. user = insert(:user)
  47. {:ok, like_activity} = CommonAPI.favorite(user, note.id)
  48. result = ObjectView.render("object.json", %{object: like_activity})
  49. assert result["id"] == like_activity.data["id"]
  50. assert result["object"] == object.data["id"]
  51. assert result["type"] == "Like"
  52. end
  53. test "renders an announce activity" do
  54. note = insert(:note_activity)
  55. object = Object.normalize(note)
  56. user = insert(:user)
  57. {:ok, announce_activity} = CommonAPI.repeat(note.id, user)
  58. result = ObjectView.render("object.json", %{object: announce_activity})
  59. assert result["id"] == announce_activity.data["id"]
  60. assert result["object"] == object.data["id"]
  61. assert result["type"] == "Announce"
  62. end
  63. end