Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.2KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.ActivityTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.Activity
  7. alias Pleroma.Bookmark
  8. import Pleroma.Factory
  9. test "returns an activity by it's AP id" do
  10. activity = insert(:note_activity)
  11. found_activity = Activity.get_by_ap_id(activity.data["id"])
  12. assert activity == found_activity
  13. end
  14. test "returns activities by it's objects AP ids" do
  15. activity = insert(:note_activity)
  16. [found_activity] = Activity.get_all_create_by_object_ap_id(activity.data["object"]["id"])
  17. assert activity == found_activity
  18. end
  19. test "returns the activity that created an object" do
  20. activity = insert(:note_activity)
  21. found_activity = Activity.get_create_by_object_ap_id(activity.data["object"]["id"])
  22. assert activity == found_activity
  23. end
  24. test "preloading a bookmark" do
  25. user = insert(:user)
  26. user2 = insert(:user)
  27. user3 = insert(:user)
  28. activity = insert(:note_activity)
  29. {:ok, _bookmark} = Bookmark.create(user.id, activity.id)
  30. {:ok, _bookmark2} = Bookmark.create(user2.id, activity.id)
  31. {:ok, bookmark3} = Bookmark.create(user3.id, activity.id)
  32. queried_activity =
  33. Ecto.Query.from(Pleroma.Activity)
  34. |> Activity.with_preloaded_bookmark(user3)
  35. |> Repo.one()
  36. assert queried_activity.bookmark == bookmark3
  37. end
  38. describe "getting a bookmark" do
  39. test "when association is loaded" do
  40. user = insert(:user)
  41. activity = insert(:note_activity)
  42. {:ok, bookmark} = Bookmark.create(user.id, activity.id)
  43. queried_activity =
  44. Ecto.Query.from(Pleroma.Activity)
  45. |> Activity.with_preloaded_bookmark(user)
  46. |> Repo.one()
  47. assert Activity.get_bookmark(queried_activity, user) == bookmark
  48. end
  49. test "when association is not loaded" do
  50. user = insert(:user)
  51. activity = insert(:note_activity)
  52. {:ok, bookmark} = Bookmark.create(user.id, activity.id)
  53. queried_activity =
  54. Ecto.Query.from(Pleroma.Activity)
  55. |> Repo.one()
  56. assert Activity.get_bookmark(queried_activity, user) == bookmark
  57. end
  58. end
  59. end